Monitoring system for electric vehicles (log various sensors, such as consumed power, solar production, speed, slope, apparent wind, etc.)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

36 lines
776 B

#include "utils.h"
#include <Arduino.h>
namespace utils
{
unsigned long IRAM_ATTR elapsed(unsigned long from, unsigned long to)
{
if(to >= from)
{
return to - from;
}
else
{
// if the counter overflowed, this computes the real duration
// of course it won't work if the counter made a "full turn" or more
const unsigned long biggestValue = (unsigned long)-1;
return (biggestValue - from) + to + 1;
}
}
uint32_t elapsed(uint32_t from, uint32_t to)
{
if(to >= from)
{
return to - from;
}
else
{
// if the counter overflowed, this computes the real duration
// of course it won't work if the counter made a "full turn" or more
const uint32_t biggestValue = (uint32_t)-1;
return (biggestValue - from) + to + 1;
}
}
}