Added a new Brand "Kamoona" to be used for other applications that are not a known brand.
Fork of RemoteIR by
TransmitterIR.cpp@12:0651f02169ee, 2015-04-19 (annotated)
- Committer:
- mskamoona
- Date:
- Sun Apr 19 19:11:32 2015 +0000
- Revision:
- 12:0651f02169ee
- Parent:
- 11:268cc2ab63bd
- Child:
- 14:257b2f794dc4
Before changing ReceiverIR.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:ec264f4ce158 | 1 | /** |
shintamainjp | 9:dcfdac59ef74 | 2 | * IR transmitter (Version 0.0.4) |
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 | #include "TransmitterIR.h" |
shintamainjp | 0:ec264f4ce158 | 9 | |
shintamainjp | 10:c54fb1204d1e | 10 | #define LOCK() |
shintamainjp | 10:c54fb1204d1e | 11 | #define UNLOCK() |
shintamainjp | 0:ec264f4ce158 | 12 | |
shintamainjp | 11:268cc2ab63bd | 13 | /** |
shintamainjp | 11:268cc2ab63bd | 14 | * Constructor. |
shintamainjp | 11:268cc2ab63bd | 15 | * |
shintamainjp | 11:268cc2ab63bd | 16 | * @param txpin Pin for transmit IR signal. |
shintamainjp | 11:268cc2ab63bd | 17 | */ |
shintamainjp | 0:ec264f4ce158 | 18 | TransmitterIR::TransmitterIR(PinName txpin) : tx(txpin) { |
shintamainjp | 0:ec264f4ce158 | 19 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 20 | tx.period_us(26.3); |
shintamainjp | 0:ec264f4ce158 | 21 | |
shintamainjp | 0:ec264f4ce158 | 22 | work.state = Idle; |
shintamainjp | 0:ec264f4ce158 | 23 | work.bitcount = 0; |
shintamainjp | 0:ec264f4ce158 | 24 | work.leader = 0; |
shintamainjp | 0:ec264f4ce158 | 25 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 26 | work.trailer = 0; |
shintamainjp | 0:ec264f4ce158 | 27 | |
shintamainjp | 0:ec264f4ce158 | 28 | data.format = RemoteIR::UNKNOWN; |
shintamainjp | 0:ec264f4ce158 | 29 | data.bitlength = 0; |
shintamainjp | 0:ec264f4ce158 | 30 | } |
shintamainjp | 0:ec264f4ce158 | 31 | |
shintamainjp | 11:268cc2ab63bd | 32 | /** |
shintamainjp | 11:268cc2ab63bd | 33 | * Destructor. |
shintamainjp | 11:268cc2ab63bd | 34 | */ |
shintamainjp | 2:08836610bd4a | 35 | TransmitterIR::~TransmitterIR() { |
shintamainjp | 2:08836610bd4a | 36 | } |
shintamainjp | 2:08836610bd4a | 37 | |
shintamainjp | 11:268cc2ab63bd | 38 | /** |
shintamainjp | 11:268cc2ab63bd | 39 | * Get state. |
shintamainjp | 11:268cc2ab63bd | 40 | * |
shintamainjp | 11:268cc2ab63bd | 41 | * @return Current state. |
shintamainjp | 11:268cc2ab63bd | 42 | */ |
shintamainjp | 0:ec264f4ce158 | 43 | TransmitterIR::State TransmitterIR::getState(void) { |
shintamainjp | 9:dcfdac59ef74 | 44 | LOCK(); |
shintamainjp | 0:ec264f4ce158 | 45 | State s = work.state; |
shintamainjp | 9:dcfdac59ef74 | 46 | UNLOCK(); |
shintamainjp | 0:ec264f4ce158 | 47 | return s; |
shintamainjp | 0:ec264f4ce158 | 48 | } |
shintamainjp | 0:ec264f4ce158 | 49 | |
shintamainjp | 11:268cc2ab63bd | 50 | /** |
shintamainjp | 11:268cc2ab63bd | 51 | * Set data. |
shintamainjp | 11:268cc2ab63bd | 52 | * |
shintamainjp | 11:268cc2ab63bd | 53 | * @param format Format. |
shintamainjp | 11:268cc2ab63bd | 54 | * @param buf Buffer of a data. |
shintamainjp | 11:268cc2ab63bd | 55 | * @param bitlength Bit length of the data. |
shintamainjp | 11:268cc2ab63bd | 56 | * |
shintamainjp | 11:268cc2ab63bd | 57 | * @return Data bit length. |
shintamainjp | 11:268cc2ab63bd | 58 | */ |
shintamainjp | 0:ec264f4ce158 | 59 | int TransmitterIR::setData(RemoteIR::Format format, uint8_t *buf, int bitlength) { |
shintamainjp | 9:dcfdac59ef74 | 60 | LOCK(); |
shintamainjp | 0:ec264f4ce158 | 61 | if (work.state != Idle) { |
shintamainjp | 9:dcfdac59ef74 | 62 | UNLOCK(); |
shintamainjp | 0:ec264f4ce158 | 63 | return -1; |
shintamainjp | 0:ec264f4ce158 | 64 | } |
shintamainjp | 0:ec264f4ce158 | 65 | |
shintamainjp | 0:ec264f4ce158 | 66 | work.state = Leader; |
shintamainjp | 0:ec264f4ce158 | 67 | work.bitcount = 0; |
shintamainjp | 0:ec264f4ce158 | 68 | work.leader = 0; |
shintamainjp | 0:ec264f4ce158 | 69 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 70 | work.trailer = 0; |
shintamainjp | 0:ec264f4ce158 | 71 | |
shintamainjp | 0:ec264f4ce158 | 72 | data.format = format; |
shintamainjp | 0:ec264f4ce158 | 73 | data.bitlength = bitlength; |
shintamainjp | 0:ec264f4ce158 | 74 | const int n = bitlength / 8 + (((bitlength % 8) != 0) ? 1 : 0); |
shintamainjp | 0:ec264f4ce158 | 75 | for (int i = 0; i < n; i++) { |
shintamainjp | 0:ec264f4ce158 | 76 | data.buffer[i] = buf[i]; |
shintamainjp | 0:ec264f4ce158 | 77 | } |
shintamainjp | 0:ec264f4ce158 | 78 | |
shintamainjp | 0:ec264f4ce158 | 79 | switch (format) { |
shintamainjp | 0:ec264f4ce158 | 80 | case RemoteIR::NEC: |
shintamainjp | 0:ec264f4ce158 | 81 | ticker.detach(); |
shintamainjp | 11:268cc2ab63bd | 82 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_NEC); |
shintamainjp | 0:ec264f4ce158 | 83 | break; |
shintamainjp | 0:ec264f4ce158 | 84 | case RemoteIR::AEHA: |
shintamainjp | 0:ec264f4ce158 | 85 | ticker.detach(); |
shintamainjp | 11:268cc2ab63bd | 86 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_AEHA); |
shintamainjp | 0:ec264f4ce158 | 87 | break; |
shintamainjp | 0:ec264f4ce158 | 88 | case RemoteIR::SONY: |
shintamainjp | 0:ec264f4ce158 | 89 | ticker.detach(); |
shintamainjp | 11:268cc2ab63bd | 90 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_SONY); |
shintamainjp | 0:ec264f4ce158 | 91 | break; |
mskamoona | 12:0651f02169ee | 92 | case RemoteIR::Samsung: |
mskamoona | 12:0651f02169ee | 93 | ticker.detach(); |
mskamoona | 12:0651f02169ee | 94 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_Samsung); |
mskamoona | 12:0651f02169ee | 95 | break; |
mskamoona | 12:0651f02169ee | 96 | case RemoteIR::Nikon: |
mskamoona | 12:0651f02169ee | 97 | ticker.detach(); |
mskamoona | 12:0651f02169ee | 98 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_Nikon); |
mskamoona | 12:0651f02169ee | 99 | break; |
shintamainjp | 0:ec264f4ce158 | 100 | } |
shintamainjp | 0:ec264f4ce158 | 101 | |
shintamainjp | 9:dcfdac59ef74 | 102 | UNLOCK(); |
shintamainjp | 0:ec264f4ce158 | 103 | return bitlength; |
shintamainjp | 0:ec264f4ce158 | 104 | } |
shintamainjp | 0:ec264f4ce158 | 105 | |
shintamainjp | 0:ec264f4ce158 | 106 | void TransmitterIR::tick(void) { |
shintamainjp | 9:dcfdac59ef74 | 107 | LOCK(); |
shintamainjp | 0:ec264f4ce158 | 108 | switch (work.state) { |
shintamainjp | 0:ec264f4ce158 | 109 | case Idle: |
shintamainjp | 0:ec264f4ce158 | 110 | work.bitcount = 0; |
shintamainjp | 0:ec264f4ce158 | 111 | work.leader = 0; |
shintamainjp | 0:ec264f4ce158 | 112 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 113 | work.trailer = 0; |
shintamainjp | 0:ec264f4ce158 | 114 | break; |
shintamainjp | 0:ec264f4ce158 | 115 | case Leader: |
shintamainjp | 0:ec264f4ce158 | 116 | if (data.format == RemoteIR::NEC) { |
shintamainjp | 0:ec264f4ce158 | 117 | /* |
shintamainjp | 0:ec264f4ce158 | 118 | * NEC. |
shintamainjp | 0:ec264f4ce158 | 119 | */ |
shintamainjp | 0:ec264f4ce158 | 120 | static const int LEADER_NEC_HEAD = 16; |
shintamainjp | 0:ec264f4ce158 | 121 | static const int LEADER_NEC_TAIL = 8; |
shintamainjp | 0:ec264f4ce158 | 122 | if (work.leader < LEADER_NEC_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 123 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 124 | } else { |
shintamainjp | 0:ec264f4ce158 | 125 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 126 | } |
shintamainjp | 0:ec264f4ce158 | 127 | work.leader++; |
shintamainjp | 0:ec264f4ce158 | 128 | if ((LEADER_NEC_HEAD + LEADER_NEC_TAIL) <= work.leader) { |
shintamainjp | 0:ec264f4ce158 | 129 | work.state = Data; |
shintamainjp | 0:ec264f4ce158 | 130 | } |
shintamainjp | 0:ec264f4ce158 | 131 | } else if (data.format == RemoteIR::AEHA) { |
shintamainjp | 0:ec264f4ce158 | 132 | /* |
shintamainjp | 0:ec264f4ce158 | 133 | * AEHA. |
shintamainjp | 0:ec264f4ce158 | 134 | */ |
shintamainjp | 0:ec264f4ce158 | 135 | static const int LEADER_AEHA_HEAD = 8; |
shintamainjp | 0:ec264f4ce158 | 136 | static const int LEADER_AEHA_TAIL = 4; |
shintamainjp | 0:ec264f4ce158 | 137 | if (work.leader < LEADER_AEHA_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 138 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 139 | } else { |
shintamainjp | 0:ec264f4ce158 | 140 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 141 | } |
shintamainjp | 0:ec264f4ce158 | 142 | work.leader++; |
shintamainjp | 0:ec264f4ce158 | 143 | if ((LEADER_AEHA_HEAD + LEADER_AEHA_TAIL) <= work.leader) { |
shintamainjp | 0:ec264f4ce158 | 144 | work.state = Data; |
shintamainjp | 0:ec264f4ce158 | 145 | } |
shintamainjp | 0:ec264f4ce158 | 146 | } else if (data.format == RemoteIR::SONY) { |
shintamainjp | 0:ec264f4ce158 | 147 | /* |
shintamainjp | 0:ec264f4ce158 | 148 | * SONY. |
shintamainjp | 0:ec264f4ce158 | 149 | */ |
shintamainjp | 0:ec264f4ce158 | 150 | static const int LEADER_SONY_HEAD = 4; |
shintamainjp | 0:ec264f4ce158 | 151 | static const int LEADER_SONY_TAIL = 0; |
shintamainjp | 0:ec264f4ce158 | 152 | if (work.leader < LEADER_SONY_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 153 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 154 | } else { |
shintamainjp | 0:ec264f4ce158 | 155 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 156 | } |
shintamainjp | 0:ec264f4ce158 | 157 | work.leader++; |
shintamainjp | 0:ec264f4ce158 | 158 | if ((LEADER_SONY_HEAD + LEADER_SONY_TAIL) <= work.leader) { |
shintamainjp | 0:ec264f4ce158 | 159 | work.state = Data; |
shintamainjp | 0:ec264f4ce158 | 160 | } |
mskamoona | 12:0651f02169ee | 161 | } else if (data.format == RemoteIR::Samsung) { |
mskamoona | 12:0651f02169ee | 162 | /* |
mskamoona | 12:0651f02169ee | 163 | * SONY. |
mskamoona | 12:0651f02169ee | 164 | */ |
mskamoona | 12:0651f02169ee | 165 | static const int LEADER_Samsung_HEAD = 8; |
mskamoona | 12:0651f02169ee | 166 | static const int LEADER_Samsung_TAIL = 8; |
mskamoona | 12:0651f02169ee | 167 | if (work.leader < LEADER_Samsung_HEAD) { |
mskamoona | 12:0651f02169ee | 168 | tx.write(0.5); |
mskamoona | 12:0651f02169ee | 169 | } else { |
mskamoona | 12:0651f02169ee | 170 | tx.write(0.0); |
mskamoona | 12:0651f02169ee | 171 | } |
mskamoona | 12:0651f02169ee | 172 | work.leader++; |
mskamoona | 12:0651f02169ee | 173 | if ((LEADER_Samsung_HEAD + LEADER_Samsung_TAIL) <= work.leader) { |
mskamoona | 12:0651f02169ee | 174 | work.state = Data; |
mskamoona | 12:0651f02169ee | 175 | } |
mskamoona | 12:0651f02169ee | 176 | } else if (data.format == RemoteIR::Nikon) { |
mskamoona | 12:0651f02169ee | 177 | /* |
mskamoona | 12:0651f02169ee | 178 | * Nikon. |
mskamoona | 12:0651f02169ee | 179 | */ |
mskamoona | 12:0651f02169ee | 180 | static const int LEADER_Nikon_HEAD = 0; |
mskamoona | 12:0651f02169ee | 181 | static const int LEADER_Nikon_TAIL = 0; |
mskamoona | 12:0651f02169ee | 182 | if (work.leader < LEADER_Nikon_HEAD) { |
mskamoona | 12:0651f02169ee | 183 | tx.write(0.5); |
mskamoona | 12:0651f02169ee | 184 | } else { |
mskamoona | 12:0651f02169ee | 185 | tx.write(0.0); |
mskamoona | 12:0651f02169ee | 186 | } |
mskamoona | 12:0651f02169ee | 187 | work.leader++; |
mskamoona | 12:0651f02169ee | 188 | if ((LEADER_Nikon_HEAD + LEADER_Nikon_TAIL) <= work.leader) { |
mskamoona | 12:0651f02169ee | 189 | work.state = Data; |
mskamoona | 12:0651f02169ee | 190 | } |
shintamainjp | 0:ec264f4ce158 | 191 | } else { |
shintamainjp | 0:ec264f4ce158 | 192 | } |
shintamainjp | 0:ec264f4ce158 | 193 | break; |
shintamainjp | 0:ec264f4ce158 | 194 | case Data: |
shintamainjp | 0:ec264f4ce158 | 195 | if (data.format == RemoteIR::NEC) { |
shintamainjp | 0:ec264f4ce158 | 196 | /* |
shintamainjp | 0:ec264f4ce158 | 197 | * NEC. |
shintamainjp | 0:ec264f4ce158 | 198 | */ |
shintamainjp | 0:ec264f4ce158 | 199 | if (work.data == 0) { |
shintamainjp | 0:ec264f4ce158 | 200 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 201 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 202 | } else { |
shintamainjp | 0:ec264f4ce158 | 203 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 204 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
shintamainjp | 0:ec264f4ce158 | 205 | if (3 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 206 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 207 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 208 | } else { |
shintamainjp | 0:ec264f4ce158 | 209 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 210 | } |
shintamainjp | 0:ec264f4ce158 | 211 | } else { |
shintamainjp | 0:ec264f4ce158 | 212 | if (1 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 213 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 214 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 215 | } else { |
shintamainjp | 0:ec264f4ce158 | 216 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 217 | } |
shintamainjp | 0:ec264f4ce158 | 218 | } |
shintamainjp | 0:ec264f4ce158 | 219 | } |
shintamainjp | 0:ec264f4ce158 | 220 | if (data.bitlength <= work.bitcount) { |
shintamainjp | 0:ec264f4ce158 | 221 | work.state = Trailer; |
shintamainjp | 0:ec264f4ce158 | 222 | } |
shintamainjp | 0:ec264f4ce158 | 223 | } else if (data.format == RemoteIR::AEHA) { |
shintamainjp | 0:ec264f4ce158 | 224 | /* |
shintamainjp | 0:ec264f4ce158 | 225 | * AEHA. |
shintamainjp | 0:ec264f4ce158 | 226 | */ |
shintamainjp | 0:ec264f4ce158 | 227 | if (work.data == 0) { |
shintamainjp | 0:ec264f4ce158 | 228 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 229 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 230 | } else { |
shintamainjp | 0:ec264f4ce158 | 231 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 232 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
shintamainjp | 0:ec264f4ce158 | 233 | if (3 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 234 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 235 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 236 | } else { |
shintamainjp | 0:ec264f4ce158 | 237 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 238 | } |
shintamainjp | 0:ec264f4ce158 | 239 | } else { |
shintamainjp | 0:ec264f4ce158 | 240 | if (1 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 241 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 242 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 243 | } else { |
shintamainjp | 0:ec264f4ce158 | 244 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 245 | } |
shintamainjp | 0:ec264f4ce158 | 246 | } |
shintamainjp | 0:ec264f4ce158 | 247 | } |
shintamainjp | 0:ec264f4ce158 | 248 | if (data.bitlength <= work.bitcount) { |
shintamainjp | 0:ec264f4ce158 | 249 | work.state = Trailer; |
shintamainjp | 0:ec264f4ce158 | 250 | } |
shintamainjp | 0:ec264f4ce158 | 251 | } else if (data.format == RemoteIR::SONY) { |
shintamainjp | 0:ec264f4ce158 | 252 | /* |
shintamainjp | 0:ec264f4ce158 | 253 | * SONY. |
shintamainjp | 0:ec264f4ce158 | 254 | */ |
shintamainjp | 0:ec264f4ce158 | 255 | if (work.data == 0) { |
shintamainjp | 0:ec264f4ce158 | 256 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 257 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 258 | } else { |
shintamainjp | 0:ec264f4ce158 | 259 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 260 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
shintamainjp | 0:ec264f4ce158 | 261 | if (2 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 262 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 263 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 264 | } else { |
shintamainjp | 0:ec264f4ce158 | 265 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 266 | } |
shintamainjp | 0:ec264f4ce158 | 267 | } else { |
shintamainjp | 0:ec264f4ce158 | 268 | if (1 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 269 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 270 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 271 | } else { |
shintamainjp | 0:ec264f4ce158 | 272 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 273 | } |
shintamainjp | 0:ec264f4ce158 | 274 | } |
shintamainjp | 0:ec264f4ce158 | 275 | } |
shintamainjp | 0:ec264f4ce158 | 276 | if (data.bitlength <= work.bitcount) { |
shintamainjp | 0:ec264f4ce158 | 277 | work.state = Trailer; |
shintamainjp | 0:ec264f4ce158 | 278 | } |
mskamoona | 12:0651f02169ee | 279 | }else if (data.format == RemoteIR::Samsung) { |
mskamoona | 12:0651f02169ee | 280 | /* |
mskamoona | 12:0651f02169ee | 281 | * Samsung. |
mskamoona | 12:0651f02169ee | 282 | */ |
mskamoona | 12:0651f02169ee | 283 | if (work.data == 0) { |
mskamoona | 12:0651f02169ee | 284 | tx.write(0.5); |
mskamoona | 12:0651f02169ee | 285 | work.data++; |
mskamoona | 12:0651f02169ee | 286 | } else { |
mskamoona | 12:0651f02169ee | 287 | tx.write(0.0); |
mskamoona | 12:0651f02169ee | 288 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
mskamoona | 12:0651f02169ee | 289 | if (1 <= work.data) { |
mskamoona | 12:0651f02169ee | 290 | work.bitcount++; |
mskamoona | 12:0651f02169ee | 291 | work.data = 0; |
mskamoona | 12:0651f02169ee | 292 | } else { |
mskamoona | 12:0651f02169ee | 293 | work.data++; |
mskamoona | 12:0651f02169ee | 294 | } |
mskamoona | 12:0651f02169ee | 295 | } else { |
mskamoona | 12:0651f02169ee | 296 | if (3 <= work.data) { |
mskamoona | 12:0651f02169ee | 297 | work.bitcount++; |
mskamoona | 12:0651f02169ee | 298 | work.data = 0; |
mskamoona | 12:0651f02169ee | 299 | } else { |
mskamoona | 12:0651f02169ee | 300 | work.data++; |
mskamoona | 12:0651f02169ee | 301 | } |
mskamoona | 12:0651f02169ee | 302 | } |
mskamoona | 12:0651f02169ee | 303 | } |
mskamoona | 12:0651f02169ee | 304 | if (data.bitlength <= work.bitcount) { |
mskamoona | 12:0651f02169ee | 305 | work.state = Trailer; |
mskamoona | 12:0651f02169ee | 306 | } else { |
shintamainjp | 0:ec264f4ce158 | 307 | } |
shintamainjp | 0:ec264f4ce158 | 308 | break; |
shintamainjp | 0:ec264f4ce158 | 309 | case Trailer: |
shintamainjp | 0:ec264f4ce158 | 310 | if (data.format == RemoteIR::NEC) { |
shintamainjp | 0:ec264f4ce158 | 311 | /* |
shintamainjp | 0:ec264f4ce158 | 312 | * NEC. |
shintamainjp | 0:ec264f4ce158 | 313 | */ |
shintamainjp | 0:ec264f4ce158 | 314 | static const int TRAILER_NEC_HEAD = 1; |
shintamainjp | 0:ec264f4ce158 | 315 | static const int TRAILER_NEC_TAIL = 2; |
shintamainjp | 0:ec264f4ce158 | 316 | if (work.trailer < TRAILER_NEC_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 317 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 318 | } else { |
shintamainjp | 0:ec264f4ce158 | 319 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 320 | } |
shintamainjp | 0:ec264f4ce158 | 321 | work.trailer++; |
shintamainjp | 0:ec264f4ce158 | 322 | if ((TRAILER_NEC_HEAD + TRAILER_NEC_TAIL) <= work.trailer) { |
shintamainjp | 0:ec264f4ce158 | 323 | work.state = Idle; |
shintamainjp | 0:ec264f4ce158 | 324 | //ticker.detach(); |
shintamainjp | 0:ec264f4ce158 | 325 | } |
shintamainjp | 0:ec264f4ce158 | 326 | } else if (data.format == RemoteIR::AEHA) { |
shintamainjp | 0:ec264f4ce158 | 327 | /* |
shintamainjp | 0:ec264f4ce158 | 328 | * AEHA. |
shintamainjp | 0:ec264f4ce158 | 329 | */ |
shintamainjp | 0:ec264f4ce158 | 330 | static const int TRAILER_AEHA_HEAD = 1; |
shintamainjp | 11:268cc2ab63bd | 331 | static const int TRAILER_AEHA_TAIL = 8000 / RemoteIR::TUS_AEHA; |
shintamainjp | 0:ec264f4ce158 | 332 | if (work.trailer < TRAILER_AEHA_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 333 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 334 | } else { |
shintamainjp | 0:ec264f4ce158 | 335 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 336 | } |
shintamainjp | 0:ec264f4ce158 | 337 | work.trailer++; |
shintamainjp | 0:ec264f4ce158 | 338 | if ((TRAILER_AEHA_HEAD + TRAILER_AEHA_TAIL) <= work.trailer) { |
shintamainjp | 0:ec264f4ce158 | 339 | work.state = Idle; |
shintamainjp | 0:ec264f4ce158 | 340 | //ticker.detach(); |
shintamainjp | 0:ec264f4ce158 | 341 | } |
shintamainjp | 0:ec264f4ce158 | 342 | } else if (data.format == RemoteIR::SONY) { |
shintamainjp | 0:ec264f4ce158 | 343 | /* |
shintamainjp | 0:ec264f4ce158 | 344 | * SONY. |
shintamainjp | 0:ec264f4ce158 | 345 | */ |
shintamainjp | 0:ec264f4ce158 | 346 | static const int TRAILER_SONY_HEAD = 0; |
shintamainjp | 0:ec264f4ce158 | 347 | static const int TRAILER_SONY_TAIL = 0; |
shintamainjp | 0:ec264f4ce158 | 348 | if (work.trailer < TRAILER_SONY_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 349 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 350 | } else { |
shintamainjp | 0:ec264f4ce158 | 351 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 352 | } |
shintamainjp | 0:ec264f4ce158 | 353 | work.trailer++; |
shintamainjp | 0:ec264f4ce158 | 354 | if ((TRAILER_SONY_HEAD + TRAILER_SONY_TAIL) <= work.trailer) { |
shintamainjp | 0:ec264f4ce158 | 355 | work.state = Idle; |
shintamainjp | 0:ec264f4ce158 | 356 | //ticker.detach(); |
shintamainjp | 0:ec264f4ce158 | 357 | } |
mskamoona | 12:0651f02169ee | 358 | }else if (data.format == RemoteIR::Samsung) { |
mskamoona | 12:0651f02169ee | 359 | /* |
mskamoona | 12:0651f02169ee | 360 | * Samsung. |
mskamoona | 12:0651f02169ee | 361 | */ |
mskamoona | 12:0651f02169ee | 362 | static const int TRAILER_Samsung_HEAD = 1; |
mskamoona | 12:0651f02169ee | 363 | static const int TRAILER_Samsung_TAIL = 55; |
mskamoona | 12:0651f02169ee | 364 | if (work.trailer < TRAILER_Samsung_HEAD) { |
mskamoona | 12:0651f02169ee | 365 | tx.write(0.5); |
mskamoona | 12:0651f02169ee | 366 | } else { |
mskamoona | 12:0651f02169ee | 367 | tx.write(0.0); |
mskamoona | 12:0651f02169ee | 368 | } |
mskamoona | 12:0651f02169ee | 369 | work.trailer++; |
mskamoona | 12:0651f02169ee | 370 | if ((TRAILER_Samsung_HEAD + TRAILER_Samsung_TAIL) <= work.trailer) { |
mskamoona | 12:0651f02169ee | 371 | work.state = Idle; |
mskamoona | 12:0651f02169ee | 372 | //ticker.detach(); |
mskamoona | 12:0651f02169ee | 373 | } |
shintamainjp | 0:ec264f4ce158 | 374 | } else { |
shintamainjp | 0:ec264f4ce158 | 375 | } |
shintamainjp | 0:ec264f4ce158 | 376 | break; |
shintamainjp | 0:ec264f4ce158 | 377 | default: |
shintamainjp | 0:ec264f4ce158 | 378 | break; |
shintamainjp | 0:ec264f4ce158 | 379 | } |
shintamainjp | 9:dcfdac59ef74 | 380 | UNLOCK(); |
shintamainjp | 0:ec264f4ce158 | 381 | } |
mskamoona | 12:0651f02169ee | 382 | } |