-
Notifications
You must be signed in to change notification settings - Fork 1
/
PWM.cpp
49 lines (41 loc) · 1.05 KB
/
PWM.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 "PWM.h"
#include "EZB.h"
PWMClass::PWMClass(EZB* ezb){
m_ezb = ezb;
for(int i = 0; i < 34; i++){
m_pwmPositions[i] = 0;
m_pwmReleased[i] = true;
}
}
int PWMClass::GetPWM(DigitalClass::DigitalPortEnum pwmPort){
return m_pwmPositions[pwmPort];
}
bool PWMClass::IsPWMStopped(DigitalClass::DigitalPortEnum pwmPort){
return m_pwmReleased[pwmPort];
}
void PWMClass::SetPWM(DigitalClass::DigitalPortEnum pwmPort, int position)
{
if (m_ezb->IsConnected()){
if (position > PWM_MAX){
position = PWM_MAX;
}
else if (position < PWM_MIN){
position = PWM_MIN;
}
m_pwmPositions[pwmPort] = position;
m_pwmReleased[pwmPort] = false;
unsigned char args[1];
args[0] = position;
m_ezb->SendCommand(EZB::SetPWMSpeed + pwmPort, args, 1);
}
}
void PWMClass::StopPWM(DigitalClass::DigitalPortEnum pwmPort)
{
if (m_ezb->IsConnected()){
m_pwmPositions[pwmPort] = 0;
m_pwmReleased[pwmPort] = true;
unsigned char args[1];
args[0] = 0;
m_ezb->SendCommand(EZB::SetPWMSpeed + pwmPort, args, 1);
}
}