Final Project로 실제 점검에 사용된 코드

Dependencies:   mbed Adafruit_GFX

Committer:
21400688
Date:
Sat Jun 15 20:52:15 2019 +0000
Revision:
0:22391cd705e2
vb

Who changed what in which revision?

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