Add led brightness

This commit is contained in:
fvanroie 2020-05-02 00:21:50 +02:00
parent c4d85bf2e4
commit d26c0c0200
2 changed files with 35 additions and 22 deletions

View File

@ -84,13 +84,6 @@ static lv_color_t haspPayloadToColor(const char * payload)
case 7: case 7:
if(!strcmp_P(payload, PSTR("magenta"))) return haspLogColor(LV_COLOR_MAGENTA); if(!strcmp_P(payload, PSTR("magenta"))) return haspLogColor(LV_COLOR_MAGENTA);
/* HEX format #rrggbb or #rrggbbaa */
int r, g, b, a;
if(*payload == '#' && sscanf(payload + 1, "%2x%2x%2x%2x", &r, &g, &b, &a) == 4) {
return haspLogColor(LV_COLOR_MAKE(r, g, b));
} else if(*payload == '#' && sscanf(payload + 1, "%2x%2x%2x", &r, &g, &b) == 3) {
return haspLogColor(LV_COLOR_MAKE(r, g, b));
}
default: default:
// if(!strcmp_P(payload, PSTR("darkblue"))) return haspLogColor(LV_COLOR_MAKE(0, 51, 102)); // if(!strcmp_P(payload, PSTR("darkblue"))) return haspLogColor(LV_COLOR_MAKE(0, 51, 102));
// if(!strcmp_P(payload, PSTR("lightblue"))) return haspLogColor(LV_COLOR_MAKE(46, 203, // if(!strcmp_P(payload, PSTR("lightblue"))) return haspLogColor(LV_COLOR_MAKE(46, 203,
@ -98,6 +91,14 @@ static lv_color_t haspPayloadToColor(const char * payload)
break; break;
} }
/* HEX format #rrggbb or #rrggbbaa */
int r, g, b, a;
if(*payload == '#' && sscanf(payload + 1, "%2x%2x%2x%2x", &r, &g, &b, &a) == 4) {
return haspLogColor(LV_COLOR_MAKE(r, g, b));
} else if(*payload == '#' && sscanf(payload + 1, "%2x%2x%2x", &r, &g, &b) == 3) {
return haspLogColor(LV_COLOR_MAKE(r, g, b));
}
/* 16-bit RGB565 Color Scheme*/ /* 16-bit RGB565 Color Scheme*/
if(only_digits(payload)) { if(only_digits(payload)) {
uint16_t c = atoi(payload); uint16_t c = atoi(payload);
@ -582,23 +583,23 @@ static void hasp_process_obj_attribute_val(lv_obj_t * obj, const char * attr, co
lv_dropdown_set_selected(obj, val); lv_dropdown_set_selected(obj, val);
return; return;
} else if(check_obj_type(objtype, LV_HASP_LMETER)) { } else if(check_obj_type(objtype, LV_HASP_LMETER)) {
lv_linemeter_set_value(obj, intval); return update ? lv_linemeter_set_value(obj, intval) : hasp_out_int(obj, attr, lv_linemeter_get_value(obj));
return;
} else if(check_obj_type(objtype, LV_HASP_SLIDER)) { } else if(check_obj_type(objtype, LV_HASP_SLIDER)) {
lv_slider_set_value(obj, intval, LV_ANIM_ON); return update ? lv_slider_set_value(obj, intval, LV_ANIM_ON)
return; : hasp_out_int(obj, attr, lv_slider_get_value(obj));
} else if(check_obj_type(objtype, LV_HASP_LED)) { } else if(check_obj_type(objtype, LV_HASP_LED)) {
lv_led_set_bright(obj, (uint8_t)val); if(update) {
return; return is_true(payload) ? lv_led_on(obj) : lv_led_off(obj);
} else {
// return hasp_out_int(obj, attr, lv_led_get_state(obj));
}
} else if(check_obj_type(objtype, LV_HASP_GAUGE)) { } else if(check_obj_type(objtype, LV_HASP_GAUGE)) {
lv_gauge_set_value(obj, 0, intval); return update ? lv_gauge_set_value(obj, 0, intval) : hasp_out_int(obj, attr, lv_gauge_get_value(obj, 0));
return;
} else if(check_obj_type(objtype, LV_HASP_ROLLER)) { } else if(check_obj_type(objtype, LV_HASP_ROLLER)) {
lv_roller_set_selected(obj, val, LV_ANIM_ON); lv_roller_set_selected(obj, val, LV_ANIM_ON);
return; return;
} else if(check_obj_type(objtype, LV_HASP_BAR)) { } else if(check_obj_type(objtype, LV_HASP_BAR)) {
lv_bar_set_value(obj, intval, LV_ANIM_OFF); return update ? lv_bar_set_value(obj, intval, LV_ANIM_ON) : hasp_out_int(obj, attr, lv_bar_get_value(obj));
return;
} else if(check_obj_type(objtype, LV_HASP_CPICKER)) { } else if(check_obj_type(objtype, LV_HASP_CPICKER)) {
return update ? (void)lv_cpicker_set_color(obj, haspPayloadToColor(payload)) return update ? (void)lv_cpicker_set_color(obj, haspPayloadToColor(payload))
: hasp_out_color(obj, attr, lv_cpicker_get_color(obj)); : hasp_out_color(obj, attr, lv_cpicker_get_color(obj));
@ -781,6 +782,16 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
} }
break; // not a options object break; // not a options object
case ATTR_BRIGHTNESS:
if(check_obj_type(obj, LV_HASP_LED)) {
if(update) {
lv_led_set_bright(obj, (uint8_t)val);
} else {
hasp_out_int(obj, attr, lv_led_get_bright(obj));
}
return;
}
// default: // default:
// hasp_local_style_attr(obj, attr, payload, update); // hasp_local_style_attr(obj, attr, payload, update);
} }
@ -794,9 +805,10 @@ void hasp_process_obj_attribute(lv_obj_t * obj, const char * attr_p, const char
* **************************/ * **************************/
static inline bool is_true(const char * s) static inline bool is_true(const char * s)
{ {
return (!strcmp_P(s, PSTR("true")) || !strcmp_P(s, PSTR("TRUE")) || !strcmp_P(s, PSTR("1")) || return (!strcmp_P(s, PSTR("true")) || !strcmp_P(s, PSTR("TRUE")) || !strcmp_P(s, PSTR("True")) ||
!strcmp_P(s, PSTR("on")) || !strcmp_P(s, PSTR("ON")) || !strcmp_P(s, PSTR("On")) || !strcmp_P(s, PSTR("on")) || !strcmp_P(s, PSTR("ON")) || !strcmp_P(s, PSTR("On")) ||
!strcmp_P(s, PSTR("yes")) || !strcmp_P(s, PSTR("YES")) || !strcmp_P(s, PSTR("Yes"))); !strcmp_P(s, PSTR("yes")) || !strcmp_P(s, PSTR("YES")) || !strcmp_P(s, PSTR("Yes")) ||
!strcmp_P(s, PSTR("1")));
} }
static inline bool only_digits(const char * s) static inline bool only_digits(const char * s)
@ -808,17 +820,17 @@ static inline bool only_digits(const char * s)
return strlen(s) == digits; return strlen(s) == digits;
} }
void hasp_out_int(lv_obj_t * obj, const char * attr, uint32_t val) void inline hasp_out_int(lv_obj_t * obj, const char * attr, uint32_t val)
{ {
hasp_send_obj_attribute_int(obj, attr, val); hasp_send_obj_attribute_int(obj, attr, val);
} }
void hasp_out_str(lv_obj_t * obj, const char * attr, const char * data) void inline hasp_out_str(lv_obj_t * obj, const char * attr, const char * data)
{ {
hasp_send_obj_attribute_str(obj, attr, data); hasp_send_obj_attribute_str(obj, attr, data);
} }
void hasp_out_color(lv_obj_t * obj, const char * attr, lv_color_t color) void inline hasp_out_color(lv_obj_t * obj, const char * attr, lv_color_t color)
{ {
hasp_send_obj_attribute_color(obj, attr, color); hasp_send_obj_attribute_color(obj, attr, color);
} }

View File

@ -212,6 +212,7 @@ _HASP_ATTRIBUTE(SCALE_END_LINE_WIDTH, scale_end_line_width, lv_style_int_t)
#define ATTR_Y 121 #define ATTR_Y 121
#define ATTR_W 119 #define ATTR_W 119
#define ATTR_H 104 #define ATTR_H 104
#define ATTR_BRIGHTNESS 10 // LED
#define ATTR_OPTIONS 29886 #define ATTR_OPTIONS 29886
#define ATTR_ENABLED 28193 #define ATTR_ENABLED 28193
#define ATTR_OPACITY 10155 #define ATTR_OPACITY 10155