From: ukw Date: Tue, 17 Nov 2015 14:25:45 +0000 (+0000) Subject: Version 2.9.7: added port to to ESP8266 and TEENSY, added PANASONIC protocol, added... X-Git-Tag: irmp-libopencm3-pre-1~20 X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/commitdiff_plain/cc052a2ddc81f1a839435ed6be99d97e00c689e9 Version 2.9.7: added port to to ESP8266 and TEENSY, added PANASONIC protocol, added BOSE support for IRSND git-svn-id: svn://mikrocontroller.net/irmp@169 aeb2e35e-bfc4-4214-b83c-9e8de998ed28 --- diff --git a/examples/Arduino.ino b/examples/Arduino.ino new file mode 100644 index 0000000..3738b19 --- /dev/null +++ b/examples/Arduino.ino @@ -0,0 +1,161 @@ ++#include +/* first include Arduino.h, the IDE includes it after irmp*.h ... */ +#include "Arduino.h" +/* ... and then chokes on uintX_t ... */ + +#include +#include + +/* undefine this if you don't want blinking LED for diagnosis */ +#define LED_PIN 13 +#define SER_BAUD 115200 + +/* F_INTERRUPTS is the interrupt frequency defined in irmpconfig.h */ +#define US (1000000 / F_INTERRUPTS) +void setup() +{ + Serial.begin(SER_BAUD); + delay(1000); + /* greeting string and debugging ouput */ + Serial.println("IRMP test sketch"); + Serial.print("US: "); + Serial.println(US); + Serial.println("Send example: P:02 A:916E C:000F (NEC Taste 1)"); +#ifdef LED_PIN + pinMode(LED_PIN, OUTPUT); +#endif + irmp_init(); + irsnd_init(); + //sei(); + led(HIGH); + delay(20); /* make sure the greeting string is out before starting */ + led(LOW); + Timer1.initialize(US); + Timer1.attachInterrupt(timerinterrupt); +} + +IRMP_DATA irmp_data[3]; +uint8_t act_data = 0; +int incomingByte = 0; // for incoming serial data + +void loop() +{ + IRMP_DATA* data = &irmp_data[act_data]; + if (irmp_get_data(data)) + { + led(HIGH); +#if IRMP_PROTOCOL_NAMES == 1 + Serial.print(irmp_protocol_names[data->protocol]); + Serial.print(" "); +#endif + Serial.print("P:"); + Serial.print(data->protocol, HEX); + Serial.print(" A:"); + Serial.print(data->address, HEX); + Serial.print(" C:"); + Serial.print(data->command, HEX); + Serial.print(" "); + Serial.print(data->flags, HEX); + Serial.println(""); + /* Serial.print is asynchronous, so the LED is only flashing very lightly */ + led(LOW); + + data->flags = 0; // reset flags! + int result = irsnd_send_data(data, TRUE); + if (result != 1) + { + Serial.println("loop : irsnd_send_data ERROR"); + } + else + { + if (++act_data >= 3) + { + act_data = 0; + } + } + } + + if (Serial.available() == 18 && readAndCheck('P') && readAndCheck(':')) + { + // read the protocol + data->protocol = readHex() * 16 + readHex(); + + if (readAndCheck(' ') && readAndCheck('A') && readAndCheck(':')) + { + // read the address + data->address = ((readHex() * 16 + readHex()) * 16 + readHex()) * 16 + readHex(); + + if (readAndCheck(' ') && readAndCheck('C') && readAndCheck(':')) + { + // read the address + data->command = ((readHex() * 16 + readHex()) * 16 + readHex()) * 16 + readHex(); + + // send ir data + data->flags = 0; + int result = irsnd_send_data(data, TRUE); + if (result) + { + Serial.print("Send IR data: "); + Serial.print("P:"); + Serial.print(data->protocol, HEX); + Serial.print(" A:"); + Serial.print(data->address, HEX); + Serial.print(" C:"); + Serial.print(data->command, HEX); + Serial.println(""); + + if (++act_data >= 3) + { + act_data = 0; + } + } + } + } + } +} + +/* helper function: attachInterrupt wants void(), but irmp_ISR is uint8_t() */ +void timerinterrupt() +{ + // only when tsop dont see the ir_led flashing + irsnd_ISR(); // call irsnd ISR + irmp_ISR(); // call irmp ISR + +/* + // do not receive when sending (tsop see the ir_led) + if (! irsnd_ISR()) // call irsnd ISR + { // if not busy... + irmp_ISR(); // call irmp ISR + } +*/ +} + +static inline void led(int state) +{ +#ifdef LED_PIN + digitalWrite(LED_PIN, state); +#endif +} + +static inline int readAndCheck(int c) +{ + return c == Serial.read(); +} + +static inline int readHex() +{ + int c = Serial.read(); + if (c >= '0' && c <= '9') + { + return c - '0'; + } + + c |= 0x20; // lowercase + + if (c >= 'a' && c <= 'f') + { + return c + 10 - 'a'; + } + + return -1; +}