keuzeproject mdev 1ITF groep: E3
Fork of RemoteIR by
TransmitterIR.cpp@12:0767bcde0d32, 2016-02-01 (annotated)
- Committer:
- 1ITF3
- Date:
- Mon Feb 01 10:20:31 2016 +0000
- Revision:
- 12:0767bcde0d32
- Parent:
- 11:268cc2ab63bd
Test code TV RC6 bij gecodeerd
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; |
1ITF3 | 12:0767bcde0d32 | 71 | |
1ITF3 | 12:0767bcde0d32 | 72 | |
shintamainjp | 0:ec264f4ce158 | 73 | |
shintamainjp | 0:ec264f4ce158 | 74 | data.format = format; |
shintamainjp | 0:ec264f4ce158 | 75 | data.bitlength = bitlength; |
shintamainjp | 0:ec264f4ce158 | 76 | const int n = bitlength / 8 + (((bitlength % 8) != 0) ? 1 : 0); |
shintamainjp | 0:ec264f4ce158 | 77 | for (int i = 0; i < n; i++) { |
shintamainjp | 0:ec264f4ce158 | 78 | data.buffer[i] = buf[i]; |
shintamainjp | 0:ec264f4ce158 | 79 | } |
shintamainjp | 0:ec264f4ce158 | 80 | |
shintamainjp | 0:ec264f4ce158 | 81 | switch (format) { |
shintamainjp | 0:ec264f4ce158 | 82 | case RemoteIR::NEC: |
shintamainjp | 0:ec264f4ce158 | 83 | ticker.detach(); |
shintamainjp | 11:268cc2ab63bd | 84 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_NEC); |
shintamainjp | 0:ec264f4ce158 | 85 | break; |
shintamainjp | 0:ec264f4ce158 | 86 | case RemoteIR::AEHA: |
shintamainjp | 0:ec264f4ce158 | 87 | ticker.detach(); |
shintamainjp | 11:268cc2ab63bd | 88 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_AEHA); |
shintamainjp | 0:ec264f4ce158 | 89 | break; |
shintamainjp | 0:ec264f4ce158 | 90 | case RemoteIR::SONY: |
shintamainjp | 0:ec264f4ce158 | 91 | ticker.detach(); |
shintamainjp | 11:268cc2ab63bd | 92 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_SONY); |
shintamainjp | 0:ec264f4ce158 | 93 | break; |
1ITF3 | 12:0767bcde0d32 | 94 | case RemoteIR::RC6: |
1ITF3 | 12:0767bcde0d32 | 95 | ticker.detach(); |
1ITF3 | 12:0767bcde0d32 | 96 | ticker.attach_us(this, &TransmitterIR::tick, RemoteIR::TUS_RC6); |
1ITF3 | 12:0767bcde0d32 | 97 | break; |
shintamainjp | 0:ec264f4ce158 | 98 | } |
shintamainjp | 0:ec264f4ce158 | 99 | |
shintamainjp | 9:dcfdac59ef74 | 100 | UNLOCK(); |
shintamainjp | 0:ec264f4ce158 | 101 | return bitlength; |
shintamainjp | 0:ec264f4ce158 | 102 | } |
shintamainjp | 0:ec264f4ce158 | 103 | |
shintamainjp | 0:ec264f4ce158 | 104 | void TransmitterIR::tick(void) { |
shintamainjp | 9:dcfdac59ef74 | 105 | LOCK(); |
shintamainjp | 0:ec264f4ce158 | 106 | switch (work.state) { |
shintamainjp | 0:ec264f4ce158 | 107 | case Idle: |
shintamainjp | 0:ec264f4ce158 | 108 | work.bitcount = 0; |
shintamainjp | 0:ec264f4ce158 | 109 | work.leader = 0; |
shintamainjp | 0:ec264f4ce158 | 110 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 111 | work.trailer = 0; |
shintamainjp | 0:ec264f4ce158 | 112 | break; |
shintamainjp | 0:ec264f4ce158 | 113 | case Leader: |
shintamainjp | 0:ec264f4ce158 | 114 | if (data.format == RemoteIR::NEC) { |
shintamainjp | 0:ec264f4ce158 | 115 | /* |
shintamainjp | 0:ec264f4ce158 | 116 | * NEC. |
shintamainjp | 0:ec264f4ce158 | 117 | */ |
shintamainjp | 0:ec264f4ce158 | 118 | static const int LEADER_NEC_HEAD = 16; |
shintamainjp | 0:ec264f4ce158 | 119 | static const int LEADER_NEC_TAIL = 8; |
1ITF3 | 12:0767bcde0d32 | 120 | |
shintamainjp | 0:ec264f4ce158 | 121 | if (work.leader < LEADER_NEC_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 122 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 123 | } else { |
shintamainjp | 0:ec264f4ce158 | 124 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 125 | } |
shintamainjp | 0:ec264f4ce158 | 126 | work.leader++; |
shintamainjp | 0:ec264f4ce158 | 127 | if ((LEADER_NEC_HEAD + LEADER_NEC_TAIL) <= work.leader) { |
shintamainjp | 0:ec264f4ce158 | 128 | work.state = Data; |
shintamainjp | 0:ec264f4ce158 | 129 | } |
1ITF3 | 12:0767bcde0d32 | 130 | } else if (data.format == RemoteIR::RC6){ |
1ITF3 | 12:0767bcde0d32 | 131 | //RC6 |
1ITF3 | 12:0767bcde0d32 | 132 | static const int LEADER_RC6_HEAD = 6; |
1ITF3 | 12:0767bcde0d32 | 133 | static const int LEADER_RC6_TAIL = 2; |
1ITF3 | 12:0767bcde0d32 | 134 | static const int LEADER_RC6_TOGGLE= 888; |
1ITF3 | 12:0767bcde0d32 | 135 | if (work.leader < LEADER_RC6_HEAD) { |
1ITF3 | 12:0767bcde0d32 | 136 | tx.write(0.5); |
1ITF3 | 12:0767bcde0d32 | 137 | |
1ITF3 | 12:0767bcde0d32 | 138 | } else { |
1ITF3 | 12:0767bcde0d32 | 139 | tx.write(0.0); |
1ITF3 | 12:0767bcde0d32 | 140 | } |
1ITF3 | 12:0767bcde0d32 | 141 | work.leader++; |
1ITF3 | 12:0767bcde0d32 | 142 | if ((LEADER_RC6_HEAD + LEADER_RC6_TAIL) <= work.leader) { |
1ITF3 | 12:0767bcde0d32 | 143 | work.state = Toggle; |
1ITF3 | 12:0767bcde0d32 | 144 | } |
shintamainjp | 0:ec264f4ce158 | 145 | } else if (data.format == RemoteIR::AEHA) { |
shintamainjp | 0:ec264f4ce158 | 146 | /* |
shintamainjp | 0:ec264f4ce158 | 147 | * AEHA. |
shintamainjp | 0:ec264f4ce158 | 148 | */ |
shintamainjp | 0:ec264f4ce158 | 149 | static const int LEADER_AEHA_HEAD = 8; |
shintamainjp | 0:ec264f4ce158 | 150 | static const int LEADER_AEHA_TAIL = 4; |
shintamainjp | 0:ec264f4ce158 | 151 | if (work.leader < LEADER_AEHA_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 152 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 153 | } else { |
shintamainjp | 0:ec264f4ce158 | 154 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 155 | } |
shintamainjp | 0:ec264f4ce158 | 156 | work.leader++; |
shintamainjp | 0:ec264f4ce158 | 157 | if ((LEADER_AEHA_HEAD + LEADER_AEHA_TAIL) <= work.leader) { |
shintamainjp | 0:ec264f4ce158 | 158 | work.state = Data; |
shintamainjp | 0:ec264f4ce158 | 159 | } |
shintamainjp | 0:ec264f4ce158 | 160 | } else if (data.format == RemoteIR::SONY) { |
shintamainjp | 0:ec264f4ce158 | 161 | /* |
shintamainjp | 0:ec264f4ce158 | 162 | * SONY. |
shintamainjp | 0:ec264f4ce158 | 163 | */ |
shintamainjp | 0:ec264f4ce158 | 164 | static const int LEADER_SONY_HEAD = 4; |
shintamainjp | 0:ec264f4ce158 | 165 | static const int LEADER_SONY_TAIL = 0; |
shintamainjp | 0:ec264f4ce158 | 166 | if (work.leader < LEADER_SONY_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 167 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 168 | } else { |
shintamainjp | 0:ec264f4ce158 | 169 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 170 | } |
shintamainjp | 0:ec264f4ce158 | 171 | work.leader++; |
shintamainjp | 0:ec264f4ce158 | 172 | if ((LEADER_SONY_HEAD + LEADER_SONY_TAIL) <= work.leader) { |
shintamainjp | 0:ec264f4ce158 | 173 | work.state = Data; |
shintamainjp | 0:ec264f4ce158 | 174 | } |
shintamainjp | 0:ec264f4ce158 | 175 | } else { |
shintamainjp | 0:ec264f4ce158 | 176 | } |
shintamainjp | 0:ec264f4ce158 | 177 | break; |
1ITF3 | 12:0767bcde0d32 | 178 | work.state = Leader; |
1ITF3 | 12:0767bcde0d32 | 179 | |
1ITF3 | 12:0767bcde0d32 | 180 | case Toggle: |
1ITF3 | 12:0767bcde0d32 | 181 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
1ITF3 | 12:0767bcde0d32 | 182 | if (1 <= work.data) { |
1ITF3 | 12:0767bcde0d32 | 183 | tx.write(0.5); |
1ITF3 | 12:0767bcde0d32 | 184 | } else { |
1ITF3 | 12:0767bcde0d32 | 185 | work.data++; |
1ITF3 | 12:0767bcde0d32 | 186 | } |
1ITF3 | 12:0767bcde0d32 | 187 | |
1ITF3 | 12:0767bcde0d32 | 188 | |
1ITF3 | 12:0767bcde0d32 | 189 | } else { |
1ITF3 | 12:0767bcde0d32 | 190 | work.data++; |
1ITF3 | 12:0767bcde0d32 | 191 | } |
1ITF3 | 12:0767bcde0d32 | 192 | |
1ITF3 | 12:0767bcde0d32 | 193 | |
1ITF3 | 12:0767bcde0d32 | 194 | break; |
shintamainjp | 0:ec264f4ce158 | 195 | case Data: |
shintamainjp | 0:ec264f4ce158 | 196 | if (data.format == RemoteIR::NEC) { |
shintamainjp | 0:ec264f4ce158 | 197 | /* |
shintamainjp | 0:ec264f4ce158 | 198 | * NEC. |
shintamainjp | 0:ec264f4ce158 | 199 | */ |
shintamainjp | 0:ec264f4ce158 | 200 | if (work.data == 0) { |
shintamainjp | 0:ec264f4ce158 | 201 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 202 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 203 | } else { |
shintamainjp | 0:ec264f4ce158 | 204 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 205 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
shintamainjp | 0:ec264f4ce158 | 206 | if (3 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 207 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 208 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 209 | } else { |
shintamainjp | 0:ec264f4ce158 | 210 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 211 | } |
shintamainjp | 0:ec264f4ce158 | 212 | } else { |
shintamainjp | 0:ec264f4ce158 | 213 | if (1 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 214 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 215 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 216 | } else { |
shintamainjp | 0:ec264f4ce158 | 217 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 218 | } |
shintamainjp | 0:ec264f4ce158 | 219 | } |
shintamainjp | 0:ec264f4ce158 | 220 | } |
shintamainjp | 0:ec264f4ce158 | 221 | if (data.bitlength <= work.bitcount) { |
shintamainjp | 0:ec264f4ce158 | 222 | work.state = Trailer; |
shintamainjp | 0:ec264f4ce158 | 223 | } |
1ITF3 | 12:0767bcde0d32 | 224 | } else if (data.format == RemoteIR::RC6) { |
1ITF3 | 12:0767bcde0d32 | 225 | //RC6 |
1ITF3 | 12:0767bcde0d32 | 226 | |
1ITF3 | 12:0767bcde0d32 | 227 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
1ITF3 | 12:0767bcde0d32 | 228 | if (1 <= work.data) { |
1ITF3 | 12:0767bcde0d32 | 229 | tx.write(0.5); |
1ITF3 | 12:0767bcde0d32 | 230 | } else { |
1ITF3 | 12:0767bcde0d32 | 231 | work.data++; |
1ITF3 | 12:0767bcde0d32 | 232 | } |
1ITF3 | 12:0767bcde0d32 | 233 | } else { |
1ITF3 | 12:0767bcde0d32 | 234 | if (0 <= work.data) { |
1ITF3 | 12:0767bcde0d32 | 235 | tx.write(0.0); |
1ITF3 | 12:0767bcde0d32 | 236 | |
1ITF3 | 12:0767bcde0d32 | 237 | } else { |
1ITF3 | 12:0767bcde0d32 | 238 | work.data++; |
1ITF3 | 12:0767bcde0d32 | 239 | } |
1ITF3 | 12:0767bcde0d32 | 240 | |
1ITF3 | 12:0767bcde0d32 | 241 | } |
1ITF3 | 12:0767bcde0d32 | 242 | if (data.bitlength <= work.bitcount) { |
1ITF3 | 12:0767bcde0d32 | 243 | work.state = Trailer; |
1ITF3 | 12:0767bcde0d32 | 244 | } |
1ITF3 | 12:0767bcde0d32 | 245 | |
shintamainjp | 0:ec264f4ce158 | 246 | } else if (data.format == RemoteIR::AEHA) { |
shintamainjp | 0:ec264f4ce158 | 247 | /* |
shintamainjp | 0:ec264f4ce158 | 248 | * AEHA. |
shintamainjp | 0:ec264f4ce158 | 249 | */ |
shintamainjp | 0:ec264f4ce158 | 250 | if (work.data == 0) { |
shintamainjp | 0:ec264f4ce158 | 251 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 252 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 253 | } else { |
shintamainjp | 0:ec264f4ce158 | 254 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 255 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
shintamainjp | 0:ec264f4ce158 | 256 | if (3 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 257 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 258 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 259 | } else { |
shintamainjp | 0:ec264f4ce158 | 260 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 261 | } |
shintamainjp | 0:ec264f4ce158 | 262 | } else { |
shintamainjp | 0:ec264f4ce158 | 263 | if (1 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 264 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 265 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 266 | } else { |
shintamainjp | 0:ec264f4ce158 | 267 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 268 | } |
1ITF3 | 12:0767bcde0d32 | 269 | |
shintamainjp | 0:ec264f4ce158 | 270 | } |
1ITF3 | 12:0767bcde0d32 | 271 | |
shintamainjp | 0:ec264f4ce158 | 272 | } |
shintamainjp | 0:ec264f4ce158 | 273 | if (data.bitlength <= work.bitcount) { |
shintamainjp | 0:ec264f4ce158 | 274 | work.state = Trailer; |
shintamainjp | 0:ec264f4ce158 | 275 | } |
shintamainjp | 0:ec264f4ce158 | 276 | } else if (data.format == RemoteIR::SONY) { |
shintamainjp | 0:ec264f4ce158 | 277 | /* |
shintamainjp | 0:ec264f4ce158 | 278 | * SONY. |
shintamainjp | 0:ec264f4ce158 | 279 | */ |
shintamainjp | 0:ec264f4ce158 | 280 | if (work.data == 0) { |
shintamainjp | 0:ec264f4ce158 | 281 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 282 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 283 | } else { |
shintamainjp | 0:ec264f4ce158 | 284 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 285 | if (0 != (data.buffer[work.bitcount / 8] & (1 << work.bitcount % 8))) { |
shintamainjp | 0:ec264f4ce158 | 286 | if (2 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 287 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 288 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 289 | } else { |
shintamainjp | 0:ec264f4ce158 | 290 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 291 | } |
shintamainjp | 0:ec264f4ce158 | 292 | } else { |
shintamainjp | 0:ec264f4ce158 | 293 | if (1 <= work.data) { |
shintamainjp | 0:ec264f4ce158 | 294 | work.bitcount++; |
shintamainjp | 0:ec264f4ce158 | 295 | work.data = 0; |
shintamainjp | 0:ec264f4ce158 | 296 | } else { |
shintamainjp | 0:ec264f4ce158 | 297 | work.data++; |
shintamainjp | 0:ec264f4ce158 | 298 | } |
shintamainjp | 0:ec264f4ce158 | 299 | } |
shintamainjp | 0:ec264f4ce158 | 300 | } |
shintamainjp | 0:ec264f4ce158 | 301 | if (data.bitlength <= work.bitcount) { |
shintamainjp | 0:ec264f4ce158 | 302 | work.state = Trailer; |
shintamainjp | 0:ec264f4ce158 | 303 | } |
shintamainjp | 0:ec264f4ce158 | 304 | } else { |
shintamainjp | 0:ec264f4ce158 | 305 | } |
shintamainjp | 0:ec264f4ce158 | 306 | break; |
shintamainjp | 0:ec264f4ce158 | 307 | case Trailer: |
shintamainjp | 0:ec264f4ce158 | 308 | if (data.format == RemoteIR::NEC) { |
shintamainjp | 0:ec264f4ce158 | 309 | /* |
shintamainjp | 0:ec264f4ce158 | 310 | * NEC. |
shintamainjp | 0:ec264f4ce158 | 311 | */ |
shintamainjp | 0:ec264f4ce158 | 312 | static const int TRAILER_NEC_HEAD = 1; |
shintamainjp | 0:ec264f4ce158 | 313 | static const int TRAILER_NEC_TAIL = 2; |
shintamainjp | 0:ec264f4ce158 | 314 | if (work.trailer < TRAILER_NEC_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 315 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 316 | } else { |
shintamainjp | 0:ec264f4ce158 | 317 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 318 | } |
shintamainjp | 0:ec264f4ce158 | 319 | work.trailer++; |
shintamainjp | 0:ec264f4ce158 | 320 | if ((TRAILER_NEC_HEAD + TRAILER_NEC_TAIL) <= work.trailer) { |
shintamainjp | 0:ec264f4ce158 | 321 | work.state = Idle; |
shintamainjp | 0:ec264f4ce158 | 322 | //ticker.detach(); |
shintamainjp | 0:ec264f4ce158 | 323 | } |
1ITF3 | 12:0767bcde0d32 | 324 | } else if (data.format == RemoteIR::RC6) { |
1ITF3 | 12:0767bcde0d32 | 325 | //RC6 |
1ITF3 | 12:0767bcde0d32 | 326 | static const int TRAILER_RC6_HEAD = 0; |
1ITF3 | 12:0767bcde0d32 | 327 | static const int TRAILER_RC6_TAIL = 1; |
1ITF3 | 12:0767bcde0d32 | 328 | if (work.trailer < TRAILER_RC6_HEAD) { |
1ITF3 | 12:0767bcde0d32 | 329 | tx.write(0.5); |
1ITF3 | 12:0767bcde0d32 | 330 | } else { |
1ITF3 | 12:0767bcde0d32 | 331 | tx.write(0.0); |
1ITF3 | 12:0767bcde0d32 | 332 | } |
1ITF3 | 12:0767bcde0d32 | 333 | work.trailer++; |
1ITF3 | 12:0767bcde0d32 | 334 | if ((TRAILER_RC6_HEAD + TRAILER_RC6_TAIL) <= work.trailer) { |
1ITF3 | 12:0767bcde0d32 | 335 | work.state = Idle; |
1ITF3 | 12:0767bcde0d32 | 336 | //ticker.detach(); |
1ITF3 | 12:0767bcde0d32 | 337 | } |
shintamainjp | 0:ec264f4ce158 | 338 | } else if (data.format == RemoteIR::AEHA) { |
shintamainjp | 0:ec264f4ce158 | 339 | /* |
shintamainjp | 0:ec264f4ce158 | 340 | * AEHA. |
shintamainjp | 0:ec264f4ce158 | 341 | */ |
shintamainjp | 0:ec264f4ce158 | 342 | static const int TRAILER_AEHA_HEAD = 1; |
shintamainjp | 11:268cc2ab63bd | 343 | static const int TRAILER_AEHA_TAIL = 8000 / RemoteIR::TUS_AEHA; |
shintamainjp | 0:ec264f4ce158 | 344 | if (work.trailer < TRAILER_AEHA_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 345 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 346 | } else { |
shintamainjp | 0:ec264f4ce158 | 347 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 348 | } |
shintamainjp | 0:ec264f4ce158 | 349 | work.trailer++; |
shintamainjp | 0:ec264f4ce158 | 350 | if ((TRAILER_AEHA_HEAD + TRAILER_AEHA_TAIL) <= work.trailer) { |
shintamainjp | 0:ec264f4ce158 | 351 | work.state = Idle; |
shintamainjp | 0:ec264f4ce158 | 352 | //ticker.detach(); |
shintamainjp | 0:ec264f4ce158 | 353 | } |
shintamainjp | 0:ec264f4ce158 | 354 | } else if (data.format == RemoteIR::SONY) { |
shintamainjp | 0:ec264f4ce158 | 355 | /* |
shintamainjp | 0:ec264f4ce158 | 356 | * SONY. |
shintamainjp | 0:ec264f4ce158 | 357 | */ |
shintamainjp | 0:ec264f4ce158 | 358 | static const int TRAILER_SONY_HEAD = 0; |
shintamainjp | 0:ec264f4ce158 | 359 | static const int TRAILER_SONY_TAIL = 0; |
shintamainjp | 0:ec264f4ce158 | 360 | if (work.trailer < TRAILER_SONY_HEAD) { |
shintamainjp | 0:ec264f4ce158 | 361 | tx.write(0.5); |
shintamainjp | 0:ec264f4ce158 | 362 | } else { |
shintamainjp | 0:ec264f4ce158 | 363 | tx.write(0.0); |
shintamainjp | 0:ec264f4ce158 | 364 | } |
shintamainjp | 0:ec264f4ce158 | 365 | work.trailer++; |
shintamainjp | 0:ec264f4ce158 | 366 | if ((TRAILER_SONY_HEAD + TRAILER_SONY_TAIL) <= work.trailer) { |
shintamainjp | 0:ec264f4ce158 | 367 | work.state = Idle; |
shintamainjp | 0:ec264f4ce158 | 368 | //ticker.detach(); |
shintamainjp | 0:ec264f4ce158 | 369 | } |
shintamainjp | 0:ec264f4ce158 | 370 | } else { |
shintamainjp | 0:ec264f4ce158 | 371 | } |
shintamainjp | 0:ec264f4ce158 | 372 | break; |
shintamainjp | 0:ec264f4ce158 | 373 | default: |
shintamainjp | 0:ec264f4ce158 | 374 | break; |
shintamainjp | 0:ec264f4ce158 | 375 | } |
shintamainjp | 9:dcfdac59ef74 | 376 | UNLOCK(); |
shintamainjp | 0:ec264f4ce158 | 377 | } |