diff --git a/TODO.md b/TODO.md index ccda621fb..78d666222 100644 --- a/TODO.md +++ b/TODO.md @@ -1,16 +1,20 @@ # High priority Items to complete before the first alpha release. -* make debug info screen show real data (including battery level & charging) +* post sample video to signal forum * retest BLE software update for both board types +* default to enter deep sleep if no LORA received for two hours (indicates user has probably left the meshS) * first alpha release, article writeup for hackaday * send note about Adafruit Clue * send note to the guy who designed the cases * send pr https://github.com/ThingPulse/esp8266-oled-ssd1306 to tell them about this project +* update the prebuilt bins for different regulatory regions # Medium priority Items to complete before the first beta release. +* Use the Periodic class for both position and user periodic broadcasts +* make debug info screen show real data (including battery level & charging) * don't forward redundent pings or ping responses to the phone, it just wastes phone battery * don't treat north as up, instead adjust shown bearings for our guess at the users heading (i.e. subtract one from the other) * answer to pings with our latest location @@ -136,3 +140,4 @@ Items after the first final candidate release. * add receive timestamps to messages, inserted by esp32 when message is received but then shown on the phone * update build to generate both board types * have node info screen show real info (including distance and heading) +* blink the power led less often \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 536c3274e..00e1e90dc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -30,6 +30,6 @@ We currently support two brands of radios. The [TTGO T-Beam](https://www.aliexp sure to buy the frequency range which is legal for your country. For the USA, you should buy the 915MHz version. Getting a version that include a screen is optional, but highly recommended. -We don't yet distribute prebuilt binaries. But soon (by Feb 22) we will have a file that you can fairly easily install on your radio via USB. Once our software is installed, all future software updates happen over bluetooth from your phone. +We don't yet distribute prebuilt binaries. But soon (by Feb 22) we will have a file that you can easily install on your radio via USB. Once our software is installed, all future software updates happen over bluetooth from your phone. For a nice 3D printable case see this [design](https://www.thingiverse.com/thing:3773717) by [bsiege](https://www.thingiverse.com/bsiege). diff --git a/src/Periodic.h b/src/Periodic.h new file mode 100644 index 000000000..fe7b67df3 --- /dev/null +++ b/src/Periodic.h @@ -0,0 +1,32 @@ +#pragma once + +#include + +/** + * Periodically invoke a callback. + * + * FIXME: currently just syntatic sugar for polling in loop (you must call .loop), but eventually + * generalize with the freertos scheduler so we can save lots of power by having everything either in + * something like this or triggered off of an irq. + */ +class Periodic +{ + uint32_t lastMsec = 0; + uint32_t period = 1; // call soon after creation + uint32_t (*callback)(); + +public: + // callback returns the period for the next callback invocation (or 0 if we should no longer be called) + Periodic(uint32_t (*_callback)()) : callback(_callback) {} + + // for the time being this must be called from loop + void loop() + { + uint32_t now = millis(); + if (period && (now - lastMsec) >= period) + { + lastMsec = now; + period = (*callback)(); + } + } +}; diff --git a/src/configuration.h b/src/configuration.h index 783b9044f..36171b9ce 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -41,8 +41,8 @@ along with this program. If not, see . // Select which board is being used. If the outside build environment has sent a choice, just use that #if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32) -//#define T_BEAM_V10 // AKA Rev1 (second board released) -#define HELTEC_LORA32 +#define T_BEAM_V10 // AKA Rev1 (second board released) +//#define HELTEC_LORA32 #endif // If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled) diff --git a/src/main.ino b/src/main.ino index 9e572e890..945e35593 100644 --- a/src/main.ino +++ b/src/main.ino @@ -32,6 +32,7 @@ #include "GPS.h" #include "screen.h" #include "NodeDB.h" +#include "Periodic.h" #ifdef T_BEAM_V10 #include "axp20x.h" @@ -392,6 +393,29 @@ void setup() enableModemSleep(); } + +uint32_t ledBlinker() +{ + static bool ledOn; + ledOn ^= 1; + +#ifdef LED_PIN + // toggle the led so we can get some rough sense of how often loop is pausing + digitalWrite(LED_PIN, ledOn); +#endif + + if (axp192_found) + { + // blink the axp led + axp.setChgLEDMode(ledOn ? AXP20X_LED_LOW_LEVEL : AXP20X_LED_OFF); + } + + // have a very sparse duty cycle of LED being on + return ledOn ? 2 : 1000; +} + +Periodic ledPeriodic(ledBlinker); + void loop() { uint32_t msecstosleep = 1000 * 30; // How long can we sleep before we again need to service the main loop? @@ -399,24 +423,13 @@ void loop() gps.loop(); msecstosleep = min(screen_loop(), msecstosleep); service.loop(); + ledPeriodic.loop(); loopBLE(); - static bool ledon; - ledon ^= 1; - -#ifdef LED_PIN - // toggle the led so we can get some rough sense of how often loop is pausing - digitalWrite(LED_PIN, ledon); -#endif - - // DEBUG_MSG("led %d\n", ledon); #ifdef T_BEAM_V10 if (axp192_found) { - // blink the axp led - axp.setChgLEDMode(ledon ? AXP20X_LED_LOW_LEVEL : AXP20X_LED_OFF); - #ifdef PMU_IRQ if (pmu_irq) {