Skip to content

Commit 266b5d7

Browse files
authored
lvgl API: use lv_obj_has_state to check state value (#198)
1 parent 4067f94 commit 266b5d7

File tree

4 files changed

+16
-32
lines changed

4 files changed

+16
-32
lines changed

CYD-Klipper/src/core/bambu/bambu_printer_panels.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct
161161
};
162162
} __internal_bambu_file_state = {};
163163

164-
#define SET_BOOL_STATE(bool_name, func_name) static void func_name (lv_event_t * e) { auto state = lv_obj_get_state(lv_event_get_target(e)); bool_name = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); }
164+
#define SET_BOOL_STATE(bool_name, func_name) static void func_name (lv_event_t * e) { bool_name = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED); }
165165

166166
SET_BOOL_STATE(__internal_bambu_file_state.bambu_option_use_ams, set_bambu_option_use_ams)
167167
SET_BOOL_STATE(__internal_bambu_file_state.bambu_option_timelapse, set_bambu_option_timelapse)

CYD-Klipper/src/ui/macros.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ int macros_add_macros_to_panel(lv_obj_t * root_panel, BasePrinter* printer)
4747

4848
static void power_device_toggle(lv_event_t * e)
4949
{
50-
auto state = lv_obj_get_state(lv_event_get_target(e));
51-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
50+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
5251
DoubleStorage* device = (DoubleStorage*)lv_event_get_user_data(e);
5352
LOG_F(("Power Device: %s, State: %d -> %d\n", device->power_device_name, !checked, checked))
5453

CYD-Klipper/src/ui/panels/settings_panel.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
#endif // REPO_VERSION
1616

1717
static void invert_color_switch(lv_event_t * e){
18-
auto state = lv_obj_get_state(lv_event_get_target(e));
19-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
18+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
2019
global_config.printer_config[global_config.printer_index].invert_colors = checked;
2120
write_global_config();
2221
set_invert_display();
@@ -46,16 +45,14 @@ static void reset_ip_click(lv_event_t * e){
4645
}
4746

4847
static void light_mode_switch(lv_event_t * e){
49-
auto state = lv_obj_get_state(lv_event_get_target(e));
50-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
48+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
5149
get_current_printer()->printer_config->light_mode = checked;
5250
write_global_config();
5351
set_color_scheme();
5452
}
5553

5654
static void filament_move_mode_switch(lv_event_t * e){
57-
auto state = lv_obj_get_state(lv_event_get_target(e));
58-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
55+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
5956
get_current_printer()->printer_config->custom_filament_move_macros = checked;
6057
write_global_config();
6158
}
@@ -97,60 +94,52 @@ static void wake_timeout_dropdown(lv_event_t * e){
9794
}
9895

9996
static void dualusb_screen_fix_switch(lv_event_t* e){
100-
auto state = lv_obj_get_state(lv_event_get_target(e));
101-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
97+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
10298
global_config.display_mode = checked;
10399
write_global_config();
104100
ESP.restart();
105101
}
106102

107103
static void disable_m117_messaging_switch(lv_event_t* e){
108-
auto state = lv_obj_get_state(lv_event_get_target(e));
109-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
104+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
110105
global_config.disable_m117_messaging = checked;
111106
write_global_config();
112107
}
113108

114109
static void sort_macros_switch(lv_event_t* e){
115-
auto state = lv_obj_get_state(lv_event_get_target(e));
116-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
110+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
117111
global_config.sort_macros = checked;
118112
write_global_config();
119113
}
120114

121115
static void show_estop_switch(lv_event_t* e){
122-
auto state = lv_obj_get_state(lv_event_get_target(e));
123-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
116+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
124117
global_config.show_estop = checked;
125118
write_global_config();
126119
}
127120

128121
static void full_filenames_switch(lv_event_t* e){
129-
auto state = lv_obj_get_state(lv_event_get_target(e));
130-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
122+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
131123
global_config.full_filenames = checked;
132124
write_global_config();
133125
}
134126

135127
static void double_size_gcode_img_switch(lv_event_t* e){
136-
auto state = lv_obj_get_state(lv_event_get_target(e));
137-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
128+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
138129
global_config.double_size_gcode_img = checked;
139130
write_global_config();
140131
}
141132

142133
static void rotate_screen_switch(lv_event_t* e){
143-
auto state = lv_obj_get_state(lv_event_get_target(e));
144-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
134+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
145135
global_config.rotate_screen = checked;
146136
global_config.screen_calibrated = false;
147137
write_global_config();
148138
ESP.restart();
149139
}
150140

151141
static void on_during_print_switch(lv_event_t* e){
152-
auto state = lv_obj_get_state(lv_event_get_target(e));
153-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
142+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
154143
global_config.on_during_print = checked;
155144
check_if_screen_needs_to_be_disabled();
156145
write_global_config();
@@ -161,15 +150,13 @@ static void btn_ota_do_update(lv_event_t * e){
161150
}
162151

163152
static void auto_ota_update_switch(lv_event_t* e){
164-
auto state = lv_obj_get_state(lv_event_get_target(e));
165-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
153+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
166154
global_config.auto_ota_update = checked;
167155
write_global_config();
168156
}
169157

170158
static void multi_printer_switch(lv_event_t* e){
171-
auto state = lv_obj_get_state(lv_event_get_target(e));
172-
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
159+
bool checked = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
173160
global_config.multi_printer_mode = checked;
174161
write_global_config();
175162
nav_buttons_setup(PANEL_SETTINGS);

CYD-Klipper/src/ui/panels/temp_panel.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ static void set_temp_via_preset(lv_event_t * e){
161161
}
162162

163163
static void btn_toggleable_edit(lv_event_t * e){
164-
lv_obj_t * btn = lv_event_get_target(e);
165-
auto state = lv_obj_get_state(btn);
166-
temp_edit_mode = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
164+
temp_edit_mode = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
167165
}
168166

169167
static void btn_retract(lv_event_t * e){

0 commit comments

Comments
 (0)