Fri, 20 Jun 2014 17:42:36 +0200
Compiles with 1-wire bus on PC hardware
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 | * 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
|
9 | * 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
|
10 | * 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
|
11 | * later version. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * 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
|
14 | * 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
|
15 | * 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
|
16 | * 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
|
17 | * |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * 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
|
19 | * 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
|
20 | * 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
|
21 | *****************************************************************************/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
51
a03b6dac5398
Removed library, bumped to version 0.0.7
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
23 | #include "rc433.h" |
20
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 | |
23
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
26 | #ifdef HAVE_WIRINGPI_H |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
27 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | int main(int argc, char *argv[]) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
30 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | input PIN is hardcoded for testing purposes |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
32 | see https://projects.drogon.net/raspberry-pi/wiringpi/pins/ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
33 | for pin mapping of the raspberry pi GPIO connector |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | int PIN = 2; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | if (wiringPiSetup () ) |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | return 1; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | enableReceiveIRQ(PIN); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
42 | while (1) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
43 | if (available()) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
44 | |
29
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
45 | unsigned long int value = getReceivedValue(); |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
46 | int bitlen = getReceivedBitlength(); |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | if (value == 0) { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | printf("Unknown encoding\n"); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | } else { |
29
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
51 | if (bitlen == 24) { |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
52 | printf("Received 0x%06lx/24 bit %s Protocol: %d", value, dec2binWzerofill(value, bitlen), getReceivedProtocol() ); |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
53 | if ((value & 0x00000000000003f0) == 0x0000000000000150) { |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
54 | printf(" Type A "); |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
55 | printf("%c%c%c%c%c ", (value & 0xc00000) ? '0' : '1', (value & 0x300000) ? '0' : '1', (value & 0x0c0000) ? '0' : '1', (value & 0x030000) ? '0' : '1', (value & 0x00c000) ? '0' : '1'); |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
56 | printf("%c%c%c%c%c ", (value & 0x003000) ? '0' : '1', (value & 0x000c00) ? '0' : '1', (value & 0x000300) ? '0' : '1', (value & 0x0000c0) ? '0' : '1', (value & 0x000030) ? '0' : '1'); |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
57 | } |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
58 | if ((value & 0x000000000000001c) == 0x0000000000000000) { |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
59 | printf(" Type E"); |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
60 | } |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
61 | printf("\n"); |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
62 | } else { |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
63 | printf("Received 0x%lx/%d bit %s Protocol: %d\n", value, bitlen, dec2binWzerofill(value, bitlen), getReceivedProtocol() ); |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
23
diff
changeset
|
64 | } |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
65 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
67 | resetAvailable(); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
68 | } else { |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
69 | /* |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
70 | * Don't hog the CPU. |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
71 | */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
72 | delay(10); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
73 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
74 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
75 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
76 | return 0; |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
77 | } |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
78 | |
23
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
79 | #else |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
80 | |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
81 | int main(int argc, char *argv[]) { |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
82 | fprintf(stderr, "This program does nothing without the wiringPi library\n"); |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
83 | return 0; |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
84 | } |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
85 | |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
86 | #endif |
d820a6f3ec16
Added more conditional compile switches
Michiel Broek <mbroek@mbse.eu>
parents:
20
diff
changeset
|
87 |