1818#define TAG "Machine"
1919
2020reprap_axes_t reprap_axes ;
21- static lv_style_t not_homed_style ;
21+ reprap_params_t reprap_params ;
22+
23+ static lv_style_t not_homed_style , homed_style ;
2224static char * cali_opt_map [] = {"True Bed Leveling" , "Mesh Bed Leveling" };
2325static char * cali_opt_list = {"True Bed Leveling\nMesh Bed Leveling" };
2426
2527#define AWAY_BTN 0
2628#define CLOSER_BTN 1
2729
30+ #define USE_LIGHTNING
31+ #define LIGHTNING_CMD_ON "M42 P2 S1"
32+ #define LIGHTNING_CMD_HALF "M42 P2 S0.5"
33+ #define LIGHTNING_CMD_OFF "M42 P2 S0"
34+
2835lv_obj_t * machine_page ;
2936lv_obj_t * ddlist_cali_options ;
3037lv_obj_t * btnm_height ;
3138lv_obj_t * btn_closer ;
3239lv_obj_t * btn_away ;
3340lv_obj_t * cont_heigh_adj_diag , * label_z_pos_cali ;
3441lv_obj_t * btn_home_all , * btn_home_y , * btn_home_x , * btn_home_z ;
42+ lv_obj_t * btn_power , * label_power ;
43+ lv_obj_t * btn_fan_off , * label_fan , * slider ;
44+
45+ #ifdef USE_LIGHTNING
46+ lv_obj_t * btn_light_off , * btn_light_half , * btn_light_on ;
47+ #endif
48+
3549
3650static void _home_all_event (lv_obj_t * obj , lv_event_t event ) {
3751 if (event == LV_EVENT_CLICKED ) {
@@ -57,6 +71,47 @@ static void _home_z_event(lv_obj_t *obj, lv_event_t event) {
5771 }
5872}
5973
74+ #ifdef USE_LIGHTNING
75+ static void _light_off_event (lv_obj_t * obj , lv_event_t event ) {
76+ if (event == LV_EVENT_CLICKED ) {
77+ reprap_send_gcode (LIGHTNING_CMD_OFF );
78+ }
79+ }
80+
81+ static void _light_half_event (lv_obj_t * obj , lv_event_t event ) {
82+ if (event == LV_EVENT_CLICKED ) {
83+ reprap_send_gcode (LIGHTNING_CMD_HALF );
84+ }
85+ }
86+
87+ static void _light_on_event (lv_obj_t * obj , lv_event_t event ) {
88+ if (event == LV_EVENT_CLICKED ) {
89+ reprap_send_gcode (LIGHTNING_CMD_ON );
90+ }
91+ }
92+ #endif
93+
94+ static void _power_toggle_event (lv_obj_t * obj , lv_event_t event ) {
95+ if (event == LV_EVENT_CLICKED ) {
96+ reprap_send_gcode (reprap_params .power ? "M81" : "M80" );
97+ }
98+ }
99+
100+ static void _fan_off_event (lv_obj_t * obj , lv_event_t event ) {
101+ if (event == LV_EVENT_CLICKED ) {
102+ reprap_send_gcode ("M106 S0" );
103+ }
104+ }
105+
106+ static void slider_event_cb (lv_obj_t * slider , lv_event_t event )
107+ {
108+ if (event == LV_EVENT_RELEASED ) {
109+ static char buf [11 ]; /* max 10 bytes for number plus 1 null terminating byte */
110+ snprintf (buf , 11 , "M106 S%.2f" , (lv_slider_get_value (slider ) / 100. ));
111+ reprap_send_gcode (buf );
112+ }
113+ }
114+
60115static void _next_height_adjust_event (lv_obj_t * obj , lv_event_t event ) {
61116 if (event == LV_EVENT_CLICKED ) {
62117 if (reprap_send_gcode ("M292" )) {
@@ -185,12 +240,8 @@ void update_ui_machine() {
185240 portENTER_CRITICAL (& mutex ); // not sure this really helps?!
186241 if (label_z_pos_cali ) lv_label_set_text_fmt (label_z_pos_cali , "%.02f mm" , reprap_axes .z );
187242 portEXIT_CRITICAL (& mutex );
243+
188244 if (btn_home_x ) {
189- static lv_style_t homed_style ;
190- lv_style_copy (& homed_style , lv_btn_get_style (btn_home_x , LV_BTN_STYLE_REL ));
191- homed_style .body .main_color = REP_PANEL_DARK_ACCENT ;
192- homed_style .body .grad_color = REP_PANEL_DARK_ACCENT ;
193- homed_style .text .color = REP_PANEL_DARK ;
194245 if (reprap_axes .x_homed )
195246 lv_btn_set_style (btn_home_x , LV_BTN_STYLE_REL , & homed_style );
196247 else
@@ -211,6 +262,19 @@ void update_ui_machine() {
211262 else
212263 lv_btn_set_style (btn_home_all , LV_BTN_STYLE_REL , & not_homed_style );
213264 }
265+ if (btn_power ) {
266+ if (reprap_params .power ) {
267+ lv_btn_set_style (btn_power , LV_BTN_STYLE_REL , & homed_style );
268+ lv_label_set_text (label_power , "On" );
269+ } else {
270+ lv_btn_set_style (btn_power , LV_BTN_STYLE_REL , & not_homed_style );
271+ lv_label_set_text (label_power , "Off" );
272+ }
273+ }
274+ if (label_fan ) {
275+ lv_label_set_text_fmt (label_fan , " %u%% " , reprap_params .fan );
276+ lv_slider_set_value (slider , reprap_params .fan , LV_ANIM_ON );
277+ }
214278}
215279
216280void draw_machine (lv_obj_t * parent_screen ) {
@@ -229,11 +293,16 @@ void draw_machine(lv_obj_t *parent_screen) {
229293 btn_home_x = create_button (home_cont , btn_home_x , " X " , _home_x_event );
230294 btn_home_y = create_button (home_cont , btn_home_y , " Y " , _home_y_event );
231295 btn_home_z = create_button (home_cont , btn_home_z , " Z " , _home_z_event );
296+
232297 lv_style_copy (& not_homed_style , lv_btn_get_style (btn_home_x , LV_BTN_STYLE_REL ));
298+ lv_style_copy (& homed_style , lv_btn_get_style (btn_home_x , LV_BTN_STYLE_REL ));
299+ homed_style .body .main_color = REP_PANEL_DARK_ACCENT ;
300+ homed_style .body .grad_color = REP_PANEL_DARK_ACCENT ;
301+ homed_style .text .color = REP_PANEL_DARK ;
233302
234303 lv_obj_t * cont_cali = lv_cont_create (machine_page , NULL );
235304 lv_cont_set_fit (cont_cali , LV_FIT_TIGHT );
236- lv_cont_set_layout (cont_cali , LV_LAYOUT_ROW_M );
305+ lv_cont_set_layout (cont_cali , LV_LAYOUT_ROW_M );
237306
238307 ddlist_cali_options = lv_ddlist_create (cont_cali , NULL );
239308 lv_ddlist_set_options (ddlist_cali_options , cali_opt_list );
@@ -245,5 +314,41 @@ void draw_machine(lv_obj_t *parent_screen) {
245314 static lv_obj_t * do_cali_butn ;
246315 create_button (cont_cali , do_cali_butn , "Start" , _start_cali_event );
247316
317+ lv_obj_t * power_cont = lv_cont_create (machine_page , NULL );
318+ lv_cont_set_layout (power_cont , LV_LAYOUT_ROW_M );
319+ lv_cont_set_fit (power_cont , LV_FIT_TIGHT );
320+ lv_obj_t * label_power_header = lv_label_create (power_cont , NULL );
321+ lv_label_set_text (label_power_header , "Power:" );
322+
323+ btn_power = lv_btn_create (power_cont , NULL );
324+ lv_btn_set_fit (btn_power , LV_FIT_TIGHT );
325+ lv_obj_set_event_cb (btn_power , _power_toggle_event );
326+ lv_obj_align (btn_power , power_cont , LV_ALIGN_CENTER , 0 , 0 );
327+ label_power = lv_label_create (btn_power , NULL );
328+ lv_label_set_text (label_power , reprap_params .power ? "On" : "Off" );
329+
330+ #ifdef USE_LIGHTNING
331+ lv_obj_t * label_light = lv_label_create (power_cont , NULL );
332+ lv_label_set_text (label_light , "Light:" );
333+ btn_light_on = create_button (power_cont , btn_light_on , "On" , _light_on_event );
334+ btn_light_half = create_button (power_cont , btn_light_half , "50%" , _light_half_event );
335+ btn_light_off = create_button (power_cont , btn_light_off , "Off" , _light_off_event );
336+ #endif
337+
338+ lv_obj_t * fan_cont = lv_cont_create (machine_page , NULL );
339+ lv_cont_set_layout (fan_cont , LV_LAYOUT_ROW_M );
340+ lv_cont_set_fit (fan_cont , LV_FIT_TIGHT );
341+ lv_obj_t * label_fan_title = lv_label_create (fan_cont , NULL );
342+ lv_label_set_text (label_fan_title , "Fan: " );
343+
344+ slider = lv_slider_create (fan_cont , NULL );
345+ lv_obj_set_width (slider , LV_DPI * 2 );
346+ lv_obj_align (slider , NULL , LV_ALIGN_CENTER , 0 , 0 );
347+ lv_obj_set_event_cb (slider , slider_event_cb );
348+ lv_slider_set_range (slider , 0 , 100 );
349+ label_fan = lv_label_create (fan_cont , NULL );
350+ lv_label_set_text_fmt (label_fan , " %u%% " , reprap_params .fan );
351+ btn_fan_off = create_button (fan_cont , btn_fan_off , " Off " , _fan_off_event );
352+
248353 update_ui_machine ();
249354}
0 commit comments