]>
Commit | Line | Data |
---|---|---|
ea29682a | 1 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r |
2 | * irmp-main-mbed.cpp - demo main module to test IRMP decoder on AVR\r | |
3 | *\r | |
4 | * $Id: irmp-main-mbed.cpp,v 1.1 2016/01/12 11:55:05 fm Exp $\r | |
5 | *\r | |
6 | * This demo module is runnable on MBED boards\r | |
7 | *\r | |
8 | * This program is free software; you can redistribute it and/or modify\r | |
9 | * it under the terms of the GNU General Public License as published by\r | |
10 | * the Free Software Foundation; either version 2 of the License, or\r | |
11 | * (at your option) any later version.\r | |
12 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
13 | */\r | |
14 | \r | |
15 | #include "mbed.h"\r | |
16 | #include "irmp.h"\r | |
17 | \r | |
18 | #define LED_ON 0\r | |
19 | #define LED_OFF 1\r | |
20 | \r | |
21 | DigitalOut led(P0_14, 1);\r | |
22 | DigitalOut flash(P0_12, 1);\r | |
23 | \r | |
24 | Ticker t;\r | |
25 | \r | |
26 | // only for performance test\r | |
27 | Timer timerPerfTest;\r | |
28 | int timeISRMax = 0;\r | |
29 | float timeISRAvg;\r | |
30 | int timeISRAvgSum = 0;\r | |
31 | int countISRCalls = 0;\r | |
32 | \r | |
33 | void irmpISR(void)\r | |
34 | {\r | |
35 | int t1 = timerPerfTest.read_us();\r | |
36 | \r | |
37 | irmp_ISR(); // call irmp ISR\r | |
38 | \r | |
39 | int timeISR = timerPerfTest.read_us() - t1; // calc time spent in worker ISR\r | |
40 | if (timeISR > timeISRMax) // store maximum\r | |
41 | {\r | |
42 | timeISRMax = timeISR;\r | |
43 | }\r | |
44 | timeISRAvgSum += timeISR; // sum for avg\r | |
45 | countISRCalls++;\r | |
46 | }\r | |
47 | \r | |
48 | int main()\r | |
49 | {\r | |
50 | printf("IRMP on mbed\n");\r | |
51 | \r | |
52 | led = LED_OFF;\r | |
53 | timerPerfTest.start();\r | |
54 | \r | |
55 | IRMP_DATA irmp_data;\r | |
56 | \r | |
57 | irmp_init(); // initialize irmp\r | |
58 | t.attach_us(&irmpISR, 1E6 / F_INTERRUPTS); // call ISR 15000/s\r | |
59 | \r | |
60 | // infinite loop, interrupts will toggle PORTD pins and handle UART communications.\r | |
61 | while (1)\r | |
62 | {\r | |
63 | flash = !flash;\r | |
64 | \r | |
65 | if (irmp_get_data (&irmp_data))\r | |
66 | {\r | |
67 | // ir signal decoded, do something here...\r | |
68 | // irmp_data.protocol is the protocol, see irmp.h\r | |
69 | // irmp_data.address is the address/manufacturer code of ir sender\r | |
70 | // irmp_data.command is the command code\r | |
71 | // irm_data.flags is press/release information\r | |
72 | // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)\r | |
73 | // printf("proto %d addr %d cmd %d\n", irmp_data.protocol, irmp_data.address, irmp_data.command );\r | |
74 | \r | |
75 | // sample decoding, toggle LED\r | |
76 | if (irmp_data.protocol == IRMP_RC5_PROTOCOL && irmp_data.address == 5) // old RC5 VCR Remote. TV uses address 0\r | |
77 | {\r | |
78 | if (irmp_data.flags == 0) // switch only on button press\r | |
79 | {\r | |
80 | switch (irmp_data.command)\r | |
81 | {\r | |
82 | case 0: // Key '0'\r | |
83 | led = LED_OFF;\r | |
84 | break;\r | |
85 | case 1: // Key '1'\r | |
86 | led = LED_ON;\r | |
87 | break;\r | |
88 | case 53: // Key 'play'\r | |
89 | printf("bring me a beer!\n");\r | |
90 | break;\r | |
91 | case 54: // Key 'stop'\r | |
92 | timeISRAvg = (float)timeISRAvgSum / countISRCalls;\r | |
93 | timeISRAvgSum = 0;\r | |
94 | countISRCalls = 0;\r | |
95 | printf("ISR max / avg runtime [microseconds] : %d / %5.2f\n", timeISRMax, timeISRAvg);\r | |
96 | timeISRMax = 0;\r | |
97 | break;\r | |
98 | }\r | |
99 | }\r | |
100 | }\r | |
101 | \r | |
102 | // log to stdout\r | |
103 | printf("proto %d addr %d cmd %d flags %x name %s\n", irmp_data.protocol, irmp_data.address, irmp_data.command, irmp_data.flags, irmp_protocol_names[irmp_data.protocol] );\r | |
104 | }\r | |
105 | }\r | |
106 | }\r |