Fixed beacon timeout handling.

This commit is contained in:
nobody 2020-11-01 23:19:32 +01:00
parent faa93833af
commit 00fe727f55
2 changed files with 15 additions and 6 deletions

View file

@ -11,6 +11,7 @@ lib_deps =
sandeepmistry/LoRa @ 0.7.2
peterus/APRS-Decoder-Lib @ 0.0.5
mikalhart/TinyGPSPlus @ 1.0.2
paulstoffregen/Time @ 1.6
check_tool = cppcheck
check_flags =
cppcheck: --suppress=*:*.pio\* --inline-suppr

View file

@ -6,6 +6,7 @@
#include "settings.h"
#include "display.h"
#include "pins.h"
#include <TimeLib.h>
#ifdef TTGO_T_Beam_V1_0
#include <axp20x.h>
@ -21,6 +22,10 @@ String create_long_aprs(RawDegrees lng);
void setup_lora();
static time_t nowTimeStamp = -1;
static time_t nextUpdateTimeStamp = -1;
static bool send_update = true;
// cppcheck-suppress unusedFunction
void setup()
{
@ -59,23 +64,26 @@ void loop()
gps.encode(c);
}
static unsigned long next_update = -1;
static bool send_update = true;
bool gps_time_update = false;
if(gps.time.isUpdated())
{
gps_time_update = true;
}
if(gps.time.isValid() && (next_update <= gps.time.minute() || next_update == -1))
if(gps.time.isValid())
{
send_update = true;
setTime(gps.time.hour(),gps.time.minute(),gps.time.second(),gps.date.day(),gps.date.month(),gps.date.year());
nowTimeStamp = now();
if (nextUpdateTimeStamp <= nowTimeStamp || nextUpdateTimeStamp == -1)
{
send_update = true;
}
}
if(send_update && gps.location.isValid() && gps.location.isUpdated())
{
next_update = (gps.time.minute() + BEACON_TIMEOUT) % 60;
nextUpdateTimeStamp = nowTimeStamp + (BEACON_TIMEOUT * 60);
send_update = false;
APRSMessage msg;