Skip to content

Commit 657be5a

Browse files
committed
changed: voltcraft heartbeat timer
1 parent a4a7084 commit 657be5a

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

hardware/VolcraftCO20.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,14 @@ CVolcraftCO20::CVolcraftCO20(const int ID)
2929
{
3030
m_HwdID=ID;
3131
m_stoprequested=false;
32-
Init();
3332
}
3433

3534
CVolcraftCO20::~CVolcraftCO20(void)
3635
{
3736
}
3837

39-
void CVolcraftCO20::Init()
40-
{
41-
m_LastPollTime=mytime(NULL)-VolcraftCO20_POLL_INTERVAL+2;
42-
}
43-
4438
bool CVolcraftCO20::StartHardware()
4539
{
46-
Init();
4740
//Start worker thread
4841
m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&CVolcraftCO20::Do_Work, this)));
4942
m_bIsStarted=true;
@@ -73,20 +66,16 @@ bool CVolcraftCO20::StopHardware()
7366
void CVolcraftCO20::Do_Work()
7467
{
7568
time_t atime;
69+
int sec_counter=VolcraftCO20_POLL_INTERVAL-5;
7670
while (!m_stoprequested)
7771
{
7872
sleep_seconds(1);
79-
atime=mytime(NULL);
80-
81-
struct tm ltime;
82-
localtime_r(&atime, &ltime);
83-
84-
85-
if (ltime.tm_sec % 12 == 0) {
73+
sec_counter++;
74+
if (sec_counter%12==0)
8675
mytime(&m_LastHeartbeat);
8776
}
8877

89-
if (atime-m_LastPollTime>=VolcraftCO20_POLL_INTERVAL)
78+
if (sec_counter%VolcraftCO20_POLL_INTERVAL==0)
9079
{
9180
GetSensorDetails();
9281
m_LastPollTime=mytime(NULL);

hardware/VolcraftCO20.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ class CVolcraftCO20 : public CDomoticzHardwareBase
1414
bool WriteToHardware(const char *pdata, const unsigned char length);
1515
private:
1616
volatile bool m_stoprequested;
17-
time_t m_LastPollTime;
1817
boost::shared_ptr<boost::thread> m_thread;
1918

20-
void Init();
2119
bool StartHardware();
2220
bool StopHardware();
2321
void Do_Work();

0 commit comments

Comments
 (0)