-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdig_in.cpp
More file actions
62 lines (54 loc) · 1.39 KB
/
dig_in.cpp
File metadata and controls
62 lines (54 loc) · 1.39 KB
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
#include "config.h"
#include "dig_in.h"
int digPins[] = { DIN0, DIN1, DIN2, DIN3 };
int currSector = 1;
//the dimensions are AB first, then BC, then CA [0] is when it is off, [1] is when it is on.
//returned value is sector number where sector 1 is based at 0 and each one up is 60 degrees more
//sector 0 is special and is an error state
/* Old version that I think is dead wrong (well, rotated 180 degrees)
int hallToSector[2][2][2] =
{
{ //AB off
{5, 6}, //BC off
{0, 1} //BC On
},
{ //AB on
{4, 0}, //BC off
{3, 2} //BC on
}
}; */
int hallToSector[2][2][2] =
{
{ //AB off
{2, 3}, //BC off
{0, 4} //BC On
},
{ //AB on
{1, 0}, //BC off
{6, 5} //BC on
}
};
void setup_digital_inputs()
{
for (int x = 0; x < 4; x++) pinMode(digPins[x], INPUT);
}
bool getDigitalInput(int input)
{
if (input < 0) return false;
if (input > 3) return false;
return (!digitalRead(digPins[input]));
}
int getMotorSector()
{
int A = 0, B = 0, C = 0, sector;
settings.hallAB = 2;
settings.hallBC = 1;
settings.hallCA = 0;
if (getDigitalInput(settings.hallAB)) A = 1;
if (getDigitalInput(settings.hallBC)) B = 1;
if (getDigitalInput(settings.hallCA)) C = 1;
sector = hallToSector[A][B][C];
if (sector == 0) sector = currSector;
else currSector = sector;
return sector;
}