|
|
@@ -11,6 +11,23 @@
|
|
|
class MiLightRadioConfig {
|
|
|
public:
|
|
|
static const size_t NUM_CHANNELS = 3;
|
|
|
+
|
|
|
+ // We can set this to two possible values. It only has an affect on the nRF24 radio. The
|
|
|
+ // LT8900/PL1167 radio will always use the raw syncwords. For the nRF24, this controls what
|
|
|
+ // we set the "address" to, which roughly corresponds to the LT8900 syncword.
|
|
|
+ //
|
|
|
+ // The PL1167 packet is structured as follows (lengths in bits):
|
|
|
+ // Preamble ( 8) | Syncword (32) | Trailer ( 4) | Packet Len ( 8) | Packet (...)
|
|
|
+ //
|
|
|
+ // 4 -- Use the raw syncword bits as the address. This means the Trailer will be included in
|
|
|
+ // the packet data. Since the Trailer is 4 bits, packet data will not be byte-aligned,
|
|
|
+ // and the data must be bitshifted every time it's received.
|
|
|
+ //
|
|
|
+ // 5 -- Include the Trailer in the syncword. Avoids us needing to bitshift packet data. The
|
|
|
+ // downside is that the Trailer is hardcoded and assumed based on received packets.
|
|
|
+ //
|
|
|
+ // In general, this should be set to 5 unless packets that should be showing up are
|
|
|
+ // mysteriously not present.
|
|
|
static const uint8_t SYNCWORD_LENGTH = 5;
|
|
|
|
|
|
MiLightRadioConfig(
|
|
|
@@ -35,15 +52,22 @@ public:
|
|
|
// precompute the syncword for the nRF24. we include the fixed preamble and trailer in the
|
|
|
// syncword to avoid needing to bitshift packets. trailer is 4 bits, so the actual syncword
|
|
|
// is no longer byte-aligned.
|
|
|
- syncwordBytes[ --ix ] = reverseBits(
|
|
|
- ((syncword0 << 4) & 0xF0) | (preamble & 0x0F)
|
|
|
- );
|
|
|
- syncwordBytes[ --ix ] = reverseBits((syncword0 >> 4) & 0xFF);
|
|
|
- syncwordBytes[ --ix ] = reverseBits(((syncword0 >> 12) & 0x0F) + ((syncword3 << 4) & 0xF0));
|
|
|
- syncwordBytes[ --ix ] = reverseBits((syncword3 >> 4) & 0xFF);
|
|
|
- syncwordBytes[ --ix ] = reverseBits(
|
|
|
- ((syncword3 >> 12) & 0x0F) | ((trailer << 4) & 0xF0)
|
|
|
- );
|
|
|
+ if (SYNCWORD_LENGTH == 5) {
|
|
|
+ syncwordBytes[ --ix ] = reverseBits(
|
|
|
+ ((syncword0 << 4) & 0xF0) | (preamble & 0x0F)
|
|
|
+ );
|
|
|
+ syncwordBytes[ --ix ] = reverseBits((syncword0 >> 4) & 0xFF);
|
|
|
+ syncwordBytes[ --ix ] = reverseBits(((syncword0 >> 12) & 0x0F) + ((syncword3 << 4) & 0xF0));
|
|
|
+ syncwordBytes[ --ix ] = reverseBits((syncword3 >> 4) & 0xFF);
|
|
|
+ syncwordBytes[ --ix ] = reverseBits(
|
|
|
+ ((syncword3 >> 12) & 0x0F) | ((trailer << 4) & 0xF0)
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ syncwordBytes[ --ix ] = reverseBits(syncword0 & 0xff);
|
|
|
+ syncwordBytes[ --ix ] = reverseBits( (syncword0 >> 8) & 0xff);
|
|
|
+ syncwordBytes[ --ix ] = reverseBits(syncword3 & 0xff);
|
|
|
+ syncwordBytes[ --ix ] = reverseBits( (syncword3 >> 8) & 0xff);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
uint8_t channels[3];
|