Skip to content

Commit

Permalink
Prepare new settings pages for alarm and interlock behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrkan committed Apr 15, 2024
1 parent 288e050 commit 8e10266
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/LVGL/lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@

#define LV_USE_CANVAS 0

#define LV_USE_CHECKBOX 0
#define LV_USE_CHECKBOX 1

#define LV_USE_DROPDOWN 0 /*Requires: lv_label*/

Expand Down
6 changes: 3 additions & 3 deletions src/Grbl/grbl_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ GrblState grbl_state_from_string(char *state) {
const char *grbl_state_to_string(GrblState state) {
switch (state) {
case GRBL_STATE_IDLE:
return "Idle";
return "Idling";
case GRBL_STATE_RUN:
return "Run";
return "Running";
case GRBL_STATE_HOLD_0:
return "Hold: complete";
case GRBL_STATE_HOLD_1:
Expand All @@ -85,7 +85,7 @@ const char *grbl_state_to_string(GrblState state) {
case GRBL_STATE_HOME:
return "Homing";
case GRBL_STATE_SLEEP:
return "Sleep";
return "Sleeping";
default:
return "Invalid/unknown Grbl state";
}
Expand Down
67 changes: 67 additions & 0 deletions src/UI/screens/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ static lv_obj_t *ui_settings_wifi_page;
static lv_obj_t *ui_settings_bed_page;
static lv_obj_t *ui_settings_probes_page;
static lv_obj_t *ui_settings_ota_page;
static lv_obj_t *ui_settings_alarm_page;
static lv_obj_t *ui_settings_interlock_page;

static lv_obj_t *ui_settings_keyboard;

Expand All @@ -47,6 +49,16 @@ static lv_obj_t *ui_settings_probes_cooling_temp_max_value;
static lv_obj_t *ui_settings_ota_login_value;
static lv_obj_t *ui_settings_ota_password_value;

static lv_obj_t *ui_settings_alarm_enable_when_running_value;
static lv_obj_t *ui_settings_alarm_enable_when_not_idling_value;
static lv_obj_t *ui_settings_alarm_enable_when_flame_sensor_triggered_value;
static lv_obj_t *ui_settings_alarm_enable_when_cooling_issue_value;
static lv_obj_t *ui_settings_alarm_enable_when_lid_opened_value;

static lv_obj_t *ui_settings_interlock_disable_when_lid_opened_value;
static lv_obj_t *ui_settings_interlock_disable_when_cooling_issue_value;
static lv_obj_t *ui_settings_interlock_disable_when_flame_sensor_triggered_value;

static void ui_settings_load_bed_settings() {
// Acquire bed settings mutex
TAKE_MUTEX(bed_settings_mutex)
Expand Down Expand Up @@ -267,6 +279,20 @@ static lv_obj_t *ui_settings_create_textarea_field(lv_obj_t *parent, const char
return textarea;
}

static lv_obj_t *ui_settings_create_checkbox_field(lv_obj_t *parent, const char *label) {
lv_obj_t *cont = lv_menu_cont_create(parent);
lv_obj_set_style_pad_ver(cont, 0, LV_PART_MAIN | LV_STATE_DEFAULT);

lv_obj_t *checkbox = lv_checkbox_create(cont);
lv_obj_set_width(checkbox, lv_pct(100));
lv_checkbox_set_text(checkbox, label);

// Handle change events
lv_obj_add_event_cb(checkbox, ui_settings_field_value_changed_handler, LV_EVENT_VALUE_CHANGED, NULL);

return checkbox;
}

static void ui_settings_init_screen_content() {
// Make sure the screen is empty
lv_obj_clean(ui_settings_screen);
Expand Down Expand Up @@ -296,11 +322,15 @@ static void ui_settings_init_screen_content() {
char bed_page_name[] = "Bed";
char probes_page_name[] = "Probes";
char ota_page_name[] = "OTA Updates";
char alarm_page_name[] = "Alarm behavior";
char interlock_page_name[] = "Interlock behavior";

ui_settings_wifi_page = lv_menu_page_create(ui_settings_menu, wifi_page_name);
ui_settings_bed_page = lv_menu_page_create(ui_settings_menu, bed_page_name);
ui_settings_probes_page = lv_menu_page_create(ui_settings_menu, probes_page_name);
ui_settings_ota_page = lv_menu_page_create(ui_settings_menu, ota_page_name);
ui_settings_alarm_page = lv_menu_page_create(ui_settings_menu, alarm_page_name);
ui_settings_interlock_page = lv_menu_page_create(ui_settings_menu, interlock_page_name);

// Disable scroll momentum/elasticity
lv_obj_clear_flag(ui_settings_wifi_page, LV_OBJ_FLAG_SCROLL_MOMENTUM);
Expand All @@ -311,6 +341,10 @@ static void ui_settings_init_screen_content() {
lv_obj_clear_flag(ui_settings_probes_page, LV_OBJ_FLAG_SCROLL_ELASTIC);
lv_obj_clear_flag(ui_settings_ota_page, LV_OBJ_FLAG_SCROLL_MOMENTUM);
lv_obj_clear_flag(ui_settings_ota_page, LV_OBJ_FLAG_SCROLL_ELASTIC);
lv_obj_clear_flag(ui_settings_alarm_page, LV_OBJ_FLAG_SCROLL_MOMENTUM);
lv_obj_clear_flag(ui_settings_alarm_page, LV_OBJ_FLAG_SCROLL_ELASTIC);
lv_obj_clear_flag(ui_settings_interlock_page, LV_OBJ_FLAG_SCROLL_MOMENTUM);
lv_obj_clear_flag(ui_settings_interlock_page, LV_OBJ_FLAG_SCROLL_ELASTIC);

// Root page
ui_settings_root_page = lv_menu_page_create(ui_settings_menu, NULL);
Expand Down Expand Up @@ -338,6 +372,16 @@ static void ui_settings_init_screen_content() {
lv_label_set_text(item_label, LV_SYMBOL_CODE_PULL_REQUEST " OTA Updates");
lv_menu_set_load_page_event(ui_settings_menu, item_cont, ui_settings_ota_page);

item_cont = lv_menu_cont_create(ui_settings_root_page);
item_label = lv_label_create(item_cont);
lv_label_set_text(item_label, LV_SYMBOL_WARNING " Alarm behavior");
lv_menu_set_load_page_event(ui_settings_menu, item_cont, ui_settings_alarm_page);

item_cont = lv_menu_cont_create(ui_settings_root_page);
item_label = lv_label_create(item_cont);
lv_label_set_text(item_label, LV_SYMBOL_UNLOCK " Interlock behavior");
lv_menu_set_load_page_event(ui_settings_menu, item_cont, ui_settings_interlock_page);

// Keyboard
ui_settings_keyboard = lv_keyboard_create(ui_settings_screen);
lv_obj_set_width(ui_settings_keyboard, lv_pct(100));
Expand Down Expand Up @@ -439,6 +483,29 @@ static void ui_settings_init_screen_content() {
ui_settings_ota_login_value = ui_settings_create_textarea_field(ui_settings_ota_page, "Login");
ui_settings_ota_password_value = ui_settings_create_textarea_field(ui_settings_ota_page, "Password");

// Alarm page
ui_settings_alarm_enable_when_running_value =
ui_settings_create_checkbox_field(ui_settings_alarm_page, "Enable alarm when Grbl status is 'Running'");
ui_settings_alarm_enable_when_not_idling_value = ui_settings_create_checkbox_field(
ui_settings_alarm_page,
"Enable alarm when Grbl status is different from 'Idling'");
ui_settings_alarm_enable_when_flame_sensor_triggered_value =
ui_settings_create_checkbox_field(ui_settings_alarm_page, "Enable alarm when flame sensor is triggered");
ui_settings_alarm_enable_when_cooling_issue_value =
ui_settings_create_checkbox_field(ui_settings_alarm_page, "Enable alarm when a cooling issue is detected");
ui_settings_alarm_enable_when_lid_opened_value =
ui_settings_create_checkbox_field(ui_settings_alarm_page, "Enable alarm when a lid is opened");

// Interlock page
ui_settings_interlock_disable_when_lid_opened_value =
ui_settings_create_checkbox_field(ui_settings_interlock_page, "Prevent laser from firing when a lid is opened");
ui_settings_interlock_disable_when_cooling_issue_value = ui_settings_create_checkbox_field(
ui_settings_interlock_page,
"Prevent laser from firing when a cooling issue is detected");
ui_settings_interlock_disable_when_flame_sensor_triggered_value = ui_settings_create_checkbox_field(
ui_settings_interlock_page,
"Prevent laser from firing when flame sensor is triggered");

// Init fields with current settings
ui_settings_load_bed_settings();
ui_settings_load_probes_settings();
Expand Down

0 comments on commit 8e10266

Please sign in to comment.