Daisen Remote library

DAISEN リモコン用ライブラリ

Sample

リモコンの受信機(受信モジュール)とはシリアル(UART)で接続します。

#include "mbed.h"
#include "daisenRemote.h"

Serial pc(USBTX, USBRX);
DigitalOut myled(LED1);

daisenRemote remote(p10, daisenRemote::RF); // rx, type

void isrRemote () {
    pc.printf("Recv: %d\r\n", remote.read());
}

int main() {
    pc.baud(115200);
    pc.printf("*** REMOTE\r\n");
    remote.attach(isrRemote);
    for (;;) {
        led1 = ! led1;
        wait(0.2);
    }
}
Revision:
0:9edcf415fe92
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/daisenRemote.h	Tue Apr 21 02:07:53 2015 +0000
@@ -0,0 +1,42 @@
+/*
+ * Daisen Remote library
+ * Copyright (c) 2015 Hiroshi Suga
+ * Released under the MIT License: http://mbed.org/license/mit
+ *
+ *   2.4GHz: http://www.daisendenshi.com/category_list.php?master_categories_id=102&categories_id=141&categories_name=2.4GHz%91%D1%96%B3%90%FC%83%8A%83%82%83R%83%93%91%97%90M%8A%ED
+ *   Infrared: http://www.daisendenshi.com/category_list.php?master_categories_id=102&categories_id=106&categories_name=%90%D4%8AO%83%8A%83%82%83R%83%93%91%97%90M%8A%ED
+ */
+
+#include "mbed.h"
+#include "FunctionPointer.h"
+
+class daisenRemote {
+public:
+    enum remoteType {
+        RF, // 2.4GHz
+        IR, // Infrared
+    };
+
+    daisenRemote (PinName rx, remoteType type = RF);
+
+    int read ();
+ 
+    void attach(void (*fptr)(void)) { 
+        _func.attach(fptr);
+    }
+    template<typename T>
+    void attach(T *tptr, void (T::*mptr)(void)) { 
+        _func.attach(tptr, mptr); 
+    }
+
+private:
+    RawSerial _ir;
+    remoteType _type;
+    int _recv;
+    int _count;
+    char _buf[20];
+
+    FunctionPointer _func;
+
+    void isrRemote ();
+};