E8WATS
Fork of RemoteIR by
ReceiverIR.h@1:4adf16017a0f, 2010-08-17 (annotated)
- Committer:
- shintamainjp
- Date:
- Tue Aug 17 09:14:49 2010 +0000
- Revision:
- 1:4adf16017a0f
- Parent:
- 0:ec264f4ce158
- Child:
- 4:2304646f6ff5
Who changed what in which revision?
User | Revision | Line number | New 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 | /** |
shintamainjp | 0:ec264f4ce158 | 44 | * Get state. |
shintamainjp | 0:ec264f4ce158 | 45 | * |
shintamainjp | 0:ec264f4ce158 | 46 | * @return Current state. |
shintamainjp | 0:ec264f4ce158 | 47 | */ |
shintamainjp | 0:ec264f4ce158 | 48 | State getState(); |
shintamainjp | 0:ec264f4ce158 | 49 | |
shintamainjp | 0:ec264f4ce158 | 50 | /** |
shintamainjp | 0:ec264f4ce158 | 51 | * Get data. |
shintamainjp | 0:ec264f4ce158 | 52 | * |
shintamainjp | 0:ec264f4ce158 | 53 | * @param format Pointer to format. |
shintamainjp | 0:ec264f4ce158 | 54 | * @param buf Buffer of data. |
shintamainjp | 0:ec264f4ce158 | 55 | * @param bufsiz Buffer byte size. |
shintamainjp | 0:ec264f4ce158 | 56 | * |
shintamainjp | 0:ec264f4ce158 | 57 | * @return Data bit length. |
shintamainjp | 0:ec264f4ce158 | 58 | */ |
shintamainjp | 0:ec264f4ce158 | 59 | int getData(RemoteIR::Format *format, uint8_t *buf, int bufsiz); |
shintamainjp | 0:ec264f4ce158 | 60 | |
shintamainjp | 0:ec264f4ce158 | 61 | private: |
shintamainjp | 0:ec264f4ce158 | 62 | |
shintamainjp | 0:ec264f4ce158 | 63 | typedef struct { |
shintamainjp | 0:ec264f4ce158 | 64 | State state; |
shintamainjp | 0:ec264f4ce158 | 65 | RemoteIR::Format format; |
shintamainjp | 0:ec264f4ce158 | 66 | int bitcount; |
shintamainjp | 0:ec264f4ce158 | 67 | uint8_t buffer[64]; |
shintamainjp | 0:ec264f4ce158 | 68 | } data_t; |
shintamainjp | 0:ec264f4ce158 | 69 | |
shintamainjp | 0:ec264f4ce158 | 70 | typedef struct { |
shintamainjp | 0:ec264f4ce158 | 71 | int c1; |
shintamainjp | 0:ec264f4ce158 | 72 | int c2; |
shintamainjp | 0:ec264f4ce158 | 73 | int c3; |
shintamainjp | 0:ec264f4ce158 | 74 | int d1; |
shintamainjp | 0:ec264f4ce158 | 75 | int d2; |
shintamainjp | 0:ec264f4ce158 | 76 | } work_t; |
shintamainjp | 0:ec264f4ce158 | 77 | |
shintamainjp | 0:ec264f4ce158 | 78 | static const int TUS_NEC = 562; |
shintamainjp | 0:ec264f4ce158 | 79 | static const int TUS_AEHA = 425; |
shintamainjp | 0:ec264f4ce158 | 80 | static const int TUS_SONY = 600; |
shintamainjp | 0:ec264f4ce158 | 81 | |
shintamainjp | 0:ec264f4ce158 | 82 | InterruptIn evt; /**< Interrupt based input for input. */ |
shintamainjp | 0:ec264f4ce158 | 83 | Timer timer; /**< Timer for WDT. */ |
shintamainjp | 0:ec264f4ce158 | 84 | Ticker ticker; /**< Tciker for tick. */ |
shintamainjp | 0:ec264f4ce158 | 85 | Semaphore sem; /**< Semaphore for data. */ |
shintamainjp | 0:ec264f4ce158 | 86 | Timeout timeout; /**< Timeout for tail. */ |
shintamainjp | 0:ec264f4ce158 | 87 | |
shintamainjp | 0:ec264f4ce158 | 88 | data_t data; |
shintamainjp | 0:ec264f4ce158 | 89 | work_t work; |
shintamainjp | 0:ec264f4ce158 | 90 | |
shintamainjp | 0:ec264f4ce158 | 91 | void init_state(void); |
shintamainjp | 0:ec264f4ce158 | 92 | |
shintamainjp | 0:ec264f4ce158 | 93 | void isr_wdt(void); |
shintamainjp | 0:ec264f4ce158 | 94 | void isr_fall(void); |
shintamainjp | 0:ec264f4ce158 | 95 | void isr_rise(void); |
shintamainjp | 0:ec264f4ce158 | 96 | |
shintamainjp | 0:ec264f4ce158 | 97 | /** |
shintamainjp | 0:ec264f4ce158 | 98 | * ISR timeout for tail detection. |
shintamainjp | 0:ec264f4ce158 | 99 | */ |
shintamainjp | 0:ec264f4ce158 | 100 | void isr_timeout(void); |
shintamainjp | 0:ec264f4ce158 | 101 | |
shintamainjp | 0:ec264f4ce158 | 102 | }; |
shintamainjp | 0:ec264f4ce158 | 103 | |
shintamainjp | 0:ec264f4ce158 | 104 | #endif |