Skip to content

Commit 3364c07

Browse files
committed
Merge pull request #9 from hmeyers/master
Fixed MySensor::millis() Implementation
2 parents 51550fe + e2a5610 commit 3364c07

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
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);

PiGatewaySerial.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ int main(int argc, char **argv)
197197

198198
/* create MySensors Gateway object */
199199
#ifdef __PI_BPLUS
200-
gw = new MyGateway(RPI_BPLUS_GPIO_J8_15, RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ, 60);
200+
gw = new MyGateway(RPI_BPLUS_GPIO_J8_15, RPI_BPLUS_GPIO_J8_24, BCM2835_SPI_SPEED_8MHZ, 1);
201201
#else
202-
gw = new MyGateway(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ, 60);
202+
gw = new MyGateway(RPI_V2_GPIO_P1_22, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_8MHZ, 1);
203203
#endif
204204
if (gw == NULL)
205205
{

0 commit comments

Comments
 (0)