Skip to content

Add_New_Remote_Part_2

frownbreaker edited this page Apr 29, 2018 · 10 revisions

Updating the RCSwitch Library

Checklist (Before you start)

  1. Have the results from your completed code sampling and analysis
  2. Have a working 433/315mHz transmitter
  3. A Basic Understanding of C/C++ and Github
  4. Toolchain to edit/debug code working with your device. If in doubt work with an Arduino Uno type unit then port to ESP8266 etc

Updating the code

  1. Create a new Github Repo to host your copy of RCSwitch. This will allow others to review your code and mistakes won't impact others! Use the same license as RCSwitch i.e. Lesser GPL 2.1
  2. My remote has a signal that has 1 sync bit + 52 data bits. That is quite a long train of pulses and I will need to modify the source code of the library (cpp + h files) to hold the data (currently RCSwitch uses a 32-bits int, I need a 64-bits int) for both, sending and receiving.
  3. From my sample data I analysed I got: 2 integers (4315972465486165 and 4315972465486182) that represent the 52-bit data to send for Switch ON and OFF. I need to modify the library to use 64-bit int rather than 32-bit. I could create a send64 command so the name does not clash with the existing 32bit send function or I could modify the existing library to work with both. The later seems like a good option, though it will need more memory for the receive / transmit buffer. The larger memory footprint might seem like a deal breaker but its the only way to support the longer data stream that my device needs.
  4. I know I can set the pulse length to 605µs so no code change for this.
  5. rc-switch/RCSwitch.cpp added protcol 7 { 605, { 1, 28 }, { 1, 2 }, { 1, 1 }, false }
  6. rc-switch/RCSwitch.h "1 sync bit + 52" =53 bits, "You need up+down for each bit." = 2 state changes per bit = Low to high, high to low = 2* 53 =106 #define RCSWITCH_MAX_CHANGES 106
  7. rc-switch/RCSwitch.h "(calculate to accommodate 64 bits)" void send(unsigned long long code, unsigned int length);Guaranteed by the C standard (ISO C99) to be at least 64 bits✓
  8. rc-switch/RCSwitch.cpp void RCSwitch::send(unsigned long long code, unsigned int length) {
  9. rc-switch/RCSwitch.h unsigned long long getReceivedValue();
  10. rc-switch/RCSwitch.h static unsigned long long nReceivedValue;This was line 142 in RCSwitch.h not line 170
  11. rc-switch/RCSwitch.cpp unsigned long long RCSwitch::getReceivedValue() {
  12. rc-switch/RCSwitch.cpp unsigned long long code = 0;
  13. rc-switch/RCSwitch.cpp unsigned long long RCSwitch::nReceivedValue = 0;