34 #ifndef _IR_BANG_OLUFSEN_HPP
35 #define _IR_BANG_OLUFSEN_HPP
93 #if defined(DECODE_BEO)
94 # if defined(ENABLE_BEO_WITHOUT_FRAME_GAP)
95 # if RECORD_GAP_MICROS > 13000
96 #warning If defined ENABLE_BEO_WITHOUT_FRAME_GAP, RECORD_GAP_MICROS must be set to 1300 by "#define RECORD_GAP_MICROS 13000"
99 # if RECORD_GAP_MICROS < 16000
100 #error If not defined ENABLE_BEO_WITHOUT_FRAME_GAP, RECORD_GAP_MICROS must be set to a value >= 1600 by "#define RECORD_GAP_MICROS 16000"
105 #define BEO_DATA_BITS 8 // Command or character
107 #define BEO_UNIT 3125 // All timings are in microseconds
109 #define BEO_IR_MARK 200 // The length of a mark in the IR protocol
110 #define BEO_DATALINK_MARK (BEO_UNIT / 2) // The length of a mark in the Datalink protocol
112 #define BEO_PULSE_LENGTH_ZERO BEO_UNIT // The length of a one to zero transition
113 #define BEO_PULSE_LENGTH_EQUAL (2 * BEO_UNIT) // 6250 The length of an equal bit
114 #define BEO_PULSE_LENGTH_ONE (3 * BEO_UNIT) // 9375 The length of a zero to one transition
115 #define BEO_PULSE_LENGTH_TRAILING_BIT (4 * BEO_UNIT) // 12500 The length of the stop bit
116 #define BEO_PULSE_LENGTH_START_BIT (5 * BEO_UNIT) // 15625 The length of the start bit
122 #ifdef BEO_LOCAL_DEBUG
123 # define BEO_DEBUG_PRINT(...) Serial.print(__VA_ARGS__)
124 # define BEO_DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__)
126 # define BEO_DEBUG_PRINT(...) void()
127 # define BEO_DEBUG_PRINTLN(...) void()
130 #ifdef BEO_LOCAL_TRACE
131 # undef BEO_TRACE_PRINT
132 # undef BEO_TRACE_PRINTLN
133 # define BEO_TRACE_PRINT(...) Serial.print(__VA_ARGS__)
134 # define BEO_TRACE_PRINTLN(...) Serial.println(__VA_ARGS__)
136 # define BEO_TRACE_PRINT(...) void()
137 # define BEO_TRACE_PRINTLN(...) void()
149 sendBangOlufsenRaw((uint32_t(aHeader) << 8) | aData, aNumberOfHeaderBits + 8, i != 0);
163 #if defined(USE_NO_SEND_PWM) || BEO_KHZ == 38 // BEO_KHZ == 38 is for unit test which runs the B&O protocol with 38 kHz
183 bool tLastBitValueWasOne =
false;
186 uint32_t mask = 1UL << (aBits - 1);
187 for (; mask; mask >>= 1) {
188 if (tLastBitValueWasOne && !(aRawData & mask)) {
191 tLastBitValueWasOne =
false;
192 }
else if (!tLastBitValueWasOne && (aRawData & mask)) {
195 tLastBitValueWasOne =
true;
207 #if !defined(DISABLE_CODE_FOR_RECEIVER)
223 #if defined(USE_NO_SEND_PWM) || BEO_KHZ == 38 // BEO_KHZ == 38 is for unit test which runs the B&O protocol with 38 kHz instead 0f 455 kHz
233 mark(tSendBEOMarkLength);
236 mark(tSendBEOMarkLength);
238 mark(tSendBEOMarkLength);
243 mark(tSendBEOMarkLength);
245 bool tLastBitValueWasOne =
false;
248 uint32_t mask = 1UL << (aBits - 1);
249 for (; mask; mask >>= 1) {
250 if (tLastBitValueWasOne && !(aRawData & mask)) {
251 mark(tSendBEOMarkLength);
253 tLastBitValueWasOne =
false;
254 }
else if (!tLastBitValueWasOne && (aRawData & mask)) {
255 mark(tSendBEOMarkLength);
257 tLastBitValueWasOne =
true;
259 mark(tSendBEOMarkLength);
265 mark(tSendBEOMarkLength);
267 mark(tSendBEOMarkLength);
269 #if !defined(DISABLE_CODE_FOR_RECEIVER)
275 (void) aUseDatalinkTiming;
280 #define BEO_MATCH_DELTA (BEO_UNIT / 2 - MICROS_PER_TICK)
281 static bool matchBeoLength(uint16_t aMeasuredTicks, uint16_t aMatchValueMicros) {
287 #if defined(ENABLE_BEO_WITHOUT_FRAME_GAP)
295 #if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE)
296 uint16_t protocolMarkLength = 0;
297 uint64_t tDecodedRawData = 0;
299 uint32_t tDecodedRawData = 0;
301 uint8_t tLastDecodedBitValue = 0;
302 uint8_t tPulseNumber = 0;
303 uint8_t tBitNumber = 0;
310 #if defined(ENABLE_BEO_WITHOUT_FRAME_GAP)
335 #if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE)
364 #if !defined(ENABLE_BEO_WITHOUT_FRAME_GAP)
369 if (tPulseNumber < 4) {
370 if (tPulseNumber < 2) {
377 if (tPulseNumber == 3) {
379 #if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE)
405 #if defined(SUPPORT_BEO_DATALINK_TIMING_FOR_DECODE)
406 if (!
matchMark(markLength, protocolMarkLength)) {
424 #if !defined(ENABLE_BEO_WITHOUT_FRAME_GAP)
437 tLastDecodedBitValue = 1;
439 tLastDecodedBitValue = 0;
449 tDecodedRawData <<= 1;
450 tDecodedRawData |= tLastDecodedBitValue;
459 #if !defined(ENABLE_BEO_WITHOUT_FRAME_GAP)
475 #if defined(ENABLE_BEO_WITHOUT_FRAME_GAP)
489 #endif // _IR_BANG_OLUFSEN_HPP