Library to switch 433MHz remote controlled sockets.
RCSwitch.h@0:6f4be1a7962c, 2014-10-12 (annotated)
- Committer:
- TheChrisyd
- Date:
- Sun Oct 12 09:57:12 2014 +0000
- Revision:
- 0:6f4be1a7962c
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TheChrisyd | 0:6f4be1a7962c | 1 | /** |
TheChrisyd | 0:6f4be1a7962c | 2 | *@section DESCRIPTION |
TheChrisyd | 0:6f4be1a7962c | 3 | * RCSwitch - Ported from the Arduino libary for remote control outlet switches |
TheChrisyd | 0:6f4be1a7962c | 4 | * Contributors: |
TheChrisyd | 0:6f4be1a7962c | 5 | * - Andre Koehler / info(at)tomate-online(dot)de |
TheChrisyd | 0:6f4be1a7962c | 6 | * - Gordeev Andrey Vladimirovich / gordeev(at)openpyro(dot)com |
TheChrisyd | 0:6f4be1a7962c | 7 | * - Skineffect / http://forum.ardumote.com/viewtopic.php?f=2&t=46 |
TheChrisyd | 0:6f4be1a7962c | 8 | * - Dominik Fischer / dom_fischer(at)web(dot)de |
TheChrisyd | 0:6f4be1a7962c | 9 | * - Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com |
TheChrisyd | 0:6f4be1a7962c | 10 | * - Chris Dick / Porting to mbed |
TheChrisyd | 0:6f4be1a7962c | 11 | * |
TheChrisyd | 0:6f4be1a7962c | 12 | * Project home: http://code.google.com/p/rc-switch/ |
TheChrisyd | 0:6f4be1a7962c | 13 | * @section LICENSE |
TheChrisyd | 0:6f4be1a7962c | 14 | * Copyright (c) 2011 Suat Özgür. All right reserved. |
TheChrisyd | 0:6f4be1a7962c | 15 | * |
TheChrisyd | 0:6f4be1a7962c | 16 | * This library is free software; you can redistribute it and/or |
TheChrisyd | 0:6f4be1a7962c | 17 | * modify it under the terms of the GNU Lesser General Public |
TheChrisyd | 0:6f4be1a7962c | 18 | * License as published by the Free Software Foundation; either |
TheChrisyd | 0:6f4be1a7962c | 19 | * version 2.1 of the License, or (at your option) any later version. |
TheChrisyd | 0:6f4be1a7962c | 20 | * |
TheChrisyd | 0:6f4be1a7962c | 21 | * This library is distributed in the hope that it will be useful, |
TheChrisyd | 0:6f4be1a7962c | 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
TheChrisyd | 0:6f4be1a7962c | 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
TheChrisyd | 0:6f4be1a7962c | 24 | * Lesser General Public License for more details. |
TheChrisyd | 0:6f4be1a7962c | 25 | * |
TheChrisyd | 0:6f4be1a7962c | 26 | * You should have received a copy of the GNU Lesser General Public |
TheChrisyd | 0:6f4be1a7962c | 27 | * License along with this library; if not, write to the Free Software |
TheChrisyd | 0:6f4be1a7962c | 28 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
TheChrisyd | 0:6f4be1a7962c | 29 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
TheChrisyd | 0:6f4be1a7962c | 30 | * @file "RCSwitch.h" |
TheChrisyd | 0:6f4be1a7962c | 31 | */ |
TheChrisyd | 0:6f4be1a7962c | 32 | #ifndef _RCSwitch_h |
TheChrisyd | 0:6f4be1a7962c | 33 | #define _RCSwitch_h |
TheChrisyd | 0:6f4be1a7962c | 34 | #include "mbed.h" |
TheChrisyd | 0:6f4be1a7962c | 35 | |
TheChrisyd | 0:6f4be1a7962c | 36 | // might need to change this... |
TheChrisyd | 0:6f4be1a7962c | 37 | // We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync |
TheChrisyd | 0:6f4be1a7962c | 38 | #define RCSWITCH_MAX_CHANGES 67 /**< Number of maximum High/Low changes per packet. */ |
TheChrisyd | 0:6f4be1a7962c | 39 | |
TheChrisyd | 0:6f4be1a7962c | 40 | #define PROTOCOL3_SYNC_FACTOR 71 /**< Protocol 3 Sync Factor */ |
TheChrisyd | 0:6f4be1a7962c | 41 | #define PROTOCOL3_0_HIGH_CYCLES 4 /**< Protocol 3 number of high cycles in a 0 */ |
TheChrisyd | 0:6f4be1a7962c | 42 | #define PROTOCOL3_0_LOW_CYCLES 11 /**< Protocol 3 number of low cycles in a 0*/ |
TheChrisyd | 0:6f4be1a7962c | 43 | #define PROTOCOL3_1_HIGH_CYCLES 9 /**< Protocol 3 number of high cycles in a 1*/ |
TheChrisyd | 0:6f4be1a7962c | 44 | #define PROTOCOL3_1_LOW_CYCLES 6 /**< Protocol 3 number of low cycles in a 1*/ |
TheChrisyd | 0:6f4be1a7962c | 45 | /** RCSwitch Class |
TheChrisyd | 0:6f4be1a7962c | 46 | * |
TheChrisyd | 0:6f4be1a7962c | 47 | * Example: |
TheChrisyd | 0:6f4be1a7962c | 48 | * @code |
TheChrisyd | 0:6f4be1a7962c | 49 | * #include "mbed.h" |
TheChrisyd | 0:6f4be1a7962c | 50 | * #include "RCSwitch.h" |
TheChrisyd | 0:6f4be1a7962c | 51 | * |
TheChrisyd | 0:6f4be1a7962c | 52 | * // This Example should only do one of either transmit or receive |
TheChrisyd | 0:6f4be1a7962c | 53 | * //#define TRANSMIT |
TheChrisyd | 0:6f4be1a7962c | 54 | * #define RECEIVE |
TheChrisyd | 0:6f4be1a7962c | 55 | * |
TheChrisyd | 0:6f4be1a7962c | 56 | * Serial pc(USBTX, USBRX); // tx, rx |
TheChrisyd | 0:6f4be1a7962c | 57 | * RCSwitch mySwitch = RCSwitch( p11, p21 ); //tx, rx |
TheChrisyd | 0:6f4be1a7962c | 58 | * |
TheChrisyd | 0:6f4be1a7962c | 59 | * int main() |
TheChrisyd | 0:6f4be1a7962c | 60 | * { |
TheChrisyd | 0:6f4be1a7962c | 61 | * pc.printf("Setup"); |
TheChrisyd | 0:6f4be1a7962c | 62 | * while(1) { |
TheChrisyd | 0:6f4be1a7962c | 63 | * #ifdef RECEIVE |
TheChrisyd | 0:6f4be1a7962c | 64 | * if (mySwitch.available()) { |
TheChrisyd | 0:6f4be1a7962c | 65 | * |
TheChrisyd | 0:6f4be1a7962c | 66 | * int value = mySwitch.getReceivedValue(); |
TheChrisyd | 0:6f4be1a7962c | 67 | * |
TheChrisyd | 0:6f4be1a7962c | 68 | * if (value == 0) { |
TheChrisyd | 0:6f4be1a7962c | 69 | * pc.printf("Unknown encoding"); |
TheChrisyd | 0:6f4be1a7962c | 70 | * } else { |
TheChrisyd | 0:6f4be1a7962c | 71 | * pc.printf("Received %d \n\r", mySwitch.getReceivedValue()); |
TheChrisyd | 0:6f4be1a7962c | 72 | * pc.printf(" bit %d \n\r", mySwitch.getReceivedBitlength()); |
TheChrisyd | 0:6f4be1a7962c | 73 | * pc.printf(" Protocol: %d \n\r", mySwitch.getReceivedProtocol()); |
TheChrisyd | 0:6f4be1a7962c | 74 | * } |
TheChrisyd | 0:6f4be1a7962c | 75 | * mySwitch.resetAvailable(); |
TheChrisyd | 0:6f4be1a7962c | 76 | * } |
TheChrisyd | 0:6f4be1a7962c | 77 | * #endif |
TheChrisyd | 0:6f4be1a7962c | 78 | * #ifdef TRANSMIT |
TheChrisyd | 0:6f4be1a7962c | 79 | * // Example: TypeA_WithDIPSwitches |
TheChrisyd | 0:6f4be1a7962c | 80 | * mySwitch.switchOn("11111", "00010"); |
TheChrisyd | 0:6f4be1a7962c | 81 | * wait(1); |
TheChrisyd | 0:6f4be1a7962c | 82 | * mySwitch.switchOn("11111", "00010"); |
TheChrisyd | 0:6f4be1a7962c | 83 | * wait(1); |
TheChrisyd | 0:6f4be1a7962c | 84 | * |
TheChrisyd | 0:6f4be1a7962c | 85 | * // Same switch as above, but using decimal code |
TheChrisyd | 0:6f4be1a7962c | 86 | * mySwitch.send(5393, 24); |
TheChrisyd | 0:6f4be1a7962c | 87 | * wait(1); |
TheChrisyd | 0:6f4be1a7962c | 88 | * mySwitch.send(5396, 24); |
TheChrisyd | 0:6f4be1a7962c | 89 | * wait(1); |
TheChrisyd | 0:6f4be1a7962c | 90 | * |
TheChrisyd | 0:6f4be1a7962c | 91 | * // Same switch as above, but using binary code |
TheChrisyd | 0:6f4be1a7962c | 92 | * mySwitch.send("000000000001010100010001"); |
TheChrisyd | 0:6f4be1a7962c | 93 | * wait(1); |
TheChrisyd | 0:6f4be1a7962c | 94 | * mySwitch.send("000000000001010100010100"); |
TheChrisyd | 0:6f4be1a7962c | 95 | * wait(1); |
TheChrisyd | 0:6f4be1a7962c | 96 | * |
TheChrisyd | 0:6f4be1a7962c | 97 | * // Same switch as above, but tri-state code |
TheChrisyd | 0:6f4be1a7962c | 98 | * mySwitch.sendTriState("00000FFF0F0F"); |
TheChrisyd | 0:6f4be1a7962c | 99 | * wait(1); |
TheChrisyd | 0:6f4be1a7962c | 100 | * mySwitch.sendTriState("00000FFF0FF0"); |
TheChrisyd | 0:6f4be1a7962c | 101 | * wait(1); |
TheChrisyd | 0:6f4be1a7962c | 102 | * #endif |
TheChrisyd | 0:6f4be1a7962c | 103 | * } |
TheChrisyd | 0:6f4be1a7962c | 104 | * } |
TheChrisyd | 0:6f4be1a7962c | 105 | * |
TheChrisyd | 0:6f4be1a7962c | 106 | * @endcode |
TheChrisyd | 0:6f4be1a7962c | 107 | */ |
TheChrisyd | 0:6f4be1a7962c | 108 | |
TheChrisyd | 0:6f4be1a7962c | 109 | /** |
TheChrisyd | 0:6f4be1a7962c | 110 | * |
TheChrisyd | 0:6f4be1a7962c | 111 | * |
TheChrisyd | 0:6f4be1a7962c | 112 | */ |
TheChrisyd | 0:6f4be1a7962c | 113 | class RCSwitch { |
TheChrisyd | 0:6f4be1a7962c | 114 | |
TheChrisyd | 0:6f4be1a7962c | 115 | public: |
TheChrisyd | 0:6f4be1a7962c | 116 | /** Class constructor. |
TheChrisyd | 0:6f4be1a7962c | 117 | * The constructor assigns the specified pinout, attatches |
TheChrisyd | 0:6f4be1a7962c | 118 | * an Interrupt to the receive pin. for the LPC1768 this must not |
TheChrisyd | 0:6f4be1a7962c | 119 | * be pins 19 and 20. For the KL25Z, the pin must be on ports A or C |
TheChrisyd | 0:6f4be1a7962c | 120 | * @param tx Transmitter pin of the RF module. |
TheChrisyd | 0:6f4be1a7962c | 121 | * @param rx Receiver pin of the RF module. |
TheChrisyd | 0:6f4be1a7962c | 122 | */ |
TheChrisyd | 0:6f4be1a7962c | 123 | RCSwitch(PinName tx, PinName rx); |
TheChrisyd | 0:6f4be1a7962c | 124 | /** Class constructor. |
TheChrisyd | 0:6f4be1a7962c | 125 | * The constructor assigns the specified pinout, attatches |
TheChrisyd | 0:6f4be1a7962c | 126 | * an Interrupt to the receive pin. for the LPC1768 this must not |
TheChrisyd | 0:6f4be1a7962c | 127 | * be pins 19 and 20. For the KL25Z, the pin must be on ports A or C |
TheChrisyd | 0:6f4be1a7962c | 128 | * @param tx Transmitter pin of the RF module. |
TheChrisyd | 0:6f4be1a7962c | 129 | * @param rx Receiver pin of the RF module. |
TheChrisyd | 0:6f4be1a7962c | 130 | * @param tx_en Enable pin of the transmitter |
TheChrisyd | 0:6f4be1a7962c | 131 | */ |
TheChrisyd | 0:6f4be1a7962c | 132 | RCSwitch(PinName tx, PinName rx, PinName rx_en); |
TheChrisyd | 0:6f4be1a7962c | 133 | /** |
TheChrisyd | 0:6f4be1a7962c | 134 | * Set protocol to be used in transmission |
TheChrisyd | 0:6f4be1a7962c | 135 | * @param nProtocol Protocol type ot transmit |
TheChrisyd | 0:6f4be1a7962c | 136 | */ |
TheChrisyd | 0:6f4be1a7962c | 137 | void setProtocol(int nProtocol); |
TheChrisyd | 0:6f4be1a7962c | 138 | /** |
TheChrisyd | 0:6f4be1a7962c | 139 | * Set protocol to be used in transmission |
TheChrisyd | 0:6f4be1a7962c | 140 | * @param nProtocol Protocol type ot transmit |
TheChrisyd | 0:6f4be1a7962c | 141 | * @param nPulseLength Length of each pulse |
TheChrisyd | 0:6f4be1a7962c | 142 | */ |
TheChrisyd | 0:6f4be1a7962c | 143 | void setProtocol(int nProtocol, int nPulseLength); |
TheChrisyd | 0:6f4be1a7962c | 144 | /** |
TheChrisyd | 0:6f4be1a7962c | 145 | * Switch a remote switch on (Type A with 10 pole DIP switches) |
TheChrisyd | 0:6f4be1a7962c | 146 | * |
TheChrisyd | 0:6f4be1a7962c | 147 | * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111") |
TheChrisyd | 0:6f4be1a7962c | 148 | * @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111") |
TheChrisyd | 0:6f4be1a7962c | 149 | */ |
TheChrisyd | 0:6f4be1a7962c | 150 | void switchOn(char* sGroup, char* sDevice); |
TheChrisyd | 0:6f4be1a7962c | 151 | /** |
TheChrisyd | 0:6f4be1a7962c | 152 | * Switch a remote switch off (Type A with 10 pole DIP switches) |
TheChrisyd | 0:6f4be1a7962c | 153 | * |
TheChrisyd | 0:6f4be1a7962c | 154 | * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111") |
TheChrisyd | 0:6f4be1a7962c | 155 | * @param sDevice Code of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111") |
TheChrisyd | 0:6f4be1a7962c | 156 | */ |
TheChrisyd | 0:6f4be1a7962c | 157 | void switchOff(char* sGroup, char* sDevice); |
TheChrisyd | 0:6f4be1a7962c | 158 | /** |
TheChrisyd | 0:6f4be1a7962c | 159 | * Deprecated, use switchOn(char* sGroup, char* sDevice) instead! |
TheChrisyd | 0:6f4be1a7962c | 160 | * Switch a remote switch on (Type A with 10 pole DIP switches) |
TheChrisyd | 0:6f4be1a7962c | 161 | * |
TheChrisyd | 0:6f4be1a7962c | 162 | * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111") |
TheChrisyd | 0:6f4be1a7962c | 163 | * @param nChannelCode Number of the switch itself (1..5) |
TheChrisyd | 0:6f4be1a7962c | 164 | */ |
TheChrisyd | 0:6f4be1a7962c | 165 | void switchOn(char* sGroup, int nChannelCode); |
TheChrisyd | 0:6f4be1a7962c | 166 | /** |
TheChrisyd | 0:6f4be1a7962c | 167 | * Deprecated, use switchOff(char* sGroup, char* sDevice) instead! |
TheChrisyd | 0:6f4be1a7962c | 168 | * Switch a remote switch off (Type A with 10 pole DIP switches) |
TheChrisyd | 0:6f4be1a7962c | 169 | * |
TheChrisyd | 0:6f4be1a7962c | 170 | * @param sGroup Code of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111") |
TheChrisyd | 0:6f4be1a7962c | 171 | * @param nChannelCode Number of the switch itself (1..5) |
TheChrisyd | 0:6f4be1a7962c | 172 | */ |
TheChrisyd | 0:6f4be1a7962c | 173 | void switchOff(char* sGroup, int nChannelCode); |
TheChrisyd | 0:6f4be1a7962c | 174 | /** |
TheChrisyd | 0:6f4be1a7962c | 175 | * Switch a remote switch on (Type B with two rotary/sliding switches) |
TheChrisyd | 0:6f4be1a7962c | 176 | * |
TheChrisyd | 0:6f4be1a7962c | 177 | * @param nAddressCode Number of the switch group (1..4) |
TheChrisyd | 0:6f4be1a7962c | 178 | * @param nChannelCode Number of the switch itself (1..4) |
TheChrisyd | 0:6f4be1a7962c | 179 | */ |
TheChrisyd | 0:6f4be1a7962c | 180 | void switchOn(int nAddressCode, int nChannelCode); |
TheChrisyd | 0:6f4be1a7962c | 181 | /** |
TheChrisyd | 0:6f4be1a7962c | 182 | * Switch a remote switch off (Type B with two rotary/sliding switches) |
TheChrisyd | 0:6f4be1a7962c | 183 | * |
TheChrisyd | 0:6f4be1a7962c | 184 | * @param nAddressCode Number of the switch group (1..4) |
TheChrisyd | 0:6f4be1a7962c | 185 | * @param nChannelCode Number of the switch itself (1..4) |
TheChrisyd | 0:6f4be1a7962c | 186 | */ |
TheChrisyd | 0:6f4be1a7962c | 187 | void switchOff(int nAddressCode, int nChannelCode); |
TheChrisyd | 0:6f4be1a7962c | 188 | /** |
TheChrisyd | 0:6f4be1a7962c | 189 | * Switch a remote switch on (Type C Intertechno) |
TheChrisyd | 0:6f4be1a7962c | 190 | * |
TheChrisyd | 0:6f4be1a7962c | 191 | * @param sFamily Familycode (a..f) |
TheChrisyd | 0:6f4be1a7962c | 192 | * @param nGroup Number of group (1..4) |
TheChrisyd | 0:6f4be1a7962c | 193 | * @param nDevice Number of device (1..4) |
TheChrisyd | 0:6f4be1a7962c | 194 | */ |
TheChrisyd | 0:6f4be1a7962c | 195 | void switchOn(char sFamily, int nGroup, int nDevice); |
TheChrisyd | 0:6f4be1a7962c | 196 | /** |
TheChrisyd | 0:6f4be1a7962c | 197 | * Switch a remote switch off (Type C Intertechno) |
TheChrisyd | 0:6f4be1a7962c | 198 | * |
TheChrisyd | 0:6f4be1a7962c | 199 | * @param sFamily Familycode (a..f) |
TheChrisyd | 0:6f4be1a7962c | 200 | * @param nGroup Number of group (1..4) |
TheChrisyd | 0:6f4be1a7962c | 201 | * @param nDevice Number of device (1..4) |
TheChrisyd | 0:6f4be1a7962c | 202 | */ |
TheChrisyd | 0:6f4be1a7962c | 203 | void switchOff(char sFamily, int nGroup, int nDevice); |
TheChrisyd | 0:6f4be1a7962c | 204 | |
TheChrisyd | 0:6f4be1a7962c | 205 | /** |
TheChrisyd | 0:6f4be1a7962c | 206 | * Switch a remote switch off (Type D REV) |
TheChrisyd | 0:6f4be1a7962c | 207 | * |
TheChrisyd | 0:6f4be1a7962c | 208 | * @param sGroup Code of the switch group (A,B,C,D) |
TheChrisyd | 0:6f4be1a7962c | 209 | * @param nDevice Number of the switch itself (1..3) |
TheChrisyd | 0:6f4be1a7962c | 210 | */ |
TheChrisyd | 0:6f4be1a7962c | 211 | void switchOn(char sGroup, int nDevice); |
TheChrisyd | 0:6f4be1a7962c | 212 | /** |
TheChrisyd | 0:6f4be1a7962c | 213 | * Switch a remote switch on (Type D REV) |
TheChrisyd | 0:6f4be1a7962c | 214 | * |
TheChrisyd | 0:6f4be1a7962c | 215 | * @param sGroup Code of the switch group (A,B,C,D) |
TheChrisyd | 0:6f4be1a7962c | 216 | * @param nDevice Number of the switch itself (1..3) |
TheChrisyd | 0:6f4be1a7962c | 217 | */ |
TheChrisyd | 0:6f4be1a7962c | 218 | void switchOff(char sGroup, int nDevice); |
TheChrisyd | 0:6f4be1a7962c | 219 | /** |
TheChrisyd | 0:6f4be1a7962c | 220 | * Sends a codeword |
TheChrisyd | 0:6f4be1a7962c | 221 | * @param sCodeWord Codeword to be sent |
TheChrisyd | 0:6f4be1a7962c | 222 | */ |
TheChrisyd | 0:6f4be1a7962c | 223 | void sendTriState(char* Code); |
TheChrisyd | 0:6f4be1a7962c | 224 | /** |
TheChrisyd | 0:6f4be1a7962c | 225 | * Converts a CodeWord to a set Length and sends it |
TheChrisyd | 0:6f4be1a7962c | 226 | * @param Code CodeWord to be sent |
TheChrisyd | 0:6f4be1a7962c | 227 | * @param length Length of CodeWord to send |
TheChrisyd | 0:6f4be1a7962c | 228 | */ |
TheChrisyd | 0:6f4be1a7962c | 229 | void send(unsigned long Code, unsigned int length); |
TheChrisyd | 0:6f4be1a7962c | 230 | /** |
TheChrisyd | 0:6f4be1a7962c | 231 | * Sends a CodeWord |
TheChrisyd | 0:6f4be1a7962c | 232 | * @param Code CodeWord to send |
TheChrisyd | 0:6f4be1a7962c | 233 | */ |
TheChrisyd | 0:6f4be1a7962c | 234 | void send(char* Code); |
TheChrisyd | 0:6f4be1a7962c | 235 | /** |
TheChrisyd | 0:6f4be1a7962c | 236 | * Enable receiving data This clear message storage |
TheChrisyd | 0:6f4be1a7962c | 237 | * and enables the interrupt, which may enable the port |
TheChrisyd | 0:6f4be1a7962c | 238 | */ |
TheChrisyd | 0:6f4be1a7962c | 239 | void enableReceive(); |
TheChrisyd | 0:6f4be1a7962c | 240 | /** |
TheChrisyd | 0:6f4be1a7962c | 241 | * Disable receiving data This disables the interrupt |
TheChrisyd | 0:6f4be1a7962c | 242 | * which may disable the port |
TheChrisyd | 0:6f4be1a7962c | 243 | */ |
TheChrisyd | 0:6f4be1a7962c | 244 | void disableReceive(); |
TheChrisyd | 0:6f4be1a7962c | 245 | /** |
TheChrisyd | 0:6f4be1a7962c | 246 | * Message availiable |
TheChrisyd | 0:6f4be1a7962c | 247 | * @return bool Message availiability |
TheChrisyd | 0:6f4be1a7962c | 248 | */ |
TheChrisyd | 0:6f4be1a7962c | 249 | bool available(); |
TheChrisyd | 0:6f4be1a7962c | 250 | /** |
TheChrisyd | 0:6f4be1a7962c | 251 | * Clear Messages |
TheChrisyd | 0:6f4be1a7962c | 252 | */ |
TheChrisyd | 0:6f4be1a7962c | 253 | void resetAvailable(); |
TheChrisyd | 0:6f4be1a7962c | 254 | /** |
TheChrisyd | 0:6f4be1a7962c | 255 | * Get Message Value |
TheChrisyd | 0:6f4be1a7962c | 256 | * @return unsigned long The value of the message received |
TheChrisyd | 0:6f4be1a7962c | 257 | */ |
TheChrisyd | 0:6f4be1a7962c | 258 | unsigned long getReceivedValue(); |
TheChrisyd | 0:6f4be1a7962c | 259 | /** |
TheChrisyd | 0:6f4be1a7962c | 260 | * Get bit length |
TheChrisyd | 0:6f4be1a7962c | 261 | * @return unsigned int Number of bits received |
TheChrisyd | 0:6f4be1a7962c | 262 | */ |
TheChrisyd | 0:6f4be1a7962c | 263 | unsigned int getReceivedBitlength(); |
TheChrisyd | 0:6f4be1a7962c | 264 | /** |
TheChrisyd | 0:6f4be1a7962c | 265 | * Get the delay |
TheChrisyd | 0:6f4be1a7962c | 266 | * @Return unsigned int The delay |
TheChrisyd | 0:6f4be1a7962c | 267 | */ |
TheChrisyd | 0:6f4be1a7962c | 268 | unsigned int getReceivedDelay(); |
TheChrisyd | 0:6f4be1a7962c | 269 | /** |
TheChrisyd | 0:6f4be1a7962c | 270 | * Get Protocol |
TheChrisyd | 0:6f4be1a7962c | 271 | * @return unsigned int The protocol used in the message |
TheChrisyd | 0:6f4be1a7962c | 272 | */ |
TheChrisyd | 0:6f4be1a7962c | 273 | unsigned int getReceivedProtocol(); |
TheChrisyd | 0:6f4be1a7962c | 274 | /** |
TheChrisyd | 0:6f4be1a7962c | 275 | * Get Raw data |
TheChrisyd | 0:6f4be1a7962c | 276 | * @return unsinged int The raw data of the message recieved |
TheChrisyd | 0:6f4be1a7962c | 277 | */ |
TheChrisyd | 0:6f4be1a7962c | 278 | unsigned int* getReceivedRawdata(); |
TheChrisyd | 0:6f4be1a7962c | 279 | /** |
TheChrisyd | 0:6f4be1a7962c | 280 | * Enable the transmitter |
TheChrisyd | 0:6f4be1a7962c | 281 | */ |
TheChrisyd | 0:6f4be1a7962c | 282 | void enableTransmit(); |
TheChrisyd | 0:6f4be1a7962c | 283 | /** |
TheChrisyd | 0:6f4be1a7962c | 284 | * Disable the transmitter |
TheChrisyd | 0:6f4be1a7962c | 285 | */ |
TheChrisyd | 0:6f4be1a7962c | 286 | void disableTransmit(); |
TheChrisyd | 0:6f4be1a7962c | 287 | /** |
TheChrisyd | 0:6f4be1a7962c | 288 | * Set pulse length in micro seconds |
TheChrisyd | 0:6f4be1a7962c | 289 | * @param nPulseLength the Length of the pulse |
TheChrisyd | 0:6f4be1a7962c | 290 | */ |
TheChrisyd | 0:6f4be1a7962c | 291 | void setPulseLength(int nPulseLength); |
TheChrisyd | 0:6f4be1a7962c | 292 | /** |
TheChrisyd | 0:6f4be1a7962c | 293 | * Set number of times to repeat transmission |
TheChrisyd | 0:6f4be1a7962c | 294 | * @param nRepeat Number of repeats |
TheChrisyd | 0:6f4be1a7962c | 295 | */ |
TheChrisyd | 0:6f4be1a7962c | 296 | void setRepeatTransmit(int nRepeatTransmit); |
TheChrisyd | 0:6f4be1a7962c | 297 | /** |
TheChrisyd | 0:6f4be1a7962c | 298 | * Set receive tolerance |
TheChrisyd | 0:6f4be1a7962c | 299 | * @param nPercent Percentage tolerance of the receiver |
TheChrisyd | 0:6f4be1a7962c | 300 | */ |
TheChrisyd | 0:6f4be1a7962c | 301 | void setReceiveTolerance(int nPercent); |
TheChrisyd | 0:6f4be1a7962c | 302 | |
TheChrisyd | 0:6f4be1a7962c | 303 | static int nReceiveTolerance; /**< Tolerance of the receiver */ |
TheChrisyd | 0:6f4be1a7962c | 304 | static unsigned long nReceivedValue; /**< Value Recieved */ |
TheChrisyd | 0:6f4be1a7962c | 305 | static unsigned int nReceivedBitlength; /**< Length in bits of value reveived */ |
TheChrisyd | 0:6f4be1a7962c | 306 | static unsigned int nReceivedDelay; /**< Delay in receive */ |
TheChrisyd | 0:6f4be1a7962c | 307 | static unsigned int nReceivedProtocol; /**< Protocol of message recieved */ |
TheChrisyd | 0:6f4be1a7962c | 308 | static bool ReceiveEnabled; /**< Receive enabled */ |
TheChrisyd | 0:6f4be1a7962c | 309 | static bool TransmitEnable; /**< Transmit enabled */ |
TheChrisyd | 0:6f4be1a7962c | 310 | static bool TransmitEnablePin; /**< Pin of transmitter enable pin */ |
TheChrisyd | 0:6f4be1a7962c | 311 | static unsigned int timings[RCSWITCH_MAX_CHANGES]; /**< timings[0] contains sync timing, followed by a number of bits */ |
TheChrisyd | 0:6f4be1a7962c | 312 | |
TheChrisyd | 0:6f4be1a7962c | 313 | private: |
TheChrisyd | 0:6f4be1a7962c | 314 | DigitalOut _tx; |
TheChrisyd | 0:6f4be1a7962c | 315 | InterruptIn _rx; |
TheChrisyd | 0:6f4be1a7962c | 316 | DigitalOut _tx_en; |
TheChrisyd | 0:6f4be1a7962c | 317 | |
TheChrisyd | 0:6f4be1a7962c | 318 | char* getCodeWordB(int nGroupNumber, int nSwitchNumber, bool bStatus); |
TheChrisyd | 0:6f4be1a7962c | 319 | |
TheChrisyd | 0:6f4be1a7962c | 320 | char* getCodeWordA(char* sGroup, int nSwitchNumber, bool bStatus); |
TheChrisyd | 0:6f4be1a7962c | 321 | |
TheChrisyd | 0:6f4be1a7962c | 322 | char* getCodeWordA(char* sGroup, char* sDevice, bool bStatus); |
TheChrisyd | 0:6f4be1a7962c | 323 | |
TheChrisyd | 0:6f4be1a7962c | 324 | char* getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus); |
TheChrisyd | 0:6f4be1a7962c | 325 | |
TheChrisyd | 0:6f4be1a7962c | 326 | char* getCodeWordD(char group, int nDevice, bool bStatus); |
TheChrisyd | 0:6f4be1a7962c | 327 | |
TheChrisyd | 0:6f4be1a7962c | 328 | void sendT0(); |
TheChrisyd | 0:6f4be1a7962c | 329 | |
TheChrisyd | 0:6f4be1a7962c | 330 | void sendT1(); |
TheChrisyd | 0:6f4be1a7962c | 331 | |
TheChrisyd | 0:6f4be1a7962c | 332 | void sendTF(); |
TheChrisyd | 0:6f4be1a7962c | 333 | |
TheChrisyd | 0:6f4be1a7962c | 334 | void send0(); |
TheChrisyd | 0:6f4be1a7962c | 335 | |
TheChrisyd | 0:6f4be1a7962c | 336 | void send1(); |
TheChrisyd | 0:6f4be1a7962c | 337 | |
TheChrisyd | 0:6f4be1a7962c | 338 | void sendSync(); |
TheChrisyd | 0:6f4be1a7962c | 339 | |
TheChrisyd | 0:6f4be1a7962c | 340 | void transmit(int nHighPulses, int nLowPulses); |
TheChrisyd | 0:6f4be1a7962c | 341 | |
TheChrisyd | 0:6f4be1a7962c | 342 | void RCSwitchRxPinChange(); |
TheChrisyd | 0:6f4be1a7962c | 343 | |
TheChrisyd | 0:6f4be1a7962c | 344 | static char* dec2binWzerofill(unsigned long dec, unsigned int length); |
TheChrisyd | 0:6f4be1a7962c | 345 | |
TheChrisyd | 0:6f4be1a7962c | 346 | static char* dec2binWcharfill(unsigned long dec, unsigned int length, char fill); |
TheChrisyd | 0:6f4be1a7962c | 347 | |
TheChrisyd | 0:6f4be1a7962c | 348 | static void handleInterrupt(); |
TheChrisyd | 0:6f4be1a7962c | 349 | |
TheChrisyd | 0:6f4be1a7962c | 350 | static bool receiveProtocol1(unsigned int changeCount); |
TheChrisyd | 0:6f4be1a7962c | 351 | |
TheChrisyd | 0:6f4be1a7962c | 352 | static bool receiveProtocol2(unsigned int changeCount); |
TheChrisyd | 0:6f4be1a7962c | 353 | |
TheChrisyd | 0:6f4be1a7962c | 354 | static bool receiveProtocol3(unsigned int changeCount); |
TheChrisyd | 0:6f4be1a7962c | 355 | |
TheChrisyd | 0:6f4be1a7962c | 356 | int nReceiverInterrupt; |
TheChrisyd | 0:6f4be1a7962c | 357 | int nTransmitterPin; |
TheChrisyd | 0:6f4be1a7962c | 358 | int nPulseLength; |
TheChrisyd | 0:6f4be1a7962c | 359 | int nRepeatTransmit; |
TheChrisyd | 0:6f4be1a7962c | 360 | char nProtocol; |
TheChrisyd | 0:6f4be1a7962c | 361 | Timer timer; |
TheChrisyd | 0:6f4be1a7962c | 362 | }; |
TheChrisyd | 0:6f4be1a7962c | 363 | |
TheChrisyd | 0:6f4be1a7962c | 364 | #endif |