-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement uptime device prop, fix #52
- Loading branch information
1 parent
f23700a
commit d6319f8
Showing
5 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "Clock.hpp" | ||
|
||
using namespace HomieInternals; | ||
|
||
ClockClass::ClockClass() | ||
: _seconds(0) | ||
, _lastTick(0) | ||
{ | ||
} | ||
|
||
void ClockClass::tick() { | ||
unsigned long now = millis(); | ||
this->_seconds += (now - this->_lastTick) / 1000UL; | ||
this->_lastTick = now; | ||
} | ||
|
||
unsigned long ClockClass::getSeconds() { | ||
return this->_seconds; | ||
} | ||
|
||
ClockClass HomieInternals::Clock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include "Arduino.h" | ||
|
||
namespace HomieInternals { | ||
class ClockClass { | ||
public: | ||
ClockClass(); | ||
void tick(); | ||
unsigned long getSeconds(); | ||
|
||
private: | ||
unsigned long _seconds; | ||
unsigned long _lastTick; | ||
}; | ||
|
||
extern ClockClass Clock; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters