mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-05 05:04:46 +00:00
Merge pull request #43 from geeksville/one-wire-gps
fixes to make one-wire gpses work and cope with tbeams with crummy rx buffers
This commit is contained in:
commit
c9e2e6c386
73
src/GPS.cpp
73
src/GPS.cpp
@ -1,25 +1,25 @@
|
|||||||
|
|
||||||
#include "GPS.h"
|
#include "GPS.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include "configuration.h"
|
|
||||||
|
|
||||||
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
|
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
|
||||||
|
|
||||||
RTC_DATA_ATTR bool timeSetFromGPS; // We only reset our time once per _boot_ after that point just run from the internal clock (even across sleeps)
|
RTC_DATA_ATTR bool timeSetFromGPS; // We only reset our time once per _boot_ after that point just run from the internal clock
|
||||||
|
// (even across sleeps)
|
||||||
|
|
||||||
GPS gps;
|
GPS gps;
|
||||||
|
|
||||||
// stuff that really should be in in the instance instead...
|
// stuff that really should be in in the instance instead...
|
||||||
static uint32_t timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time
|
static uint32_t
|
||||||
|
timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time
|
||||||
static uint64_t zeroOffsetSecs; // GPS based time in secs since 1970 - only updated once on initial lock
|
static uint64_t zeroOffsetSecs; // GPS based time in secs since 1970 - only updated once on initial lock
|
||||||
|
|
||||||
static bool hasValidLocation; // default to false, until we complete our first read
|
static bool hasValidLocation; // default to false, until we complete our first read
|
||||||
static bool wantNewLocation = true;
|
static bool wantNewLocation = true;
|
||||||
|
|
||||||
GPS::GPS() : PeriodicTask()
|
GPS::GPS() : PeriodicTask() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPS::setup()
|
void GPS::setup()
|
||||||
{
|
{
|
||||||
@ -35,28 +35,24 @@ void GPS::setup()
|
|||||||
isConnected = ublox.begin(_serial_gps);
|
isConnected = ublox.begin(_serial_gps);
|
||||||
|
|
||||||
// try a second time, the ublox lib serial parsing is buggy?
|
// try a second time, the ublox lib serial parsing is buggy?
|
||||||
// if(!isConnected) isConnected = ublox.begin(_serial_gps);
|
if(!isConnected) isConnected = ublox.begin(_serial_gps);
|
||||||
|
|
||||||
if (isConnected)
|
if (isConnected) {
|
||||||
{
|
|
||||||
DEBUG_MSG("Connected to GPS successfully, TXpin=%d\n", GPS_TX_PIN);
|
DEBUG_MSG("Connected to GPS successfully, TXpin=%d\n", GPS_TX_PIN);
|
||||||
|
|
||||||
bool factoryReset = false;
|
bool factoryReset = false;
|
||||||
bool ok;
|
bool ok;
|
||||||
if (factoryReset)
|
if (factoryReset) {
|
||||||
{
|
// It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have
|
||||||
// It is useful to force back into factory defaults (9600baud, NEMA to test the behavior of boards that don't have GPS_TX connected)
|
// GPS_TX connected)
|
||||||
ublox.factoryReset();
|
ublox.factoryReset();
|
||||||
delay(2000);
|
delay(2000);
|
||||||
isConnected = ublox.begin(_serial_gps);
|
isConnected = ublox.begin(_serial_gps);
|
||||||
DEBUG_MSG("Factory reset success=%d\n", isConnected);
|
DEBUG_MSG("Factory reset success=%d\n", isConnected);
|
||||||
if (isConnected)
|
if (isConnected) {
|
||||||
{
|
|
||||||
ublox.assumeAutoPVT(true, true); // Just parse NEMA for now
|
ublox.assumeAutoPVT(true, true); // Just parse NEMA for now
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ok = ublox.setUART1Output(COM_TYPE_UBX, 500); // Use native API
|
ok = ublox.setUART1Output(COM_TYPE_UBX, 500); // Use native API
|
||||||
assert(ok);
|
assert(ok);
|
||||||
ok = ublox.setNavigationFrequency(1, 500); // Produce 4x/sec to keep the amount of time we stall in getPVT low
|
ok = ublox.setNavigationFrequency(1, 500); // Produce 4x/sec to keep the amount of time we stall in getPVT low
|
||||||
@ -70,15 +66,14 @@ void GPS::setup()
|
|||||||
}
|
}
|
||||||
ok = ublox.saveConfiguration(2000);
|
ok = ublox.saveConfiguration(2000);
|
||||||
assert(ok);
|
assert(ok);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Some boards might have only the TX line from the GPS connected, in that case, we can't configure it at all. Just
|
// Some boards might have only the TX line from the GPS connected, in that case, we can't configure it at all. Just
|
||||||
// assume NEMA at 9600 baud.
|
// assume NEMA at 9600 baud.
|
||||||
DEBUG_MSG("ERROR: No bidirectional GPS found, hoping that it still might work\n");
|
DEBUG_MSG("ERROR: No bidirectional GPS found, hoping that it still might work\n");
|
||||||
|
|
||||||
// tell lib, we are expecting the module to send PVT messages by itself to our Rx pin
|
// tell lib, we are expecting the module to send PVT messages by itself to our Rx pin
|
||||||
// you can set second parameter to "false" if you want to control the parsing and eviction of the data (need to call checkUblox cyclically)
|
// you can set second parameter to "false" if you want to control the parsing and eviction of the data (need to call
|
||||||
|
// checkUblox cyclically)
|
||||||
ublox.assumeAutoPVT(true, true);
|
ublox.assumeAutoPVT(true, true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -88,8 +83,7 @@ void GPS::readFromRTC()
|
|||||||
{
|
{
|
||||||
struct timeval tv; /* btw settimeofday() is helpfull here too*/
|
struct timeval tv; /* btw settimeofday() is helpfull here too*/
|
||||||
|
|
||||||
if (!gettimeofday(&tv, NULL))
|
if (!gettimeofday(&tv, NULL)) {
|
||||||
{
|
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
|
|
||||||
DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS);
|
DEBUG_MSG("Read RTC time as %ld (cur millis %u) valid=%d\n", tv.tv_sec, now, timeSetFromGPS);
|
||||||
@ -101,8 +95,7 @@ void GPS::readFromRTC()
|
|||||||
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
|
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
|
||||||
void GPS::perhapsSetRTC(const struct timeval *tv)
|
void GPS::perhapsSetRTC(const struct timeval *tv)
|
||||||
{
|
{
|
||||||
if (!timeSetFromGPS)
|
if (!timeSetFromGPS) {
|
||||||
{
|
|
||||||
timeSetFromGPS = true;
|
timeSetFromGPS = true;
|
||||||
DEBUG_MSG("Setting RTC %ld secs\n", tv->tv_sec);
|
DEBUG_MSG("Setting RTC %ld secs\n", tv->tv_sec);
|
||||||
settimeofday(tv, NULL);
|
settimeofday(tv, NULL);
|
||||||
@ -144,27 +137,29 @@ void GPS::prepareSleep()
|
|||||||
void GPS::doTask()
|
void GPS::doTask()
|
||||||
{
|
{
|
||||||
#ifdef GPS_RX_PIN
|
#ifdef GPS_RX_PIN
|
||||||
if (isConnected)
|
uint8_t fixtype = 3; // If we are only using the RX pin, assume we have a 3d fix
|
||||||
{
|
|
||||||
|
if (isConnected) {
|
||||||
// Consume all characters that have arrived
|
// Consume all characters that have arrived
|
||||||
|
|
||||||
// getPVT automatically calls checkUblox
|
// getPVT automatically calls checkUblox
|
||||||
ublox.checkUblox(); // See if new data is available. Process bytes as they come in.
|
ublox.checkUblox(); // See if new data is available. Process bytes as they come in.
|
||||||
|
|
||||||
|
// If we don't have a fix (a quick check), don't try waiting for a solution)
|
||||||
|
fixtype = ublox.getFixType();
|
||||||
|
DEBUG_MSG("fix type %d\n", fixtype);
|
||||||
|
}
|
||||||
|
|
||||||
// DEBUG_MSG("sec %d\n", ublox.getSecond());
|
// DEBUG_MSG("sec %d\n", ublox.getSecond());
|
||||||
// DEBUG_MSG("lat %d\n", ublox.getLatitude());
|
// DEBUG_MSG("lat %d\n", ublox.getLatitude());
|
||||||
|
|
||||||
// If we don't have a fix (a quick check), don't try waiting for a solution)
|
|
||||||
uint8_t fixtype = ublox.getFixType();
|
|
||||||
DEBUG_MSG("fix type %d\n", fixtype);
|
|
||||||
|
|
||||||
// any fix that has time
|
// any fix that has time
|
||||||
if ((fixtype >= 2 && fixtype <= 5) && !timeSetFromGPS && ublox.getT())
|
if ((fixtype >= 2 && fixtype <= 5) && !timeSetFromGPS && ublox.getT()) {
|
||||||
{
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
/* Convert to unix time
|
/* Convert to unix time
|
||||||
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January 1, 1970
|
||||||
|
(midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
||||||
*/
|
*/
|
||||||
struct tm t;
|
struct tm t;
|
||||||
t.tm_sec = ublox.getSecond();
|
t.tm_sec = ublox.getSecond();
|
||||||
@ -192,19 +187,17 @@ void GPS::doTask()
|
|||||||
DEBUG_MSG("new gps pos lat=%f, lon=%f, alt=%d\n", latitude, longitude, altitude);
|
DEBUG_MSG("new gps pos lat=%f, lon=%f, alt=%d\n", latitude, longitude, altitude);
|
||||||
|
|
||||||
hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0
|
hasValidLocation = (latitude != 0) || (longitude != 0); // bogus lat lon is reported as 0,0
|
||||||
if (hasValidLocation)
|
if (hasValidLocation) {
|
||||||
{
|
|
||||||
wantNewLocation = false;
|
wantNewLocation = false;
|
||||||
notifyObservers();
|
notifyObservers();
|
||||||
// ublox.powerOff();
|
// ublox.powerOff();
|
||||||
}
|
}
|
||||||
}
|
} else // we didn't get a location update, go back to sleep and hope the characters show up
|
||||||
else // we didn't get a location update, go back to sleep and hope the characters show up
|
|
||||||
wantNewLocation = true;
|
wantNewLocation = true;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 1s until we have something over the serial
|
// Once we have sent a location once we only poll the GPS rarely, otherwise check back every 1s until we have something over
|
||||||
|
// the serial
|
||||||
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 10 * 1000);
|
setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 10 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
#include "PowerFSM.h"
|
#include "PowerFSM.h"
|
||||||
#include "CallbackCharacteristic.h"
|
#include "CallbackCharacteristic.h"
|
||||||
|
|
||||||
|
#include "GPS.h"
|
||||||
|
|
||||||
// This scratch buffer is used for various bluetooth reads/writes - but it is safe because only one bt operation can be in proccess at once
|
// This scratch buffer is used for various bluetooth reads/writes - but it is safe because only one bt operation can be in proccess at once
|
||||||
static uint8_t trBytes[_max(_max(_max(_max(ToRadio_size, RadioConfig_size), User_size), MyNodeInfo_size), FromRadio_size)];
|
static uint8_t trBytes[_max(_max(_max(_max(ToRadio_size, RadioConfig_size), User_size), MyNodeInfo_size), FromRadio_size)];
|
||||||
|
|
||||||
@ -93,6 +95,7 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// wrap our protobuf version with something that forces the service to reload the config
|
// wrap our protobuf version with something that forces the service to reload the config
|
||||||
class RadioCharacteristic : public ProtobufCharacteristic
|
class RadioCharacteristic : public ProtobufCharacteristic
|
||||||
{
|
{
|
||||||
@ -102,6 +105,16 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onRead(BLECharacteristic *c)
|
||||||
|
{
|
||||||
|
DEBUG_MSG("Reading radio config\n");
|
||||||
|
|
||||||
|
// update gps connection state
|
||||||
|
devicestate.has_radio = gps.isConnected;
|
||||||
|
|
||||||
|
BLEKeepAliveCallbacks::onRead(c);
|
||||||
|
}
|
||||||
|
|
||||||
void onWrite(BLECharacteristic *c)
|
void onWrite(BLECharacteristic *c)
|
||||||
{
|
{
|
||||||
ProtobufCharacteristic::onWrite(c);
|
ProtobufCharacteristic::onWrite(c);
|
||||||
|
@ -52,7 +52,7 @@ void NodeDB::init()
|
|||||||
devicestate.has_my_node = true;
|
devicestate.has_my_node = true;
|
||||||
devicestate.has_radio = true;
|
devicestate.has_radio = true;
|
||||||
devicestate.has_owner = true;
|
devicestate.has_owner = true;
|
||||||
devicestate.has_radio = true;
|
devicestate.has_radio = false;
|
||||||
devicestate.radio.has_channel_settings = true;
|
devicestate.radio.has_channel_settings = true;
|
||||||
devicestate.radio.has_preferences = true;
|
devicestate.radio.has_preferences = true;
|
||||||
devicestate.node_db_count = 0;
|
devicestate.node_db_count = 0;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
#include "sleep.h"
|
#include "PowerFSM.h"
|
||||||
|
#include "GPS.h"
|
||||||
#include "MeshService.h"
|
#include "MeshService.h"
|
||||||
#include "NodeDB.h"
|
#include "NodeDB.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "screen.h"
|
|
||||||
#include "PowerFSM.h"
|
|
||||||
#include "GPS.h"
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "sleep.h"
|
||||||
|
|
||||||
static void sdsEnter()
|
static void sdsEnter()
|
||||||
{
|
{
|
||||||
@ -33,7 +33,8 @@ static void lsEnter()
|
|||||||
|
|
||||||
gps.prepareSleep(); // abandon in-process parsing
|
gps.prepareSleep(); // abandon in-process parsing
|
||||||
|
|
||||||
//if (!isUSBPowered) // FIXME - temp hack until we can put gps in sleep mode, if we have AC when we go to sleep then leave GPS on
|
// if (!isUSBPowered) // FIXME - temp hack until we can put gps in sleep mode, if we have AC when we go to sleep then
|
||||||
|
// leave GPS on
|
||||||
// setGPSPower(false); // kill GPS power
|
// setGPSPower(false); // kill GPS power
|
||||||
|
|
||||||
DEBUG_MSG("lsEnter end\n");
|
DEBUG_MSG("lsEnter end\n");
|
||||||
@ -47,8 +48,7 @@ static void lsIdle()
|
|||||||
esp_sleep_source_t wakeCause = ESP_SLEEP_WAKEUP_UNDEFINED;
|
esp_sleep_source_t wakeCause = ESP_SLEEP_WAKEUP_UNDEFINED;
|
||||||
bool reached_ls_secs = false;
|
bool reached_ls_secs = false;
|
||||||
|
|
||||||
while (!reached_ls_secs)
|
while (!reached_ls_secs) {
|
||||||
{
|
|
||||||
// Briefly come out of sleep long enough to blink the led once every few seconds
|
// Briefly come out of sleep long enough to blink the led once every few seconds
|
||||||
uint32_t sleepTime = 5;
|
uint32_t sleepTime = 5;
|
||||||
|
|
||||||
@ -67,19 +67,21 @@ static void lsIdle()
|
|||||||
}
|
}
|
||||||
setLed(false);
|
setLed(false);
|
||||||
|
|
||||||
if (reached_ls_secs)
|
if (reached_ls_secs) {
|
||||||
{
|
|
||||||
// stay in LS mode but let loop check whatever it wants
|
// stay in LS mode but let loop check whatever it wants
|
||||||
DEBUG_MSG("reached ls_secs, servicing loop()\n");
|
DEBUG_MSG("reached ls_secs, servicing loop()\n");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
DEBUG_MSG("wakeCause %d\n", wakeCause);
|
DEBUG_MSG("wakeCause %d\n", wakeCause);
|
||||||
|
|
||||||
// Regardless of why we woke just transition to NB (and that state will handle stuff like IRQs etc)
|
if (!digitalRead(BUTTON_PIN)) // If we woke because of press, instead generate a PRESS event.
|
||||||
|
{
|
||||||
|
powerFSM.trigger(EVENT_PRESS);
|
||||||
|
} else {
|
||||||
|
// Otherwise let the NB state handle the IRQ (and that state will handle stuff like IRQs etc)
|
||||||
powerFSM.trigger(EVENT_WAKE_TIMER);
|
powerFSM.trigger(EVENT_WAKE_TIMER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void lsExit()
|
static void lsExit()
|
||||||
{
|
{
|
||||||
@ -104,12 +106,18 @@ static void onEnter()
|
|||||||
{
|
{
|
||||||
screen.setOn(true);
|
screen.setOn(true);
|
||||||
setBluetoothEnable(true);
|
setBluetoothEnable(true);
|
||||||
|
|
||||||
|
static uint32_t lastPingMs;
|
||||||
|
|
||||||
|
uint32_t now = millis();
|
||||||
|
|
||||||
|
if (now - lastPingMs > 60 * 1000) { // if more than a minute since our last press, ask other nodes to update their state
|
||||||
|
service.sendNetworkPing();
|
||||||
|
lastPingMs = now;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void wakeForPing() {}
|
||||||
static void wakeForPing()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void screenPress()
|
static void screenPress()
|
||||||
{
|
{
|
||||||
@ -128,14 +136,13 @@ void PowerFSM_setup()
|
|||||||
powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL, "Boot");
|
powerFSM.add_transition(&stateDARK, &stateON, EVENT_BOOT, NULL, "Boot");
|
||||||
powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, wakeForPing, "Wake timer");
|
powerFSM.add_transition(&stateLS, &stateDARK, EVENT_WAKE_TIMER, wakeForPing, "Wake timer");
|
||||||
|
|
||||||
// Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it handles things
|
// Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it
|
||||||
// powerFSM.add_transition(&stateLS, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet");
|
// handles things powerFSM.add_transition(&stateLS, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet");
|
||||||
|
|
||||||
powerFSM.add_transition(&stateNB, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet, resetting win wake");
|
powerFSM.add_transition(&stateNB, &stateNB, EVENT_RECEIVED_PACKET, NULL, "Received packet, resetting win wake");
|
||||||
|
|
||||||
// Note we don't really use this transition, because when we wake from light sleep we _always_ transition to NB and then it handles things
|
// Handle press events
|
||||||
// powerFSM.add_transition(&stateLS, &stateON, EVENT_PRESS, NULL, "Press");
|
powerFSM.add_transition(&stateLS, &stateON, EVENT_PRESS, NULL, "Press");
|
||||||
|
|
||||||
powerFSM.add_transition(&stateNB, &stateON, EVENT_PRESS, NULL, "Press");
|
powerFSM.add_transition(&stateNB, &stateON, EVENT_PRESS, NULL, "Press");
|
||||||
powerFSM.add_transition(&stateDARK, &stateON, EVENT_PRESS, NULL, "Press");
|
powerFSM.add_transition(&stateDARK, &stateON, EVENT_PRESS, NULL, "Press");
|
||||||
powerFSM.add_transition(&stateON, &stateON, EVENT_PRESS, screenPress, "Press"); // reenter On to restart our timers
|
powerFSM.add_transition(&stateON, &stateON, EVENT_PRESS, screenPress, "Press"); // reenter On to restart our timers
|
||||||
@ -162,11 +169,14 @@ void PowerFSM_setup()
|
|||||||
|
|
||||||
powerFSM.add_timed_transition(&stateNB, &stateLS, radioConfig.preferences.min_wake_secs * 1000, NULL, "Min wake timeout");
|
powerFSM.add_timed_transition(&stateNB, &stateLS, radioConfig.preferences.min_wake_secs * 1000, NULL, "Min wake timeout");
|
||||||
|
|
||||||
powerFSM.add_timed_transition(&stateDARK, &stateLS, radioConfig.preferences.wait_bluetooth_secs * 1000, NULL, "Bluetooth timeout");
|
powerFSM.add_timed_transition(&stateDARK, &stateLS, radioConfig.preferences.wait_bluetooth_secs * 1000, NULL,
|
||||||
|
"Bluetooth timeout");
|
||||||
|
|
||||||
powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.mesh_sds_timeout_secs * 1000, NULL, "mesh timeout");
|
powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.mesh_sds_timeout_secs * 1000, NULL,
|
||||||
|
"mesh timeout");
|
||||||
// removing for now, because some users don't even have phones
|
// removing for now, because some users don't even have phones
|
||||||
// powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.phone_sds_timeout_sec * 1000, NULL, "phone timeout");
|
// powerFSM.add_timed_transition(&stateLS, &stateSDS, radioConfig.preferences.phone_sds_timeout_sec * 1000, NULL, "phone
|
||||||
|
// timeout");
|
||||||
|
|
||||||
powerFSM.run_machine(); // run one interation of the state machine, so we run our on enter tasks for the initial DARK state
|
powerFSM.run_machine(); // run one interation of the state machine, so we run our on enter tasks for the initial DARK state
|
||||||
}
|
}
|
19
src/main.cpp
19
src/main.cpp
@ -370,8 +370,7 @@ void loop()
|
|||||||
#ifdef BUTTON_PIN
|
#ifdef BUTTON_PIN
|
||||||
// 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 lastPingMs;
|
|
||||||
|
|
||||||
if (!digitalRead(BUTTON_PIN))
|
if (!digitalRead(BUTTON_PIN))
|
||||||
{
|
{
|
||||||
@ -383,15 +382,6 @@ void loop()
|
|||||||
// esp_pm_dump_locks(stdout); // FIXME, do this someplace better
|
// esp_pm_dump_locks(stdout); // FIXME, do this someplace better
|
||||||
wasPressed = true;
|
wasPressed = true;
|
||||||
|
|
||||||
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();
|
|
||||||
lastPingMs = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
powerFSM.trigger(EVENT_PRESS);
|
powerFSM.trigger(EVENT_PRESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -399,13 +389,6 @@ void loop()
|
|||||||
{
|
{
|
||||||
// we just did a release
|
// we just did a release
|
||||||
wasPressed = false;
|
wasPressed = false;
|
||||||
if (millis() > minPressMs)
|
|
||||||
{
|
|
||||||
// held long enough
|
|
||||||
screen_print("Erasing prefs");
|
|
||||||
delay(5000); // Give some time to read the screen
|
|
||||||
// ESP.restart();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user