added save_position command and button
This commit is contained in:
@@ -28,6 +28,7 @@ CONF_POSITION1 = "position1"
|
|||||||
CONF_POSITION2 = "position2"
|
CONF_POSITION2 = "position2"
|
||||||
CONF_POSITION3 = "position3"
|
CONF_POSITION3 = "position3"
|
||||||
CONF_POSITION4 = "position4"
|
CONF_POSITION4 = "position4"
|
||||||
|
CONF_SAVE_POSITION = "save_position"
|
||||||
|
|
||||||
|
|
||||||
button_constants = {}
|
button_constants = {}
|
||||||
@@ -38,6 +39,7 @@ button_constants[CONF_POSITION1] = 3
|
|||||||
button_constants[CONF_POSITION2] = 4
|
button_constants[CONF_POSITION2] = 4
|
||||||
button_constants[CONF_POSITION3] = 5
|
button_constants[CONF_POSITION3] = 5
|
||||||
button_constants[CONF_POSITION4] = 6
|
button_constants[CONF_POSITION4] = 6
|
||||||
|
button_constants[CONF_SAVE_POSITION] = 7
|
||||||
|
|
||||||
number_constants = {}
|
number_constants = {}
|
||||||
number_constants[CONF_HEIGHT] = 0
|
number_constants[CONF_HEIGHT] = 0
|
||||||
@@ -95,6 +97,7 @@ CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({
|
|||||||
cv.Optional(CONF_POSITION2): button.BUTTON_SCHEMA.extend({cv.GenerateID(): cv.declare_id(JiecangDeskButton)}),
|
cv.Optional(CONF_POSITION2): button.BUTTON_SCHEMA.extend({cv.GenerateID(): cv.declare_id(JiecangDeskButton)}),
|
||||||
cv.Optional(CONF_POSITION3): button.BUTTON_SCHEMA.extend({cv.GenerateID(): cv.declare_id(JiecangDeskButton)}),
|
cv.Optional(CONF_POSITION3): button.BUTTON_SCHEMA.extend({cv.GenerateID(): cv.declare_id(JiecangDeskButton)}),
|
||||||
cv.Optional(CONF_POSITION4): button.BUTTON_SCHEMA.extend({cv.GenerateID(): cv.declare_id(JiecangDeskButton)}),
|
cv.Optional(CONF_POSITION4): button.BUTTON_SCHEMA.extend({cv.GenerateID(): cv.declare_id(JiecangDeskButton)}),
|
||||||
|
cv.Optional(CONF_SAVE_POSITION): button.BUTTON_SCHEMA.extend({cv.GenerateID(): cv.declare_id(JiecangDeskButton)}),
|
||||||
}),
|
}),
|
||||||
}).extend(uart.UART_DEVICE_SCHEMA)
|
}).extend(uart.UART_DEVICE_SCHEMA)
|
||||||
|
|
||||||
|
|||||||
@@ -172,8 +172,25 @@ namespace esphome {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JiecangDeskController::save_position(int pos) {
|
||||||
|
switch (pos) {
|
||||||
|
case 1:
|
||||||
|
send_simple_command(0x03);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
send_simple_command(0x04);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
send_simple_command(0x25);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
send_simple_command(0x26);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void JiecangDeskController::goto_height(float height) {
|
void JiecangDeskController::goto_height(float height) {
|
||||||
unsigned char cmd = 0x01B;
|
unsigned char cmd = 0x1B;
|
||||||
unsigned char high_byte = ((int) height * 10) >> 8;
|
unsigned char high_byte = ((int) height * 10) >> 8;
|
||||||
unsigned char low_byte = ((int) height * 10) & 0xFF;
|
unsigned char low_byte = ((int) height * 10) & 0xFF;
|
||||||
|
|
||||||
@@ -205,19 +222,43 @@ namespace esphome {
|
|||||||
break;
|
break;
|
||||||
case BUTTON_STOP:
|
case BUTTON_STOP:
|
||||||
stop();
|
stop();
|
||||||
|
save_position_mode = false;
|
||||||
break;
|
break;
|
||||||
case BUTTON_POSITION1:
|
case BUTTON_POSITION1:
|
||||||
|
if (save_position_mode) {
|
||||||
|
save_position_mode = false;
|
||||||
|
save_position(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
goto_position(1);
|
goto_position(1);
|
||||||
break;
|
break;
|
||||||
case BUTTON_POSITION2:
|
case BUTTON_POSITION2:
|
||||||
|
if (save_position_mode) {
|
||||||
|
save_position_mode = false;
|
||||||
|
save_position(2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
goto_position(2);
|
goto_position(2);
|
||||||
break;
|
break;
|
||||||
case BUTTON_POSITION3:
|
case BUTTON_POSITION3:
|
||||||
|
if (save_position_mode) {
|
||||||
|
save_position_mode = false;
|
||||||
|
save_position(3);
|
||||||
|
return;
|
||||||
|
}
|
||||||
goto_position(3);
|
goto_position(3);
|
||||||
break;
|
break;
|
||||||
case BUTTON_POSITION4:
|
case BUTTON_POSITION4:
|
||||||
|
if (save_position_mode) {
|
||||||
|
save_position_mode = false;
|
||||||
|
save_position(4);
|
||||||
|
return;
|
||||||
|
}
|
||||||
goto_position(4);
|
goto_position(4);
|
||||||
break;
|
break;
|
||||||
|
case BUTTON_SAVE_POSITION:
|
||||||
|
save_position_mode = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#define BUTTON_POSITION2 4
|
#define BUTTON_POSITION2 4
|
||||||
#define BUTTON_POSITION3 5
|
#define BUTTON_POSITION3 5
|
||||||
#define BUTTON_POSITION4 6
|
#define BUTTON_POSITION4 6
|
||||||
|
#define BUTTON_SAVE_POSITION 7
|
||||||
|
|
||||||
#define NUMBER_HEIGHT 0
|
#define NUMBER_HEIGHT 0
|
||||||
|
|
||||||
@@ -30,6 +31,8 @@ namespace esphome {
|
|||||||
float physical_min = 0;
|
float physical_min = 0;
|
||||||
float physical_max = 0;
|
float physical_max = 0;
|
||||||
|
|
||||||
|
bool save_position_mode = false;
|
||||||
|
|
||||||
float byte2float(int high, int low);
|
float byte2float(int high, int low);
|
||||||
bool bufferMessage(int data, unsigned int *buffer, int len);
|
bool bufferMessage(int data, unsigned int *buffer, int len);
|
||||||
void handleMessage(unsigned int *message);
|
void handleMessage(unsigned int *message);
|
||||||
@@ -55,6 +58,7 @@ namespace esphome {
|
|||||||
void lower();
|
void lower();
|
||||||
void stop();
|
void stop();
|
||||||
void goto_position(int pos);
|
void goto_position(int pos);
|
||||||
|
void save_position(int pos);
|
||||||
void goto_height(float height);
|
void goto_height(float height);
|
||||||
|
|
||||||
void request_physical_limits();
|
void request_physical_limits();
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ jiecang_desk_controller:
|
|||||||
name: "Position 3"
|
name: "Position 3"
|
||||||
position4:
|
position4:
|
||||||
name: "Position 4"
|
name: "Position 4"
|
||||||
|
save_position:
|
||||||
|
name: "Save Position"
|
||||||
numbers:
|
numbers:
|
||||||
height:
|
height:
|
||||||
name: "Height"
|
name: "Height"
|
||||||
@@ -81,21 +83,13 @@ jiecang_desk_controller:
|
|||||||
# on_press:
|
# on_press:
|
||||||
# lambda: "id(my_desk).stop();"
|
# lambda: "id(my_desk).stop();"
|
||||||
# - platform: template
|
# - platform: template
|
||||||
# name: "Position 1"
|
|
||||||
# on_press:
|
|
||||||
# lambda: "id(my_desk).goto_position(1);"
|
|
||||||
# - platform: template
|
|
||||||
# name: "Position 2"
|
# name: "Position 2"
|
||||||
# on_press:
|
# on_press:
|
||||||
# lambda: "id(my_desk).goto_position(2);"
|
# lambda: "id(my_desk).goto_position(2);"
|
||||||
# - platform: template
|
# - platform: template
|
||||||
# name: "Position 3"
|
# name: "Save Position 4"
|
||||||
# on_press:
|
# on_press:
|
||||||
# lambda: "id(my_desk).goto_position(3);"
|
# lambda: "id(my_desk).save_position(4);"
|
||||||
# - platform: template
|
|
||||||
# name: "Position 4"
|
|
||||||
# on_press:
|
|
||||||
# lambda: "id(my_desk).goto_position(4);"
|
|
||||||
# - platform: template
|
# - platform: template
|
||||||
# name: "Go to 100cm"
|
# name: "Go to 100cm"
|
||||||
# on_press:
|
# on_press:
|
||||||
|
|||||||
Reference in New Issue
Block a user