diff --git a/src/main.c b/src/main.c --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,7 @@ #include "uart.h" #include "gpio.h" #include "wspr.h" +#include "rtc.h" #include "gps.h" @@ -34,6 +35,7 @@ int main(void) HAL_Init(); sysclk_init(); + rtc_init(); gpio_init(); adc_init(); i2c_init(); @@ -97,6 +99,7 @@ int main(void) case SYSTEM_IDLE: { blink_rate = BLINK_SLOW; + HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); // Wait for RTC wakeup interrupt //wfi(); //enter_sleep(); @@ -117,7 +120,8 @@ int main(void) gps_poweron(); // power on and initialize GPS module } - if(gps_getdata()->fixtype > 0 && gps_getdata()->pdop < 5) + // If 3d fix with a decent enough precision + if( ((gps_getdata()->fixtype == 2) || (gps_getdata()->fixtype == 3)) && gps_getdata()->pdop < 10) { // Disable GPS module gps_poweroff(); @@ -130,11 +134,13 @@ int main(void) fix_acq_starttime = 0; state = SYSTEM_WSPRTX; } - // If no fix in 2 minutes - else if(HAL_GetTick() - fix_acq_starttime > 120000) + // If no decent fix in 3 minutes + else if(HAL_GetTick() - fix_acq_starttime > 60000 * 3) { - // Flash error code and go to idle probably? or just try forever? + // Flash error code and go to idle, try again next time led_blink(4); + gps_poweroff(); + state = SYSTEM_IDLE; } } break;