MKS LVGL UI: Display/edit fan percentage (#21544)
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
parent
a6105ef37f
commit
61af08d499
@ -32,8 +32,7 @@
|
|||||||
#include "../../../../inc/MarlinConfig.h"
|
#include "../../../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
extern lv_group_t *g;
|
extern lv_group_t *g;
|
||||||
static lv_obj_t *scr;
|
static lv_obj_t *scr, *fanText;
|
||||||
static lv_obj_t *fanText;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ID_F_ADD = 1,
|
ID_F_ADD = 1,
|
||||||
@ -44,43 +43,23 @@ enum {
|
|||||||
ID_F_RETURN
|
ID_F_RETURN
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint8_t fanSpeed;
|
|
||||||
|
|
||||||
static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
||||||
if (event != LV_EVENT_RELEASED) return;
|
if (event != LV_EVENT_RELEASED) return;
|
||||||
|
uint8_t fanPercent = map(thermalManager.fan_speed[0], 0, 255, 0, 100);
|
||||||
switch (obj->mks_obj_id) {
|
switch (obj->mks_obj_id) {
|
||||||
case ID_F_ADD:
|
case ID_F_ADD: if (fanPercent < 100) fanPercent++; break;
|
||||||
if (fanSpeed < 254) fanSpeed++;
|
case ID_F_DEC: if (fanPercent != 0) fanPercent--; break;
|
||||||
break;
|
case ID_F_HIGH: fanPercent = 100; break;
|
||||||
case ID_F_DEC:
|
case ID_F_MID: fanPercent = 50; break;
|
||||||
if (fanSpeed > 0) fanSpeed--;
|
case ID_F_OFF: fanPercent = 0; break;
|
||||||
break;
|
case ID_F_RETURN: clear_cur_ui(); draw_return_ui(); return;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed);
|
thermalManager.set_fan_speed(0, map(fanPercent, 0, 100, 0, 255));
|
||||||
gcode.process_subcommands_now(public_buf_l);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void lv_draw_fan() {
|
void lv_draw_fan() {
|
||||||
lv_obj_t *buttonAdd;
|
lv_obj_t *buttonAdd;
|
||||||
|
|
||||||
#if HAS_FAN
|
|
||||||
fanSpeed = thermalManager.fan_speed[0];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
scr = lv_screen_create(FAN_UI);
|
scr = lv_screen_create(FAN_UI);
|
||||||
// Create an Image button
|
// 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);
|
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() {
|
void disp_fan_value() {
|
||||||
char buf1[10] = {0};
|
#if HAS_FAN
|
||||||
public_buf_l[0] = '\0';
|
sprintf_P(public_buf_l, PSTR("%s: %3d%%"), fan_menu.state, (int)map(thermalManager.fan_speed[0], 0, 255, 0, 100));
|
||||||
strcat(public_buf_l, fan_menu.state);
|
#else
|
||||||
strcat_P(public_buf_l, PSTR(": "));
|
sprintf_P(public_buf_l, PSTR("%s: ---"), fan_menu.state);
|
||||||
sprintf_P(buf1, PSTR("%3d"), thermalManager.fan_speed[0]);
|
#endif
|
||||||
strcat(public_buf_l, buf1);
|
|
||||||
lv_label_set_text(fanText, public_buf_l);
|
lv_label_set_text(fanText, public_buf_l);
|
||||||
lv_obj_align(fanText, nullptr, LV_ALIGN_CENTER, 0, -65);
|
lv_obj_align(fanText, nullptr, LV_ALIGN_CENTER, 0, -65);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user