Files
Arduino-GSM-Chata/lib/Helper/Helper.cpp
T
2024-04-24 03:29:50 +02:00

30 lines
717 B
C++

#include <limits.h>
#include <Arduino.h>
#include "Helper.h"
unsigned long currentTime = millis();
unsigned long lastOverflowTime = 0; // Add missing declaration and initialization
// Function to check for overflow and update lastOverflowTime
bool Helper::hasOverflowed()
{
if (currentTime < lastOverflowTime)
{
lastOverflowTime = currentTime;
return true;
}
return false;
}
// Calculate elapsed time considering overflow
unsigned long Helper::getElapsedTime()
{
unsigned long elapsedTime = currentTime - lastOverflowTime;
if (hasOverflowed())
{
elapsedTime += (ULONG_MAX - lastOverflowTime); // Add the time since last overflow
}
return elapsedTime;
}