-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInput.cpp
67 lines (54 loc) · 1.13 KB
/
Input.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"
//if no message received from KSP for more than 2s, go idle
#define IDLETIMER 4000
unsigned long deadtime, deadtimeOld;
typedef unsigned char byte;
HandShakePacket HPacket;
VData_s VData;
// Handshake
void Handshake(){
//digitalWrite(GLED,HIGH);
HPacket.id = 0;
HPacket.M1 = 3;
HPacket.M2 = 1;
HPacket.M3 = 4;
KSPBoardSendData(details(HPacket));
//Serial.println(F("KSP;0"));
//delay(1000);
}
int input()
{
int returnValue = -1;
unsigned long now = millis();
if (KSPBoardReceiveData()){
deadtimeOld = now;
returnValue = id;
switch(id) {
case 0: //Handshake packet
Handshake();
break;
case 1:
//Indicators();
break;
}
//We got some data, turn the green led on
//digitalWrite(GLED,HIGH);
Connected = true;
}
else
{ //if no message received for a while, go idle
deadtime = now - deadtimeOld;
if (deadtime > IDLETIMER)
{
deadtimeOld = now;
Handshake();
Connected = false;
//LEDSAllOff();
}
}
return returnValue;
}
byte ControlStatus(byte n)
{
return ((VData.ActionGroups >> n) & 1) == 1;
}