mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-23 11:16:45 +00:00
Add alarm
This commit is contained in:
parent
b41d6ee9f4
commit
6804a49769
@ -63,7 +63,7 @@ void delete_event_handler(lv_obj_t* obj, lv_event_t event)
|
||||
|
||||
case LV_HASP_MSGBOX:
|
||||
my_msgbox_map_clear(obj);
|
||||
break;
|
||||
break;
|
||||
|
||||
case LV_HASP_IMAGE:
|
||||
my_image_release_resources(obj);
|
||||
@ -647,6 +647,50 @@ void selector_event_handler(lv_obj_t* obj, lv_event_t event)
|
||||
// attr_out_str(obj, property, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a btnmatrix value has changed
|
||||
* @param obj pointer to a dropdown list or roller
|
||||
* @param event type of event that occured
|
||||
*/
|
||||
void alarm_event_handler(lv_obj_t* obj, lv_event_t event)
|
||||
{
|
||||
log_event("alarm", event);
|
||||
|
||||
uint8_t hasp_event_id;
|
||||
if(!translate_event(obj, event, hasp_event_id)) return; // Use LV_EVENT_VALUE_CHANGED
|
||||
|
||||
/* Get the new value */
|
||||
// char buffer[128] = "";
|
||||
uint16_t val = 0;
|
||||
|
||||
val = lv_btnmatrix_get_active_btn(obj);
|
||||
if(val != LV_BTNMATRIX_BTN_NONE && hasp_event_id == HASP_EVENT_UP) {
|
||||
lv_obj_t* ta = hasp_find_obj_from_parent_id(lv_obj_get_parent(obj), 5);
|
||||
const char* txt = lv_btnmatrix_get_btn_text(obj, val);
|
||||
if(!strcmp(txt, LV_SYMBOL_BACKSPACE))
|
||||
lv_textarea_del_char(ta);
|
||||
else if(!strcmp(txt, LV_SYMBOL_CLOSE))
|
||||
lv_textarea_set_text(ta, "");
|
||||
else if(strlen(txt) == 1)
|
||||
lv_textarea_add_text(ta, txt);
|
||||
else
|
||||
;
|
||||
// strncpy(buffer, txt, sizeof(buffer));
|
||||
}
|
||||
|
||||
if(hasp_event_id == HASP_EVENT_CHANGED && last_value_sent == val && last_obj_sent == obj)
|
||||
return; // same object and value as before
|
||||
|
||||
last_value_sent = val;
|
||||
last_obj_sent = obj;
|
||||
// event_object_selection_changed(obj, hasp_event_id, val, buffer);
|
||||
|
||||
// if(max > 0) // max a cannot be 0, its the divider
|
||||
// if(hasp_event_id == HASP_EVENT_UP || hasp_event_id == LV_EVENT_VALUE_CHANGED) {
|
||||
// event_update_group(obj->user_data.groupid, obj, last_value_sent, 0, max);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a btnmatrix value has changed
|
||||
* @param obj pointer to a dropdown list or roller
|
||||
|
@ -27,6 +27,7 @@ void msgbox_event_handler(lv_obj_t* obj, lv_event_t event);
|
||||
void cpicker_event_handler(lv_obj_t* obj, lv_event_t event);
|
||||
void calendar_event_handler(lv_obj_t* obj, lv_event_t event);
|
||||
void textarea_event_handler(lv_obj_t* obj, lv_event_t event);
|
||||
void alarm_event_handler(lv_obj_t* obj, lv_event_t event);
|
||||
|
||||
// Other functions
|
||||
void event_reset_last_value_sent();
|
||||
|
@ -278,13 +278,23 @@ void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id)
|
||||
}
|
||||
|
||||
switch(sdbm) {
|
||||
/* ----- Custom Objects ------ */
|
||||
case LV_HASP_ALARM:
|
||||
case HASP_OBJ_ALARM:
|
||||
obj = lv_obj_create(parent_obj, NULL);
|
||||
if(obj) obj->user_data.objid = LV_HASP_ALARM;
|
||||
break;
|
||||
|
||||
/* ----- Basic Objects ------ */
|
||||
case LV_HASP_BTNMATRIX:
|
||||
case HASP_OBJ_BTNMATRIX:
|
||||
obj = lv_btnmatrix_create(parent_obj, NULL);
|
||||
if(obj) {
|
||||
lv_btnmatrix_set_recolor(obj, true);
|
||||
lv_obj_set_event_cb(obj, btnmatrix_event_handler);
|
||||
if(obj_check_type(parent_obj, LV_HASP_ALARM))
|
||||
lv_obj_set_event_cb(obj, alarm_event_handler);
|
||||
else
|
||||
lv_obj_set_event_cb(obj, btnmatrix_event_handler);
|
||||
|
||||
lv_btnmatrix_ext_t* ext = (lv_btnmatrix_ext_t*)lv_obj_get_ext_attr(obj);
|
||||
btnmatrix_default_map = ext->map_p; // store the static pointer to the default lvgl btnmap
|
||||
|
@ -77,6 +77,9 @@ enum lv_hasp_obj_type_t {
|
||||
LV_HASP_IMAGE = 37, // placeholder
|
||||
LV_HASP_CANVAS = 38, // placeholder
|
||||
LV_HASP_MASK = 39, // placeholder
|
||||
|
||||
/* Custom */
|
||||
LV_HASP_ALARM = 60,
|
||||
};
|
||||
|
||||
void hasp_new_object(const JsonObject& config, uint8_t& saved_page_id);
|
||||
@ -112,7 +115,7 @@ inline lv_hasp_obj_type_t obj_get_type(const lv_obj_t* obj)
|
||||
*/
|
||||
inline const char* obj_get_type_name(const lv_obj_t* obj)
|
||||
{
|
||||
if (obj_get_type(obj) == LV_HASP_TAB) return "tab"; // LVGL reports tab objects as "lv_page"
|
||||
if(obj_get_type(obj) == LV_HASP_TAB) return "tab"; // LVGL reports tab objects as "lv_page"
|
||||
|
||||
lv_obj_type_t list;
|
||||
lv_obj_get_type(obj, &list);
|
||||
@ -175,5 +178,6 @@ inline bool obj_check_type(const lv_obj_t* obj, lv_hasp_obj_type_t haspobjtype)
|
||||
#define HASP_OBJ_TABVIEW 63226
|
||||
#define HASP_OBJ_TAB 7861
|
||||
#define HASP_OBJ_ARC 64594
|
||||
#define HASP_OBJ_ALARM 3153
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user