added wakeup signal after 5 seconds

Cherry picked from https://github.com/alexw23/esphome_components
Fixes #4
This commit is contained in:
Rocka84
2025-05-17 17:54:17 +02:00
parent 5533a35801
commit eb37a408ab
2 changed files with 14 additions and 0 deletions

View File

@@ -50,6 +50,7 @@ namespace esphome {
void JiecangDeskController::handleMessage(unsigned int *message) {
// ESP_LOGV("jiecang_desk_controller", "message %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", message[0], message[1], message[2], message[3], message[4], message[5], message[6], message[7], message[8], message[9]);
this->last_message_time = millis();
switch (message[0]) {
case 0x01:
@@ -138,6 +139,17 @@ namespace esphome {
}
void JiecangDeskController::send_simple_command(unsigned char cmd) {
// If more than 5 seconds passed since last message, assume desk is asleep
if (millis() - this->last_message_time >= 5000) {
ESP_LOGV(TAG, "Sending wake-up signal.");
write_command(0x2B); // send STOP to wake up
delay(100); // brief delay to allow the desk to wake up
}
write_command(cmd);
}
void JiecangDeskController::write_command(unsigned char cmd) {
write_array({ 0xF1, 0xF1, cmd, 0x00, cmd, 0x7E });
}

View File

@@ -28,6 +28,7 @@ namespace esphome {
class JiecangDeskController : public PollingComponent, public sensor::Sensor, public uart::UARTDevice {
private:
uint32_t last_message_time = 0;
float current_height = 0;
float limit_min = 0;
float limit_max = 0;
@@ -39,6 +40,7 @@ namespace esphome {
float byte2float(int high, int low);
bool bufferMessage(int data, unsigned int *buffer, int len);
void handleMessage(unsigned int *message);
void write_command(unsigned char cmd);
public:
void update() override;