나중에 급하게 PID 알고리즘을 적용해 짜본 코드... 시간이 충분치 않아서 그냥 원래 있던 코드를 수정해서 하기로 했기에 버려진 코드지만, 교수님께 참고용으로 Publish를 했다.

Dependencies:   mbed Adafruit_GFX

Committer:
21400688
Date:
Sat Jun 15 20:39:39 2019 +0000
Revision:
0:c4c874d702f9
first commit

Who changed what in which revision?

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