mirror of https://github.com/arendst/Tasmota.git
Merge pull request #15845 from s-hadinger/zigbee_leds_esp32
Zigbee reenable leds for ESP32
This commit is contained in:
commit
956cc0fdbd
|
@ -19,6 +19,8 @@
|
|||
|
||||
#ifdef USE_ZIGBEE
|
||||
|
||||
const uint32_t ZIGBEE_LED_SERIAL = 0; // LED<1> blinks when receiving
|
||||
|
||||
#ifdef USE_ZIGBEE_ZNP
|
||||
const uint32_t ZIGBEE_BUFFER_SIZE = 256; // Max ZNP frame is SOF+LEN+CMD1+CMD2+250+FCS = 255
|
||||
const uint8_t ZIGBEE_SOF = 0xFE;
|
||||
|
@ -28,11 +30,8 @@ const uint8_t ZIGBEE_SOF_ALT = 0xFF;
|
|||
#ifdef USE_ZIGBEE_EZSP
|
||||
const uint32_t ZIGBEE_BUFFER_SIZE = 256;
|
||||
const uint8_t ZIGBEE_EZSP_CANCEL = 0x1A; // cancel byte
|
||||
const uint8_t ZIGBEE_EZSP_EOF = 0x7E; // end of frame
|
||||
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
|
||||
const uint8_t ZIGBEE_EZSP_EOF = 0x7E; // end of frame
|
||||
const uint8_t ZIGBEE_EZSP_ESCAPE = 0x7D; // escape byte
|
||||
|
||||
class EZSP_Serial_t {
|
||||
public:
|
||||
|
@ -47,27 +46,27 @@ public:
|
|||
|
||||
EZSP_Serial_t EZSP_Serial;
|
||||
|
||||
#endif // USE_ZIGBEE_EZSP
|
||||
|
||||
//
|
||||
// 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) {
|
||||
static bool led_status_on = false;
|
||||
static uint32_t led_on_time = 0;
|
||||
|
||||
if (onoff) {
|
||||
SetLedPowerIdx(ZIGBEE_LED_RECEIVE, 1);
|
||||
SetLedPowerIdx(ZIGBEE_LED_SERIAL, 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);
|
||||
SetLedPowerIdx(ZIGBEE_LED_SERIAL, 0);
|
||||
led_status_on = false;
|
||||
}
|
||||
return led_status_on;
|
||||
}
|
||||
|
||||
#endif // USE_ZIGBEE_EZSP
|
||||
|
||||
#include <TasmotaSerial.h>
|
||||
TasmotaSerial *ZigbeeSerial = nullptr;
|
||||
|
||||
|
@ -89,7 +88,10 @@ void ZigbeeInputLoop(void) {
|
|||
// 04..FD - Data Field
|
||||
// FE (or last) - FCS Checksum
|
||||
|
||||
Z_LedStatusSet(false);
|
||||
while (ZigbeeSerial->available()) {
|
||||
Z_LedStatusSet(true); // turn on receive LED<1>
|
||||
|
||||
yield();
|
||||
uint8_t zigbee_in_byte = ZigbeeSerial->read();
|
||||
//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
|
||||
|
||||
if (ZigbeeSerial) {
|
||||
// turn send led on
|
||||
Z_LedStatusSet(true);
|
||||
|
||||
uint8_t fcs = data_len;
|
||||
|
||||
ZigbeeSerial->write(ZIGBEE_SOF); // 0xFE
|
||||
|
|
|
@ -1524,12 +1524,14 @@ void CmndZbEZSPListen(void) {
|
|||
|
||||
ResponseCmndDone();
|
||||
}
|
||||
#endif // USE_ZIGBEE_EZSP
|
||||
|
||||
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 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
|
||||
if (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
|
||||
int led_pin = Pin(GPIO_LEDLNK);
|
||||
if (led_pin >= 0) {
|
||||
#ifdef ESP32
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // USE_ZIGBEE_EZSP
|
||||
}
|
||||
|
||||
// check if the permitjoin timer has expired
|
||||
void ZigbeePermitJoinUpdate(void) {
|
||||
|
@ -1559,9 +1563,7 @@ void ZigbeePermitJoinUpdate(void) {
|
|||
zigbee.permit_end_time = 0; // disable timer
|
||||
Z_PermitJoinDisable();
|
||||
}
|
||||
#ifdef USE_ZIGBEE_EZSP
|
||||
ZigbeeGlowPermitJoinLight(); // update glowing light accordingly
|
||||
#endif // USE_ZIGBEE_EZSP
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue