-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathir.h
89 lines (62 loc) · 2.07 KB
/
ir.h
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
84
85
86
87
88
89
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
IRsend irsend;
static const byte progMsg = 0b001011;
static const byte driveMsg = 0b000111;
static const byte necStartT = 0x1;
static const byte necStrategyT = 0x2;
static const byte necVarT = 0x3;
static const byte necEventT = 0x4;
static const byte necEndT = 0x6;
static const int IR_DELAY = 50;
uint32_t message(uint16_t addr, uint8_t type, uint8_t cmd) {
return ((uint32_t) addr << 20) | ((uint32_t) type << 16) | ((uint32_t) cmd << 8) | ((uint8_t) ~cmd);
}
void startMiniSumo() {
irsend.sendRC5((driveMsg << 6) | (ring << 1) | 1 , 12);
delay(IR_DELAY);
irsend.sendRC5((driveMsg << 6) | (ring << 1) | 1 , 12);
delay(IR_DELAY);
irsend.sendRC5((driveMsg << 6) | (ring << 1) | 1 , 12);
}
void stopMiniSumo() {
irsend.sendRC5((driveMsg << 6) | (ring << 1) | 0 , 12);
delay(IR_DELAY);
irsend.sendRC5((driveMsg << 6) | (ring << 1) | 0 , 12);
delay(IR_DELAY);
irsend.sendRC5((driveMsg << 6) | (ring << 1) | 0 , 12);
}
void programMiniSumo() {
irsend.sendRC5((progMsg << 6) | (ring << 1) | 1 , 12);
delay(IR_DELAY);
irsend.sendRC5((progMsg << 6) | (ring << 1) | 1 , 12);
delay(IR_DELAY);
irsend.sendRC5((progMsg << 6) | (ring << 1) | 1 , 12);
}
bool sendStrat() {
// Stretegy variable check
if (!varNames[0].equals(STRAT_NUM) && varVals[0] < 256 && varVals[0] >= 0) return false;
int8 msgNum = 3 + (vars - 1) * 2;
// Start of transmission message
irsend.sendNEC(message(necAddr, necStartT, msgNum), 32);
delay(IR_DELAY);
// Strategy message
irsend.sendNEC(message(necAddr, necStrategyT, varVals[0]), 32);
delay(IR_DELAY);
// Variables
for (int x = 1; x < vars; x++) {
irsend.sendNEC(message(necAddr, necVarT, x - 1), 32);
delay(IR_DELAY);
uint32_t sendVar;
memcpy(&sendVar, &varVals[x], sizeof(uint32_t));
irsend.sendNEC(sendVar, 32);
delay(IR_DELAY);
}
// End of transmission
irsend.sendNEC(message(necAddr, necEndT, msgNum), 32);
return true;
}
void sendEvent(int8 event) {
irsend.sendNEC(message(necAddr, necEventT, event), 32);
}