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.
 
 
 
 
 
 

21 lines
436 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;
}
}
}