Browse Source

fix millis()

lightsleep
Hendrik Langer 7 years ago
parent
commit
1611283015
  1. 18
      src/main.cpp

18
src/main.cpp

@ -370,6 +370,16 @@ void ICACHE_FLASH_ATTR sendValues() {
delay(1); // yield(); delay(1); // yield();
} }
// WARNING: SOME TIME THE CALIBRATION VALUE CHANGES AND IT WILL RETURN A LOWER VALUE THAN BEFORE, BREAKING INTERVAL CHECKS!!!
unsigned long getTime() {
uint64_t rtc_t = system_get_rtc_time();
uint32_t cal = system_rtc_clock_cali_proc();
// uint32_t timemicrosec = rtc_t*((uint64) ((cal * 1000) >> 12));
// Serial.printf("cal: %d.%d \r\n", ((cal*1000)>>12)/1000, ((cal*1000)>>12)%1000 );
// Serial.printf("cal: %u\n", cal);
return ((uint64_t)(rtc_t*(uint64_t)cal) >> 12)/1000;
}
void fpm_wakup_cb_func1(void) { void fpm_wakup_cb_func1(void) {
//gpio_pin_wakeup_disable(); //gpio_pin_wakeup_disable();
//ESP.wdtFeed(); //ESP.wdtFeed();
@ -439,11 +449,13 @@ void setup() {
} }
void loop() { void loop() {
if (millis() - previousMillis >= postingInterval) { unsigned long currentMillis = getTime();
if ((long)(currentMillis - previousMillis) >= postingInterval) {
DEBUG_MSG("sending values... previousMillis:%u, millis():%u, difference:%d\n", previousMillis, currentMillis, currentMillis-previousMillis);
sendValues(); sendValues();
previousMillis = millis(); previousMillis = getTime();
} }
DEBUG_MSG("sleeping now... previousMillis:%u, millis():%u\n", previousMillis, millis()); DEBUG_MSG("sleeping now...\n");
delay(10); delay(10);
lightsleep(); lightsleep();
delay(10); delay(10);

Loading…
Cancel
Save