![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.
Dependencies: mbed Adafruit_GFX
ReceiverIR.h@95:250afd53b710, 2019-06-08 (annotated)
- Committer:
- ParkChunMyong
- Date:
- Sat Jun 08 12:00:38 2019 +0000
- Revision:
- 95:250afd53b710
first init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ParkChunMyong | 95:250afd53b710 | 1 | /** |
ParkChunMyong | 95:250afd53b710 | 2 | * IR receiver (Version 0.0.4) |
ParkChunMyong | 95:250afd53b710 | 3 | * |
ParkChunMyong | 95:250afd53b710 | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
ParkChunMyong | 95:250afd53b710 | 5 | * http://shinta.main.jp/ |
ParkChunMyong | 95:250afd53b710 | 6 | */ |
ParkChunMyong | 95:250afd53b710 | 7 | |
ParkChunMyong | 95:250afd53b710 | 8 | #ifndef _RECEIVER_IR_H_ |
ParkChunMyong | 95:250afd53b710 | 9 | #define _RECEIVER_IR_H_ |
ParkChunMyong | 95:250afd53b710 | 10 | |
ParkChunMyong | 95:250afd53b710 | 11 | #include <mbed.h> |
ParkChunMyong | 95:250afd53b710 | 12 | |
ParkChunMyong | 95:250afd53b710 | 13 | #include "RemoteIR.h" |
ParkChunMyong | 95:250afd53b710 | 14 | |
ParkChunMyong | 95:250afd53b710 | 15 | /** |
ParkChunMyong | 95:250afd53b710 | 16 | * IR receiver class. |
ParkChunMyong | 95:250afd53b710 | 17 | */ |
ParkChunMyong | 95:250afd53b710 | 18 | class ReceiverIR { |
ParkChunMyong | 95:250afd53b710 | 19 | public: |
ParkChunMyong | 95:250afd53b710 | 20 | |
ParkChunMyong | 95:250afd53b710 | 21 | /** |
ParkChunMyong | 95:250afd53b710 | 22 | * Constructor. |
ParkChunMyong | 95:250afd53b710 | 23 | * |
ParkChunMyong | 95:250afd53b710 | 24 | * @param rxpin Pin for receive IR signal. |
ParkChunMyong | 95:250afd53b710 | 25 | */ |
ParkChunMyong | 95:250afd53b710 | 26 | explicit ReceiverIR(PinName rxpin); |
ParkChunMyong | 95:250afd53b710 | 27 | |
ParkChunMyong | 95:250afd53b710 | 28 | /** |
ParkChunMyong | 95:250afd53b710 | 29 | * Destructor. |
ParkChunMyong | 95:250afd53b710 | 30 | */ |
ParkChunMyong | 95:250afd53b710 | 31 | ~ReceiverIR(); |
ParkChunMyong | 95:250afd53b710 | 32 | |
ParkChunMyong | 95:250afd53b710 | 33 | /** |
ParkChunMyong | 95:250afd53b710 | 34 | * State. |
ParkChunMyong | 95:250afd53b710 | 35 | */ |
ParkChunMyong | 95:250afd53b710 | 36 | typedef enum { |
ParkChunMyong | 95:250afd53b710 | 37 | Idle, |
ParkChunMyong | 95:250afd53b710 | 38 | Receiving, |
ParkChunMyong | 95:250afd53b710 | 39 | Received |
ParkChunMyong | 95:250afd53b710 | 40 | } State; |
ParkChunMyong | 95:250afd53b710 | 41 | |
ParkChunMyong | 95:250afd53b710 | 42 | /** |
ParkChunMyong | 95:250afd53b710 | 43 | * Get state. |
ParkChunMyong | 95:250afd53b710 | 44 | * |
ParkChunMyong | 95:250afd53b710 | 45 | * @return Current state. |
ParkChunMyong | 95:250afd53b710 | 46 | */ |
ParkChunMyong | 95:250afd53b710 | 47 | State getState(); |
ParkChunMyong | 95:250afd53b710 | 48 | |
ParkChunMyong | 95:250afd53b710 | 49 | /** |
ParkChunMyong | 95:250afd53b710 | 50 | * Get data. |
ParkChunMyong | 95:250afd53b710 | 51 | * |
ParkChunMyong | 95:250afd53b710 | 52 | * @param format Pointer to format. |
ParkChunMyong | 95:250afd53b710 | 53 | * @param buf Buffer of a data. |
ParkChunMyong | 95:250afd53b710 | 54 | * @param bitlength Bit length of the buffer. |
ParkChunMyong | 95:250afd53b710 | 55 | * |
ParkChunMyong | 95:250afd53b710 | 56 | * @return Data bit length. |
ParkChunMyong | 95:250afd53b710 | 57 | */ |
ParkChunMyong | 95:250afd53b710 | 58 | int getData(RemoteIR::Format *format, uint8_t *buf, int bitlength); |
ParkChunMyong | 95:250afd53b710 | 59 | |
ParkChunMyong | 95:250afd53b710 | 60 | private: |
ParkChunMyong | 95:250afd53b710 | 61 | |
ParkChunMyong | 95:250afd53b710 | 62 | typedef struct { |
ParkChunMyong | 95:250afd53b710 | 63 | RemoteIR::Format format; |
ParkChunMyong | 95:250afd53b710 | 64 | int bitcount; |
ParkChunMyong | 95:250afd53b710 | 65 | uint8_t buffer[64]; |
ParkChunMyong | 95:250afd53b710 | 66 | } data_t; |
ParkChunMyong | 95:250afd53b710 | 67 | |
ParkChunMyong | 95:250afd53b710 | 68 | typedef struct { |
ParkChunMyong | 95:250afd53b710 | 69 | State state; |
ParkChunMyong | 95:250afd53b710 | 70 | int c1; |
ParkChunMyong | 95:250afd53b710 | 71 | int c2; |
ParkChunMyong | 95:250afd53b710 | 72 | int c3; |
ParkChunMyong | 95:250afd53b710 | 73 | int d1; |
ParkChunMyong | 95:250afd53b710 | 74 | int d2; |
ParkChunMyong | 95:250afd53b710 | 75 | } work_t; |
ParkChunMyong | 95:250afd53b710 | 76 | |
ParkChunMyong | 95:250afd53b710 | 77 | InterruptIn evt; /**< Interrupt based input for input. */ |
ParkChunMyong | 95:250afd53b710 | 78 | Timer timer; /**< Timer for WDT. */ |
ParkChunMyong | 95:250afd53b710 | 79 | Ticker ticker; /**< Tciker for tick. */ |
ParkChunMyong | 95:250afd53b710 | 80 | Timeout timeout; /**< Timeout for tail. */ |
ParkChunMyong | 95:250afd53b710 | 81 | |
ParkChunMyong | 95:250afd53b710 | 82 | data_t data; |
ParkChunMyong | 95:250afd53b710 | 83 | work_t work; |
ParkChunMyong | 95:250afd53b710 | 84 | |
ParkChunMyong | 95:250afd53b710 | 85 | void init_state(void); |
ParkChunMyong | 95:250afd53b710 | 86 | |
ParkChunMyong | 95:250afd53b710 | 87 | void isr_wdt(void); |
ParkChunMyong | 95:250afd53b710 | 88 | void isr_fall(void); |
ParkChunMyong | 95:250afd53b710 | 89 | void isr_rise(void); |
ParkChunMyong | 95:250afd53b710 | 90 | |
ParkChunMyong | 95:250afd53b710 | 91 | /** |
ParkChunMyong | 95:250afd53b710 | 92 | * ISR timeout for tail detection. |
ParkChunMyong | 95:250afd53b710 | 93 | */ |
ParkChunMyong | 95:250afd53b710 | 94 | void isr_timeout(void); |
ParkChunMyong | 95:250afd53b710 | 95 | |
ParkChunMyong | 95:250afd53b710 | 96 | }; |
ParkChunMyong | 95:250afd53b710 | 97 | |
ParkChunMyong | 95:250afd53b710 | 98 | #endif |
ParkChunMyong | 95:250afd53b710 | 99 |