|
| 1 | +/* |
| 2 | + This file is part of ArduinoIoTCloud. |
| 3 | +
|
| 4 | + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 5 | +
|
| 6 | + This software is released under the GNU General Public License version 3, |
| 7 | + which covers the main part of arduino-cli. |
| 8 | + The terms of this license can be found at: |
| 9 | + https://www.gnu.org/licenses/gpl-3.0.en.html |
| 10 | +
|
| 11 | + You can be released from the requirements of the above licenses by purchasing |
| 12 | + a commercial license. Buying such a license is mandatory if you want to modify or |
| 13 | + otherwise use the software for commercial activities involving the Arduino |
| 14 | + software without disclosing the source code of your own applications. To purchase |
| 15 | + a commercial license, send an email to [email protected]. |
| 16 | +*/ |
| 17 | + |
| 18 | +#ifdef ARDUINO_ARCH_ESP8266 |
| 19 | + |
| 20 | +/************************************************************************************** |
| 21 | + * INCLUDE |
| 22 | + **************************************************************************************/ |
| 23 | + |
| 24 | +#include <Arduino.h> |
| 25 | +#include "RTCMillis.h" |
| 26 | + |
| 27 | +/************************************************************************************** |
| 28 | + * CTOR/DTOR |
| 29 | + **************************************************************************************/ |
| 30 | + |
| 31 | +RTCMillis::RTCMillis() |
| 32 | +: _last_rtc_update_tick(0) |
| 33 | +, _last_rtc_update_value(0) |
| 34 | +{ |
| 35 | + |
| 36 | +} |
| 37 | + |
| 38 | +/************************************************************************************** |
| 39 | + * PUBLIC MEMBER FUNCTIONS |
| 40 | + **************************************************************************************/ |
| 41 | + |
| 42 | +void RTCMillis::begin() |
| 43 | +{ |
| 44 | + |
| 45 | +} |
| 46 | + |
| 47 | +void RTCMillis::set(unsigned long time) |
| 48 | +{ |
| 49 | + _last_rtc_update_tick = millis(); |
| 50 | + _last_rtc_update_value = time; |
| 51 | +} |
| 52 | + |
| 53 | +unsigned long RTCMillis::get() |
| 54 | +{ |
| 55 | + unsigned long current_tick = millis(); |
| 56 | + unsigned long const elapsed_s = (current_tick - _last_rtc_update_tick) / 1000; |
| 57 | + if(elapsed_s) { |
| 58 | + set(_last_rtc_update_value + elapsed_s); |
| 59 | + } |
| 60 | + return _last_rtc_update_value; |
| 61 | +} |
| 62 | + |
| 63 | +#endif /* ARDUINO_ARCH_ESP8266 */ |
0 commit comments