]>
cloudbase.mooo.com Git - irmp.git/blob - irmp-main-mbed.cpp
b04d887c72668e75dd36e3815a7622fc9635e419
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * irmp-main-mbed.cpp - demo main module to test IRMP decoder on AVR
4 * $Id: irmp-main-mbed.cpp,v 1.1 2016/01/12 11:55:05 fm Exp $
6 * This demo module is runnable on MBED boards
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *---------------------------------------------------------------------------------------------------------------------------------------------------
21 DigitalOut
led(P0_14
, 1);
22 DigitalOut
flash(P0_12
, 1);
26 // only for performance test
30 int timeISRAvgSum
= 0;
31 int countISRCalls
= 0;
35 int t1
= timerPerfTest
.read_us();
37 irmp_ISR(); // call irmp ISR
39 int timeISR
= timerPerfTest
.read_us() - t1
; // calc time spent in worker ISR
40 if (timeISR
> timeISRMax
) // store maximum
44 timeISRAvgSum
+= timeISR
; // sum for avg
50 printf("IRMP on mbed\n");
53 timerPerfTest
.start();
57 irmp_init(); // initialize irmp
58 t
.attach_us(&irmpISR
, 1E6
/ F_INTERRUPTS
); // call ISR 15000/s
60 // infinite loop, interrupts will toggle PORTD pins and handle UART communications.
65 if (irmp_get_data (&irmp_data
))
67 // ir signal decoded, do something here...
68 // irmp_data.protocol is the protocol, see irmp.h
69 // irmp_data.address is the address/manufacturer code of ir sender
70 // irmp_data.command is the command code
71 // irm_data.flags is press/release information
72 // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)
73 // printf("proto %d addr %d cmd %d\n", irmp_data.protocol, irmp_data.address, irmp_data.command );
75 // sample decoding, toggle LED
76 if (irmp_data
.protocol
== IRMP_RC5_PROTOCOL
&& irmp_data
.address
== 5) // old RC5 VCR Remote. TV uses address 0
78 if (irmp_data
.flags
== 0) // switch only on button press
80 switch (irmp_data
.command
)
88 case 53: // Key 'play'
89 printf("bring me a beer!\n");
91 case 54: // Key 'stop'
92 timeISRAvg
= (float)timeISRAvgSum
/ countISRCalls
;
95 printf("ISR max / avg runtime [microseconds] : %d / %5.2f\n", timeISRMax
, timeISRAvg
);
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
] );