-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend.cpp
More file actions
56 lines (49 loc) · 1.34 KB
/
send.cpp
File metadata and controls
56 lines (49 loc) · 1.34 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
#include <iostream>
#include <string>
#include "GPIOPin.hpp"
#include "PT22x2.hpp"
#include "Command.hpp"
using std::cout;
using std::cin;
using std::endl;
using std::stoi;
using std::string;
void send(PT22x2::Encoder encoder, unsigned int system_code, unsigned int channel, Command::State state) {
Command cmd(system_code, channel, state);
auto codeword = cmd.getCodeword();
for (int i=0; i<5; i++) {
encoder.send(codeword);
}
}
int main(int argc, char* argv[]) {
if (argc != 4) {
cout << "usage: send <system_code> <channel>|all on|off" << endl;
return -1;
}
GPIOPin pin(24);
pin.setOutput();
PT22x2::Encoder encoder(pin);
unsigned int system_code = stoi(argv[1]);
Command::State state;
if (argv[3] == string("on")) {
state = Command::State::On;
}
else if (argv[3] == string("off")) {
state = Command::State::Off;
}
else {
cout << "state has to be 'on' or 'off'" << endl;
return -1;
}
if (argv[2] == string("all")) {
send(encoder, system_code, 1, state);
send(encoder, system_code, 2, state);
send(encoder, system_code, 4, state);
send(encoder, system_code, 8, state);
}
else {
unsigned int channel = stoi(argv[2]);
send(encoder, system_code, channel, state);
}
return 0;
}