|
|
@@ -67,6 +67,14 @@ void MiLightClient::write(uint8_t packet[]) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+#ifdef DEBUG_PRINTF
|
|
|
+ printf("Sending packet: ");
|
|
|
+ for (int i = 0; i < currentRadio->config.getPacketLength(); i++) {
|
|
|
+ printf("%02X", packet[i]);
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+#endif
|
|
|
+
|
|
|
for (int i = 0; i < this->resendCount; i++) {
|
|
|
currentRadio->getRadio()->write(packet, currentRadio->config.getPacketLength());
|
|
|
}
|
|
|
@@ -83,24 +91,8 @@ void MiLightClient::updateHue(const uint16_t hue) {
|
|
|
}
|
|
|
|
|
|
void MiLightClient::updateBrightness(const uint8_t brightness) {
|
|
|
- const MiLightRadioType type = currentRadio->config.type;
|
|
|
-
|
|
|
- if (type == CCT || type == RGB) {
|
|
|
- const unsigned int oldResend = resendCount;
|
|
|
- setResendCount(MILIGHT_DEFAULT_RESEND_COUNT);
|
|
|
-
|
|
|
- for (int i = 0; i < MILIGHT_CCT_INTERVALS; i++) {
|
|
|
- decreaseBrightness();
|
|
|
- }
|
|
|
- for (int i = 0; i < brightness/(100/MILIGHT_CCT_INTERVALS); i++) {
|
|
|
- increaseBrightness();
|
|
|
- }
|
|
|
-
|
|
|
- setResendCount(oldResend);
|
|
|
- } else {
|
|
|
- formatter->updateBrightness(brightness);
|
|
|
- flushPacket();
|
|
|
- }
|
|
|
+ formatter->updateBrightness(brightness);
|
|
|
+ flushPacket();
|
|
|
}
|
|
|
|
|
|
void MiLightClient::updateStatus(MiLightStatus status, uint8_t groupId) {
|
|
|
@@ -176,24 +168,8 @@ void MiLightClient::decreaseTemperature() {
|
|
|
}
|
|
|
|
|
|
void MiLightClient::updateTemperature(const uint8_t temperature) {
|
|
|
- MiLightRadioType type = currentRadio->config.type;
|
|
|
-
|
|
|
- if (type == CCT) {
|
|
|
- const unsigned int oldResend = resendCount;
|
|
|
- setResendCount(MILIGHT_DEFAULT_RESEND_COUNT);
|
|
|
-
|
|
|
- for (int i = 0; i < MILIGHT_CCT_INTERVALS; i++) {
|
|
|
- decreaseTemperature();
|
|
|
- }
|
|
|
- for (int i = 0; i < temperature/(100/MILIGHT_CCT_INTERVALS); i++) {
|
|
|
- increaseTemperature();
|
|
|
- }
|
|
|
-
|
|
|
- setResendCount(oldResend);
|
|
|
- } else {
|
|
|
- formatter->updateTemperature(temperature);
|
|
|
- flushPacket();
|
|
|
- }
|
|
|
+ formatter->updateTemperature(temperature);
|
|
|
+ flushPacket();
|
|
|
}
|
|
|
|
|
|
void MiLightClient::command(uint8_t command, uint8_t arg) {
|
|
|
@@ -207,6 +183,12 @@ void MiLightClient::formatPacket(uint8_t* packet, char* buffer) {
|
|
|
|
|
|
void MiLightClient::flushPacket() {
|
|
|
PacketStream& stream = formatter->buildPackets();
|
|
|
+ const size_t prevNumRepeats = this->resendCount;
|
|
|
+
|
|
|
+ // When sending multiple packets, normalize the number of repeats
|
|
|
+ if (stream.numPackets > 1) {
|
|
|
+ setResendCount(MILIGHT_DEFAULT_RESEND_COUNT);
|
|
|
+ }
|
|
|
|
|
|
while (stream.hasNext()) {
|
|
|
write(stream.next());
|
|
|
@@ -216,5 +198,6 @@ void MiLightClient::flushPacket() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ setResendCount(prevNumRepeats);
|
|
|
formatter->reset();
|
|
|
}
|