-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitchrcsocket.c
46 lines (40 loc) · 1.08 KB
/
switchrcsocket.c
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
#include <wiringPi.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <chrono>
#include <thread>
#include "RCSocketTransmitter.hpp"
/**
timing used in the tranmitter protocoll, may depend on the brand of the sockets, for mine 380 microseconds works well
*/
constexpr int timing = 380;
/**
gpio pin the transmitter is attache to
*/
constexpr int pin = 0;
int main(int argc, char **args){
if(argc < 4) {
std::cout << "args: <systemcode> <socket number> <state>" << std::endl;
std::cout << "Example: " << args[0] << "00000 0 1" << std::endl;
exit(-1);
}
const int code = std::stoi (args[1], nullptr, 2);
const int socketId = std::stoi (args[2], nullptr, 10);
const int state = std::stoi (args[3], nullptr, 10);
RCSocket::RCSocketTransmitter socket(timing, pin, code);
/**
repeat transmission 16 times to make it work more reliable
*/
for(int i = 0; i < 15; i++){
if(state)
socket.switchOn(socketId);
else
socket.switchOff(socketId);
if(i % 5 == 0){
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
return 0;
}