mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Change colorpicker val to color attribute
This commit is contained in:
parent
1b64ec7747
commit
847647272e
@ -1446,13 +1446,6 @@ bool hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, const cha
|
|||||||
lv_roller_set_selected(obj, (uint16_t)intval, LV_ANIM_ON);
|
lv_roller_set_selected(obj, (uint16_t)intval, LV_ANIM_ON);
|
||||||
} else if(check_obj_type(obj, LV_HASP_BAR)) {
|
} else if(check_obj_type(obj, LV_HASP_BAR)) {
|
||||||
update ? lv_bar_set_value(obj, intval, LV_ANIM_ON) : hasp_out_int(obj, attr, lv_bar_get_value(obj));
|
update ? lv_bar_set_value(obj, intval, LV_ANIM_ON) : hasp_out_int(obj, attr, lv_bar_get_value(obj));
|
||||||
} else if(check_obj_type(obj, LV_HASP_CPICKER)) {
|
|
||||||
if(update) {
|
|
||||||
lv_color_t color;
|
|
||||||
if(haspPayloadToColor(payload, color)) lv_cpicker_set_color(obj, color);
|
|
||||||
} else {
|
|
||||||
hasp_out_color(obj, attr, lv_cpicker_get_color(obj));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1612,6 +1605,19 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
|
|||||||
hasp_process_obj_attribute_txt(obj, attr, payload, update);
|
hasp_process_obj_attribute_txt(obj, attr, payload, update);
|
||||||
break; // attribute_found
|
break; // attribute_found
|
||||||
|
|
||||||
|
case ATTR_COLOR:
|
||||||
|
if(check_obj_type(obj, LV_HASP_CPICKER)) {
|
||||||
|
if(update) {
|
||||||
|
lv_color_t color;
|
||||||
|
if(haspPayloadToColor(payload, color)) lv_cpicker_set_color(obj, color);
|
||||||
|
} else {
|
||||||
|
hasp_out_color(obj, attr, lv_cpicker_get_color(obj));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
goto attribute_not_found;
|
||||||
|
}
|
||||||
|
break; // attribute_found
|
||||||
|
|
||||||
case ATTR_VAL:
|
case ATTR_VAL:
|
||||||
if(!hasp_process_obj_attribute_val(obj, attr, payload, update)) goto attribute_not_found;
|
if(!hasp_process_obj_attribute_val(obj, attr, payload, update)) goto attribute_not_found;
|
||||||
break; // attribute_found
|
break; // attribute_found
|
||||||
|
@ -271,6 +271,7 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t)
|
|||||||
#define ATTR_MIN 46130
|
#define ATTR_MIN 46130
|
||||||
#define ATTR_MAX 45636
|
#define ATTR_MAX 45636
|
||||||
#define ATTR_VAL 15809
|
#define ATTR_VAL 15809
|
||||||
|
#define ATTR_COLOR 58979
|
||||||
#define ATTR_TXT 9328
|
#define ATTR_TXT 9328
|
||||||
#define ATTR_SRC 4964
|
#define ATTR_SRC 4964
|
||||||
#define ATTR_ID 6715
|
#define ATTR_ID 6715
|
||||||
|
@ -269,22 +269,32 @@ void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char *
|
|||||||
{
|
{
|
||||||
if(!attribute || !data) return;
|
if(!attribute || !data) return;
|
||||||
|
|
||||||
char topic[12];
|
|
||||||
char payload[32 + strlen(data) + strlen(attribute)];
|
char payload[32 + strlen(data) + strlen(attribute)];
|
||||||
snprintf_P(topic, sizeof(payload), PSTR("p%ub%u"), pageid, btnid);
|
|
||||||
snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":\"%s\"}"), attribute, data);
|
snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":\"%s\"}"), attribute, data);
|
||||||
mqtt_send_state_str(topic, payload);
|
|
||||||
|
mqtt_send_object_state(pageid, btnid, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val)
|
void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val)
|
||||||
{
|
{
|
||||||
if(!attribute) return;
|
if(!attribute) return;
|
||||||
|
|
||||||
char topic[12];
|
|
||||||
char payload[64 + strlen(attribute)];
|
char payload[64 + strlen(attribute)];
|
||||||
snprintf_P(topic, sizeof(payload), PSTR("p%ub%u"), pageid, btnid);
|
|
||||||
snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":%d}"), attribute, val);
|
snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":%d}"), attribute, val);
|
||||||
mqtt_send_state_str(topic, payload);
|
|
||||||
|
mqtt_send_object_state(pageid, btnid, payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char * attribute, uint8_t r, uint8_t g,
|
||||||
|
uint8_t b)
|
||||||
|
{
|
||||||
|
if(!attribute) return;
|
||||||
|
|
||||||
|
char payload[64 + strlen(attribute)];
|
||||||
|
snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":\"#%02x%02x%02x\",\"r\":%d,\"g\":%d,\"b\":%d}"), attribute, r, g,
|
||||||
|
b, r, g, b);
|
||||||
|
|
||||||
|
mqtt_send_object_state(pageid, btnid, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
@ -796,7 +806,7 @@ void dispatch_factory_reset(const char *, const char *)
|
|||||||
static void dispatch_add_command(const char * p_cmdstr, void (*func)(const char *, const char *))
|
static void dispatch_add_command(const char * p_cmdstr, void (*func)(const char *, const char *))
|
||||||
{
|
{
|
||||||
if(nCommands >= sizeof(commands) / sizeof(haspCommand_t)) {
|
if(nCommands >= sizeof(commands) / sizeof(haspCommand_t)) {
|
||||||
Log.fatal(TAG_MSGR, F("Dispatchcer command array overflow: %d"), nCommands);
|
Log.fatal(TAG_MSGR, F("CMD overflow %d"), nCommands);
|
||||||
while(1) {
|
while(1) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,7 +56,9 @@ void dispatch_normalized_group_value(uint8_t groupid, uint16_t value, lv_obj_t *
|
|||||||
|
|
||||||
void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data);
|
void dispatch_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data);
|
||||||
void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val);
|
void dispatch_send_obj_attribute_int(uint8_t pageid, uint8_t btnid, const char * attribute, int32_t val);
|
||||||
|
void dispatch_send_obj_attribute_color(uint8_t pageid, uint8_t btnid, const char * attribute, uint8_t r, uint8_t g,
|
||||||
|
uint8_t b);
|
||||||
|
|
||||||
/* ===== Getter and Setter Functions ===== */
|
/* ===== Getter and Setter Functions ===== */
|
||||||
|
|
||||||
/* ===== Read/Write Configuration ===== */
|
/* ===== Read/Write Configuration ===== */
|
||||||
|
@ -230,13 +230,14 @@ void hasp_send_obj_attribute_int(lv_obj_t * obj, const char * attribute, int32_t
|
|||||||
|
|
||||||
void hasp_send_obj_attribute_color(lv_obj_t * obj, const char * attribute, lv_color_t color)
|
void hasp_send_obj_attribute_color(lv_obj_t * obj, const char * attribute, lv_color_t color)
|
||||||
{
|
{
|
||||||
char buffer[40]; // "#ffffff","r":"255","g":"255","b":"255"
|
uint8_t pageid;
|
||||||
lv_color32_t c32;
|
uint8_t objid;
|
||||||
|
|
||||||
c32.full = lv_color_to32(color);
|
if(hasp_find_id_from_obj(obj, &pageid, &objid)) {
|
||||||
snprintf_P(buffer, sizeof(buffer), PSTR("#%02x%02x%02x\",\"r\":\"%d\",\"g\":\"%d\",\"b\":\"%d"), c32.ch.red,
|
lv_color32_t c32;
|
||||||
c32.ch.green, c32.ch.blue, c32.ch.red, c32.ch.green, c32.ch.blue);
|
c32.full = lv_color_to32(color);
|
||||||
hasp_send_obj_attribute_str(obj, attribute, buffer);
|
dispatch_send_obj_attribute_color(pageid, objid, attribute, c32.ch.red, c32.ch.green, c32.ch.blue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ##################### Value Senders ########################################################
|
// ##################### Value Senders ########################################################
|
||||||
|
@ -130,45 +130,18 @@ void mqtt_send_lwt(bool online)
|
|||||||
// mqttResult(res, tmp_topic, tmp_payload);
|
// mqttResult(res, tmp_topic, tmp_payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRAM_ATTR mqtt_send_state_str(char * subtopic, char * payload)
|
void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload)
|
||||||
{
|
{
|
||||||
char tmp_topic[strlen(mqttNodeTopic) + 20];
|
|
||||||
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/%s"), mqttNodeTopic, subtopic);
|
|
||||||
bool res = mqttPublish(tmp_topic, payload);
|
|
||||||
// mqttResult(res, tmp_topic, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IRAM_ATTR mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload)
|
|
||||||
{
|
|
||||||
char tmp_topic[strlen(mqttNodeTopic) + 20];
|
|
||||||
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/%s"), mqttNodeTopic, subtopic);
|
|
||||||
bool res = mqttPublish(tmp_topic, payload);
|
|
||||||
// mqttResult(res, tmp_topic, payload);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data)
|
|
||||||
{
|
|
||||||
// if(mqttIsConnected()) {
|
|
||||||
char tmp_topic[strlen(mqttNodeTopic) + 12];
|
char tmp_topic[strlen(mqttNodeTopic) + 12];
|
||||||
char payload[25 + strlen(data) + strlen(attribute)];
|
|
||||||
|
|
||||||
// snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/json"), mqttNodeTopic);
|
|
||||||
// unsigned int len =
|
|
||||||
// snprintf_P(payload, sizeof(payload), PSTR("{\"p[%u].b[%u].%s\":\"%s\"}"), pageid, btnid, attribute, data);
|
|
||||||
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/p%ub%u"), mqttNodeTopic, pageid, btnid);
|
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/p%ub%u"), mqttNodeTopic, pageid, btnid);
|
||||||
unsigned int len = snprintf_P(payload, sizeof(payload), PSTR("{\"%s\":\"%s\"}"), attribute, data);
|
bool res = mqttPublish(tmp_topic, payload);
|
||||||
|
}
|
||||||
|
|
||||||
bool res = mqttPublish(tmp_topic, payload, len); //, false);
|
void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload)
|
||||||
// mqttResult(res, tmp_topic, payload);
|
{
|
||||||
|
char tmp_topic[strlen(mqttNodeTopic) + 20];
|
||||||
// } else {
|
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%sstate/%s"), mqttNodeTopic, subtopic);
|
||||||
// return mqtt_log_no_connection();
|
bool res = mqttPublish(tmp_topic, payload);
|
||||||
// }
|
|
||||||
|
|
||||||
// Log after char buffers are cleared
|
|
||||||
// Log.notice(TAG_MQTT_PUB, F("%sstate/json = {\"p[%u].b[%u].%s\":\"%s\"}"), mqttNodeTopic, pageid, btnid,
|
|
||||||
// attribute,
|
|
||||||
// data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -12,9 +12,8 @@ void mqttEvery5Seconds(bool wifiIsConnected);
|
|||||||
void mqttStart();
|
void mqttStart();
|
||||||
void mqttStop();
|
void mqttStop();
|
||||||
|
|
||||||
void IRAM_ATTR mqtt_send_state_str(char * subtopic, char * payload);
|
void mqtt_send_object_state(uint8_t pageid, uint8_t btnid, char * payload);
|
||||||
void IRAM_ATTR mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload);
|
void mqtt_send_state(const __FlashStringHelper * subtopic, const char * payload);
|
||||||
void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const char * attribute, const char * data);
|
|
||||||
|
|
||||||
bool IRAM_ATTR mqttIsConnected();
|
bool IRAM_ATTR mqttIsConnected();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user