Browse Source

Merge 17f34c56bc into 5f3b7f25d0

pull/1972/merge
Wessel 23 hours ago
committed by GitHub
parent
commit
01f896e2f1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 21
      examples/companion_radio/ui-new/UITask.cpp
  2. 4
      examples/companion_radio/ui-new/UITask.h
  3. 10
      examples/companion_radio/ui-orig/UITask.cpp
  4. 9
      examples/simple_repeater/UITask.cpp
  5. 9
      examples/simple_room_server/UITask.cpp
  6. 9
      examples/simple_sensor/UITask.cpp
  7. 11
      src/Dispatcher.cpp
  8. 11
      src/helpers/ArduinoHelpers.h
  9. 2
      src/helpers/NRF52Board.cpp
  10. 7
      src/helpers/esp32/SerialBLEInterface.cpp
  11. 3
      src/helpers/radiolib/CustomSX1276.h
  12. 3
      src/helpers/sensors/EnvironmentSensorManager.cpp
  13. 5
      src/helpers/sensors/MicroNMEALocationProvider.h
  14. 4
      variants/heltec_mesh_solar/target.cpp
  15. 5
      variants/heltec_tracker/target.cpp
  16. 5
      variants/meshadventurer/target.cpp
  17. 4
      variants/nano_g2_ultra/target.cpp
  18. 5
      variants/t1000-e/target.cpp
  19. 8
      variants/thinknode_m1/target.cpp

21
examples/companion_radio/ui-new/UITask.cpp

