Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: measurement/Temperature.cpp
- Revision:
- 123:311fa85af2b3
- Parent:
- 117:e831cdb799ab
- Child:
- 136:a52821cdb108
--- a/measurement/Temperature.cpp Wed May 27 09:22:24 2015 +0000 +++ b/measurement/Temperature.cpp Fri May 29 12:05:01 2015 +0000 @@ -8,6 +8,14 @@ // Timeout for forcing a sending even if readings are similar [seconds]. #define TIME_LIMIT_TEMP 900 +static inline bool valueChanged(float V0, float V1) +{ + if (abs(V0-V1) <= abs(V0)*THRESHOLD_PERCENT_TEMP) + return false; + else + return true; +} + size_t Temperature::read(char *buf, size_t maxLen, char *status, size_t num) { static const char *fmt = "105,%ld,%f\r\n"; @@ -15,17 +23,15 @@ return 0; float data = sensor.temp(); - if (abs(oldValue-data) <= abs(oldValue)*THRESHOLD_PERCENT_TEMP) { - time_t t_interval = time(NULL) - t_start; - if (t_interval < TIME_LIMIT_TEMP) { - return 0; - } + float t_interval = timer.read(); + if (!valueChanged(oldValue, data) && t_interval < TIME_LIMIT_TEMP) { + return 0; } size_t l = snprintf(buf, maxLen, fmt, deviceID, data); if (status) { snprintf(status, num, "Send Temp %.2f", data); } oldValue = data; - t_start = time(NULL); + timer.reset(); return l; } \ No newline at end of file