Merge pull request #9055 from s-hadinger/zigbee_ezsp_green_brighter

ZBBridge make green LED brighter
This commit is contained in:
Theo Arends 2020-08-09 09:13:45 +02:00 committed by GitHub
commit 1845821f2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 16 deletions

View File

@ -47,6 +47,25 @@ public:
EZSP_Serial_t EZSP_Serial; EZSP_Serial_t EZSP_Serial;
//
// 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;
}
#endif // USE_ZIGBEE_EZSP #endif // USE_ZIGBEE_EZSP
#include <TasmotaSerial.h> #include <TasmotaSerial.h>
@ -150,16 +169,15 @@ void ZigbeeInputLoop(void) {
static uint32_t zigbee_polling_window = 0; // number of milliseconds since first byte static uint32_t zigbee_polling_window = 0; // number of milliseconds since first byte
static bool escape = false; // was the previous byte an escape? static bool escape = false; // was the previous byte an escape?
bool frame_complete = false; // frame is ready and complete 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: // Receive only valid EZSP frames:
// 1A - Cancel - cancel all previous bytes // 1A - Cancel - cancel all previous bytes
// 7D - Escape byte - following byte is escaped // 7D - Escape byte - following byte is escaped
// 7E - end of frame // 7E - end of frame
Z_LedStatusSet(false);
while (ZigbeeSerial->available()) { while (ZigbeeSerial->available()) {
// turn on receive LED<1> Z_LedStatusSet(true); // turn on receive LED<1>
SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 1);
led_status_on = true; // don't forget to switch it off
yield(); yield();
uint8_t zigbee_in_byte = ZigbeeSerial->read(); uint8_t zigbee_in_byte = ZigbeeSerial->read();
@ -205,10 +223,6 @@ void ZigbeeInputLoop(void) {
zigbee_polling_window = millis(); // Wait for more data zigbee_polling_window = millis(); // Wait for more data
} // adding bytes } // adding bytes
} // while (ZigbeeSerial->available()) } // while (ZigbeeSerial->available())
// turn receive led off
if (led_status_on) {
SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 0);
}
uint32_t frame_len = zigbee_buffer->len(); uint32_t frame_len = zigbee_buffer->len();
if (frame_complete || (frame_len && (millis() > (zigbee_polling_window + ZIGBEE_POLLING)))) { 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 frame
// send_cancel: should we first send a EZSP_CANCEL (0x1A) before the message to clear any leftover // 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) { void ZigbeeEZSPSendRaw(const uint8_t *msg, size_t len, bool send_cancel) {
bool led_status_on = false;
if ((len < 1) || (len > 252)) { if ((len < 1) || (len > 252)) {
// abort, message cannot be less than 2 bytes for CMD1 and CMD2 // 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); 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 uint8_t data_len = len - 2; // removing CMD1 and CMD2
// turn send led on // turn send led on
SetLedPowerIdx(ZIGBEE_LED_SEND, 1); Z_LedStatusSet(true);
led_status_on = true;
if (ZigbeeSerial) { if (ZigbeeSerial) {
if (send_cancel) { if (send_cancel) {
@ -479,10 +490,6 @@ void ZigbeeEZSPSendRaw(const uint8_t *msg, size_t len, bool send_cancel) {
// finally send End of Frame // finally send End of Frame
ZigbeeSerial->write(ZIGBEE_EZSP_EOF); // 0x1A 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 // Now send a MQTT message to report the sent message
char hex_char[(len * 2) + 2]; char hex_char[(len * 2) + 2];