-
Notifications
You must be signed in to change notification settings - Fork 1
/
Digital.cpp
49 lines (38 loc) · 1.22 KB
/
Digital.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Digital.h"
#include "EZB.h"
DigitalClass::DigitalClass(EZB* ezb){
m_ezb = ezb;
MinPoolTimeMS = 100;
}
bool DigitalClass::GetDigitalPort(DigitalPortEnum digitalPort){
struct timespec now;
clock_gettime(1, &now);
unsigned long nowms = (now.tv_sec * 1000) + (now.tv_nsec / 1000000);
if(MinPoolTimeMS > 0 && m_last_request[digitalPort] + MinPoolTimeMS < nowms){
unsigned char* retval = m_ezb->SendCommand(digitalPort + EZB::GetDigitalPort, 1);
if(retval[0])
m_last_value[digitalPort] = true;
else
m_last_value[digitalPort] = false;
delete [] retval;
clock_gettime(1, &now);
m_last_request[digitalPort] = (now.tv_sec * 1000) + (now.tv_nsec / 1000000);
}
return m_last_value[digitalPort];
}
int DigitalClass::GetDigitalPortAsInt(DigitalPortEnum digitalPort){
if( GetDigitalPort(digitalPort))
return 1;
else
return 0;
}
bool DigitalClass::GetLastDigitalPortSet(DigitalPortEnum digitalPort){
return true;
}
void DigitalClass::SetDigitalPort(DigitalPortEnum digitalPort, bool status){
if(status)
m_ezb->SendCommand(digitalPort + EZB::SetDigitalPortOn);
else
m_ezb->SendCommand(digitalPort + EZB::SetDigitalPortOff);
m_last_value[digitalPort] = status;
}