Procházet zdrojové kódy

support for new protocol (RGB+CCT)

Chris Mullins před 8 roky
rodič
revize
abc7c16348

+ 2 - 0
lib/MiLight/MiLightClient.cpp

@@ -267,6 +267,8 @@ MiLightRadioType MiLightClient::getRadioType(const String& typeName) {
     return RGBW;
   } else if (typeName.equalsIgnoreCase("cct")) {
     return CCT;
+  } else if (typeName.equalsIgnoreCase("rgbw_cct")) {
+    return RGBW_CCT;
   } else {
     return UNKNOWN;
   }

+ 5 - 7
lib/MiLight/MiLightRadio.cpp

@@ -52,7 +52,8 @@ int MiLightRadio::configure() {
     return retval;
   }
 
-  retval = _pl1167.setMaxPacketLength(8);
+  // +1 to be able to buffer the length 
+  retval = _pl1167.setMaxPacketLength(config.packetLength + 1);
   if (retval < 0) {
     return retval;
   }
@@ -60,10 +61,7 @@ int MiLightRadio::configure() {
   return 0;
 }
 
-bool MiLightRadio::available()
-{
-  configure();
-  
+bool MiLightRadio::available() {
   if (_waiting) {
 #ifdef DEBUG_PRINTF
   printf("_waiting\n");
@@ -73,14 +71,14 @@ bool MiLightRadio::available()
   
   if (_pl1167.receive(config.channels[0]) > 0) {
 #ifdef DEBUG_PRINTF
-  printf("0");
+  printf("MiLightRadio - received packet!\n");
 #endif
     size_t packet_length = sizeof(_packet);
     if (_pl1167.readFIFO(_packet, packet_length) < 0) {
       return false;
     }
 #ifdef DEBUG_PRINTF
-  printf("1");
+  printf("MiLightRadio - Checking packet length (expecting %d, is %d)\n", _packet[0] + 1U, packet_length);
 #endif
     if (packet_length == 0 || packet_length != _packet[0] + 1U) {
       return false;

+ 3 - 1
lib/MiLight/MiLightRadio.h

@@ -32,12 +32,14 @@ class MiLightRadio {
     int write(uint8_t frame[], size_t frame_length);
     int resend();
     int configure();
+    
   private:
     AbstractPL1167 &_pl1167;
     const MiLightRadioConfig& config;
     uint32_t _prev_packet_id;
 
-    uint8_t _packet[8], _out_packet[8];
+    uint8_t _packet[10];
+    uint8_t _out_packet[10];
     bool _waiting;
     int _dupes_received;
 };

+ 1 - 1
lib/MiLight/MiLightRadioConfig.h

@@ -46,7 +46,7 @@ static MiLightRadioConfig MilightCctConfig(
 
 const uint8_t RGBWCCT_CHANNELS[] = {70, 39, 8};
 static MiLightRadioConfig MilightRgbwCctConfig(
-  0x7236, 0x1809, 8, RGBWCCT_CHANNELS, 3, RGBW_CCT
+  0x7236, 0x1809, 9, RGBWCCT_CHANNELS, 3, RGBW_CCT
 );
 
 #endif

+ 14 - 3
lib/MiLight/PL1167_nRF24.cpp

@@ -146,12 +146,17 @@ int PL1167_nRF24::receive(uint8_t channel)
   _radio.startListening();
   if (_radio.available()) {
 #ifdef DEBUG_PRINTF
-  printf("Radio is available");
+  printf("Radio is available\n");
 #endif
     internal_receive();
   }
 
   if(_received) {
+#ifdef DEBUG_PRINTF
+  if (_packet_length > 0) {
+    printf("Received packet (len = %d)!\n", _packet_length);
+  }
+#endif
     return _packet_length;
   } else {
     return 0;
@@ -285,7 +290,7 @@ int PL1167_nRF24::internal_receive()
 #ifdef DEBUG_PRINTF
   printf("Packet received: ");
   for (int i = 0; i < _receive_length; i++) {
-    printf("%02X", reverse_bits(tmp[i]));
+    printf("%02X", tmp[i]);
   }
   printf("\n");
 #endif
@@ -360,7 +365,8 @@ int PL1167_nRF24::internal_receive()
     uint16_t crc = calc_crc(tmp, outp - 2);
     if ( ((crc & 0xff) != tmp[outp - 2]) || (((crc >> 8) & 0xff) != tmp[outp - 1]) ) {
 #ifdef DEBUG_PRINTF
-  printf("Failed CRC: expected %d, got (%d,%d)\n", crc, tmp[outp-2], tmp[outp-1]);
+  uint16_t recv_crc = ((tmp[outp - 2] & 0xFF) << 8) | (tmp[outp - 1] & 0xFF);
+  printf("Failed CRC: expected %d, got %d\n", crc, recv_crc);
 #endif
       return 0;
     }
@@ -371,6 +377,11 @@ int PL1167_nRF24::internal_receive()
   
   _packet_length = outp;
   _received = true;
+  
+#ifdef DEBUG_PRINTF
+  printf("Successfully parsed packet of length %d\n", _packet_length);
+#endif
+  
   return outp;
 }
 

+ 2 - 0
lib/MiLight/PL1167_nRF24.h

@@ -12,6 +12,8 @@
 #include "AbstractPL1167.h"
 #include "RF24.h"
 
+#define DEBUG_PRINTF
+
 #ifndef PL1167_NRF24_H_
 #define PL1167_NRF24_H_