-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathADC.cpp
36 lines (25 loc) · 878 Bytes
/
ADC.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
#include "ADC.h"
#include "EZB.h"
ADCClass::ADCClass(EZB* ezb){
m_ezb = ezb;
MinPoolTimeMS=100;
}
int ADCClass::GetADCValue(ADCPortEnum sendSensor){
struct timespec now;
clock_gettime(1, &now);
unsigned long nowms = (now.tv_sec * 1000) + (now.tv_nsec / 1000000);
if(MinPoolTimeMS > 0 && m_last_request[sendSensor] + MinPoolTimeMS < nowms){
unsigned char* retval = m_ezb->SendCommand(EZB::GetADCValue + sendSensor, 1);
m_last_value[sendSensor] = retval[0];
delete [] retval;
clock_gettime(1, &now);
m_last_request[sendSensor] = (now.tv_sec * 1000) + (now.tv_nsec / 1000000);
}
return m_last_value[sendSensor];
}
float ADCClass::GetADCVoltage(ADCPortEnum sendSensor){
return GetADCVoltageFromValue(GetADCValue(sendSensor));
}
float ADCClass::GetADCVoltageFromValue(int adcValue){
return (float)((float)adcValue * 0.01960784f);
}