@ -77,7 +77,7 @@ public:
} }
void poll() override { void poll() override {
if (millis() >= dismiss_after) { if (millis_passed(dismiss_after)) {
_task->gotoHomeScreen(); _task->gotoHomeScreen();
} }
} }
@ -153,10 +153,11 @@ class HomeScreen : public UIScreen {
int sensors_nb = 0; int sensors_nb = 0;
bool sensors_scroll = false; bool sensors_scroll = false;
int sensors_scroll_offset = 0; int sensors_scroll_offset = 0;
int next_sensors_refresh = 0; unsigned long next_sensors_refresh = 0;
void refresh_sensors() { void refresh_sensors() {
if (millis() > next_sensors_refresh) { if (millis_passed(next_sensors_refresh)) {
sensors_lpp.reset(); sensors_lpp.reset();
sensors_nb = 0; sensors_nb = 0;
sensors_lpp.addVoltage(TELEM_CHANNEL_SELF, (float)board.getBattMilliVolts() / 1000.0f); sensors_lpp.addVoltage(TELEM_CHANNEL_SELF, (float)board.getBattMilliVolts() / 1000.0f);
@ -652,8 +653,8 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, i
void UITask::userLedHandler() { void UITask::userLedHandler() {
#ifdef PIN_STATUS_LED #ifdef PIN_STATUS_LED
int cur_time = millis(); unsigned long cur_time = millis();
if (cur_time > next_led_change) { if (millis_passed(next_led_change)) {
if (led_state == 0) { if (led_state == 0) {
led_state = 1; led_state = 1;
if (_msgcount > 0) { if (_msgcount > 0) {
@ -764,7 +765,7 @@ void UITask::loop() {
} }
#endif #endif
#if defined(BACKLIGHT_BTN) #if defined(BACKLIGHT_BTN)
if (millis() > next_backlight_btn_check) { if (millis_passed(next_backlight_btn_check)) {
bool touch_state = digitalRead(PIN_BUTTON2); bool touch_state = digitalRead(PIN_BUTTON2);
#if defined(DISP_BACKLIGHT) #if defined(DISP_BACKLIGHT)
digitalWrite(DISP_BACKLIGHT, !touch_state); digitalWrite(DISP_BACKLIGHT, !touch_state);
@ -790,10 +791,10 @@ void UITask::loop() {
if (curr) curr->poll(); if (curr) curr->poll();
if (_display != NULL && _display->isOn()) { if (_display != NULL && _display->isOn()) {
if (millis() >= _next_refresh && curr) { if (millis_passed(_next_refresh) && curr) {
_display->startFrame(); _display->startFrame();
int delay_millis = curr->render(*_display); int delay_millis = curr->render(*_display);
if (millis() < _alert_expiry) { // render alert popup if (!millis_passed(_alert_expiry)) { // render alert popup
_display->setTextSize(1); _display->setTextSize(1);
int y = _display->height() / 3; int y = _display->height() / 3;
int p = _display->height() / 32; int p = _display->height() / 32;
@ -818,7 +819,7 @@ void UITask::loop() {
_auto_off = millis() + AUTO_OFF_MILLIS; _auto_off = millis() + AUTO_OFF_MILLIS;
} }
#endif #endif
if (millis() > _auto_off) { if (millis_passed(_auto_off)) {
_display->turnOff(); _display->turnOff();
} }
#endif #endif
@ -829,7 +830,7 @@ void UITask::loop() {
#endif #endif
#ifdef AUTO_SHUTDOWN_MILLIVOLTS #ifdef AUTO_SHUTDOWN_MILLIVOLTS
if (millis() > next_batt_chck) { if (millis_passed(next_batt_chck)) {
uint16_t milliVolts = getBattMilliVolts(); uint16_t milliVolts = getBattMilliVolts();
if (milliVolts > 0 && milliVolts < AUTO_SHUTDOWN_MILLIVOLTS) { if (milliVolts > 0 && milliVolts < AUTO_SHUTDOWN_MILLIVOLTS) {
if(!board.isExternalPowered()) { if(!board.isExternalPowered()) {

4
examples/companion_radio/ui-new/UITask.h

@ -37,10 +37,10 @@ class UITask : public AbstractUITask {
unsigned long _alert_expiry; unsigned long _alert_expiry;
int _msgcount; int _msgcount;
unsigned long ui_started_at, next_batt_chck; unsigned long ui_started_at, next_batt_chck;
int next_backlight_btn_check = 0; unsigned long next_backlight_btn_check = 0;
#ifdef PIN_STATUS_LED #ifdef PIN_STATUS_LED
int led_state = 0; int led_state = 0;
int next_led_change = 0; unsigned long next_led_change = 0;
int last_led_increment = 0; int last_led_increment = 0;
#endif #endif

10
examples/companion_radio/ui-orig/UITask.cpp

@ -264,11 +264,11 @@ void UITask::renderCurrScreen() {
void UITask::userLedHandler() { void UITask::userLedHandler() {
#ifdef PIN_STATUS_LED #ifdef PIN_STATUS_LED
static int state = 0; static int state = 0;
static int next_change = 0; static unsigned long next_change = 0;
static int last_increment = 0; static int last_increment = 0;
int cur_time = millis(); unsigned long cur_time = millis();
if (cur_time > next_change) { if (millis_passed(next_change)) {
if (state == 0) { if (state == 0) {
state = 1; state = 1;
if (_msgcount > 0) { if (_msgcount > 0) {
@ -335,7 +335,7 @@ void UITask::loop() {
_need_refresh = true; _need_refresh = true;
_firstBoot = false; _firstBoot = false;
} }
if (millis() >= _next_refresh && _need_refresh) { if (millis_passed(_next_refresh) && _need_refresh) {
_display->startFrame(); _display->startFrame();
renderCurrScreen(); renderCurrScreen();
_display->endFrame(); _display->endFrame();
@ -351,7 +351,7 @@ void UITask::loop() {
_auto_off = millis() + AUTO_OFF_MILLIS; _auto_off = millis() + AUTO_OFF_MILLIS;
} }
#endif #endif
if (millis() > _auto_off) { if (millis_passed(_auto_off)) {
_display->turnOff(); _display->turnOff();
} }
} }

9
examples/simple_repeater/UITask.cpp

@ -1,6 +1,7 @@
#include "UITask.h" #include "UITask.h"
#include <Arduino.h> #include <Arduino.h>
#include <helpers/CommonCLI.h> #include <helpers/CommonCLI.h>
#include <helpers/ArduinoHelpers.h>
#ifndef USER_BTN_PRESSED #ifndef USER_BTN_PRESSED
#define USER_BTN_PRESSED LOW #define USER_BTN_PRESSED LOW
@ -46,7 +47,7 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
void UITask::renderCurrScreen() { void UITask::renderCurrScreen() {
char tmp[80]; char tmp[80];
if (millis() < BOOT_SCREEN_MILLIS) { // boot screen if (!millis_passed(BOOT_SCREEN_MILLIS)) { // boot screen
// meshcore logo // meshcore logo
_display->setColor(DisplayDriver::BLUE); _display->setColor(DisplayDriver::BLUE);
int logoWidth = 128; int logoWidth = 128;
@ -94,7 +95,7 @@ void UITask::renderCurrScreen() {
void UITask::loop() { void UITask::loop() {
#ifdef PIN_USER_BTN #ifdef PIN_USER_BTN
if (millis() >= _next_read) { if (millis_passed(_next_read)) {
int btnState = digitalRead(PIN_USER_BTN); int btnState = digitalRead(PIN_USER_BTN);
if (btnState != _prevBtnState) { if (btnState != _prevBtnState) {
if (btnState == USER_BTN_PRESSED) { // pressed? if (btnState == USER_BTN_PRESSED) { // pressed?
@ -112,14 +113,14 @@ void UITask::loop() {
#endif #endif
if (_display->isOn()) { if (_display->isOn()) {
if (millis() >= _next_refresh) { if (millis_passed(_next_refresh)) {
_display->startFrame(); _display->startFrame();
renderCurrScreen(); renderCurrScreen();
_display->endFrame(); _display->endFrame();
_next_refresh = millis() + 1000; // refresh every second _next_refresh = millis() + 1000; // refresh every second
} }
if (millis() > _auto_off) { if (millis_passed(_auto_off)) {
_display->turnOff(); _display->turnOff();
} }
} }

9
examples/simple_room_server/UITask.cpp

@ -1,6 +1,7 @@
#include "UITask.h" #include "UITask.h"
#include <Arduino.h> #include <Arduino.h>
#include <helpers/CommonCLI.h> #include <helpers/CommonCLI.h>
#include <helpers/ArduinoHelpers.h>
#ifndef USER_BTN_PRESSED #ifndef USER_BTN_PRESSED
#define USER_BTN_PRESSED LOW #define USER_BTN_PRESSED LOW
@ -46,7 +47,7 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
void UITask::renderCurrScreen() { void UITask::renderCurrScreen() {
char tmp[80]; char tmp[80];
if (millis() < BOOT_SCREEN_MILLIS) { // boot screen if (!millis_passed(BOOT_SCREEN_MILLIS)) { // boot screen
// meshcore logo // meshcore logo
_display->setColor(DisplayDriver::BLUE); _display->setColor(DisplayDriver::BLUE);
int logoWidth = 128; int logoWidth = 128;
@ -94,7 +95,7 @@ void UITask::renderCurrScreen() {
void UITask::loop() { void UITask::loop() {
#ifdef PIN_USER_BTN #ifdef PIN_USER_BTN
if (millis() >= _next_read) { if (millis_passed(_next_read)) {
int btnState = digitalRead(PIN_USER_BTN); int btnState = digitalRead(PIN_USER_BTN);
if (btnState != _prevBtnState) { if (btnState != _prevBtnState) {
if (btnState == USER_BTN_PRESSED) { // pressed? if (btnState == USER_BTN_PRESSED) { // pressed?
@ -112,14 +113,14 @@ void UITask::loop() {
#endif #endif
if (_display->isOn()) { if (_display->isOn()) {
if (millis() >= _next_refresh) { if (millis_passed(_next_refresh)) {
_display->startFrame(); _display->startFrame();
renderCurrScreen(); renderCurrScreen();
_display->endFrame(); _display->endFrame();
_next_refresh = millis() + 1000; // refresh every second _next_refresh = millis() + 1000; // refresh every second
} }
if (millis() > _auto_off) { if (millis_passed(_auto_off)) {
_display->turnOff(); _display->turnOff();
} }
} }

9
examples/simple_sensor/UITask.cpp

@ -1,6 +1,7 @@
#include "UITask.h" #include "UITask.h"
#include <Arduino.h> #include <Arduino.h>
#include <helpers/CommonCLI.h> #include <helpers/CommonCLI.h>
#include <helpers/ArduinoHelpers.h>
#ifndef USER_BTN_PRESSED #ifndef USER_BTN_PRESSED
#define USER_BTN_PRESSED LOW #define USER_BTN_PRESSED LOW
@ -46,7 +47,7 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
void UITask::renderCurrScreen() { void UITask::renderCurrScreen() {
char tmp[80]; char tmp[80];
if (millis() < BOOT_SCREEN_MILLIS) { // boot screen if (!millis_passed(BOOT_SCREEN_MILLIS)) { // boot screen
// meshcore logo // meshcore logo
_display->setColor(DisplayDriver::BLUE); _display->setColor(DisplayDriver::BLUE);
int logoWidth = 128; int logoWidth = 128;
@ -94,7 +95,7 @@ void UITask::renderCurrScreen() {
void UITask::loop() { void UITask::loop() {
#ifdef PIN_USER_BTN #ifdef PIN_USER_BTN
if (millis() >= _next_read) { if (millis_passed(_next_read)) {
int btnState = digitalRead(PIN_USER_BTN); int btnState = digitalRead(PIN_USER_BTN);
if (btnState != _prevBtnState) { if (btnState != _prevBtnState) {
if (btnState == USER_BTN_PRESSED) { // pressed? if (btnState == USER_BTN_PRESSED) { // pressed?
@ -112,14 +113,14 @@ void UITask::loop() {
#endif #endif
if (_display->isOn()) { if (_display->isOn()) {
if (millis() >= _next_refresh) { if (millis_passed(_next_refresh)) {
_display->startFrame(); _display->startFrame();
renderCurrScreen(); renderCurrScreen();
_display->endFrame(); _display->endFrame();
_next_refresh = millis() + 1000; // refresh every second _next_refresh = millis() + 1000; // refresh every second
} }
if (millis() > _auto_off) { if (millis_passed(_auto_off)) {
_display->turnOff(); _display->turnOff();
} }
} }

11
src/Dispatcher.cpp

@ -20,7 +20,16 @@ void Dispatcher::begin() {
n_sent_flood = n_sent_direct = 0; n_sent_flood = n_sent_direct = 0;
n_recv_flood = n_recv_direct = 0; n_recv_flood = n_recv_direct = 0;
_err_flags = 0; _err_flags = 0;
radio_nonrx_start = _ms->getMillis();
unsigned long now = _ms->getMillis();
radio_nonrx_start = now;
// Initialize timers to "just passed" so millisHasNowPassed() returns true
// immediately. Using 0 breaks when millis is in the upper half of uint32
// range (near the 49-day wrap), because the signed comparison trick
// interprets 0 as a future timestamp.
next_tx_time = now;
next_floor_calib_time = now;
next_agc_reset_time = now;
duty_cycle_window_ms = getDutyCycleWindowMs(); duty_cycle_window_ms = getDutyCycleWindowMs();
float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor()); float duty_cycle = 1.0f / (1.0f + getAirtimeBudgetFactor());

11
src/helpers/ArduinoHelpers.h

@ -24,6 +24,17 @@ public:
unsigned long getMillis() override { return millis(); } unsigned long getMillis() override { return millis(); }
}; };
/**
* \brief Wrap-safe millis deadline check, handling the 49-day millis() overflow.
* \param target The deadline timestamp obtained from millis() + delay.
* \returns true when the deadline has passed.
* \note Use this instead of \c millis()>=target which fails near the 32-bit wrap.
* Works via signed subtraction (2's complement).
*/
inline bool millis_passed(unsigned long target) {
return (long)(millis() - target) > 0;
}
class StdRNG : public mesh::RNG { class StdRNG : public mesh::RNG {
public: public:
void begin(long seed) { randomSeed(seed); } void begin(long seed) { randomSeed(seed); }

2
src/helpers/NRF52Board.cpp

@ -281,7 +281,7 @@ void NRF52Board::sleep(uint32_t secs) {
float NRF52Board::getMCUTemperature() { float NRF52Board::getMCUTemperature() {
NRF_TEMP->TASKS_START = 1; // Start temperature measurement NRF_TEMP->TASKS_START = 1; // Start temperature measurement
long startTime = millis(); unsigned long startTime = millis();
while (NRF_TEMP->EVENTS_DATARDY == 0) { // Wait for completion. Should complete in 50us while (NRF_TEMP->EVENTS_DATARDY == 0) { // Wait for completion. Should complete in 50us
if(millis() - startTime > 5) { // To wait 5ms just in case if(millis() - startTime > 5) { // To wait 5ms just in case
NRF_TEMP->TASKS_STOP = 1; NRF_TEMP->TASKS_STOP = 1;

7
src/helpers/esp32/SerialBLEInterface.cpp

@ -1,5 +1,6 @@
#include "SerialBLEInterface.h" #include "SerialBLEInterface.h"
#include "esp_mac.h" #include "esp_mac.h"
#include <helpers/ArduinoHelpers.h>
// See the following for generating UUIDs: // See the following for generating UUIDs:
// https://www.uuidgenerator.net/ // https://www.uuidgenerator.net/
@ -183,12 +184,12 @@ size_t SerialBLEInterface::writeFrame(const uint8_t src[], size_t len) {
#define BLE_WRITE_MIN_INTERVAL 60 #define BLE_WRITE_MIN_INTERVAL 60
bool SerialBLEInterface::isWriteBusy() const { bool SerialBLEInterface::isWriteBusy() const {
return millis() < _last_write + BLE_WRITE_MIN_INTERVAL; // still too soon to start another write? return !millis_passed(_last_write + BLE_WRITE_MIN_INTERVAL); // still too soon to start another write?
} }
size_t SerialBLEInterface::checkRecvFrame(uint8_t dest[]) { size_t SerialBLEInterface::checkRecvFrame(uint8_t dest[]) {
if (send_queue_len > 0 // first, check send queue if (send_queue_len > 0 // first, check send queue
&& millis() >= _last_write + BLE_WRITE_MIN_INTERVAL // space the writes apart && millis_passed(_last_write + BLE_WRITE_MIN_INTERVAL) // space the writes apart
) { ) {
_last_write = millis(); _last_write = millis();
pTxCharacteristic->setValue(send_queue[0].buf, send_queue[0].len); pTxCharacteristic->setValue(send_queue[0].buf, send_queue[0].len);
@ -238,7 +239,7 @@ size_t SerialBLEInterface::checkRecvFrame(uint8_t dest[]) {
oldDeviceConnected = deviceConnected; oldDeviceConnected = deviceConnected;
} }
if (adv_restart_time && millis() >= adv_restart_time) { if (adv_restart_time && millis_passed(adv_restart_time)) {
if (pServer->getConnectedCount() == 0) { if (pServer->getConnectedCount() == 0) {
BLE_DEBUG_PRINTLN("SerialBLEInterface -> re-starting advertising"); BLE_DEBUG_PRINTLN("SerialBLEInterface -> re-starting advertising");
pServer->getAdvertising()->start(); // re-Start advertising pServer->getAdvertising()->start(); // re-Start advertising

3
src/helpers/radiolib/CustomSX1276.h

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <RadioLib.h> #include <RadioLib.h>
#include <helpers/ArduinoHelpers.h>
#define RH_RF95_MODEM_STATUS_CLEAR 0x10 #define RH_RF95_MODEM_STATUS_CLEAR 0x10
#define RH_RF95_MODEM_STATUS_HEADER_INFO_VALID 0x08 #define RH_RF95_MODEM_STATUS_HEADER_INFO_VALID 0x08
@ -79,7 +80,7 @@ class CustomSX1276 : public SX1276 {
// wait for channel activity detected or timeout // wait for channel activity detected or timeout
unsigned long timeout = millis() + 16; unsigned long timeout = millis() + 16;
while(!this->mod->hal->digitalRead(this->mod->getIrq()) && millis() < timeout) { while(!this->mod->hal->digitalRead(this->mod->getIrq()) && !millis_passed(timeout)) {
this->mod->hal->yield(); this->mod->hal->yield();
if(this->mod->hal->digitalRead(this->mod->getGpio())) { if(this->mod->hal->digitalRead(this->mod->getGpio())) {
return(RADIOLIB_PREAMBLE_DETECTED); return(RADIOLIB_PREAMBLE_DETECTED);

3
src/helpers/sensors/EnvironmentSensorManager.cpp

@ -1,4 +1,5 @@
#include "EnvironmentSensorManager.h" #include "EnvironmentSensorManager.h"
#include <helpers/ArduinoHelpers.h>
#include <Wire.h> #include <Wire.h>
@ -893,7 +894,7 @@ void EnvironmentSensorManager::loop() {
if (gps_active) { if (gps_active) {
_location->loop(); _location->loop();
} }
if (millis() > next_gps_update) { if (millis_passed(next_gps_update)) {
if(gps_active){ if(gps_active){
#ifdef RAK_WISBLOCK_GPS #ifdef RAK_WISBLOCK_GPS

5
src/helpers/sensors/MicroNMEALocationProvider.h

@ -4,6 +4,7 @@
#include <MicroNMEA.h> #include <MicroNMEA.h>
#include <RTClib.h> #include <RTClib.h>
#include <helpers/RefCountedDigitalPin.h> #include <helpers/RefCountedDigitalPin.h>
#include <helpers/ArduinoHelpers.h>
#ifndef GPS_EN #ifndef GPS_EN
#ifdef PIN_GPS_EN #ifdef PIN_GPS_EN
@ -42,7 +43,7 @@ class MicroNMEALocationProvider : public LocationProvider {
int8_t _claims = 0; int8_t _claims = 0;
int _pin_reset; int _pin_reset;
int _pin_en; int _pin_en;
long next_check = 0; unsigned long next_check = 0;
long time_valid = 0; long time_valid = 0;
unsigned long _last_time_sync = 0; unsigned long _last_time_sync = 0;
static const unsigned long TIME_SYNC_INTERVAL = 1800000; // Re-sync every 30 minutes static const unsigned long TIME_SYNC_INTERVAL = 1800000; // Re-sync every 30 minutes
@ -143,7 +144,7 @@ public :
if (!isValid()) time_valid = 0; if (!isValid()) time_valid = 0;
if (millis() > next_check) { if (millis_passed(next_check)) {
next_check = millis() + 1000; next_check = millis() + 1000;
// Re-enable time sync periodically when GPS has valid fix // Re-enable time sync periodically when GPS has valid fix
if (!_time_sync_needed && _clock != NULL && (millis() - _last_time_sync) > TIME_SYNC_INTERVAL) { if (!_time_sync_needed && _clock != NULL && (millis() - _last_time_sync) > TIME_SYNC_INTERVAL) {

4
variants/heltec_mesh_solar/target.cpp

@ -65,11 +65,11 @@ bool SolarSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP&
} }
void SolarSensorManager::loop() { void SolarSensorManager::loop() {
static long next_gps_update = 0; static unsigned long next_gps_update = 0;
_location->loop(); _location->loop();
if (millis() > next_gps_update) { if (millis_passed(next_gps_update)) {
if (_location->isValid()) { if (_location->isValid()) {
node_lat = ((double)_location->getLatitude())/1000000.; node_lat = ((double)_location->getLatitude())/1000000.;
node_lon = ((double)_location->getLongitude())/1000000.; node_lon = ((double)_location->getLongitude())/1000000.;

5
variants/heltec_tracker/target.cpp

@ -1,6 +1,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "target.h" #include "target.h"
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/MicroNMEALocationProvider.h> #include <helpers/sensors/MicroNMEALocationProvider.h>
HeltecV3Board board; HeltecV3Board board;
@ -71,11 +72,11 @@ bool HWTSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& t
} }
void HWTSensorManager::loop() { void HWTSensorManager::loop() {
static long next_gps_update = 0; static unsigned long next_gps_update = 0;
_location->loop(); _location->loop();
if (millis() > next_gps_update) { if (millis_passed(next_gps_update)) {
if (gps_active && _location->isValid()) { if (gps_active && _location->isValid()) {
node_lat = ((double)_location->getLatitude())/1000000.; node_lat = ((double)_location->getLatitude())/1000000.;
node_lon = ((double)_location->getLongitude())/1000000.; node_lon = ((double)_location->getLongitude())/1000000.;

5
variants/meshadventurer/target.cpp

@ -1,6 +1,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "target.h" #include "target.h"
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/MicroNMEALocationProvider.h> #include <helpers/sensors/MicroNMEALocationProvider.h>
MeshadventurerBoard board; MeshadventurerBoard board;
@ -65,9 +66,9 @@ bool MASensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& te
} }
void MASensorManager::loop() { void MASensorManager::loop() {
static long next_gps_update = 0; static unsigned long next_gps_update = 0;
_location->loop(); _location->loop();
if(millis() > next_gps_update && gps_active) { if(millis_passed(next_gps_update) && gps_active) {
if(_location->isValid()) { if(_location->isValid()) {
node_lat = ((double)_location->getLatitude()) / 1000000.; node_lat = ((double)_location->getLatitude()) / 1000000.;
node_lon = ((double)_location->getLongitude()) / 1000000.; node_lon = ((double)_location->getLongitude()) / 1000000.;

4
variants/nano_g2_ultra/target.cpp

@ -73,7 +73,7 @@ bool NanoG2UltraSensorManager::querySensors(uint8_t requester_permissions, Cayen
} }
void NanoG2UltraSensorManager::loop() { void NanoG2UltraSensorManager::loop() {
static long next_gps_update = 0; static unsigned long next_gps_update = 0;
if (!gps_active) { if (!gps_active) {
return; // GPS is not active, skip further processing return; // GPS is not active, skip further processing
@ -81,7 +81,7 @@ void NanoG2UltraSensorManager::loop() {
_location->loop(); _location->loop();
if (millis() > next_gps_update) { if (millis_passed(next_gps_update)) {
if (_location->isValid()) { if (_location->isValid()) {
node_lat = ((double)_location->getLatitude()) / 1000000.; node_lat = ((double)_location->getLatitude()) / 1000000.;
node_lon = ((double)_location->getLongitude()) / 1000000.; node_lon = ((double)_location->getLongitude()) / 1000000.;

5
variants/t1000-e/target.cpp

@ -1,6 +1,7 @@
#include <Arduino.h> #include <Arduino.h>
#include "t1000e_sensors.h" #include "t1000e_sensors.h"
#include "target.h" #include "target.h"
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/MicroNMEALocationProvider.h> #include <helpers/sensors/MicroNMEALocationProvider.h>
T1000eBoard board; T1000eBoard board;
@ -147,11 +148,11 @@ bool T1000SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP&
} }
void T1000SensorManager::loop() { void T1000SensorManager::loop() {
static long next_gps_update = 0; static unsigned long next_gps_update = 0;
_nmea->loop(); _nmea->loop();
if (millis() > next_gps_update) { if (millis_passed(next_gps_update)) {
if (gps_active && _nmea->isValid()) { if (gps_active && _nmea->isValid()) {
node_lat = ((double)_nmea->getLatitude())/1000000.; node_lat = ((double)_nmea->getLatitude())/1000000.;
node_lon = ((double)_nmea->getLongitude())/1000000.; node_lon = ((double)_nmea->getLongitude())/1000000.;

8
variants/thinknode_m1/target.cpp

@ -69,11 +69,11 @@ bool ThinkNodeM1SensorManager::querySensors(uint8_t requester_permissions, Cayen
} }
void ThinkNodeM1SensorManager::loop() { void ThinkNodeM1SensorManager::loop() {
static long next_gps_update = 0; static unsigned long next_gps_update = 0;
static long last_switch_check = 0; static unsigned long last_switch_check = 0;
// Check GPS switch state every second // Check GPS switch state every second
if (millis() - last_switch_check > 1000) { if (millis_passed(last_switch_check + 1000)) {
bool current_switch_state = digitalRead(PIN_GPS_SWITCH); bool current_switch_state = digitalRead(PIN_GPS_SWITCH);
// Detect switch state change // Detect switch state change
@ -98,7 +98,7 @@ void ThinkNodeM1SensorManager::loop() {
_location->loop(); _location->loop();
if (millis() > next_gps_update) { if (millis_passed(next_gps_update)) {
if (_location->isValid()) { if (_location->isValid()) {
node_lat = ((double)_location->getLatitude())/1000000.; node_lat = ((double)_location->getLatitude())/1000000.;
node_lon = ((double)_location->getLongitude())/1000000.; node_lon = ((double)_location->getLongitude())/1000000.;

Loading…
Cancel
Save