나중에 급하게 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 transmitter (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 _TRANSMITTER_IR_H_
21400688 0:c4c874d702f9 9 #define _TRANSMITTER_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 transmitter class.
21400688 0:c4c874d702f9 17 */
21400688 0:c4c874d702f9 18 class TransmitterIR {
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 txpin Pin for transmit IR signal.
21400688 0:c4c874d702f9 25 */
21400688 0:c4c874d702f9 26 explicit TransmitterIR(PinName txpin);
21400688 0:c4c874d702f9 27
21400688 0:c4c874d702f9 28 /**
21400688 0:c4c874d702f9 29 * Destructor.
21400688 0:c4c874d702f9 30 */
21400688 0:c4c874d702f9 31 ~TransmitterIR();
21400688 0:c4c874d702f9 32
21400688 0:c4c874d702f9 33 typedef enum {
21400688 0:c4c874d702f9 34 Idle,
21400688 0:c4c874d702f9 35 Leader,
21400688 0:c4c874d702f9 36 Data,
21400688 0:c4c874d702f9 37 Trailer
21400688 0:c4c874d702f9 38 } State;
21400688 0:c4c874d702f9 39
21400688 0:c4c874d702f9 40 /**
21400688 0:c4c874d702f9 41 * Get state.
21400688 0:c4c874d702f9 42 *
21400688 0:c4c874d702f9 43 * @return Current state.
21400688 0:c4c874d702f9 44 */
21400688 0:c4c874d702f9 45 State getState(void);
21400688 0:c4c874d702f9 46
21400688 0:c4c874d702f9 47 /**
21400688 0:c4c874d702f9 48 * Set data.
21400688 0:c4c874d702f9 49 *
21400688 0:c4c874d702f9 50 * @param format Format.
21400688 0:c4c874d702f9 51 * @param buf Buffer of a data.
21400688 0:c4c874d702f9 52 * @param bitlength Bit length of the data.
21400688 0:c4c874d702f9 53 *
21400688 0:c4c874d702f9 54 * @return Data bit length.
21400688 0:c4c874d702f9 55 */
21400688 0:c4c874d702f9 56 int setData(RemoteIR::Format format, uint8_t *buf, int bitlength);
21400688 0:c4c874d702f9 57
21400688 0:c4c874d702f9 58 private:
21400688 0:c4c874d702f9 59
21400688 0:c4c874d702f9 60 typedef struct {
21400688 0:c4c874d702f9 61 State state;
21400688 0:c4c874d702f9 62 int bitcount;
21400688 0:c4c874d702f9 63 int leader;
21400688 0:c4c874d702f9 64 int data;
21400688 0:c4c874d702f9 65 int trailer;
21400688 0:c4c874d702f9 66 } work_t;
21400688 0:c4c874d702f9 67
21400688 0:c4c874d702f9 68 typedef struct {
21400688 0:c4c874d702f9 69 RemoteIR::Format format;
21400688 0:c4c874d702f9 70 int bitlength;
21400688 0:c4c874d702f9 71 uint8_t buffer[64];
21400688 0:c4c874d702f9 72 } data_t;
21400688 0:c4c874d702f9 73
21400688 0:c4c874d702f9 74 PwmOut tx;
21400688 0:c4c874d702f9 75 Ticker ticker;
21400688 0:c4c874d702f9 76 data_t data;
21400688 0:c4c874d702f9 77 work_t work;
21400688 0:c4c874d702f9 78
21400688 0:c4c874d702f9 79 void tick();
21400688 0:c4c874d702f9 80
21400688 0:c4c874d702f9 81 };
21400688 0:c4c874d702f9 82
21400688 0:c4c874d702f9 83 #endif