millis() overflow logic reworked
This commit is contained in:
parent
069c5ec3ec
commit
a04e6440d4
@ -12,6 +12,6 @@
|
||||
void do_reset(bool warmstart);
|
||||
void do_after_reset(void);
|
||||
void enter_deepsleep(const uint64_t wakeup_sec, const gpio_num_t wakeup_gpio);
|
||||
uint64_t uptime(void);
|
||||
unsigned long long uptime(void);
|
||||
|
||||
#endif // _RESET_H
|
@ -26,7 +26,6 @@ bsec_virtual_sensor_t sensorList[10] = {
|
||||
};
|
||||
|
||||
uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE] = {0};
|
||||
uint16_t stateUpdateCounter = 0;
|
||||
|
||||
Bsec iaqSensor;
|
||||
|
||||
@ -218,6 +217,7 @@ void loadState(void) {
|
||||
|
||||
void updateState(void) {
|
||||
bool update = false;
|
||||
static uint16_t stateUpdateCounter = 0;
|
||||
|
||||
if (stateUpdateCounter == 0) {
|
||||
// first state update when IAQ accuracy is >= 1
|
||||
@ -228,7 +228,7 @@ void updateState(void) {
|
||||
} else {
|
||||
|
||||
/* Update every STATE_SAVE_PERIOD minutes */
|
||||
if ((stateUpdateCounter * STATE_SAVE_PERIOD) < millis()) {
|
||||
if ((long)(millis() - stateUpdateCounter * STATE_SAVE_PERIOD) >= 0) {
|
||||
update = true;
|
||||
stateUpdateCounter++;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ void ledLoop(void *parameter) {
|
||||
// management
|
||||
if (LEDBlinkStarted && LEDBlinkDuration) {
|
||||
// Custom blink is finished, let this order, avoid millis() overflow
|
||||
if ((millis() - LEDBlinkStarted) >= LEDBlinkDuration) {
|
||||
if ((long)(millis() - LEDBlinkStarted) >= LEDBlinkDuration) {
|
||||
// Led becomes off, and stop blink
|
||||
LEDState = LED_OFF;
|
||||
LEDBlinkStarted = 0;
|
||||
|
@ -180,7 +180,7 @@ int do_ota_update() {
|
||||
|
||||
unsigned long timeout = millis();
|
||||
while (client.available() == 0) {
|
||||
if ((millis() - timeout) > (RESPONSE_TIMEOUT_MS)) {
|
||||
if ((long)(millis() - timeout) > (RESPONSE_TIMEOUT_MS)) {
|
||||
ESP_LOGI(TAG, "Client timeout");
|
||||
ota_display(3, " E", "client timeout");
|
||||
goto abort;
|
||||
|
@ -298,8 +298,8 @@ void get_config(uint8_t val[]) {
|
||||
void get_status(uint8_t val[]) {
|
||||
ESP_LOGI(TAG, "Remote command: get device status");
|
||||
payload.reset();
|
||||
payload.addStatus(read_voltage(), uptime() / 1000, temperatureRead(),
|
||||
getFreeRAM(), rtc_get_reset_reason(0),
|
||||
payload.addStatus(read_voltage(), (uint64_t)(uptime() / 1000ULL),
|
||||
temperatureRead(), getFreeRAM(), rtc_get_reset_reason(0),
|
||||
rtc_get_reset_reason(1));
|
||||
SendPayload(STATUSPORT);
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ static const char TAG[] = __FILE__;
|
||||
// variables keep its values after a wakeup from sleep
|
||||
RTC_DATA_ATTR runmode_t RTC_runmode = RUNMODE_POWERCYCLE;
|
||||
RTC_DATA_ATTR struct timeval RTC_sleep_start_time;
|
||||
RTC_DATA_ATTR unsigned long RTC_millis = 0;
|
||||
RTC_DATA_ATTR unsigned long long RTC_millis = 0;
|
||||
timeval sleep_stop_time;
|
||||
|
||||
const char *runmode[5] = {"powercycle", "normal", "wakeup", "update", "sleep"};
|
||||
@ -193,4 +193,4 @@ Error:
|
||||
do_reset(true);
|
||||
}
|
||||
|
||||
uint64_t uptime() { return (RTC_millis + millis()); }
|
||||
unsigned long long uptime() { return (RTC_millis + millis()); }
|
Loading…
Reference in New Issue
Block a user