-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
163 lines (125 loc) · 4.52 KB
/
main.cpp
File metadata and controls
163 lines (125 loc) · 4.52 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <Pokitto.h>
#include <IRremote/IRremote.h>
// PWM output for IR blaster
IRsend irSender(EXT0);
// Currently only 3+ works for the receiver.
IRrecv irReceiver(EXT3);
// Results of reading an incoming code
decode_results results;
// The duration of the raw code
unsigned int rawCode[RAWBUF];
// The length of the code
std::size_t codeLength;
// The type denoting the current operation modes
enum class Mode
{
Send,
Scan,
};
// The variable containing the currently set operation mode, defaulting to Send
Mode mode = Mode::Send;
// Stores the code for later sending
void storeCode(decode_results results)
{
using Pokitto::Display;
// codeLength is used again when sending the code, so we set it here
codeLength = results.rawlen - 1;
// To store raw codes:
// Drop first value (gap)
// Convert from ticks to microseconds
for (int i = 1; i <= codeLength; ++i)
{
rawCode[i - 1] = results.rawbuf[i] * USECPERTICK;
Display::print(rawCode[i - 1]);
Display::print(" ");
}
Display::print("\n");
}
// Prints the code being sent to the screen
void printSentCode()
{
using Pokitto::Display;
for (int i = 1; i < results.rawlen; ++i)
{
if ((i % 2) != 0)
{
Display::print(results.rawbuf[i] * USECPERTICK);
}
else
{
Display::print('-');
Display::print(static_cast<unsigned long>(results.rawbuf[i]) * USECPERTICK);
}
Display::print(" ");
}
}
int main()
{
using Pokitto::Core;
using Pokitto::Display;
using Pokitto::Buttons;
Core::begin();
Display::persistence = true;
Display::invisiblecolor = 0;
Display::setFont(font5x7);
Display::print("PEX IR test\nPress B to scan or A to send.\nC to open this menu.");
// Enable IR In on the receiver so it is ready to scan for IR codes.
irReceiver.enableIRIn();
while (Core::isRunning())
{
if (Buttons::cBtn())
{
Display::clear();
Display::print("Press B to scan or A to send.");
mode = Mode::Send;
}
if (Buttons::bBtn())
{
Display::clear();
Display::print("Entered scan mode...\n");
mode = Mode::Scan;
}
if (Buttons::aBtn())
{
// Immediately set mode to Send to prevent scanning the sent code
mode = Mode::Send;
Display::clear();
Display::print("Sending signal:\n");
printSentCode();
// Send the currently stored code
irSender.sendRaw(rawCode, codeLength, 38);
}
else if ((mode == Mode::Scan) && (irReceiver.decode(&results)))
{
// Enter Send mode to prevent Scanning the code during Send
mode = Mode::Send;
Display::clear();
Display::print("IR Received type = ");
Display::print(results.decode_type);
Display::print("\ncode = ");
Display::print(results.value);
Display::print("\n");
storeCode(results);
// Resume receiver for next time we enter Scan mode
irReceiver.resume();
Display::print("\n\nWaiting for input or command.");
}
Display::update();
}
return 0;
}
/*
test signals
//LG TV Power sequence.
unsigned int Signal_0_0[] = { 9000, 4500, 560, 560, 560, 560, 560, 1690, 560,
560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560,
560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 560,
560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560,
560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560,
1690, 560, 1690, 560 };
//Controls for hexbug channel 2 Spider walker
unsigned int up[] = {1950,500, 1950,1000, 350,1550, 400,550, 400,600, 400,600, 350,1550, 350,650, 350,1550, 350,1550, 400,1500, 400,600, 350};
unsigned int back[] = {1950,500, 1950,1000, 350,600, 400,1550, 350,600, 350,600, 400,1550, 350,1550, 400,600, 350,1550, 350,1550, 400,600, 350};
unsigned int left[] = {1950,500, 1950,1000, 350,1550, 350,1550, 400,600, 350,600, 400,1550, 350,600, 400,550, 400,1550, 350,1550, 400,600, 350};
unsigned int right[] = {2000,500, 1950,950, 400,600, 350,600, 400,1550, 350,600, 400,1550, 350,1550, 350,1550, 400,600, 350,1550, 400,600, 350};
*/