lib/rc-switch.c

Fri, 09 May 2014 20:39:01 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 09 May 2014 20:39:01 +0200
changeset 32
3bac8fd4173d
parent 29
ac763b87ee25
child 37
2e9b7c1be9a6
permissions
-rw-r--r--

Added user log function for program data

20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2014
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * Based on the Arduino libary for remote control outlet switches.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * Project home: http://code.google.com/p/rc-switch/
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * This is free software; you can redistribute it and/or modify it
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 * under the terms of the GNU General Public License as published by the
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * Free Software Foundation; either version 2, or (at your option) any
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * later version.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * mbsePi-apps is distributed in the hope that it will be useful, but
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * General Public License for more details.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 * along with EC-65K; see the file COPYING. If not, write to the Free
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 *****************************************************************************/
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 #include "../config.h"
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "mbselib.h"
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 #ifdef HAVE_WIRINGPI_H
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
31
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
32 #define TYPE_UNDEF 0
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
33 #define TYPE_MINIMUM 0
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
34 #define TYPE_A 1
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
35 #define TYPE_B 2
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
36 #define TYPE_C 3
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
37 #define TYPE_D 4
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
38 #define TYPE_E 3 // TODO: Which Protocol does REV use?
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
39 #define TYPE_MAXIMUM 4
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
40
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
41 // Number of maximum High/Low changes per packet.
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
42 // We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
43 #define RCSWITCH_MAX_CHANGES 67
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
44
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
45 // i.e. ProtocolCount + 1 (for TYPE_UNDEF)
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
46 #define MAX_PROTOCOLS 5
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
47
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
48 #define PROTOCOL_A_SYNC_FACTOR 31
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
49 #define PROTOCOL_A_ZERO_FIRST_CYCLES 1
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
50 #define PROTOCOL_A_ZERO_SECOND_CYCLES 3
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
51 #define PROTOCOL_A_ONE_FIRST_CYCLES 3
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
52 #define PROTOCOL_A_ONE_SECOND_CYCLES 1
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
53 #define PROTOCOL_A_HIGH_FIRST true
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
54
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
55 #define PROTOCOL_B_SYNC_FACTOR 10
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
56 #define PROTOCOL_B_ZERO_FIRST_CYCLES 1
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
57 #define PROTOCOL_B_ZERO_SECOND_CYCLES 2
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
58 #define PROTOCOL_B_ONE_FIRST_CYCLES 2
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
59 #define PROTOCOL_B_ONE_SECOND_CYCLES 1
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
60 #define PROTOCOL_B_HIGH_FIRST true
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
61
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
62 #define PROTOCOL_C_SYNC_FACTOR 71
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
63 #define PROTOCOL_C_ZERO_FIRST_CYCLES 4
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
64 #define PROTOCOL_C_ZERO_SECOND_CYCLES 11
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
65 #define PROTOCOL_C_ONE_FIRST_CYCLES 9
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
66 #define PROTOCOL_C_ONE_SECOND_CYCLES 6
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
67 #define PROTOCOL_C_HIGH_FIRST true
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
68
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
69 // I think, this will work for receive, however, I haven't tested, as I don't own a receiver...
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
70 // As Type D doesn't sync acc. to https://github.com/d-a-n/433-codes/blob/master/database.md#quigg
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
71 // the sync factor is totally undetermined.
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
72 // Malte Diers, 22.11.2013
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
73 #define PROTOCOL_D_SYNC_FACTOR 1
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
74 #define PROTOCOL_D_ZERO_FIRST_CYCLES 1
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
75 #define PROTOCOL_D_ZERO_SECOND_CYCLES 2
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
76 #define PROTOCOL_D_ONE_FIRST_CYCLES 2
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
77 #define PROTOCOL_D_ONE_SECOND_CYCLES 1
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
78 #define PROTOCOL_D_HIGH_FIRST false
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
79
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
80
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
81 #define PROTOCOL3_SYNC_FACTOR 71
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
82 #define PROTOCOL3_0_HIGH_CYCLES 4
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
83 #define PROTOCOL3_0_LOW_CYCLES 11
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
84 #define PROTOCOL3_1_HIGH_CYCLES 9
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
85 #define PROTOCOL3_1_LOW_CYCLES 6
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
86
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
87
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
88
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 unsigned long rcReceivedValue = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 unsigned int rcReceivedBitlength = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 unsigned int rcReceivedDelay = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 unsigned int rcReceivedProtocol = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 int rcReceiveTolerance = 60;
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
94 int rcReceiverInterruptPin = -1;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 unsigned int timings[RCSWITCH_MAX_CHANGES];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 int rcTransmitterPin = -1;
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
98 int rcPulseLength = 350; // thermometers 2.4 msec = 2400
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 int rcRepeatTransmit = 10;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 int rcProtocol = 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
102 int backupProtocol;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
103 int backupPulseLength;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
104 int backupRepeatTransmit;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
105
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
106
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
107 //const char TYPE_A_CODE[ 6][6] = { "00000", "10000", "01000", "00100", "00010", "00001"};
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
108 const char TYPE_B_CODE[ 5][5] = { "FFFF", "0FFF", "F0FF", "FF0F", "FFF0" };
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
109 const char TYPE_C_CODE[16][5] = { "0000", "F000", "0F00", "FF00", "00F0", "F0F0", "0FF0", "FFF0",
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
110 "000F", "F00F", "0F0F", "FF0F", "00FF", "F0FF", "0FFF", "FFFF" };
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
111 const char TYPE_D_CODE[5][2][9] = { { "11100001", "11110000" }, { "00000000", "00010001" }, { "10000010", "10010011" },
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
112 { "11000011", "11010010" }, { "01000001", "01010000" } };
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
113 /* Type A Type D */
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
114 const int PULSE_LENGTH[MAX_PROTOCOLS] = { 0, 350, 650, 100, 666, };
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
115 const int REPEAT_TRANSMIT[MAX_PROTOCOLS] = { 0, 10, 10, 10, 4, };
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
116 const int SYNC_FACTOR[MAX_PROTOCOLS] = { 0, PROTOCOL_A_SYNC_FACTOR, PROTOCOL_B_SYNC_FACTOR, PROTOCOL_C_SYNC_FACTOR, PROTOCOL_D_SYNC_FACTOR, };
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
117 const int ZERO_FIRST_CYCLES[MAX_PROTOCOLS] = { 0, PROTOCOL_A_ZERO_FIRST_CYCLES, PROTOCOL_B_ZERO_FIRST_CYCLES, PROTOCOL_C_ZERO_FIRST_CYCLES, PROTOCOL_D_ZERO_FIRST_CYCLES, };
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
118 const int ZERO_SECOND_CYCLES[MAX_PROTOCOLS] = { 0, PROTOCOL_A_ZERO_SECOND_CYCLES, PROTOCOL_B_ZERO_SECOND_CYCLES, PROTOCOL_C_ZERO_SECOND_CYCLES, PROTOCOL_D_ZERO_SECOND_CYCLES, };
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
119 const int ONE_FIRST_CYCLES[MAX_PROTOCOLS] = { 0, PROTOCOL_A_ONE_FIRST_CYCLES, PROTOCOL_B_ONE_FIRST_CYCLES, PROTOCOL_C_ONE_FIRST_CYCLES, PROTOCOL_D_ONE_FIRST_CYCLES, };
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
120 const int ONE_SECOND_CYCLES[MAX_PROTOCOLS] = { 0, PROTOCOL_A_ONE_SECOND_CYCLES, PROTOCOL_B_ONE_SECOND_CYCLES, PROTOCOL_C_ONE_SECOND_CYCLES, PROTOCOL_D_ONE_SECOND_CYCLES, };
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
121 const bool HIGH_FIRST[MAX_PROTOCOLS] = { 0, PROTOCOL_A_HIGH_FIRST, PROTOCOL_B_HIGH_FIRST, PROTOCOL_C_HIGH_FIRST, PROTOCOL_D_HIGH_FIRST, };
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
122
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 char *getCodeWordA(char*, char*, bool);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 char *getCodeWordB(int, int, bool);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 char *getCodeWordC(char, int, int, bool);
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
127
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
128 char *getCodeWordE(char, int, bool);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 void sendTriState(char*);
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
130 void transmit(int, int, bool);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 void send0(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 void send1(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 void sendT0(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 void sendT1(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 void sendTF(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 void sendSync(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 bool receiveProtocol1(unsigned int);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 bool receiveProtocol2(unsigned int);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 bool receiveProtocol3(unsigned int);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 void handleInterrupt(void);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 char *dec2binWcharfill(unsigned long, unsigned int, char);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
143 void setReceiveTolerance(int);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
144 void setProtocol(int);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
145
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
146 void saveProtocol(int);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
147 void loadProtocol(void);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 * Sets the protocol to send.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 void setProtocol(int nProtocol) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
156 if ((nProtocol < TYPE_MINIMUM) || (nProtocol > TYPE_MAXIMUM)) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
157 return;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
158 }
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
160 rcProtocol = nProtocol;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
161 rcPulseLength = PULSE_LENGTH[nProtocol];
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
162 rcRepeatTransmit = REPEAT_TRANSMIT[nProtocol];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 * Set Receiving Tolerance
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 void setReceiveTolerance(int nPercent) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 rcReceiveTolerance = nPercent;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
175
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 * Enable transmissions
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 * @param nTransmitterPin Pin to which the sender is connected to
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 void enableTransmit(int nTransmitterPin) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 rcTransmitterPin = nTransmitterPin;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 pinMode(rcTransmitterPin, OUTPUT);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 * Disable transmissions
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 void disableTransmit(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 rcTransmitterPin = -1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 /*
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
198 * Toggle switch, a command looks like B,3,2,1 which means switch type B,
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
199 * group 3, device 2, status on.
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
200 */
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
201 int toggleSwitch(char *command)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
202 {
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
203 static char *cmd = NULL;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
204 char *s, cType;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
205 int rc, iGroup, iDevice, iState;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
206
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
207 cmd = xstrcpy(command);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
208 s = strtok(cmd, ",\0");
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
209 cType = s[0];
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
210
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
211 if (cType == 'A') {
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
212
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
213 } else if (cType == 'B') {
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
214 s = strtok(NULL, ",\0");
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
215 rc = sscanf(s, "%d", &iGroup);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
216 if (rc != 1)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
217 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
218 s = strtok(NULL, ",\0");
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
219 rc = sscanf(s, "%d", &iDevice);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
220 if (rc != 1)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
221 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
222 s = strtok(NULL, ",\0");
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
223 rc = sscanf(s, "%d", &iState);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
224 if (rc != 1)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
225 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
226 free(cmd);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
227 return toggleTypeB(iGroup, iDevice, iState);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
228 }
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
229
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
230 free(cmd);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
231 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
232 }
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
233
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
234
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
235
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
236 /*
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
237 * Switch a remote switch on (Type E REV)
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 *
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
239 * @param sGroup Code of the switch group (A,B,C,D)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
240 * @param nDevice Number of the switch itself (1..3)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
241 * @param bStatus Status to toggle to
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 */
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
243 int toggleTypeE(char sGroup, int nDevice, bool bStatus) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
244 sendTriState( getCodeWordE(sGroup, nDevice, bStatus) );
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
245 return 0;
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
246 }
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
248
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
249
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
250 /*
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 * Switch a remote switch on (Type C Intertechno)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 * @param sFamily Familycode (a..f)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 * @param nGroup Number of group (1..4)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 * @param nDevice Number of device (1..4)
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
256 * @param bStatus Status to toggle to
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 */
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
258 int toggleTypeC(char sFamily, int nGroup, int nDevice, bool bStatus) {
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
259 char *str = xstrcpy(getCodeWordC(sFamily, nGroup, nDevice, bStatus));
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
260
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
261 if (strlen(str) == 0)
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
262 return 1;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
263
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
264 saveProtocol(TYPE_A); // ???
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
265 sendTriState( str );
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
266 loadProtocol();
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
267 free(str);
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
268 return 0;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 /*
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
274 * Switch a remote switch on/off (Type B with two rotary/sliding switches)
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 *
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
276 * @param iGroup Number of the switch group (1..4)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
277 * @param iDevice Number of the switch itself (1..4)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
278 * @param bStatus Status to toggle to
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 */
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
280 int toggleTypeB(int iGroup, int iDevice, bool bStatus)
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
281 {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
282 char *str = xstrcpy(getCodeWordB(iGroup, iDevice, bStatus));
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
283
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
284 if (strlen(str) == 0)
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
285 return 1;
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
286
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
287 saveProtocol(TYPE_A); // They do better with protocol A timings.
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
288 sendTriState( str );
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
289 loadProtocol();
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
290 free(str);
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
291 return 0;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
296 /*
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 * Switch a remote switch on (Type A with 10 pole DIP switches)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 *
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
299 * @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")
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
300 * @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")
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
301 * @param bStatus Status to toggle to
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302 */
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
303 int toggleTypeA(char* sGroup, char* sDevice, bool bStatus) {
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
304 char *str = xstrcpy(getCodeWordA(sGroup, sDevice, bStatus));
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
305
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
306 if (strlen(str) == 0)
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
307 return 1;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
308
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
309 saveProtocol(TYPE_A);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
310 sendTriState( str );
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
311 loadProtocol();
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
312 free(str);
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 25
diff changeset
313 return 0;
22
a3b058c67289 All four types RC switches are now implemented
Michiel Broek <mbroek@mbse.eu>
parents: 20
diff changeset
314 }
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 * Returns a char[13], representing the Code Word to be send.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320 * A Code Word consists of 9 address bits, 3 data bits and one sync bit but in our case only the first 8 address bits and the last 2 data bits were used.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 * A Code Bit can have 4 different states: "F" (floating), "0" (low), "1" (high), "S" (synchronous bit)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323 * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324 * | 4 bits address (switch group) | 4 bits address (switch number) | 1 bit address (not used, so never mind) | 1 bit address (not used, so never mind) | 2 data bits (on|off) | 1 sync bit |
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325 * | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | F | F | on=FF off=F0 | S |
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 * +-------------------------------+--------------------------------+-----------------------------------------+-----------------------------------------+----------------------+------------+
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 * @param nAddressCode Number of the switch group (1..4)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 * @param nChannelCode Number of the switch itself (1..4)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 * @param bStatus Wether to switch on (true) or off (false)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 * @return char[13]
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 char *getCodeWordB(int nAddressCode, int nChannelCode, bool bStatus)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 int i, nReturnPos = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 static char sReturn[13];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 if (nAddressCode < 1 || nAddressCode > 4 || nChannelCode < 1 || nChannelCode > 4) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 return '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 for (i = 0; i<4; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
343 sReturn[nReturnPos++] = TYPE_B_CODE[nAddressCode][i];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 for (i = 0; i<4; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
347 sReturn[nReturnPos++] = TYPE_B_CODE[nChannelCode][i];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 sReturn[nReturnPos++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 sReturn[nReturnPos++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 sReturn[nReturnPos++] = 'F';
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
353 sReturn[nReturnPos++] = bStatus ? 'F' : '0';
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 sReturn[nReturnPos] = '\0';
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
355
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 return sReturn;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 * Returns a char[13], representing the Code Word to be send.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 * getCodeWordA(char*, char*)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367 char *getCodeWordA(char* sGroup, char* sDevice, bool bOn)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 static char sDipSwitches[13];
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
370 int i, j = 0;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
372 for (i=0; i < 5; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
373 sDipSwitches[j++] = (sGroup[i] == '0') ? 'F' : '0';
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
374 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
375
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
376 for (i=0; i < 5; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
377 sDipSwitches[j++] = (sDevice[i] == '0') ? 'F' : '0';
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 }
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
379
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 if ( bOn ) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 sDipSwitches[j++] = '0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 sDipSwitches[j++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 sDipSwitches[j++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385 sDipSwitches[j++] = '0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 sDipSwitches[j] = '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 return sDipSwitches;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 * Like getCodeWord (Type C = Intertechno)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397 char *getCodeWordC(char sFamily, int nGroup, int nDevice, bool bStatus)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 static char sReturn[13];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 int i, nReturnPos = 0;
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
401
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
402 if (sFamily < 'a') {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
403 // To also enable capital 'A' to 'F'
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
404 sFamily += 32;
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
405 }
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
406
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
407 if ( sFamily < 'a' || sFamily > 'f' || nGroup < 1 || nGroup > 4 || nDevice < 1 || nDevice > 4) {
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408 return '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 for (i = 0; i<4; i++) {
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
412 sReturn[nReturnPos++] = TYPE_C_CODE[ sFamily - 'a' ][i];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 }
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
414
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
415 char *sDeviceGroupCode = dec2binWzerofill( (nDevice-1) + (nGroup-1)*4, 4 );
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 for (i = 0; i<4; i++) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417 sReturn[nReturnPos++] = (sDeviceGroupCode[3-i] == '1' ? 'F' : '0');
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 sReturn[nReturnPos++] = '0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 sReturn[nReturnPos++] = 'F';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422 sReturn[nReturnPos++] = 'F';
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
423 sReturn[nReturnPos++] = bStatus ? 'F' : '0';
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
424 sReturn[nReturnPos] = '\0';
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
425
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
426 return sReturn;
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
427 }
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
428
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
429
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
430
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
431 /*
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
432 * Decoding for the Quigg Switch Type
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
433 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
434 * Returns a char[22], representing the States to be send.
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
435 * A Code Word consists of 1 start bit, 12 address bits and 8 command data bits.
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
436 * A Code Bit can have 2 different states: "0" (low), "1" (high)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
437 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
438 * +--------------+--------------------------------+------------------------------+
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
439 * | 1 bits start | 12 bits address (device group) | 8 bits (command/switch data) |
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
440 * | 1 | 110011001100 | 00010001 |
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
441 * +--------------+--------------------------------+------------------------------+
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
442 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
443 * Source: https://github.com/d-a-n/433-codes/blob/master/database.md#quigg
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
444 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
445 * @param sGroup 12-bit Binary ID of the Device Group
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
446 * @param nDevice Number of the switch itself (1..4, or 0 to switch the entire Group)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
447 * @param bStatus Wether to switch on (true) or off (false)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
448 *
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
449 * @return char[22]
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
450 */
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
451 char *getCodeWordD(char *sGroup, int nDevice, bool bStatus)
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
452 {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
453 static char sReturn[22];
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
454 int i, nReturnPos = 0;
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
455
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
456 /* Startbit */
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
457 sReturn[nReturnPos++] = '1';
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
458
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
459 /* 12 bit Group */
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
460 for (i = 0; i < 12; ++i) {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
461 sReturn[nReturnPos++] = sGroup[i];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462 }
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
463
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
464 /* 8 Bit Device Identifier + Status (undividable!) */
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
465 for (i = 0; i < 8; ++i) {
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
466 sReturn[nReturnPos++] = TYPE_D_CODE[nDevice][bStatus][i];
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
467 }
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
468 sReturn[nReturnPos] = 0;
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
469
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 return sReturn;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 * Decoding for the REV Switch Type
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 * Returns a char[13], representing the Tristate to be send.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 * A Code Word consists of 7 address bits and 5 command data bits.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 * A Code Bit can have 3 different states: "F" (floating), "0" (low), "1" (high)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 * +-------------------------------+--------------------------------+-----------------------+
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483 * | 4 bits address (switch group) | 3 bits address (device number) | 5 bits (command data) |
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484 * | A=1FFF B=F1FF C=FF1F D=FFF1 | 1=0FFF 2=F0FF 3=FF0F 4=FFF0 | on=00010 off=00001 |
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485 * +-------------------------------+--------------------------------+-----------------------+
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487 * Source: http://www.the-intruder.net/funksteckdosen-von-rev-uber-arduino-ansteuern/
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489 * @param sGroup Name of the switch group (A..D, resp. a..d)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490 * @param nDevice Number of the switch itself (1..3)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
491 * @param bStatus Wether to switch on (true) or off (false)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
492 *
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
493 * @return char[13]
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
494 */
25
5e0695f6add5 Better interface for rc-switch library code
Michiel Broek <mbroek@mbse.eu>
parents: 24
diff changeset
495 char *getCodeWordE(char sGroup, int nDevice, bool bStatus){
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496 static char sReturn[13];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497 int i, nReturnPos = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
499 // Building 4 bits address
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
500 // (Potential problem if dec2binWcharfill not returning correct string)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501 char *sGroupCode;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
502 switch(sGroup){
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 case 'a':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504 case 'A':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505 sGroupCode = dec2binWcharfill(8, 4, 'F'); break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
506 case 'b':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507 case 'B':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
508 sGroupCode = dec2binWcharfill(4, 4, 'F'); break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509 case 'c':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
510 case 'C':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511 sGroupCode = dec2binWcharfill(2, 4, 'F'); break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512 case 'd':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513 case 'D':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514 sGroupCode = dec2binWcharfill(1, 4, 'F'); break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515 default:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516 return '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
517 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519 for (i = 0; i<4; i++) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520 sReturn[nReturnPos++] = sGroupCode[i];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
521 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
522
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524 // Building 3 bits address
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525 // (Potential problem if dec2binWcharfill not returning correct string)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
526 char *sDevice;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
527 switch(nDevice) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528 case 1:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529 sDevice = dec2binWcharfill(4, 3, 'F'); break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
530 case 2:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
531 sDevice = dec2binWcharfill(2, 3, 'F'); break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532 case 3:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
533 sDevice = dec2binWcharfill(1, 3, 'F'); break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
534 default:
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535 return '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
537
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 for (i = 0; i<3; i++)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
539 sReturn[nReturnPos++] = sDevice[i];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
541 // fill up rest with zeros
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
542 for (i = 0; i<5; i++)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
543 sReturn[nReturnPos++] = '0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
544
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
545 // encode on or off
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546 if (bStatus)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
547 sReturn[10] = '1';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
548 else
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
549 sReturn[11] = '1';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
550
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551 // last position terminate string
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
552 sReturn[12] = '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 return sReturn;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
555 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 * @param sCodeWord /^[10FS]*$/ -> see getCodeWord
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 void sendTriState(char* sCodeWord) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
563 int nRepeat;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
564
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565 for (nRepeat = 0; nRepeat < rcRepeatTransmit; nRepeat++) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 int i = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 while (sCodeWord[i] != '\0') {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 switch(sCodeWord[i]) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569 case '0':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
570 sendT0();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571 break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 case 'F':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 sendTF();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 case '1':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576 sendT1();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
577 break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
578 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
579 i++;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
580 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581 sendSync();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
588 void RCSwitch::send(unsigned long Code, unsigned int length) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 this->send( this->dec2binWzerofill(Code, length) );
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
592 void RCSwitch::send(char* sCodeWord) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593 for (int nRepeat=0; nRepeat<nRepeatTransmit; nRepeat++) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
594 int i = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595 while (sCodeWord[i] != '\0') {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596 switch(sCodeWord[i]) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
597 case '0':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 this->send0();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600 case '1':
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
601 this->send1();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
602 break;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604 i++;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
605 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606 this->sendSync();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
608 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
609 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
612 void transmit(int nFirstPulses, int nSecondPulses, bool bHighFirst)
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
613 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
614 bool disabled_Receive = false;
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
615 int nReceiverInterrupt_backup = rcReceiverInterruptPin;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
616
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
617 if (rcTransmitterPin != -1) {
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
618 if (rcReceiverInterruptPin != -1) {
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
619 disableReceive();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
620 disabled_Receive = true;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
621 }
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
622 digitalWrite(rcTransmitterPin, bHighFirst ? HIGH : LOW);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
623 delayMicroseconds( rcPulseLength * nFirstPulses);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
624 digitalWrite(rcTransmitterPin, bHighFirst ? LOW : HIGH);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
625 delayMicroseconds( rcPulseLength * nSecondPulses);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
626
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
627 if (disabled_Receive) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
628 enableReceiveIRQ(nReceiverInterrupt_backup);
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
629 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
630 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
631 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
632
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
633
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
634
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
635 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
636 * Sends a "0" Bit
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
637 * _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
638 * Waveform Protocol 1: | |___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
639 * _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
640 * Waveform Protocol 2: | |__
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
641 * ____
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
642 * Waveform Protocol 3: | |___________
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
643 */
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
644 //void send0(void) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
645 // if (rcProtocol == 1){
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
646 // transmit(1,3);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
647 // }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
648 // else if (rcProtocol == 2) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
649 // transmit(1,2);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
650 // }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
651 // else if (rcProtocol == 3) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
652 // transmit(4,11);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
653 // }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
654 //}
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
655
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
656
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
657
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
658 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
659 * Sends a "1" Bit
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
660 * ___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
661 * Waveform Protocol 1: | |_
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
662 * __
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
663 * Waveform Protocol 2: | |_
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
664 * _________
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
665 * Waveform Protocol 3: | |______
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
666 */
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
667 //void send1(void) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
668 // if (rcProtocol == 1){
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
669 // transmit(3,1);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
670 // }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
671 // else if (rcProtocol == 2) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
672 // transmit(2,1);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
673 // }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
674 // else if (rcProtocol == 3) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
675 // transmit(9,6);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
676 // }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
677 //}
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
678
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
679
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
680
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
681 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
682 * Sends a Tri-State "0" Bit
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
683 * _ _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
684 * Waveform: | |___| |___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
685 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
686 void sendT0(void) {
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
687 transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
688 transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
689 // transmit(1,3,true);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
690 // transmit(1,3,true);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
691 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
692
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
693
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
694
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
695 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
696 * Sends a Tri-State "1" Bit
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
697 * ___ ___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
698 * Waveform: | |_| |_
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
699 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
700 void sendT1(void) {
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
701 transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
702 transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
703 // transmit(3,1,true);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
704 // transmit(3,1,true);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
705 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
706
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
707
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
708
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
709 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
710 * Sends a Tri-State "F" Bit
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
711 * _ ___
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
712 * Waveform: | |___| |_
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
713 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
714 void sendTF(void) {
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
715 transmit(ZERO_FIRST_CYCLES[rcProtocol], ZERO_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
716 transmit(ONE_FIRST_CYCLES[rcProtocol], ONE_SECOND_CYCLES[rcProtocol], HIGH_FIRST[rcProtocol]);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
717 // transmit(1,3,true);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
718 // transmit(3,1,true);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
719 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
720
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
721
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
722
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
723 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
724 * Sends a "Sync" Bit
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
725 * _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
726 * Waveform Protocol 1: | |_______________________________
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
727 * _
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
728 * Waveform Protocol 2: | |__________
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
729 * ____
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
730 * Waveform Protocol 3: | |_______________________________________________________________________
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
731 *
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
732 * Waveform Protocol D: (none, just pause 80 msecs)
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
733 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
734 void sendSync(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
735
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
736 if (rcProtocol == TYPE_A) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
737 transmit(1,31,true);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
738 } else if (rcProtocol == TYPE_B) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
739 transmit(1,10,true);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
740 } else if (rcProtocol == TYPE_C) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
741 transmit(4,71,true);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
742 } else if (rcProtocol == TYPE_D) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
743 transmit(0,1,false);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
744 delayMicroseconds(80000);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
745 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
746 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
747
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
748
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
749
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
750 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
751 * Enable receiving data
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
752 */
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
753 void enableReceiveIRQ(int Pin) {
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
754 rcReceiverInterruptPin = Pin;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
755 enableReceive();
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
756 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
757
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
758 void enableReceive(void) {
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
759 if (rcReceiverInterruptPin != -1) {
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
760 rcReceivedValue = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
761 rcReceivedBitlength = 0;
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
762 wiringPiISR(rcReceiverInterruptPin, INT_EDGE_BOTH, &handleInterrupt);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
763 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
764 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
765
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
766
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
767
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
768 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
769 * Disable receiving data
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
770 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
771 void disableReceive() {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
772 // wiringPi disable interrupts ???
24
873786a20a61 Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents: 22
diff changeset
773 rcReceiverInterruptPin = -1;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
774 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
775
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
776
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
777
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
778 bool available(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
779 return rcReceivedValue != 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
780 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
781
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
782
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
783
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
784 void resetAvailable(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
785 rcReceivedValue = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
786 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
787
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
788
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
789
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
790 unsigned long getReceivedValue(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
791 return rcReceivedValue;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
792 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
793
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
794
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
795
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
796 unsigned int getReceivedBitlength(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
797 return rcReceivedBitlength;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
798 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
799
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
800
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
801
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
802 unsigned int getReceivedDelay(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
803 return rcReceivedDelay;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
804 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
805
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
806
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
807
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
808 unsigned int getReceivedProtocol(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
809 return rcReceivedProtocol;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
810 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
811
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
812
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
813
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
814 unsigned int* getReceivedRawdata(void) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
815 return timings;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
816 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
817
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
818
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
819
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
820 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
821 * ASK protool 1
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
822 */
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
823 bool receiveProtocol(int prot, unsigned int changeCount)
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
824 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
825 unsigned long code = 0;
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
826 unsigned long ldelay = timings[0] / SYNC_FACTOR[prot];
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
827 unsigned long delayTolerance = ldelay * rcReceiveTolerance * 0.01;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
828 int i;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
829
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
830 if (prot < TYPE_MINIMUM || prot > TYPE_MAXIMUM) {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
831 return false;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
832 }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
833
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
834 for (i = 1; i<changeCount ; i=i+2) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
835
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
836 if (timings[i] > ldelay * ZERO_FIRST_CYCLES[prot] - delayTolerance &&
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
837 timings[i] < ldelay * ZERO_FIRST_CYCLES[prot] + delayTolerance &&
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
838 timings[i+1] > ldelay * ZERO_SECOND_CYCLES[prot] - delayTolerance &&
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
839 timings[i+1] < ldelay * ZERO_SECOND_CYCLES[prot] + delayTolerance) {
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840 code = code << 1;
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
841 } else if (timings[i] > ldelay * ONE_FIRST_CYCLES[prot] - delayTolerance &&
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
842 timings[i] < ldelay * ONE_FIRST_CYCLES[prot] + delayTolerance &&
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
843 timings[i+1] > ldelay * ONE_SECOND_CYCLES[prot] - delayTolerance &&
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
844 timings[i+1] < ldelay * ONE_SECOND_CYCLES[prot] + delayTolerance) {
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
845 code+=1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
846 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
847 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
848 // Failed
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
849 i = changeCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
850 code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
851 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
852 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
853 code = code >> 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
854 if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
855 rcReceivedValue = code;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
856 rcReceivedBitlength = changeCount / 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
857 rcReceivedDelay = ldelay;
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
858 rcReceivedProtocol = prot;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
859 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
860
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
861 return (code != 0);
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
862 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
863
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
864
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
865
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
866 bool receiveProtocol2(unsigned int changeCount)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
867 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
868 unsigned long code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
869 unsigned long ldelay = timings[0] / 10;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
870 unsigned long delayTolerance = ldelay * rcReceiveTolerance * 0.01;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
871 int i;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
872
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
873 for (i = 1; i<changeCount ; i=i+2) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
874 if (timings[i] > ldelay-delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
875 timings[i] < ldelay+delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
876 timings[i+1] > ldelay*2-delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
877 timings[i+1] < ldelay*2+delayTolerance) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
878 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
879 } else if (timings[i] > ldelay*2-delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
880 timings[i] < ldelay*2+delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
881 timings[i+1] > ldelay-delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
882 timings[i+1] < ldelay+delayTolerance) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
883 code+=1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
884 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
885 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
886 // Failed
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
887 i = changeCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
888 code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
889 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
890 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
891 code = code >> 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
892
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
893 if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
894 rcReceivedValue = code;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
895 rcReceivedBitlength = changeCount / 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
896 rcReceivedDelay = ldelay;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
897 rcReceivedProtocol = 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
898 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
899
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
900 if (code == 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
901 return false;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
902 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
903 return true;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
904 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
905
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
906
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
907
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
908 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
909 * Protocol 3 is used by BL35P02.
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
910 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
911 bool receiveProtocol3(unsigned int changeCount)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
912 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
913 unsigned long code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
914 unsigned long ldelay = timings[0] / PROTOCOL3_SYNC_FACTOR;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
915 unsigned long delayTolerance = ldelay * rcReceiveTolerance * 0.01;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
916 int i;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
917
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
918 for (i = 1; i<changeCount ; i=i+2) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
919
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
920 if (timings[i] > ldelay*PROTOCOL3_0_HIGH_CYCLES - delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
921 timings[i] < ldelay*PROTOCOL3_0_HIGH_CYCLES + delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
922 timings[i+1] > ldelay*PROTOCOL3_0_LOW_CYCLES - delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
923 timings[i+1] < ldelay*PROTOCOL3_0_LOW_CYCLES + delayTolerance) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
924 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
925 } else if (timings[i] > ldelay*PROTOCOL3_1_HIGH_CYCLES - delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
926 timings[i] < ldelay*PROTOCOL3_1_HIGH_CYCLES + delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
927 timings[i+1] > ldelay*PROTOCOL3_1_LOW_CYCLES - delayTolerance &&
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
928 timings[i+1] < ldelay*PROTOCOL3_1_LOW_CYCLES + delayTolerance) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
929 code+=1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
930 code = code << 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
931 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
932 // Failed
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
933 i = changeCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
934 code = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
935 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
936 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
937 code = code >> 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
938 if (changeCount > 6) { // ignore < 4bit values as there are no devices sending 4bit values => noise
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
939 rcReceivedValue = code;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
940 rcReceivedBitlength = changeCount / 2;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
941 rcReceivedDelay = ldelay;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
942 rcReceivedProtocol = 3;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
943 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
944
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
945 if (code == 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
946 return false;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
947 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
948 return true;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
949 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
950
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
951
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
952
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
953 void handleInterrupt() {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
954
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
955 static unsigned int duration;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
956 static unsigned int changeCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
957 static unsigned long lastTime;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
958 static unsigned int repeatCount;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
959
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
960
32
3bac8fd4173d Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
961 long thistime = micros();
3bac8fd4173d Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
962 duration = thistime - lastTime;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
963
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
964 if (duration > 5000 && duration > timings[0] - 200 && duration < timings[0] + 200) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
965 repeatCount++;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
966 changeCount--;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
967 if (repeatCount == 2) {
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
968 if (receiveProtocol(TYPE_A, changeCount) == false){
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
969 if (receiveProtocol(TYPE_B, changeCount) == false){
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
970 if (receiveProtocol(TYPE_C, changeCount) == false){
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
971 //failed
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
972 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
973 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
974 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
975 repeatCount = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
976 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
977 changeCount = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
978 } else if (duration > 5000) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
979 changeCount = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
980 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
981
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
982 if (changeCount >= RCSWITCH_MAX_CHANGES) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
983 changeCount = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
984 repeatCount = 0;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
985 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
986 timings[changeCount++] = duration;
32
3bac8fd4173d Added user log function for program data
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
987 lastTime = thistime;
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
988 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
989
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
990
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
991
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
992 /*
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
993 * Turns a decimal value to its binary representation
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
994 */
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
995 char *dec2binWzerofill(unsigned long Dec, unsigned int bitLength)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
996 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
997 return dec2binWcharfill(Dec, bitLength, '0');
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
998 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
999
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1000 char *dec2binWcharfill(unsigned long Dec, unsigned int bitLength, char fill)
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1001 {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1002 static char bin[64];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1003 unsigned int i = 0, j;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1004
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1005 while (Dec > 0) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1006 bin[32+i++] = ((Dec & 1) > 0) ? '1' : fill;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1007 Dec = Dec >> 1;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1008 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1009
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1010 for (j = 0; j< bitLength; j++) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1011 if (j >= bitLength - i) {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1012 bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1013 } else {
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1014 bin[j] = fill;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1015 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1016 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1017 bin[bitLength] = '\0';
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1018
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1019 return bin;
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1020 }
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1021
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1022
29
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1023 void saveProtocol(int prot)
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1024 {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1025 backupProtocol = rcProtocol;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1026 backupPulseLength = rcPulseLength;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1027 backupRepeatTransmit = rcRepeatTransmit;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1028
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1029 setProtocol(prot);
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1030 }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1031
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1032
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1033
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1034 void loadProtocol(void)
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1035 {
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1036 rcProtocol = backupProtocol;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1037 rcPulseLength = backupPulseLength;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1038 rcRepeatTransmit = backupRepeatTransmit;
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1039 }
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1040
ac763b87ee25 Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents: 28
diff changeset
1041
20
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1042 #endif
f7f9463cdefd Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1043

mercurial