Skip to content

Commit 78b7766

Browse files
committed
Add 'README.md' file
1 parent f9ab47e commit 78b7766

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# RCSwitch Common Library
2+
3+
Adaptation of ["RCSwitch"](https://github.com/sui77/rc-switch) Arduino library to be used on any system to encode and decode RC codes of supported protocols.
4+
5+
Works on any **libc++** compatible system, such as macOS, FreeBSD, Linux, and even Windows.
6+
7+
[![License: LGPL v3](https://img.shields.io/badge/License-LGPL%20v3-blue.svg)](https://www.gnu.org/licenses/lgpl-3.0)
8+
9+
Originally developed for Arduino framework, it has been ported to Raspberry Pi using the WiringPi library.
10+
11+
Its main use is to capture and reproduce operation codes of radio control devices like the popular low cost power outlet sockets, which works on the 315Mhz or 433MHz frequency in AM ASK/OOK modulation.
12+
13+
It supports only a few very basic protocols (up to 64 pulses):
14+
- SC5262 / SC5272
15+
- HX2262 / HX2272
16+
- PT2262 / PT2272
17+
- EV1527 / RT1527 / FP1527 / HS1527
18+
- Intertechno outlets
19+
- HT6P20X
20+
21+
There are other similar projects that support a large number of protocols, including some very complex ones, with a large number of pulses, such as [**PiCode**](https://github.com/latchdevel/PiCode). However, RCSwitch is very popular for its simplicity and ease of use.
22+
23+
## Usage
24+
RCSwitch Common Library is a C++ library built statically and dynamically on any **libc++** compatible system.
25+
26+
It implements the original RCSwitch class, simulating the transmissions and receptions of RC codes, exchanging objects of the [**std::list** class](https://en.cppreference.com/w/cpp/container/list) that store the pulse trains.
27+
28+
```c++
29+
typedef std::list<unsigned int> pulse_list_t;
30+
```
31+
32+
### Encode
33+
You can use any transmission RCSwitch class method to encode an RC code into a pulse train.
34+
35+
```c++
36+
pulse_list_t switchOn(int nGroupNumber, int nSwitchNumber);
37+
pulse_list_t switchOff(int nGroupNumber, int nSwitchNumber);
38+
pulse_list_t switchOn(const char* sGroup, int nSwitchNumber);
39+
pulse_list_t switchOff(const char* sGroup, int nSwitchNumber);
40+
pulse_list_t switchOn(char sFamily, int nGroup, int nDevice);
41+
pulse_list_t switchOff(char sFamily, int nGroup, int nDevice);
42+
pulse_list_t switchOn(const char* sGroup, const char* sDevice);
43+
pulse_list_t switchOff(const char* sGroup, const char* sDevice);
44+
pulse_list_t switchOn(char sGroup, int nDevice);
45+
pulse_list_t switchOff(char sGroup, int nDevice);
46+
pulse_list_t sendTriState(const char* sCodeWord);
47+
pulse_list_t send(unsigned long code, unsigned int length);
48+
pulse_list_t send(const char* sCodeWord);
49+
```
50+
51+
All related TX methods are functional:
52+
```c++
53+
void setProtocol(int nProtocol);
54+
void setPulseLength(uint16_t nPulseLength);
55+
void setRepeatTransmit(int nRepeatTransmit);
56+
```
57+
58+
### Decode
59+
To decode a pulse train, a specific method has been added to the RCSwitch class that takes a pulse train as a parameter, simulating its reception as an AM ASK/OOK radio frequency receiver.
60+
```c++
61+
bool decodePulseTrain(pulse_list_t);
62+
```
63+
Returns a bool indicating whether it was successfully decoded, and any case all related RX methods are functional:
64+
```c++
65+
bool available();
66+
void resetAvailable();
67+
unsigned long getReceivedValue();
68+
unsigned int getReceivedBitlength();
69+
unsigned int getReceivedDelay();
70+
unsigned int getReceivedProtocol();
71+
unsigned int* getReceivedRawdata();
72+
void setReceiveTolerance(int nPercent);
73+
```
74+
75+
## BUILD
76+
No external depends, can run on any libc++ compatible system, such as macOS, FreeBSD, Linux, and even Windows.
77+
78+
Requires a **C++** compiler, **CMake** and **git** optionally. Debian linux based example: `apt install build-essential cmake git`
79+
80+
```
81+
$ git clone https://github.com/latchdevel/rc-switch-lib (or download .zip)
82+
$ cd rc-switch-lib
83+
$ mkdir build
84+
$ cd build
85+
$ cmake .. (or "cmake -DCMAKE_BUILD_TYPE=debug .." for debug)
86+
$ make
87+
$ make install (optional)
88+
$ make uninstall (to uninstall)
89+
```
90+
91+
### Output
92+
Example of use: `$ ./example`
93+
```
94+
Encoding: switchOn("11111", "00010")
95+
raw_pulses[50]={350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,1050,350,350,1050,1050,350,350,1050,1050,350,350,1050,350,1050,350,1050,1050,350,350,1050,350,1050,350,1050,1050,350,350,10850};
96+
OK: decode value: 5393 (24 bits) Protocol: 1 Delay: 350
97+
dec_pulses[50]={350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,350,1050,1050,350,350,1050,1050,350,350,1050,1050,350,350,1050,350,1050,350,1050,1050,350,350,1050,350,1050,350,1050,1050,350,350,10850};
98+
OK: pulse lists match.
99+
```
100+
101+
# License
102+
Copyright (c) 2011 Suat Özgür. All right reserved.
103+
104+
Copyright (c) 2024 Jorge Rivera. All right reserved.
105+
106+
License GNU Lesser General Public License v3.0.
107+
108+
This program is free software; you can redistribute it and/or
109+
modify it under the terms of the GNU Lesser General Public
110+
License as published by the Free Software Foundation; either
111+
version 3 of the License, or (at your option) any later version.
112+
113+
This program is distributed in the hope that it will be useful,
114+
but WITHOUT ANY WARRANTY; without even the implied warranty of
115+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
116+
Lesser General Public License for more details.
117+
118+
You should have received a copy of the GNU Lesser General Public License
119+
along with this program; if not, write to the Free Software Foundation,
120+
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
121+
122+
See the [LICENSE](LICENSE.txt) file for license rights and limitations (lgpl-3.0).

0 commit comments

Comments
 (0)