-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEncoderClass.cpp
67 lines (59 loc) · 1.61 KB
/
EncoderClass.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @file EncoderClass.cpp
* @author Leonardo Cavagnis
* @brief Source file for the encoder module of the Portenta Machine Control.
*/
/* Includes -----------------------------------------------------------------*/
#include "EncoderClass.h"
/* Functions -----------------------------------------------------------------*/
EncoderClass::EncoderClass(PinName enc0_A_pin, PinName enc0_B_pin, PinName enc0_I_pin,
PinName enc1_A_pin, PinName enc1_B_pin, PinName enc1_I_pin)
: _enc0(enc0_A_pin, enc0_B_pin, enc0_I_pin, 0),
_enc1(enc1_A_pin, enc1_B_pin, enc1_I_pin, 0)
{ }
EncoderClass::~EncoderClass()
{ }
void EncoderClass::reset(int channel) {
switch (channel) {
case 0:
_enc0.reset();
break;
case 1:
_enc1.reset();
break;
default:
return;
}
}
int EncoderClass::getCurrentState(int channel) {
switch (channel) {
case 0:
return _enc0.getCurrentState();
case 1:
return _enc1.getCurrentState();
default:
return -1;
}
}
int EncoderClass::getPulses(int channel) {
switch (channel) {
case 0:
return _enc0.getPulses();
case 1:
return _enc1.getPulses();
default:
return -1;
}
}
int EncoderClass::getRevolutions(int channel) {
switch (channel) {
case 0:
return _enc0.getRevolutions();
case 1:
return _enc1.getRevolutions();
default:
return -1;
}
}
EncoderClass MachineControl_Encoders;
/**** END OF FILE ****/