start
This commit is contained in:
parent
2396fa4948
commit
c119f1346f
|
|
@ -97,8 +97,8 @@ APRSPacket lastReceivedPacket;
|
|||
logging::Logger logger;
|
||||
//#define DEBUG
|
||||
|
||||
bool SleepModeActive = false;
|
||||
|
||||
bool gpsSleepActive = true;
|
||||
extern bool gpsIsActive;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
|
@ -127,26 +127,22 @@ void setup() {
|
|||
WiFi.mode(WIFI_OFF);
|
||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Main", "WiFi controller stopped");
|
||||
|
||||
if (!SleepModeActive) {
|
||||
if (Config.bluetoothType == 0 || Config.bluetoothType == 2) {
|
||||
BLE_Utils::setup();
|
||||
} else {
|
||||
#ifdef HAS_BT_CLASSIC
|
||||
BLUETOOTH_Utils::setup();
|
||||
#endif
|
||||
}
|
||||
if (Config.bluetoothType == 0 || Config.bluetoothType == 2) {
|
||||
BLE_Utils::setup();
|
||||
} else {
|
||||
#ifdef HAS_BT_CLASSIC
|
||||
BLUETOOTH_Utils::setup();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!Config.simplifiedTrackerMode) {
|
||||
#ifdef BUTTON_PIN
|
||||
userButton.attachClick(BUTTON_Utils::singlePress);
|
||||
userButton.attachLongPressStart(BUTTON_Utils::longPress);
|
||||
userButton.attachDoubleClick(BUTTON_Utils::doublePress);
|
||||
userButton.attachMultiClick(BUTTON_Utils::multiPress);
|
||||
#endif
|
||||
KEYBOARD_Utils::setup();
|
||||
}
|
||||
} else {
|
||||
SLEEP_Utils::setup();
|
||||
if (!Config.simplifiedTrackerMode) {
|
||||
#ifdef BUTTON_PIN
|
||||
userButton.attachClick(BUTTON_Utils::singlePress);
|
||||
userButton.attachLongPressStart(BUTTON_Utils::longPress);
|
||||
userButton.attachDoubleClick(BUTTON_Utils::doublePress);
|
||||
userButton.attachMultiClick(BUTTON_Utils::multiPress);
|
||||
#endif
|
||||
KEYBOARD_Utils::setup();
|
||||
}
|
||||
|
||||
POWER_Utils::lowerCpuFrequency();
|
||||
|
|
@ -165,59 +161,42 @@ void loop() {
|
|||
miceActive = Config.validateMicE(currentBeacon->micE);
|
||||
}
|
||||
POWER_Utils::batteryManager();
|
||||
|
||||
if (SleepModeActive) {
|
||||
if (wakeUpFlag) {
|
||||
MSG_Utils::checkReceivedMessage(LoRa_Utils::receiveFromSleep());
|
||||
wakeUpFlag = false;
|
||||
}
|
||||
//SLEEP_Utils::handle_wakeup();
|
||||
//SLEEP_Utils::processBufferAfterSleep();
|
||||
|
||||
|
||||
SLEEP_Utils::startSleep();
|
||||
//if (!wakeUpByButton) SLEEP_Utils::startSleep();
|
||||
//if (wakeUpByButton && (millis() - wakeUpByButtonTime > 10 * 1000)) wakeUpByButton = false;
|
||||
|
||||
} else {
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// HERE STARTS NORMAL TRACKER CODE LOOP //
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
STATION_Utils::checkSmartBeaconValue();
|
||||
STATION_Utils::checkSmartBeaconValue();
|
||||
|
||||
if (!Config.simplifiedTrackerMode) {
|
||||
#ifdef BUTTON_PIN
|
||||
userButton.tick();
|
||||
#endif
|
||||
}
|
||||
|
||||
Utils::checkDisplayEcoMode();
|
||||
|
||||
KEYBOARD_Utils::read();
|
||||
#ifdef TTGO_T_DECK_GPS
|
||||
KEYBOARD_Utils::mouseRead();
|
||||
if (!Config.simplifiedTrackerMode) {
|
||||
#ifdef BUTTON_PIN
|
||||
userButton.tick();
|
||||
#endif
|
||||
}
|
||||
|
||||
Utils::checkDisplayEcoMode();
|
||||
|
||||
KEYBOARD_Utils::read();
|
||||
#ifdef TTGO_T_DECK_GPS
|
||||
KEYBOARD_Utils::mouseRead();
|
||||
#endif
|
||||
|
||||
MSG_Utils::checkReceivedMessage(LoRa_Utils::receivePacket());
|
||||
MSG_Utils::processOutputBuffer();
|
||||
MSG_Utils::clean25SegBuffer();
|
||||
MSG_Utils::ledNotification();
|
||||
Utils::checkFlashlight();
|
||||
STATION_Utils::checkListenedTrackersByTimeAndDelete();
|
||||
if (Config.bluetoothType == 0 || Config.bluetoothType == 2) {
|
||||
BLE_Utils::sendToLoRa();
|
||||
} else {
|
||||
#ifdef HAS_BT_CLASSIC
|
||||
BLUETOOTH_Utils::sendToLoRa();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (gpsIsActive) {
|
||||
GPS_Utils::getData();
|
||||
bool gps_time_update = gps.time.isUpdated();
|
||||
bool gps_loc_update = gps.location.isUpdated();
|
||||
GPS_Utils::setDateFromData();
|
||||
|
||||
MSG_Utils::checkReceivedMessage(LoRa_Utils::receivePacket());
|
||||
MSG_Utils::processOutputBuffer();
|
||||
MSG_Utils::clean25SegBuffer();
|
||||
MSG_Utils::ledNotification();
|
||||
Utils::checkFlashlight();
|
||||
STATION_Utils::checkListenedTrackersByTimeAndDelete();
|
||||
if (Config.bluetoothType == 0 || Config.bluetoothType == 2) {
|
||||
BLE_Utils::sendToLoRa();
|
||||
} else {
|
||||
#ifdef HAS_BT_CLASSIC
|
||||
BLUETOOTH_Utils::sendToLoRa();
|
||||
#endif
|
||||
}
|
||||
|
||||
int currentSpeed = (int) gps.speed.kmph();
|
||||
|
||||
if (gps_loc_update) {
|
||||
|
|
@ -225,6 +204,7 @@ void loop() {
|
|||
STATION_Utils::checkTelemetryTx();
|
||||
}
|
||||
lastTx = millis() - lastTxTime;
|
||||
|
||||
if (!sendUpdate && gps_loc_update && smartBeaconValue) {
|
||||
GPS_Utils::calculateDistanceTraveled();
|
||||
if (!sendUpdate) {
|
||||
|
|
@ -235,11 +215,22 @@ void loop() {
|
|||
STATION_Utils::checkSmartBeaconState();
|
||||
if (sendUpdate && gps_loc_update) STATION_Utils::sendBeacon(0);
|
||||
if (gps_time_update) STATION_Utils::checkSmartBeaconInterval(currentSpeed);
|
||||
|
||||
|
||||
if (millis() - refreshDisplayTime >= 1000 || gps_time_update) {
|
||||
GPS_Utils::checkStartUpFrames();
|
||||
MENU_Utils::showOnScreen();
|
||||
refreshDisplayTime = millis();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (millis() > lastTxTime + txInterval) {
|
||||
SLEEP_Utils::gpsWakeUp();
|
||||
Serial.println(txInterval);
|
||||
}
|
||||
if (millis() - refreshDisplayTime >= 1000) {
|
||||
MENU_Utils::showOnScreen();
|
||||
refreshDisplayTime = millis();
|
||||
}
|
||||
}
|
||||
// si se activa GPS y no se envia en X tiempo , se duerme...
|
||||
// crear contador de tiempo
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "station_utils.h"
|
||||
#include "boards_pinout.h"
|
||||
#include "power_utils.h"
|
||||
#include "sleep_utils.h"
|
||||
#include "gps_utils.h"
|
||||
#include "display.h"
|
||||
#include "logger.h"
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ extern String winlinkAlias;
|
|||
extern String winlinkAliasComplete;
|
||||
extern bool winlinkCommentState;
|
||||
extern int wxModuleType;
|
||||
extern bool gpsIsActive;
|
||||
|
||||
String freqChangeWarning;
|
||||
uint8_t lowBatteryPercent = 21;
|
||||
|
|
@ -546,8 +547,12 @@ namespace MENU_Utils {
|
|||
}
|
||||
|
||||
if (gps.satellites.value() <= 9) thirdRowMainMenu += " ";
|
||||
thirdRowMainMenu += String(gps.satellites.value());
|
||||
thirdRowMainMenu += hdopState;
|
||||
if (gpsIsActive) {
|
||||
thirdRowMainMenu += String(gps.satellites.value());
|
||||
thirdRowMainMenu += hdopState;
|
||||
} else {
|
||||
thirdRowMainMenu += "--";
|
||||
}
|
||||
|
||||
String fourthRowAlt = String(gps.altitude.meters(),0);
|
||||
fourthRowAlt.trim();
|
||||
|
|
@ -587,6 +592,9 @@ namespace MENU_Utils {
|
|||
fourthRowMainMenu += String(MSG_Utils::getNumAPRSMessages());
|
||||
fourthRowMainMenu += " ***";
|
||||
}
|
||||
if (!gpsIsActive) {
|
||||
fourthRowMainMenu = "*** GPS SLEEPING ***";
|
||||
}
|
||||
}
|
||||
|
||||
if (showHumanHeading) {
|
||||
|
|
|
|||
|
|
@ -319,9 +319,7 @@ namespace MSG_Utils {
|
|||
} else { // message without ack Request
|
||||
sendMessage(addressee, message);
|
||||
outputMessagesBuffer.erase(outputMessagesBuffer.begin());
|
||||
if (!SleepModeActive) {
|
||||
lastTxTime = millis();
|
||||
}
|
||||
lastTxTime = millis();
|
||||
}
|
||||
}
|
||||
if (outputAckRequestBuffer.empty()) {
|
||||
|
|
|
|||
|
|
@ -1,132 +1,32 @@
|
|||
#include <TinyGPS++.h>
|
||||
#include "boards_pinout.h"
|
||||
#include "configuration.h"
|
||||
#include "station_utils.h"
|
||||
#include "sleep_utils.h"
|
||||
#include "power_utils.h"
|
||||
#include "lora_utils.h"
|
||||
#include "msg_utils.h"
|
||||
#include "gps_utils.h"
|
||||
#include "display.h"
|
||||
|
||||
|
||||
extern Configuration Config;
|
||||
extern TinyGPSPlus gps;
|
||||
extern uint32_t lastTxTime;
|
||||
extern bool sendUpdate;
|
||||
|
||||
bool wakeUpFlag = false;
|
||||
bool wakeUpByButton = false;
|
||||
uint32_t wakeUpByButtonTime = 0;
|
||||
|
||||
bool gpsIsActive = true;
|
||||
extern bool gpsSleepActive;
|
||||
|
||||
namespace SLEEP_Utils {
|
||||
|
||||
void gpsSleep() {
|
||||
if (gpsSleepActive && gpsIsActive) {
|
||||
POWER_Utils::deactivateGPS();
|
||||
gpsIsActive = false;
|
||||
//
|
||||
Serial.println("GPS SLEEPING");
|
||||
//
|
||||
}
|
||||
|
||||
void processBeaconAfterSleep() {
|
||||
if (lastTxTime == 0 || ((millis() - lastTxTime) > 5 * 60 * 1000)) { // 5 min non-smartBeacon
|
||||
}
|
||||
|
||||
void gpsWakeUp() {
|
||||
if (gpsSleepActive && !gpsIsActive) {
|
||||
POWER_Utils::activateGPS();
|
||||
display_toggle(false);
|
||||
sendUpdate = true;
|
||||
while (sendUpdate) {
|
||||
MSG_Utils::checkReceivedMessage(LoRa_Utils::receivePacket());
|
||||
GPS_Utils::getData();
|
||||
bool gps_loc_update = gps.location.isUpdated();
|
||||
if (gps_loc_update){
|
||||
display_toggle(true); // opcional
|
||||
STATION_Utils::sendBeacon(0);
|
||||
lastTxTime = millis();
|
||||
}
|
||||
}
|
||||
gpsIsActive = true;
|
||||
//
|
||||
Serial.println("GPS WAKEUP");
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
void processBufferAfterSleep() {
|
||||
if (!MSG_Utils::checkOutputBufferEmpty()) {
|
||||
//POWER_Utils::activateGPS();
|
||||
//display_toggle(true);
|
||||
MSG_Utils::processOutputBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
void handle_wakeup() {
|
||||
esp_sleep_wakeup_cause_t wakeup_cause = esp_sleep_get_wakeup_cause();
|
||||
switch (wakeup_cause) {
|
||||
case ESP_SLEEP_WAKEUP_TIMER:
|
||||
processBeaconAfterSleep(); //Serial.println("Woken up by timer (Sending Beacon) \n");
|
||||
break;
|
||||
case ESP_SLEEP_WAKEUP_EXT1:
|
||||
//Serial.println("Woken up by EXT1 (GPIO) (Packet Received)\n");
|
||||
break;
|
||||
case ESP_SLEEP_WAKEUP_EXT0:
|
||||
Serial.println("Wakeup caused by external signal using RTC_IO");
|
||||
wakeUpByButton = true;
|
||||
wakeUpByButtonTime = millis();
|
||||
|
||||
POWER_Utils::activateGPS();
|
||||
display_toggle(true);
|
||||
|
||||
default:
|
||||
processBeaconAfterSleep(); //Serial.println("Woken up by unknown reason\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void wakeUpLoRaPacketReceived() {
|
||||
wakeUpFlag = true;
|
||||
}
|
||||
|
||||
void sleep(int seconds) {
|
||||
esp_sleep_enable_timer_wakeup(300 * 1000000);
|
||||
//esp_sleep_enable_timer_wakeup(seconds * 1000000); // 1 min = 60sec
|
||||
delay(100);
|
||||
POWER_Utils::deactivateGPS();
|
||||
delay(100);
|
||||
#ifdef ADC_CTRL
|
||||
#ifdef HELTEC_WIRELESS_TRACKER
|
||||
digitalWrite(ADC_CTRL, LOW);
|
||||
#endif
|
||||
#endif
|
||||
LoRa_Utils::wakeRadio();
|
||||
//LoRa_Utils::sleepRadio();
|
||||
delay(100);
|
||||
//esp_deep_sleep_start();
|
||||
esp_light_sleep_start();
|
||||
}
|
||||
|
||||
// this could be used for smartBeaconTime delta
|
||||
/*uint32_t getTimeToSleep() { // quizas no?
|
||||
uint32_t currentCycleTime = millis() - lastTxTime;
|
||||
uint32_t timeToSleep = 20 * 1000;//Config.nonSmartBeaconRate * 60;
|
||||
if (timeToSleep - currentCycleTime <= 0) {
|
||||
return timeToSleep / 1000;
|
||||
} else {
|
||||
return (timeToSleep - currentCycleTime) / 1000;
|
||||
}
|
||||
}*/
|
||||
|
||||
void startSleep() {
|
||||
#if defined(HELTEC_WIRELESS_TRACKER)
|
||||
esp_sleep_enable_ext1_wakeup(WAKEUP_RADIO, ESP_EXT1_WAKEUP_ANY_HIGH);
|
||||
//pinMode(BUTTON_PIN, INPUT_PULLUP); //internal pull down???
|
||||
//esp_sleep_enable_ext0_wakeup(WAKEUP_BUTTON, 0);
|
||||
#endif
|
||||
sleep(20);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
//if (SleepModeActive) ?????
|
||||
#ifdef RADIO_WAKEUP_PIN
|
||||
pinMode(RADIO_WAKEUP_PIN, INPUT);
|
||||
#if defined(HELTEC_WIRELESS_TRACKER)
|
||||
attachInterrupt(digitalPinToInterrupt(RADIO_WAKEUP_PIN), wakeUpLoRaPacketReceived, RISING);
|
||||
LoRa_Utils::wakeRadio();
|
||||
#else
|
||||
Serial.println("NO SLEEP MODE AVAILABLE FOR THIS BOARD");
|
||||
#endif
|
||||
#else
|
||||
Serial.println("NO SLEEP MODE AVAILABLE FOR THIS BOARD");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,10 +5,8 @@
|
|||
|
||||
namespace SLEEP_Utils {
|
||||
|
||||
void processBufferAfterSleep();
|
||||
void handle_wakeup();
|
||||
void startSleep();
|
||||
void setup();
|
||||
void gpsSleep();
|
||||
void gpsWakeUp();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "station_utils.h"
|
||||
#include "configuration.h"
|
||||
#include "power_utils.h"
|
||||
#include "sleep_utils.h"
|
||||
#include "lora_utils.h"
|
||||
#include "bme_utils.h"
|
||||
#include "display.h"
|
||||
|
|
@ -36,7 +37,7 @@ extern uint8_t winlinkStatus;
|
|||
extern bool winlinkCommentState;
|
||||
|
||||
extern int wxModuleType;
|
||||
extern bool SleepModeActive;
|
||||
extern bool gpsSleepActive;
|
||||
|
||||
bool sendStandingUpdate = false;
|
||||
uint8_t updateCounter = Config.sendCommentAfterXBeacons;
|
||||
|
|
@ -274,13 +275,14 @@ namespace STATION_Utils {
|
|||
previousHeading = currentHeading;
|
||||
lastTxDistance = 0.0;
|
||||
}
|
||||
if (!SleepModeActive) {
|
||||
lastTxTime = millis();
|
||||
}
|
||||
lastTxTime = millis();
|
||||
sendUpdate = false;
|
||||
#ifdef HAS_TFT
|
||||
cleanTFT();
|
||||
#endif
|
||||
if (gpsSleepActive) {
|
||||
SLEEP_Utils::gpsSleep();
|
||||
}
|
||||
}
|
||||
|
||||
void checkTelemetryTx() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue