Skip to content

Commit 46e6e03

Browse files
author
Holger Meyers
committed
Changed the implementation of unsigned long MySensor::millis() to return something close to the millis() implementation
1 parent 46edd0a commit 46e6e03

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

MySensor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ inline MyMessage& build (MyMessage &msg, uint8_t sender, uint8_t destination, ui
3737

3838
#ifdef __Raspberry_Pi
3939
MySensor::MySensor(uint8_t _cepin, uint8_t _cspin, uint32_t spispeed ) : RF24(_cepin, _cspin, spispeed){
40+
timeval curTime;
41+
gettimeofday(&curTime, NULL);
42+
millis_at_start = curTime.tv_sec;
4043
}
4144
#else
4245
MySensor::MySensor(uint8_t _cepin, uint8_t _cspin) : RF24(_cepin, _cspin) {
@@ -597,7 +600,7 @@ unsigned long MySensor::millis()
597600
{
598601
timeval curTime;
599602
gettimeofday(&curTime, NULL);
600-
return curTime.tv_usec / 1000;
603+
return ((curTime.tv_sec - millis_at_start) * 1000) + (curTime.tv_usec / 1000);
601604
}
602605

603606
/**

MySensor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ class MySensor : public RF24
280280
boolean sendWrite(uint8_t dest, MyMessage &message, bool broadcast=false);
281281

282282
#ifdef __Raspberry_Pi
283-
long unsigned int millis();
283+
unsigned long millis();
284+
unsigned long millis_at_start;
284285
char * itoa(int value, char *result, int base);
285286
char * ltoa(long value, char *result, int base);
286287
char * dtostrf(float f, int width, int decimals, char *result);

0 commit comments

Comments
 (0)