MKS LVGL UI: Display/edit fan percentage (#21544)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
Malderin 2021-04-06 04:39:57 +03:00 committed by Scott Lahteine
parent 1ba0ed8121
commit c2c73215b2

View File

@ -32,8 +32,7 @@
#include "../../../../inc/MarlinConfig.h"
extern lv_group_t *g;
static lv_obj_t *scr;
static lv_obj_t *fanText;
static lv_obj_t *scr, *fanText;
enum {
ID_F_ADD = 1,
@ -44,43 +43,23 @@ enum {
ID_F_RETURN
};
static uint8_t fanSpeed;
static void event_handler(lv_obj_t *obj, lv_event_t event) {
if (event != LV_EVENT_RELEASED) return;
uint8_t fanPercent = map(thermalManager.fan_speed[0], 0, 255, 0, 100);
switch (obj->mks_obj_id) {
case ID_F_ADD:
if (fanSpeed < 254) fanSpeed++;
break;
case ID_F_DEC:
if (fanSpeed > 0) fanSpeed--;
break;
case ID_F_HIGH:
fanSpeed = 255;
break;
case ID_F_MID:
fanSpeed = 127;
break;
case ID_F_OFF:
gcode.process_subcommands_now_P(PSTR("M107"));
return;
case ID_F_RETURN:
clear_cur_ui();
draw_return_ui();
return;
case ID_F_ADD: if (fanPercent < 100) fanPercent++; break;
case ID_F_DEC: if (fanPercent != 0) fanPercent--; break;
case ID_F_HIGH: fanPercent = 100; break;
case ID_F_MID: fanPercent = 50; break;
case ID_F_OFF: fanPercent = 0; break;
case ID_F_RETURN: clear_cur_ui(); draw_return_ui(); return;
}
sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed);
gcode.process_subcommands_now(public_buf_l);
thermalManager.set_fan_speed(0, map(fanPercent, 0, 100, 0, 255));
}
void lv_draw_fan() {
lv_obj_t *buttonAdd;
#if HAS_FAN
fanSpeed = thermalManager.fan_speed[0];
#endif
scr = lv_screen_create(FAN_UI);
// Create an Image button
buttonAdd = lv_big_button_create(scr, "F:/bmp_Add.bin", fan_menu.add, INTERVAL_V, titleHeight, event_handler, ID_F_ADD);
@ -97,12 +76,11 @@ void lv_draw_fan() {
}
void disp_fan_value() {
char buf1[10] = {0};
public_buf_l[0] = '\0';
strcat(public_buf_l, fan_menu.state);
strcat_P(public_buf_l, PSTR(": "));
sprintf_P(buf1, PSTR("%3d"), thermalManager.fan_speed[0]);
strcat(public_buf_l, buf1);
#if HAS_FAN
sprintf_P(public_buf_l, PSTR("%s: %3d%%"), fan_menu.state, (int)map(thermalManager.fan_speed[0], 0, 255, 0, 100));
#else
sprintf_P(public_buf_l, PSTR("%s: ---"), fan_menu.state);
#endif
lv_label_set_text(fanText, public_buf_l);
lv_obj_align(fanText, nullptr, LV_ALIGN_CENTER, 0, -65);
}