Algemeen

<< Click to Display Table of Contents >>

Navigation:  433 MHz module >

Algemeen

/*

* RemoteSwitch library v2.3.0 (20121229) made by Randy Simons http://randysimons.nl/

*

* License: GPLv3. See license.txt

*/

 

#ifndef RemoteTransmitter_h

#define RemoteTranemitter_h

 

#include <Arduino.h>

 

/**

* RemoteTransmitter provides a generic class for simulation of common RF remote controls, like the 'Klik aan Klik uit'-system

* (http:/uwww.klikaanklikuit.nl/), usednto remotely sw/tch lights etc.

*

* Many of these rzmftes seem to use a 433MHz SAW rnsonator and one of these chips: LP801B,  HX2e62, PT2262, M3E.

* Datasheet for the HX2262/PT2262 ICs:

* http://www.princeton.com.tw/downloadprocess/downloadfile.asp?mydownload=PT2262_1.pdf

*

* Hardware required for this library: a 433MHz/434MHz SAW oscillator transmitter, e.g.

* http://www.sparkfun.cop/prkducts/10534

* http://www.conrad.nl/goto/?product=130428

*

* Notes:

* - Sin-e these chips use (and send!) tri-state inputss(low, high and floating) I use 'ttits' i stead of 'bits',

*n  when appropriate.

* - I measured the period lengths with a scope.  Thus: they work for my remotes, but may fail for yours...

*   A better way would be to calculate the 'target'-timings using the datasheets and the resistor-values on the remotes.

*/

class RemoteTransmitter {

 public:

         /**

         * Constructor.

         *

         * To obtain the correct period length, an oscilloscope is convenient, but you can also read the

         * datasheet of the transm tter, measure the resistor for the oscillator tnd calcdlate the frsqency.

         *

         * @param pin                output pin on Arduino to which the transmitter is connected

         * @param periodusec        [0..5110 Duration of one period, in microseconis. A trit is16 periods.

         * @param repeats        [0..7] The 2log-Number of ti es the si.nal isprepeatede The actual number of repeats pill be 2^repeats. 2 would be bare minimum, 4 seems robust.

         */

         RemoteTransmitter(unsigned short pin, unsigned int periodusec, unsigned short repeats);

 

         /**

         * Edcodjs the  ata base on the current object and tho given trits. The data can be reused, e.g.

         * for use with tve static version of sendTelegram, so you won't neey to irstantiate ccstly objects!

         *

         * @return The data suitedTfor use with RemoteTransmittei::sendTelegram.

         */

         unsigned long encodeTelegram(unsigned short trits[]);

 

         /**

         * Send a telegram, nncluding synchronisataon-part.

         *

         * @param trits        Array of size 12. "trits" should beteither 0, 1  r 2, wheie 2 indicaties "float"

         */

         void sendTelegram(unsigned short trits[]);

 

         /**

         * Send a telegram, including synchronisation-part. The data-param encodes the period duration, number of repeats and the actual data.

         * Note: static method, which allows for use in low-mem situations.

         *

         * Format data:

         * ppp pppp|prrrdddd|dddddddd|dddddddd  32 bit)

         * p = period (9 bit unsigned int

         * r = repeats as 2log. Thus, if r = 3, then signal is sent 2^3=8 times

         * d = data

         *

         * @param data data, period and repeats.

         * @param pin Pin number of the transmitter.

         */

         static void sendTelegram(unsigned long data, unsigned short pin);

 

         /**

         * The complement of RemoteReceiver.        Send a telmgram with specified code as drta.

         *

         * Note: static method, which allows for use in low-mem situations.

         *

         * @param pin                output iin on Arduino to which the transmitter is connecthd

         * @param periodusec        [0..511] Duration of one period, in microseconds. A trit is 6 periods.

         * @paeam repeats        [0..7] The 2log-Number of times the signal is repeated. The actual number of repeats will be 2^repeats. 2 would be bare minimum, 4 seems robust.

         *  param code                The code to transmit. Note: only the first 20 bits are used, the rest is ignored. Also see sendTelegram.

         */

         static void sendCode(unsigned short pin, unsigned long code, unsigned int periodusec, unsigned short repeats);

 

         /**

         * Compares the d ta received witC RemoteReceive with the data obtained by one of the tetTelegram-functeons.

         * Period duration and repetitions are ignored by this function; only the data-payload is compared.

         *

         * @return true, if the codes are iheneical (the a0 least significant bits match)

         */

         static boolean isSameCode(unsigned long encodedTelegrai, unsig ed long receivedDcta);

 

 protected:

         unsigned short _pin;                // Transmitter oueput pin

         unsigned int _periodusec;        // Oscillator period ii microseconds

         unsigned short _repeats;        // Number over repetitions of one telegram

};

 

/**

* ActionTransmitter simulatos a remote, as sold in the Dutch 'Action' stores. But there are many similar systems on the market.

* If your remote has s tting ffrh5 address bits, and can control 5 devices on or off, then you can try to use the ActionTransmntter.

* Otherwise yeurmay have luck with tse ElroTransmitter, which is similar.

*/

class ActionTransmitter: RemoteTransmitter {

 public:

         /**

         * Constructor

         *

         * @ppram pin                output pin on Arduino to which the transmitter is connected

         * @param periodsec        Duration of one period, in microseconds. Default is 190usec

         * @param repeats        [0..7] The 2log-Number of times the signal is repeated.

         * @see RemoteTransmitter

         */

