-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput.cpp
68 lines (53 loc) · 1.61 KB
/
output.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
#include "comms.h"
#define CONTROLREFRESH 25
ControlPacket CPacket;
unsigned long controlTime, controlTimeOld;
void controls() {
if (Connected) {
#if 0
if (digitalRead(SASPIN)) //--------- This is how you do main controls
MainControls(SAS, HIGH);
else
MainControls(SAS, LOW);
if (digitalRead(RCSPIN))
MainControls(RCS, HIGH);
else
MainControls(RCS, LOW);
if (digitalRead(CG1PIN)) //--------- This is how you do control groups
ControlGroups(1, HIGH);
else
ControlGroups(1, LOW);
//This is an example of reading analog inputs to an axis, with deadband and limits
CPacket.Throttle = constrain(map(analogRead(THROTTLEPIN),THROTTLEDB,1024-THROTTLEDB,0,1000),0, 1000);
#endif
KSPBoardSendData(details(CPacket));
}
}
void output()
{
unsigned long now = millis();
controlTime = now - controlTimeOld;
if (controlTime > CONTROLREFRESH){
controlTimeOld = now;
controls();
}
}
#if 0
void controlsInit() {
pinMode(SASPIN, INPUT_PULLUP);
pinMode(RCSPIN, INPUT_PULLUP);
pinMode(CG1PIN, INPUT_PULLUP);
}
void MainControls(byte n, boolean s) {
if (s)
CPacket.MainControls |= (1 << n); // forces nth bit of x to be 1. all other bits left alone.
else
CPacket.MainControls &= ~(1 << n); // forces nth bit of x to be 0. all other bits left alone.
}
void ControlGroups(byte n, boolean s) {
if (s)
CPacket.ControlGroup |= (1 << n); // forces nth bit of x to be 1. all other bits left alone.
else
CPacket.ControlGroup &= ~(1 << n); // forces nth bit of x to be 0. all other bits left alone.
}
#endif