Skip to content
Snippets Groups Projects
RCSwitch.h 3.53 KiB
Newer Older
s.oezguer's avatar
s.oezguer committed
/*
  RCSwitch - Arduino libary for remote control outlet switches
  Copyright (c) 2011 Suat zgr.  All right reserved.
s.oezguer's avatar
s.oezguer committed
  - Andre Koehler / info(at)tomate-online(dot)de
  - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com
s.oezguer's avatar
s.oezguer committed
  
  Project home: http://code.google.com/p/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
s.oezguer's avatar
s.oezguer committed

s.oezguer's avatar
s.oezguer committed
#if defined(ARDUINO) && ARDUINO >= 100
s.oezguer's avatar
s.oezguer committed
    #include "Arduino.h"
s.oezguer's avatar
s.oezguer committed
#else
s.oezguer's avatar
s.oezguer committed
    #include "WProgram.h"
s.oezguer's avatar
s.oezguer committed
#endif
s.oezguer's avatar
s.oezguer committed
// 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
s.oezguer@googlemail.com's avatar
s.oezguer@googlemail.com committed
class RCSwitch {

  public:
    RCSwitch();
s.oezguer's avatar
s.oezguer committed
    
s.oezguer@googlemail.com's avatar
s.oezguer@googlemail.com committed
    void switchOn(int nGroupNumber, int nSwitchNumber);
    void switchOff(int nGroupNumber, int nSwitchNumber);
    void switchOn(char* sGroup, int nSwitchNumber);
    void switchOff(char* sGroup, int nSwitchNumber);
    void switchOn(char sFamily, int nGroup, int nDevice);
    void switchOff(char sFamily, int nGroup, int nDevice);
    void sendTriState(char* Code);
    void send(unsigned long Code, unsigned int length);
    void send(char* Code);
    
s.oezguer's avatar
s.oezguer committed
    void enableReceive(int interrupt);
    void enableReceive();
    void disableReceive();
s.oezguer's avatar
s.oezguer committed
    bool available();
	void resetAvailable();
	
s.oezguer's avatar
s.oezguer committed
    unsigned long getReceivedValue();
    unsigned int getReceivedBitlength();
    unsigned int getReceivedDelay();
s.oezguer's avatar
s.oezguer committed
	unsigned int getReceivedProtocol();
s.oezguer's avatar
s.oezguer committed
    unsigned int* getReceivedRawdata();
  
    void enableTransmit(int nTransmitterPin);
    void disableTransmit();
    void setPulseLength(int nPulseLength);
    void setRepeatTransmit(int nRepeatTransmit);
    void setReceiveTolerance(int nPercent);
s.oezguer's avatar
s.oezguer committed
	void setProtocol(int nProtocol);
	void setProtocol(int nProtocol, int nPulseLength);
s.oezguer@googlemail.com's avatar
s.oezguer@googlemail.com committed
  
  private:
    char* getCodeWordB(int nGroupNumber, int nSwitchNumber, boolean bStatus);
    char* getCodeWordA(char* sGroup, int nSwitchNumber, boolean bStatus);
    char* getCodeWordC(char sFamily, int nGroup, int nDevice, boolean bStatus);
    void sendT0();
    void sendT1();
    void sendTF();
s.oezguer@googlemail.com's avatar
s.oezguer@googlemail.com committed
    void send0();
    void send1();
    void sendSync();
    void transmit(int nHighPulses, int nLowPulses);
    static char* dec2binWzerofill(unsigned long dec, unsigned int length);
s.oezguer's avatar
s.oezguer committed
    static void handleInterrupt();
s.oezguer's avatar
s.oezguer committed
	static bool receiveProtocol1(unsigned int changeCount);
	static bool receiveProtocol2(unsigned int changeCount);
s.oezguer's avatar
s.oezguer committed
    int nReceiverInterrupt;
    int nTransmitterPin;
    int nPulseLength;
s.oezguer's avatar
s.oezguer committed
    int nRepeatTransmit;
s.oezguer's avatar
s.oezguer committed
	char nProtocol;
	static int nReceiveTolerance;
s.oezguer's avatar
s.oezguer committed
    static unsigned long nReceivedValue;
    static unsigned int nReceivedBitlength;
	static unsigned int nReceivedDelay;
s.oezguer's avatar
s.oezguer committed
	static unsigned int nReceivedProtocol;
s.oezguer's avatar
s.oezguer committed
    static unsigned int timings[RCSWITCH_MAX_CHANGES];
#endif