Christopher Mullins 7 years ago
parent
commit
a4eb74ad2e
2 changed files with 16 additions and 1 deletions
  1. 6 0
      lib/MiLight/FUT089PacketFormatter.cpp
  2. 10 1
      src/main.cpp

+ 6 - 0
lib/MiLight/FUT089PacketFormatter.cpp

@@ -84,6 +84,12 @@ void FUT089PacketFormatter::enableNightMode() {
 }
 
 BulbId FUT089PacketFormatter::parsePacket(const uint8_t *packet, JsonObject& result) {
+  if (stateStore == NULL) {
+    Serial.println(F("ERROR: stateStore not set.  Prepare was not called!  **THIS IS A BUG**"));
+    BulbId fakeId(0, 0, REMOTE_TYPE_FUT089);
+    return fakeId;
+  }
+
   uint8_t packetCopy[V2_PACKET_LEN];
   memcpy(packetCopy, packet, V2_PACKET_LEN);
   V2RFEncoding::decodeV2Packet(packetCopy);

+ 10 - 1
src/main.cpp

@@ -89,8 +89,17 @@ void initMilightUdpServers() {
 void onPacketSentHandler(uint8_t* packet, const MiLightRemoteConfig& config) {
   StaticJsonBuffer<200> buffer;
   JsonObject& result = buffer.createObject();
-  BulbId bulbId = config.packetFormatter->parsePacket(packet, result);
 
+  // This is gross.  But if a packet is received for a remote type before one is
+  // sent, prepare() won't have been called, meaning stateStore and settings will
+  // not have been initialized.  Both of these things should either be passed in
+  // as constructor parameters, or as prameters to the methods that require them.
+  // 
+  // But for now, just hackily call prepare.  At least fixes a bug.  The deviceId
+  // and groupId won't matter.
+  config.packetFormatter->prepare(0, 0, stateStore, &settings);
+
+  BulbId bulbId = config.packetFormatter->parsePacket(packet, result);
 
   // set LED mode for a packet movement
   ledStatus->oneshot(settings.ledModePacket, settings.ledModePacketCount);