only send pings a max of once per min

This commit is contained in:
geeksville 2020-02-12 14:24:57 -08:00
parent 53cc8f9da3
commit cbe2b8cafa

View File

@ -40,7 +40,6 @@ bool pmu_irq = false;
#endif #endif
bool isCharging = false; bool isCharging = false;
bool ssd1306_found = false; bool ssd1306_found = false;
bool axp192_found = false; bool axp192_found = false;
@ -154,7 +153,8 @@ void doDeepSleep(uint64_t msecToWake)
* *
* per https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/power_management.html * per https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/power_management.html
*/ */
void enableModemSleep() { void enableModemSleep()
{
static esp_pm_config_esp32_t config; // filled with zeros because bss static esp_pm_config_esp32_t config; // filled with zeros because bss
config.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ; config.max_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ;
@ -434,6 +434,7 @@ void loop()
// if user presses button for more than 3 secs, discard our network prefs and reboot (FIXME, use a debounce lib instead of this boilerplate) // if user presses button for more than 3 secs, discard our network prefs and reboot (FIXME, use a debounce lib instead of this boilerplate)
static bool wasPressed = false; static bool wasPressed = false;
static uint32_t minPressMs; // what tick should we call this press long enough static uint32_t minPressMs; // what tick should we call this press long enough
static uint32_t lastPingMs;
if (!digitalRead(BUTTON_PIN)) if (!digitalRead(BUTTON_PIN))
{ {
if (!wasPressed) if (!wasPressed)
@ -441,8 +442,16 @@ void loop()
DEBUG_MSG("pressing\n"); DEBUG_MSG("pressing\n");
// esp_pm_dump_locks(stdout); // FIXME, do this someplace better // esp_pm_dump_locks(stdout); // FIXME, do this someplace better
wasPressed = true; wasPressed = true;
minPressMs = millis() + 3000;
uint32_t now = millis();
minPressMs = now + 3000;
if (now - lastPingMs > 60 * 1000)
{ // if more than a minute since our last press, ask other nodes to update their state
service.sendNetworkPing(); service.sendNetworkPing();
lastPingMs = now;
}
screen_press(); screen_press();
} }
} }