From 88c14cb5b66204e8c0ebe8113e7ad2d49d28c334 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 8 Aug 2020 20:56:09 +0200 Subject: [PATCH 1/2] ZBBridge make green LED brighter --- tasmota/xdrv_23_zigbee_9_serial.ino | 39 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/tasmota/xdrv_23_zigbee_9_serial.ino b/tasmota/xdrv_23_zigbee_9_serial.ino index b022fcca5..83e4c9c94 100644 --- a/tasmota/xdrv_23_zigbee_9_serial.ino +++ b/tasmota/xdrv_23_zigbee_9_serial.ino @@ -52,6 +52,25 @@ EZSP_Serial_t EZSP_Serial; #include TasmotaSerial *ZigbeeSerial = nullptr; +// +// Blink Led Status +// +const uint32_t Z_LED_STATUS_ON_MILLIS = 50; // keep led on at least 50 ms +bool Z_LedStatusSet(bool onoff) { + static bool led_status_on = false; + static uint32_t led_on_time = 0; + + if (onoff) { + SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 1); + led_status_on = true; + led_on_time = millis(); + } else if ((led_status_on) && (TimePassedSince(led_on_time) >= Z_LED_STATUS_ON_MILLIS)) { + SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 0); + led_status_on = false; + } + return led_status_on; +} + /********************************************************************************************/ // // Called at event loop, checks for incoming data from the CC2530 @@ -150,16 +169,15 @@ void ZigbeeInputLoop(void) { static uint32_t zigbee_polling_window = 0; // number of milliseconds since first byte static bool escape = false; // was the previous byte an escape? bool frame_complete = false; // frame is ready and complete - bool led_status_on = false; // did we turn on the led receive led // Receive only valid EZSP frames: // 1A - Cancel - cancel all previous bytes // 7D - Escape byte - following byte is escaped // 7E - end of frame + Z_LedStatusSet(false); + while (ZigbeeSerial->available()) { - // turn on receive LED<1> - SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 1); - led_status_on = true; // don't forget to switch it off + Z_LedStatusSet(true); // turn on receive LED<1> yield(); uint8_t zigbee_in_byte = ZigbeeSerial->read(); @@ -205,10 +223,6 @@ void ZigbeeInputLoop(void) { zigbee_polling_window = millis(); // Wait for more data } // adding bytes } // while (ZigbeeSerial->available()) - // turn receive led off - if (led_status_on) { - SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 0); - } uint32_t frame_len = zigbee_buffer->len(); if (frame_complete || (frame_len && (millis() > (zigbee_polling_window + ZIGBEE_POLLING)))) { @@ -427,8 +441,6 @@ void ZigbeeEZSPSend_Out(uint8_t out_byte) { // - send frame // send_cancel: should we first send a EZSP_CANCEL (0x1A) before the message to clear any leftover void ZigbeeEZSPSendRaw(const uint8_t *msg, size_t len, bool send_cancel) { - bool led_status_on = false; - if ((len < 1) || (len > 252)) { // abort, message cannot be less than 2 bytes for CMD1 and CMD2 AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_JSON_ZIGBEE_EZSP_SENT ": bad message len %d"), len); @@ -437,8 +449,7 @@ void ZigbeeEZSPSendRaw(const uint8_t *msg, size_t len, bool send_cancel) { uint8_t data_len = len - 2; // removing CMD1 and CMD2 // turn send led on - SetLedPowerIdx(ZIGBEE_LED_SEND, 1); - led_status_on = true; + Z_LedStatusSet(true); if (ZigbeeSerial) { if (send_cancel) { @@ -479,10 +490,6 @@ void ZigbeeEZSPSendRaw(const uint8_t *msg, size_t len, bool send_cancel) { // finally send End of Frame ZigbeeSerial->write(ZIGBEE_EZSP_EOF); // 0x1A } - // turn send led off - if (led_status_on) { - SetLedPowerIdx(ZIGBEE_LED_SEND, 0); - } // Now send a MQTT message to report the sent message char hex_char[(len * 2) + 2]; From e2087b9aea60988946c983e3336f9cffac79c99b Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sat, 8 Aug 2020 20:59:35 +0200 Subject: [PATCH 2/2] Fix compilation issue --- tasmota/xdrv_23_zigbee_9_serial.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasmota/xdrv_23_zigbee_9_serial.ino b/tasmota/xdrv_23_zigbee_9_serial.ino index 83e4c9c94..da7e64095 100644 --- a/tasmota/xdrv_23_zigbee_9_serial.ino +++ b/tasmota/xdrv_23_zigbee_9_serial.ino @@ -47,11 +47,6 @@ public: EZSP_Serial_t EZSP_Serial; -#endif // USE_ZIGBEE_EZSP - -#include -TasmotaSerial *ZigbeeSerial = nullptr; - // // Blink Led Status // @@ -71,6 +66,11 @@ bool Z_LedStatusSet(bool onoff) { return led_status_on; } +#endif // USE_ZIGBEE_EZSP + +#include +TasmotaSerial *ZigbeeSerial = nullptr; + /********************************************************************************************/ // // Called at event loop, checks for incoming data from the CC2530