E8WATS

Fork of RemoteIR by Shinichiro Nakamura

Committer:
shintamainjp
Date:
Tue Aug 17 08:50:54 2010 +0000
Revision:
0:ec264f4ce158
Child:
1:4adf16017a0f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shintamainjp 0:ec264f4ce158 1 /**
shintamainjp 0:ec264f4ce158 2 * IR receiver (Version 0.0.3)
shintamainjp 0:ec264f4ce158 3 *
shintamainjp 0:ec264f4ce158 4 * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
shintamainjp 0:ec264f4ce158 5 * http://shinta.main.jp/
shintamainjp 0:ec264f4ce158 6 */
shintamainjp 0:ec264f4ce158 7
shintamainjp 0:ec264f4ce158 8 #ifndef _RECEIVER_IR_H_
shintamainjp 0:ec264f4ce158 9 #define _RECEIVER_IR_H_
shintamainjp 0:ec264f4ce158 10
shintamainjp 0:ec264f4ce158 11 #include <mbed.h>
shintamainjp 0:ec264f4ce158 12
shintamainjp 0:ec264f4ce158 13 #include "Semaphore.h"
shintamainjp 0:ec264f4ce158 14 #include "RemoteIR.h"
shintamainjp 0:ec264f4ce158 15
shintamainjp 0:ec264f4ce158 16 /**
shintamainjp 0:ec264f4ce158 17 * IR receiver class.
shintamainjp 0:ec264f4ce158 18 */
shintamainjp 0:ec264f4ce158 19 class ReceiverIR {
shintamainjp 0:ec264f4ce158 20 public:
shintamainjp 0:ec264f4ce158 21
shintamainjp 0:ec264f4ce158 22 /**
shintamainjp 0:ec264f4ce158 23 * Constructor.
shintamainjp 0:ec264f4ce158 24 *
shintamainjp 0:ec264f4ce158 25 * @param rxpin Pin for receive IR signal.
shintamainjp 0:ec264f4ce158 26 */
shintamainjp 0:ec264f4ce158 27 explicit ReceiverIR(PinName rxpin);
shintamainjp 0:ec264f4ce158 28
shintamainjp 0:ec264f4ce158 29 /**
shintamainjp 0:ec264f4ce158 30 * Destructor.
shintamainjp 0:ec264f4ce158 31 */
shintamainjp 0:ec264f4ce158 32 ~ReceiverIR();
shintamainjp 0:ec264f4ce158 33
shintamainjp 0:ec264f4ce158 34 /**
shintamainjp 0:ec264f4ce158 35 * State.
shintamainjp 0:ec264f4ce158 36 */
shintamainjp 0:ec264f4ce158 37 typedef enum {
shintamainjp 0:ec264f4ce158 38 Idle,
shintamainjp 0:ec264f4ce158 39 Receiving,
shintamainjp 0:ec264f4ce158 40 Received
shintamainjp 0:ec264f4ce158 41 } State;
shintamainjp 0:ec264f4ce158 42
shintamainjp 0:ec264f4ce158 43 void init(void);
shintamainjp 0:ec264f4ce158 44
shintamainjp 0:ec264f4ce158 45 /**
shintamainjp 0:ec264f4ce158 46 * Get state.
shintamainjp 0:ec264f4ce158 47 *
shintamainjp 0:ec264f4ce158 48 * @return Current state.
shintamainjp 0:ec264f4ce158 49 */
shintamainjp 0:ec264f4ce158 50 State getState();
shintamainjp 0:ec264f4ce158 51
shintamainjp 0:ec264f4ce158 52 /**
shintamainjp 0:ec264f4ce158 53 * Get data.
shintamainjp 0:ec264f4ce158 54 *
shintamainjp 0:ec264f4ce158 55 * @param format Pointer to format.
shintamainjp 0:ec264f4ce158 56 * @param buf Buffer of data.
shintamainjp 0:ec264f4ce158 57 * @param bufsiz Buffer byte size.
shintamainjp 0:ec264f4ce158 58 *
shintamainjp 0:ec264f4ce158 59 * @return Data bit length.
shintamainjp 0:ec264f4ce158 60 */
shintamainjp 0:ec264f4ce158 61 int getData(RemoteIR::Format *format, uint8_t *buf, int bufsiz);
shintamainjp 0:ec264f4ce158 62
shintamainjp 0:ec264f4ce158 63 private:
shintamainjp 0:ec264f4ce158 64
shintamainjp 0:ec264f4ce158 65 typedef struct {
shintamainjp 0:ec264f4ce158 66 State state;
shintamainjp 0:ec264f4ce158 67 RemoteIR::Format format;
shintamainjp 0:ec264f4ce158 68 int bitcount;
shintamainjp 0:ec264f4ce158 69 uint8_t buffer[64];
shintamainjp 0:ec264f4ce158 70 } data_t;
shintamainjp 0:ec264f4ce158 71
shintamainjp 0:ec264f4ce158 72 typedef struct {
shintamainjp 0:ec264f4ce158 73 int c1;
shintamainjp 0:ec264f4ce158 74 int c2;
shintamainjp 0:ec264f4ce158 75 int c3;
shintamainjp 0:ec264f4ce158 76 int d1;
shintamainjp 0:ec264f4ce158 77 int d2;
shintamainjp 0:ec264f4ce158 78 } work_t;
shintamainjp 0:ec264f4ce158 79
shintamainjp 0:ec264f4ce158 80 static const int TUS_NEC = 562;
shintamainjp 0:ec264f4ce158 81 static const int TUS_AEHA = 425;
shintamainjp 0:ec264f4ce158 82 static const int TUS_SONY = 600;
shintamainjp 0:ec264f4ce158 83
shintamainjp 0:ec264f4ce158 84 InterruptIn evt; /**< Interrupt based input for input. */
shintamainjp 0:ec264f4ce158 85 Timer timer; /**< Timer for WDT. */
shintamainjp 0:ec264f4ce158 86 Ticker ticker; /**< Tciker for tick. */
shintamainjp 0:ec264f4ce158 87 Semaphore sem; /**< Semaphore for data. */
shintamainjp 0:ec264f4ce158 88 Timeout timeout; /**< Timeout for tail. */
shintamainjp 0:ec264f4ce158 89
shintamainjp 0:ec264f4ce158 90 data_t data;
shintamainjp 0:ec264f4ce158 91 work_t work;
shintamainjp 0:ec264f4ce158 92
shintamainjp 0:ec264f4ce158 93 void init_state(void);
shintamainjp 0:ec264f4ce158 94
shintamainjp 0:ec264f4ce158 95 void isr_wdt(void);
shintamainjp 0:ec264f4ce158 96 void isr_fall(void);
shintamainjp 0:ec264f4ce158 97 void isr_rise(void);
shintamainjp 0:ec264f4ce158 98
shintamainjp 0:ec264f4ce158 99 /**
shintamainjp 0:ec264f4ce158 100 * ISR timeout for tail detection.
shintamainjp 0:ec264f4ce158 101 */
shintamainjp 0:ec264f4ce158 102 void isr_timeout(void);
shintamainjp 0:ec264f4ce158 103
shintamainjp 0:ec264f4ce158 104 };
shintamainjp 0:ec264f4ce158 105
shintamainjp 0:ec264f4ce158 106 #endif