forked from LucidVR/lucidgloves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_main.ino
83 lines (68 loc) · 2.34 KB
/
_main.ino
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#define ALWAYS_CALIBRATING CALIBRATION_LOOPS == -1
#define CALIB_OVERRIDE false
#if USING_CALIB_PIN && COMMUNICATION == COMM_SERIAL && PIN_CALIB == 0 && !CALIB_OVERRIDE
#error "You can't set your calibration pin to 0 over usb. You can calibrate with the BOOT button when using bluetooth only. Set CalibOverride to true to override this."
#endif
ICommunication* comm;
int loops = 0;
void setup() {
#if COMMUNICATION == COMM_SERIAL
comm = new SerialCommunication();
#elif COMMUNICATION == COMM_BTSERIAL
comm = new BTSerialCommunication();
#endif
comm->start();
setupInputs();
#if USING_FORCE_FEEDBACK
setupServoHaptics();
#endif
}
void loop() {
if (comm->isOpen()){
#if USING_CALIB_PIN
bool calibButton = getButton(PIN_CALIB) != INVERT_CALIB;
if (calibButton)
loops = 0;
#else
bool calibButton = false;
#endif
bool calibrate = false;
if (loops < CALIBRATION_LOOPS || ALWAYS_CALIBRATING){
calibrate = true;
loops++;
}
int* fingerPos = getFingerPositions(calibrate, calibButton);
bool joyButton = getButton(PIN_JOY_BTN) != INVERT_JOY;
#if TRIGGER_GESTURE
bool triggerButton = triggerGesture(fingerPos);
#else
bool triggerButton = getButton(PIN_TRIG_BTN) != INVERT_TRIGGER;
#endif
bool aButton = getButton(PIN_A_BTN) != INVERT_A;
bool bButton = getButton(PIN_B_BTN) != INVERT_B;
#if GRAB_GESTURE
bool grabButton = grabGesture(fingerPos);
#else
bool grabButton = getButton(PIN_GRAB_BTN) != INVERT_GRAB;
#endif
#if PINCH_GESTURE
bool pinchButton = pinchGesture(fingerPos);
#else
bool pinchButton = getButton(PIN_PNCH_BTN) != INVERT_PINCH;
#endif
bool menuButton = getButton(PIN_MENU_BTN) != INVERT_MENU;
comm->output(encode(fingerPos, getJoyX(), getJoyY(), joyButton, triggerButton, aButton, bButton, grabButton, pinchButton, calibButton, menuButton));
#if USING_FORCE_FEEDBACK
char received[100];
if (comm->readData(received)){
int hapticLimits[5];
//This check is a temporary hack to fix an issue with haptics on v0.5 of the driver, will make it more snobby code later
if(String(received).length() >= 10) {
decodeData(received, hapticLimits);
writeServoHaptics(hapticLimits);
}
}
#endif
delay(LOOP_TIME);
}
}