start
This commit is contained in:
parent
2396fa4948
commit
c119f1346f
|
|
@ -97,8 +97,8 @@ APRSPacket lastReceivedPacket;
|
||||||
logging::Logger logger;
|
logging::Logger logger;
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
|
|
||||||
bool SleepModeActive = false;
|
bool gpsSleepActive = true;
|
||||||
|
extern bool gpsIsActive;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
@ -127,7 +127,6 @@ void setup() {
|
||||||
WiFi.mode(WIFI_OFF);
|
WiFi.mode(WIFI_OFF);
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Main", "WiFi controller stopped");
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Main", "WiFi controller stopped");
|
||||||
|
|
||||||
if (!SleepModeActive) {
|
|
||||||
if (Config.bluetoothType == 0 || Config.bluetoothType == 2) {
|
if (Config.bluetoothType == 0 || Config.bluetoothType == 2) {
|
||||||
BLE_Utils::setup();
|
BLE_Utils::setup();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -145,9 +144,6 @@ void setup() {
|
||||||
#endif
|
#endif
|
||||||
KEYBOARD_Utils::setup();
|
KEYBOARD_Utils::setup();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
SLEEP_Utils::setup();
|
|
||||||
}
|
|
||||||
|
|
||||||
POWER_Utils::lowerCpuFrequency();
|
POWER_Utils::lowerCpuFrequency();
|
||||||
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Main", "Smart Beacon is: %s", Utils::getSmartBeaconState());
|
logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, "Main", "Smart Beacon is: %s", Utils::getSmartBeaconState());
|
||||||
|
|
@ -166,24 +162,6 @@ void loop() {
|
||||||
}
|
}
|
||||||
POWER_Utils::batteryManager();
|
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) {
|
if (!Config.simplifiedTrackerMode) {
|
||||||
|
|
@ -199,11 +177,6 @@ void loop() {
|
||||||
KEYBOARD_Utils::mouseRead();
|
KEYBOARD_Utils::mouseRead();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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::checkReceivedMessage(LoRa_Utils::receivePacket());
|
||||||
MSG_Utils::processOutputBuffer();
|
MSG_Utils::processOutputBuffer();
|
||||||
MSG_Utils::clean25SegBuffer();
|
MSG_Utils::clean25SegBuffer();
|
||||||
|
|
@ -218,6 +191,12 @@ void loop() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gpsIsActive) {
|
||||||
|
GPS_Utils::getData();
|
||||||
|
bool gps_time_update = gps.time.isUpdated();
|
||||||
|
bool gps_loc_update = gps.location.isUpdated();
|
||||||
|
GPS_Utils::setDateFromData();
|
||||||
|
|
||||||
int currentSpeed = (int) gps.speed.kmph();
|
int currentSpeed = (int) gps.speed.kmph();
|
||||||
|
|
||||||
if (gps_loc_update) {
|
if (gps_loc_update) {
|
||||||
|
|
@ -225,6 +204,7 @@ void loop() {
|
||||||
STATION_Utils::checkTelemetryTx();
|
STATION_Utils::checkTelemetryTx();
|
||||||
}
|
}
|
||||||
lastTx = millis() - lastTxTime;
|
lastTx = millis() - lastTxTime;
|
||||||
|
|
||||||
if (!sendUpdate && gps_loc_update && smartBeaconValue) {
|
if (!sendUpdate && gps_loc_update && smartBeaconValue) {
|
||||||
GPS_Utils::calculateDistanceTraveled();
|
GPS_Utils::calculateDistanceTraveled();
|
||||||
if (!sendUpdate) {
|
if (!sendUpdate) {
|
||||||
|
|
@ -241,5 +221,16 @@ void loop() {
|
||||||
MENU_Utils::showOnScreen();
|
MENU_Utils::showOnScreen();
|
||||||
refreshDisplayTime = millis();
|
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 "station_utils.h"
|
||||||
#include "boards_pinout.h"
|
#include "boards_pinout.h"
|
||||||
#include "power_utils.h"
|
#include "power_utils.h"
|
||||||
|
#include "sleep_utils.h"
|
||||||
#include "gps_utils.h"
|
#include "gps_utils.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ extern String winlinkAlias;
|
||||||
extern String winlinkAliasComplete;
|
extern String winlinkAliasComplete;
|
||||||
extern bool winlinkCommentState;
|
extern bool winlinkCommentState;
|
||||||
extern int wxModuleType;
|
extern int wxModuleType;
|
||||||
|
extern bool gpsIsActive;
|
||||||
|
|
||||||
String freqChangeWarning;
|
String freqChangeWarning;
|
||||||
uint8_t lowBatteryPercent = 21;
|
uint8_t lowBatteryPercent = 21;
|
||||||
|
|
@ -546,8 +547,12 @@ namespace MENU_Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gps.satellites.value() <= 9) thirdRowMainMenu += " ";
|
if (gps.satellites.value() <= 9) thirdRowMainMenu += " ";
|
||||||
|
if (gpsIsActive) {
|
||||||
thirdRowMainMenu += String(gps.satellites.value());
|
thirdRowMainMenu += String(gps.satellites.value());
|
||||||
thirdRowMainMenu += hdopState;
|
thirdRowMainMenu += hdopState;
|
||||||
|
} else {
|
||||||
|
thirdRowMainMenu += "--";
|
||||||
|
}
|
||||||
|
|
||||||
String fourthRowAlt = String(gps.altitude.meters(),0);
|
String fourthRowAlt = String(gps.altitude.meters(),0);
|
||||||
fourthRowAlt.trim();
|
fourthRowAlt.trim();
|
||||||
|
|
@ -587,6 +592,9 @@ namespace MENU_Utils {
|
||||||
fourthRowMainMenu += String(MSG_Utils::getNumAPRSMessages());
|
fourthRowMainMenu += String(MSG_Utils::getNumAPRSMessages());
|
||||||
fourthRowMainMenu += " ***";
|
fourthRowMainMenu += " ***";
|
||||||
}
|
}
|
||||||
|
if (!gpsIsActive) {
|
||||||
|
fourthRowMainMenu = "*** GPS SLEEPING ***";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showHumanHeading) {
|
if (showHumanHeading) {
|
||||||
|
|
|
||||||
|
|
@ -319,11 +319,9 @@ namespace MSG_Utils {
|
||||||
} else { // message without ack Request
|
} else { // message without ack Request
|
||||||
sendMessage(addressee, message);
|
sendMessage(addressee, message);
|
||||||
outputMessagesBuffer.erase(outputMessagesBuffer.begin());
|
outputMessagesBuffer.erase(outputMessagesBuffer.begin());
|
||||||
if (!SleepModeActive) {
|
|
||||||
lastTxTime = millis();
|
lastTxTime = millis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (outputAckRequestBuffer.empty()) {
|
if (outputAckRequestBuffer.empty()) {
|
||||||
ackRequestState = false;
|
ackRequestState = false;
|
||||||
} else if (!outputAckRequestBuffer.empty() && (millis() - lastMsgRxTime) >= 4500 && (millis() - lastTxTime) > 3000) {
|
} else if (!outputAckRequestBuffer.empty() && (millis() - lastMsgRxTime) >= 4500 && (millis() - lastTxTime) > 3000) {
|
||||||
|
|
|
||||||
|
|
@ -1,132 +1,32 @@
|
||||||
#include <TinyGPS++.h>
|
|
||||||
#include "boards_pinout.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "station_utils.h"
|
|
||||||
#include "sleep_utils.h"
|
#include "sleep_utils.h"
|
||||||
#include "power_utils.h"
|
#include "power_utils.h"
|
||||||
#include "lora_utils.h"
|
|
||||||
#include "msg_utils.h"
|
|
||||||
#include "gps_utils.h"
|
|
||||||
#include "display.h"
|
|
||||||
|
|
||||||
|
|
||||||
extern Configuration Config;
|
bool gpsIsActive = true;
|
||||||
extern TinyGPSPlus gps;
|
extern bool gpsSleepActive;
|
||||||
extern uint32_t lastTxTime;
|
|
||||||
extern bool sendUpdate;
|
|
||||||
|
|
||||||
bool wakeUpFlag = false;
|
|
||||||
bool wakeUpByButton = false;
|
|
||||||
uint32_t wakeUpByButtonTime = 0;
|
|
||||||
|
|
||||||
|
|
||||||
namespace SLEEP_Utils {
|
namespace SLEEP_Utils {
|
||||||
|
|
||||||
|
void gpsSleep() {
|
||||||
void processBeaconAfterSleep() {
|
if (gpsSleepActive && gpsIsActive) {
|
||||||
if (lastTxTime == 0 || ((millis() - lastTxTime) > 5 * 60 * 1000)) { // 5 min non-smartBeacon
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
POWER_Utils::deactivateGPS();
|
||||||
delay(100);
|
gpsIsActive = false;
|
||||||
#ifdef ADC_CTRL
|
//
|
||||||
#ifdef HELTEC_WIRELESS_TRACKER
|
Serial.println("GPS SLEEPING");
|
||||||
digitalWrite(ADC_CTRL, LOW);
|
//
|
||||||
#endif
|
}
|
||||||
#endif
|
|
||||||
LoRa_Utils::wakeRadio();
|
}
|
||||||
//LoRa_Utils::sleepRadio();
|
|
||||||
delay(100);
|
void gpsWakeUp() {
|
||||||
//esp_deep_sleep_start();
|
if (gpsSleepActive && !gpsIsActive) {
|
||||||
esp_light_sleep_start();
|
POWER_Utils::activateGPS();
|
||||||
}
|
gpsIsActive = true;
|
||||||
|
//
|
||||||
// this could be used for smartBeaconTime delta
|
Serial.println("GPS WAKEUP");
|
||||||
/*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 {
|
namespace SLEEP_Utils {
|
||||||
|
|
||||||
void processBufferAfterSleep();
|
void gpsSleep();
|
||||||
void handle_wakeup();
|
void gpsWakeUp();
|
||||||
void startSleep();
|
|
||||||
void setup();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "station_utils.h"
|
#include "station_utils.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "power_utils.h"
|
#include "power_utils.h"
|
||||||
|
#include "sleep_utils.h"
|
||||||
#include "lora_utils.h"
|
#include "lora_utils.h"
|
||||||
#include "bme_utils.h"
|
#include "bme_utils.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
@ -36,7 +37,7 @@ extern uint8_t winlinkStatus;
|
||||||
extern bool winlinkCommentState;
|
extern bool winlinkCommentState;
|
||||||
|
|
||||||
extern int wxModuleType;
|
extern int wxModuleType;
|
||||||
extern bool SleepModeActive;
|
extern bool gpsSleepActive;
|
||||||
|
|
||||||
bool sendStandingUpdate = false;
|
bool sendStandingUpdate = false;
|
||||||
uint8_t updateCounter = Config.sendCommentAfterXBeacons;
|
uint8_t updateCounter = Config.sendCommentAfterXBeacons;
|
||||||
|
|
@ -274,13 +275,14 @@ namespace STATION_Utils {
|
||||||
previousHeading = currentHeading;
|
previousHeading = currentHeading;
|
||||||
lastTxDistance = 0.0;
|
lastTxDistance = 0.0;
|
||||||
}
|
}
|
||||||
if (!SleepModeActive) {
|
|
||||||
lastTxTime = millis();
|
lastTxTime = millis();
|
||||||
}
|
|
||||||
sendUpdate = false;
|
sendUpdate = false;
|
||||||
#ifdef HAS_TFT
|
#ifdef HAS_TFT
|
||||||
cleanTFT();
|
cleanTFT();
|
||||||
#endif
|
#endif
|
||||||
|
if (gpsSleepActive) {
|
||||||
|
SLEEP_Utils::gpsSleep();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkTelemetryTx() {
|
void checkTelemetryTx() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue