Skip to content

Commit 26bae8a

Browse files
authored
Merge pull request #4 from vden/feature/extended-machine-settings
- Change console image button - Added power button - Added extruder fan control - Added light switch (compile time selection) - ILI9488 freeze low mem crash fix by decreasing LVGL memory
2 parents 036c5c1 + 0441922 commit 26bae8a

File tree

8 files changed

+259
-222
lines changed

8 files changed

+259
-222
lines changed

main/images/consolebutton.c

Lines changed: 126 additions & 212 deletions
Large diffs are not rendered by default.
1.31 KB
Loading

main/reppanel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void draw_header(lv_obj_t *parent_screen) {
159159
lv_obj_t *cont_header_right = lv_cont_create(cont_header, NULL);
160160
lv_cont_set_fit(cont_header_right, LV_FIT_TIGHT);
161161
lv_cont_set_layout(cont_header_right, LV_LAYOUT_ROW_M);
162-
lv_obj_align(cont_header_right, cont_header, LV_ALIGN_IN_TOP_RIGHT, -120, 12);
162+
lv_obj_align(cont_header_right, cont_header, LV_ALIGN_IN_TOP_RIGHT, -130, 12);
163163

164164
lv_obj_t *click_cont = lv_cont_create(cont_header_right, NULL);
165165
lv_cont_set_fit(click_cont, LV_FIT_TIGHT);

main/reppanel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ typedef struct {
110110
bool z_homed;
111111
} reprap_axes_t;
112112

113+
typedef struct {
114+
bool power;
115+
int fan;
116+
} reprap_params_t;
117+
113118
typedef struct {
114119
int number;
115120
char name[MAX_TOOL_NAME_LEN];
@@ -156,6 +161,7 @@ extern int num_tools; // max is MAX_NUM_TOOLS
156161
extern int current_visible_tool_indx; // current indx of tool where temp data is displayed on process screen
157162

158163
extern reprap_axes_t reprap_axes;
164+
extern reprap_params_t reprap_params;
159165
extern reprap_tool_t reprap_tools[MAX_NUM_TOOLS];
160166
extern reprap_bed_t reprap_bed;
161167
extern reprap_tool_poss_temps_t reprap_tool_poss_temps;

main/reppanel_machine.c

Lines changed: 112 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,34 @@
1818
#define TAG "Machine"
1919

2020
reprap_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;
2224
static char *cali_opt_map[] = {"True Bed Leveling", "Mesh Bed Leveling"};
2325
static 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+
2835
lv_obj_t *machine_page;
2936
lv_obj_t *ddlist_cali_options;
3037
lv_obj_t *btnm_height;
3138
lv_obj_t *btn_closer;
3239
lv_obj_t *btn_away;
3340
lv_obj_t *cont_heigh_adj_diag, *label_z_pos_cali;
3441
lv_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

3650
static 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+
60115
static 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

216280
void 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
}

main/reppanel_request.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ void process_reprap_status(char *buff) {
119119
}
120120
}
121121

122+
cJSON *params = cJSON_GetObjectItem(root, "params");
123+
if (params) {
124+
cJSON *atxPower = cJSON_GetObjectItem(params, "atxPower");
125+
if (atxPower && cJSON_IsNumber(atxPower)) {
126+
reprap_params.power = atxPower->valueint == 1;
127+
}
128+
cJSON *fanPercent = cJSON_GetObjectItem(params, "fanPercent");
129+
if (fanPercent && cJSON_IsArray(fanPercent)) {
130+
reprap_params.fan = cJSON_GetArrayItem(fanPercent, 0)->valueint;
131+
}
132+
}
133+
122134
int _heater_states[MAX_NUM_TOOLS]; // bed heater state must be on pos 0
123135
cJSON *duet_temps = cJSON_GetObjectItem(root, DUET_TEMPS);
124136
if (duet_temps) {

main/reppanel_request.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#define MAX_REQ_ADDR_LENGTH 256 + 512
99
#define JSON_BUFF_SIZE 1024 * 4 // d2wc settings is > 2800 bytes
10-
#define UART_RESP_BUFF_SIZE 1024 * 3
10+
#define UART_RESP_BUFF_SIZE 1024 * 4
1111

1212
typedef struct {
1313
char buffer[JSON_BUFF_SIZE];

sdkconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ CONFIG_LOG_DEFAULT_LEVEL=3
325325
CONFIG_LOG_COLORS=y
326326
CONFIG_LWIP_LOCAL_HOSTNAME="reppanel"
327327
# CONFIG_LWIP_L2_TO_L3_COPY is not set
328-
# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
328+
CONFIG_LWIP_IRAM_OPTIMIZATION=y
329329
CONFIG_LWIP_TIMERS_ONDEMAND=y
330330
CONFIG_LWIP_MAX_SOCKETS=10
331331
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set

0 commit comments

Comments
 (0)