Merge pull request #15845 from s-hadinger/zigbee_leds_esp32

Zigbee reenable leds for ESP32
This commit is contained in:
s-hadinger 2022-06-22 20:39:41 +02:00 committed by GitHub
commit 956cc0fdbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 17 deletions

View File

@ -19,6 +19,8 @@
#ifdef USE_ZIGBEE #ifdef USE_ZIGBEE
const uint32_t ZIGBEE_LED_SERIAL = 0; // LED<1> blinks when receiving
#ifdef USE_ZIGBEE_ZNP #ifdef USE_ZIGBEE_ZNP
const uint32_t ZIGBEE_BUFFER_SIZE = 256; // Max ZNP frame is SOF+LEN+CMD1+CMD2+250+FCS = 255 const uint32_t ZIGBEE_BUFFER_SIZE = 256; // Max ZNP frame is SOF+LEN+CMD1+CMD2+250+FCS = 255
const uint8_t ZIGBEE_SOF = 0xFE; const uint8_t ZIGBEE_SOF = 0xFE;
@ -28,11 +30,8 @@ const uint8_t ZIGBEE_SOF_ALT = 0xFF;
#ifdef USE_ZIGBEE_EZSP #ifdef USE_ZIGBEE_EZSP
const uint32_t ZIGBEE_BUFFER_SIZE = 256; const uint32_t ZIGBEE_BUFFER_SIZE = 256;
const uint8_t ZIGBEE_EZSP_CANCEL = 0x1A; // cancel byte const uint8_t ZIGBEE_EZSP_CANCEL = 0x1A; // cancel byte
const uint8_t ZIGBEE_EZSP_EOF = 0x7E; // end of frame const uint8_t ZIGBEE_EZSP_EOF = 0x7E; // end of frame
const uint8_t ZIGBEE_EZSP_ESCAPE = 0x7D; // escape byte const uint8_t ZIGBEE_EZSP_ESCAPE = 0x7D; // escape byte
const uint32_t ZIGBEE_LED_RECEIVE = 0; // LED<1> blinks when receiving
const uint32_t ZIGBEE_LED_SEND = 0; // LED<2> blinks when receiving
class EZSP_Serial_t { class EZSP_Serial_t {
public: public:
@ -47,27 +46,27 @@ public:
EZSP_Serial_t EZSP_Serial; EZSP_Serial_t EZSP_Serial;
#endif // USE_ZIGBEE_EZSP
// //
// Blink Led Status // Blink Led Status
// //
const uint32_t Z_LED_STATUS_ON_MILLIS = 50; // keep led on at least 50 ms const uint32_t Z_LED_STATUS_ON_MILLIS = 40; // keep led on at least 40 ms
bool Z_LedStatusSet(bool onoff) { bool Z_LedStatusSet(bool onoff) {
static bool led_status_on = false; static bool led_status_on = false;
static uint32_t led_on_time = 0; static uint32_t led_on_time = 0;
if (onoff) { if (onoff) {
SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 1); SetLedPowerIdx(ZIGBEE_LED_SERIAL, 1);
led_status_on = true; led_status_on = true;
led_on_time = millis(); led_on_time = millis();
} else if ((led_status_on) && (TimePassedSince(led_on_time) >= Z_LED_STATUS_ON_MILLIS)) { } else if ((led_status_on) && (TimePassedSince(led_on_time) >= Z_LED_STATUS_ON_MILLIS)) {
SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 0); SetLedPowerIdx(ZIGBEE_LED_SERIAL, 0);
led_status_on = false; led_status_on = false;
} }
return led_status_on; return led_status_on;
} }
#endif // USE_ZIGBEE_EZSP
#include <TasmotaSerial.h> #include <TasmotaSerial.h>
TasmotaSerial *ZigbeeSerial = nullptr; TasmotaSerial *ZigbeeSerial = nullptr;
@ -89,7 +88,10 @@ void ZigbeeInputLoop(void) {
// 04..FD - Data Field // 04..FD - Data Field
// FE (or last) - FCS Checksum // FE (or last) - FCS Checksum
Z_LedStatusSet(false);
while (ZigbeeSerial->available()) { while (ZigbeeSerial->available()) {
Z_LedStatusSet(true); // turn on receive LED<1>
yield(); yield();
uint8_t zigbee_in_byte = ZigbeeSerial->read(); uint8_t zigbee_in_byte = ZigbeeSerial->read();
//AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("ZbInput byte=%d len=%d"), zigbee_in_byte, zigbee_buffer->len()); //AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("ZbInput byte=%d len=%d"), zigbee_in_byte, zigbee_buffer->len());
@ -331,6 +333,9 @@ void ZigbeeZNPSend(const uint8_t *msg, size_t len) {
uint8_t data_len = len - 2; // removing CMD1 and CMD2 uint8_t data_len = len - 2; // removing CMD1 and CMD2
if (ZigbeeSerial) { if (ZigbeeSerial) {
// turn send led on
Z_LedStatusSet(true);
uint8_t fcs = data_len; uint8_t fcs = data_len;
ZigbeeSerial->write(ZIGBEE_SOF); // 0xFE ZigbeeSerial->write(ZIGBEE_SOF); // 0xFE

View File

@ -1524,12 +1524,14 @@ void CmndZbEZSPListen(void) {
ResponseCmndDone(); ResponseCmndDone();
} }
#endif // USE_ZIGBEE_EZSP
void ZigbeeGlowPermitJoinLight(void) { void ZigbeeGlowPermitJoinLight(void) {
#ifdef ESP8266 // quick fix since this causes a crash on ESP32
static const uint16_t cycle_time = 1000; // cycle up and down in 1000 ms static const uint16_t cycle_time = 1000; // cycle up and down in 1000 ms
static const uint16_t half_cycle_time = cycle_time / 2; // cycle up and down in 1000 ms static const uint16_t half_cycle_time = cycle_time / 2; // cycle up and down in 1000 ms
int led_pin = Pin(GPIO_LEDLNK);
if (led_pin >= 0) {
uint16_t led_power = 0; // turn led off uint16_t led_power = 0; // turn led off
if (zigbee.permit_end_time) { if (zigbee.permit_end_time) {
uint32_t millis_to_go = millis() - zigbee.permit_end_time; uint32_t millis_to_go = millis() - zigbee.permit_end_time;
@ -1543,13 +1545,15 @@ void ZigbeeGlowPermitJoinLight(void) {
} }
// change the led state // change the led state
int led_pin = Pin(GPIO_LEDLNK); #ifdef ESP32
if (led_pin >= 0) { if (analogAttach(led_pin, TasmotaGlobal.ledlnk_inverted) >= 0) {
analogWritePhase(led_pin, led_power, 0);
}
#else
analogWrite(led_pin, TasmotaGlobal.ledlnk_inverted ? 1023 - led_power : led_power); analogWrite(led_pin, TasmotaGlobal.ledlnk_inverted ? 1023 - led_power : led_power);
}
#endif #endif
} }
#endif // USE_ZIGBEE_EZSP }
// check if the permitjoin timer has expired // check if the permitjoin timer has expired
void ZigbeePermitJoinUpdate(void) { void ZigbeePermitJoinUpdate(void) {
@ -1559,9 +1563,7 @@ void ZigbeePermitJoinUpdate(void) {
zigbee.permit_end_time = 0; // disable timer zigbee.permit_end_time = 0; // disable timer
Z_PermitJoinDisable(); Z_PermitJoinDisable();
} }
#ifdef USE_ZIGBEE_EZSP
ZigbeeGlowPermitJoinLight(); // update glowing light accordingly ZigbeeGlowPermitJoinLight(); // update glowing light accordingly
#endif // USE_ZIGBEE_EZSP
} }
} }