Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed RCSwitch library to use with 433MHz RF simple link kit #341

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
804 changes: 804 additions & 0 deletions Firmware/Source/v1.2/grove_pi_v1_2_7/RCSwitch.cpp

Large diffs are not rendered by default.

163 changes: 163 additions & 0 deletions Firmware/Source/v1.2/grove_pi_v1_2_7/RCSwitch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
RCSwitch - Arduino libary for remote control outlet switches
Copyright (c) 2011 Suat Özgür. All right reserved.

Contributors:
- Andre Koehler / info(at)tomate-online(dot)de
- Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
- Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46
- Dominik Fischer / dom_fischer(at)web(dot)de
- Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com
- Max Horn / max(at)quendi(dot)de
- Robert ter Vehn / <first name>.<last name>(at)gmail(dot)com

Project home: https://github.com/sui77/rc-switch/

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _RCSwitch_h
#define _RCSwitch_h


#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#elif defined(ENERGIA) // LaunchPad, FraunchPad and StellarPad specific
#include "Energia.h"
#elif defined(RPI) // Raspberry Pi
#define RaspberryPi

// Include libraries for RPi:
#include <string.h> /* memcpy */
#include <stdlib.h> /* abs */
#include <wiringPi.h>
#else
#include "WProgram.h"
#endif

#include <stdint.h>


// At least for the ATTiny X4/X5, receiving has to be disabled due to
// missing libm depencies (udivmodhi4)
#if defined( __AVR_ATtinyX5__ ) or defined ( __AVR_ATtinyX4__ )
#define RCSwitchDisableReceiving
#endif

// Number of maximum High/Low changes per packet.
// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
#define RCSWITCH_MAX_CHANGES 67

class RCSwitch {

public:
RCSwitch();

void switchOn(int nGroupNumber, int nSwitchNumber);
void switchOff(int nGroupNumber, int nSwitchNumber);
void switchOn(const char* sGroup, int nSwitchNumber);
void switchOff(const char* sGroup, int nSwitchNumber);
void switchOn(char sFamily, int nGroup, int nDevice);
void switchOff(char sFamily, int nGroup, int nDevice);
void switchOn(const char* sGroup, const char* sDevice);
void switchOff(const char* sGroup, const char* sDevice);
void switchOn(char sGroup, int nDevice);
void switchOff(char sGroup, int nDevice);
unsigned long switchOnCode(int nGroupNumber, int nSwitchNumber);
unsigned long switchOffCode(int nGroupNumber, int nSwitchNumber);
unsigned long switchOnCode(char sFamily, int nGroup, int nDevice);
unsigned long switchOffCode(char sFamily, int nGroup, int nDevice);
unsigned long switchOnCode(const char* sGroup, const char* sDevice);
unsigned long switchOffCode(const char* sGroup, const char* sDevice);
unsigned long switchOnCode(char sGroup, int nDevice);
unsigned long switchOffCode(char sGroup, int nDevice);

void sendTriState(const char* sCodeWord);
void send(unsigned long code, unsigned int length);
void send(const char* sCodeWord);

#if not defined( RCSwitchDisableReceiving )
void enableReceive(int interrupt);
void enableReceive();
void disableReceive();
bool available();
void resetAvailable();

unsigned long getReceivedValue();
unsigned int getReceivedBitlength();
unsigned int getReceivedDelay();
unsigned int getReceivedProtocol();
unsigned int* getReceivedRawdata();
#endif

void enableTransmit(int nTransmitterPin);
void disableTransmit();
void setPulseLength(int nPulseLength);
void setRepeatTransmit(int nRepeatTransmit);
#if not defined( RCSwitchDisableReceiving )
void setReceiveTolerance(int nPercent);
#endif

struct HighLow {
uint8_t high;
uint8_t low;
};

struct Protocol {
int pulseLength;
HighLow syncFactor;
HighLow zero;
HighLow one;
/** @brief if true inverts the high and low logic levels in the HighLow structs */
bool invertedSignal;
};

void setProtocol(Protocol protocol);
void setProtocol(int nProtocol);
void setProtocol(int nProtocol, int nPulseLength);

private:
char* getCodeWordA(const char* sGroup, const char* sDevice, bool bStatus);
char* getCodeWordB(int nGroupNumber, int nSwitchNumber, bool bStatus);
char* getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus);
char* getCodeWordD(char group, int nDevice, bool bStatus);
unsigned long getBitPattern(const char *sCodeWord);
void transmit(HighLow pulses);

#if not defined( RCSwitchDisableReceiving )
static void handleInterrupt();
static bool receiveProtocol(const int p, unsigned int changeCount);
int nReceiverInterrupt;
#endif
int nTransmitterPin;
int nRepeatTransmit;

Protocol protocol;

#if not defined( RCSwitchDisableReceiving )
static int nReceiveTolerance;
static unsigned long nReceivedValue;
static unsigned int nReceivedBitlength;
static unsigned int nReceivedDelay;
static unsigned int nReceivedProtocol;
const static unsigned int nSeparationLimit;
/*
* timings[0] contains sync timing, followed by a number of bits
*/
static unsigned int timings[RCSWITCH_MAX_CHANGES];
#endif

};

#endif
2 changes: 1 addition & 1 deletion Firmware/Source/v1.2/grove_pi_v1_2_7/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ I2C address: 0x4
| Chainable RGB set LEDs with modulo | 94 | pin | offset | divisor | _none_ | Set color on all LEDs >= offset when mod remainder is 0 |
| Chainable RGB set level | 95 | pin | level | reverse | _none_ | Set color on all LEDs <= level, outwards unless reverse |


### Library Dependencies

* [DHT](https://github.com/karan259/DHT-sensor-library)
Expand All @@ -91,3 +90,4 @@ I2C address: 0x4
* [Grove_LED_bar](https://github.com/Seeed-Studio/Grove_LED_Bar)
* [TM1637](https://github.com/mcauser/TM1637-led-driver-7-segment)
* [Chainable_RGB_LED](https://github.com/mcauser/Grove-Chainable-RGB-LED)
* [Modified version of RCSwitch](https://github.com/sui77/rc-switch)
Loading