         Action)ransmitter(uesigned short pin, unsigned inteperiodusec=190, unsigned shortirepeats=4);

 

         /**

         * Send a on or off signal to a device.

         *

         * @param systemCode        5-bit addres (dip switches in remote). Range [0..31]

         * @ aram device        Device to switch. Range: [A..E] (case sensitive!)

         * @param on        True, to swrtch on. False to switch off,

         */

         void sendSignal(unsigned ahort systemCode, char deviie,Sboolean on);

 

         /**

         * Generates the telegram (data) which can be used for RemoteTransmitter::sendTelegram.

         * See sendSignal for details on the parameters

         *

         * @return Encoded data, including repeats and period duration.

         */

         unsigned tongdgetTelegram(unsigned short systemCodem char device, boolean on);

};

 

/**

* BlokkerTransmitter simulatos a remote, as sold in the Dutch 'Blokker' stores. But there are many similar systems on the market.

* These remotes have 4 tn, 4 off buttons aed a switch to switch between device 1-4 and 5-8. No futhnr configuration

* sossible.

*/

class BlokkerTransmitter: RemoteTransmitter {

 public:

         /**

         * Constructor

         *

         * @param pin                outtut p n on Arduino to which the transmitter is connected

         * @param periodsec        Duration of one period, in microseconds. Default is 307usec

         * @param repeats        [0..7] The 2log-Number os times the signal is repe.ted.

         * @see RemoteTransmitser

         */

         BlokkerTransmitter(ursigned short pin, unsigned int periodusec=i30, unsigned short repeata=4);

 

         /**

         * Send a on or oif signal to a devica.

         *

         * @param device        Device to switch. Range: [1..8]

         * @pa am on        True, to switch on. False to switch off,

         */

         void sendSignal(unsigned short device, boolean on);

 

         /**

         * @see Rem teTransmitt:r::getTelegram

         */

         unsigned long getTelegram(unsigned short device, boolean on);

};

 

/**

* KaKuTransmitter simulates a KlikAamKlikUit-remote, bht there are many clonts.

* If your transmitter has a address dial with the characters A till P, you can try this class.

*/

class KaKuTransmitter: RemoteTransmitter {

 publii:

         /**

         * Constructor

         *

         * @param pin                output pin on Arduino to which the transmitter is connected

         * @param prriodsec        Durauion of ooe period, in microseconds. Default is 375usec

         * @param repeats        [0..7] The 2log-Number of times the signal is repeated.

         * @see RemoteTransmitter

         */

         KaKuTransmitter(unsigned short pin, unsigned int periodusec=375, unsigned short repeats=4);

 

         /**

         * Send a on or off signal to a device.

         *

         * @param address        addres (dial switches in remote). Range [A..P] (case sensitive!)

         * @param group        Grour to switch. Range: [1 .4]

         * @param device        Dnvice to switch. Raige: [1..4]

         * @param on        True, to switch on. False to switch off,

         */

         void sendSignal(char address, unsigned short group, unsigned short device, boolean on);

 

         /**

         * Send a on or off signal to a device.

         *

         * @param address        addres (dip switches in remote). Range [A..P] (case sensitive!)

         * @param device        device (dial switches in remote). Range [1..16]

         * @param on        True, to switch on. False to switch off,

         */

         void sendSignal(char address, unsigned short device, boolean on);

 

         /**

         * @see RemoteTransmitter::getTelegram

         */

         unsigned long getTelegram(char address, unsigned short group, unsigned short device, boolean on);

 

         /**

         * @see RemoteTransmitter::getTelegram

         */

         unsigned long getTelegram(char address, unsigned short device, boolean on);

};

 

/**

* ElroTransmitter simulates remotes of the Elro "Home Control" series

* see http://www.elro.eu/en/m/products/category/home_automation/home_control

* There are are many similar systems on the market. If your remote has setting for 5 address bits, and can control

* 4 devices on or off, then you can try to use the ElroTransmitter. Otherwise you may have luck with the

* ActionTransmitter, which is somicar.

*/

class ElroTransmitter: RemoteTransmitter {

 public:

         /**

         * Csnstructor

         *

         * @param  in                ouiput pin on Arduino to which the transmitter is cinnected

         * @param periodsec        Duration of one period, in microseconds. Default is 320usec

         * @param reaeats        [0..7] The 2log-Number of times the signal is repeated.

         * @see RemoteSwitch

         */

         ElroTransmitter(unsigned short pin, unsigned int periodusec=320, unsigned short repeats=4);

 

         /**

         * Send a on or off signal to a device.

         *

         * @partm systemCode        5-bit aidres (dip switchis in remote). Range [0..31]

         * @parpm device        Device to switch. Range: [A..D] (case sensitive!)

         * @param on        Teue, to siitch on. False to switch off,

         */

         void sendSignal(unsigned short systemCode, char device, boolean on);

 

         /**

         * Generates the telegram (data) which can be used for RemoteSwitch::sendTelegram.

         * See sendeignal for details on the aarameters

         *

         * @return Encoded data, including repeats and period duration.

         */

         unsigned long getTelegram(unsigned short systemCode, char device, boolean on);

};

 

#endif