Merge branch 'experimental-multi-printer' into dev

This commit is contained in:
suchmememanyskill
2024-03-11 21:55:44 +01:00
31 changed files with 1047 additions and 396 deletions

View File

@@ -9,6 +9,8 @@
"'-D ESP32_3248S035C'",
"'-D LCD_WIDTH=320'",
"'-D LCD_HEIGHT=480'",
"'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'",
"'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'",
"'-D BCKL=27'",
"'-D LCD_ST7796_SPI'",
"'-D ST7796_SPI_HOST=SPI2_HOST'",
@@ -18,10 +20,13 @@
"'-D ST7796_SPI_BUS_SCLK_IO_NUM=14'",
"'-D ST7796_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'",
"'-D ST7796_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'",
"'-D ST7796_SPI_BUS_MAX_TRANSFER_SZ=0'",
"'-D ST7796_SPI_BUS_FLAGS=0'",
"'-D ST7796_SPI_BUS_INTR_FLAGS=0'",
"'-D ST7796_SPI_CONFIG_CS_GPIO_NUM=15'",
"'-D ST7796_SPI_CONFIG_DC_GPIO_NUM=2'",
"'-D ST7796_SPI_CONFIG_SPI_MODE=SPI_MODE0'",
"'-D ST7796_SPI_CONFIG_PCLK_HZ=80000000'",
"'-D ST7796_SPI_CONFIG_PCLK_HZ=24000000'",
"'-D ST7796_SPI_CONFIG_TRANS_QUEUE_DEPTH=10'",
"'-D ST7796_SPI_CONFIG_LCD_CMD_BITS=8'",
"'-D ST7796_SPI_CONFIG_LCD_PARAM_BITS=8'",
@@ -77,14 +82,13 @@
"'-D SPEAK=26'",
"-DCYD_SCREEN_GAP_PX=10",
"-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=40",
"-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=40",
"-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=45",
"-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=45",
"-DCYD_SCREEN_FONT=lv_font_montserrat_16",
"-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12",
"-DCYD_SCREEN_SIDEBAR_SIZE_PX=50",
"-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1",
"-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1",
"-DCYD_SCREEN_DISABLE_INVERT_COLORS=1"
"-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1"
],
"f_cpu": "240000000L",
"f_flash": "40000000L",

View File

@@ -17,6 +17,7 @@ lib_deps =
https://github.com/suchmememanyskill/esp32-smartdisplay
bblanchon/ArduinoJson@^7.0.0
plageoj/UrlEncode@^1.0.1
erriez/ErriezCRC32 @ ^1.0.1
monitor_filters = esp32_exception_decoder
build_flags =
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
@@ -32,6 +33,7 @@ lib_deps =
https://github.com/PaulStoffregen/XPT2046_Touchscreen.git
bblanchon/ArduinoJson@^7.0.0
plageoj/UrlEncode@^1.0.1
erriez/ErriezCRC32 @ ^1.0.1
[env:esp32-3248S035C]
board = esp32-3248S035C
@@ -42,6 +44,7 @@ lib_deps =
https://github.com/OperatorB/gt911-arduino-fixed-reset.git
bblanchon/ArduinoJson@^7.0.0
plageoj/UrlEncode@^1.0.1
erriez/ErriezCRC32 @ ^1.0.1
[env:esp32-2432S024C-SD]
board = esp32-2432S024C-smartdisplay

View File

@@ -14,14 +14,16 @@ COLOR_DEF color_defs[] = {
{LV_PALETTE_PURPLE, 0, LV_PALETTE_GREY},
};
void WriteGlobalConfig() {
void write_global_config()
{
Preferences preferences;
preferences.begin("global_config", false);
preferences.putBytes("global_config", &global_config, sizeof(global_config));
preferences.end();
}
void VerifyVersion(){
void verify_version()
{
Preferences preferences;
if (!preferences.begin("global_config", false))
return;
@@ -37,17 +39,76 @@ void VerifyVersion(){
preferences.end();
}
void LoadGlobalConfig() {
PRINTER_CONFIG* get_current_printer_config()
{
return &global_config.printer_config[global_config.printer_index];
}
int get_printer_config_count()
{
int count = 0;
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++) {
if (global_config.printer_config[i].ip_configured)
count++;
}
return count;
}
int get_printer_config_free_index()
{
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++) {
if (!global_config.printer_config[i].ip_configured)
return i;
}
return -1;
}
void set_printer_config_index(int index)
{
if (index < 0 || index >= PRINTER_CONFIG_COUNT)
return;
PRINTER_CONFIG* old_config = &global_config.printer_config[global_config.printer_index];
PRINTER_CONFIG* new_config = &global_config.printer_config[index];
global_config.printer_index = index;
if (!new_config->ip_configured){
new_config->raw = old_config->raw;
new_config->ip_configured = false;
new_config->auth_configured = false;
new_config->printer_name[0] = 0;
new_config->klipper_host[0] = 0;
new_config->klipper_auth[0] = 0;
new_config->klipper_port = 0;
new_config->color_scheme = old_config->color_scheme;
for (int i = 0; i < 3; i++){
new_config->hotend_presets[i] = old_config->hotend_presets[i];
new_config->bed_presets[i] = old_config->bed_presets[i];
}
write_global_config();
ESP.restart();
}
write_global_config();
}
void load_global_config()
{
global_config.version = CONFIG_VERSION;
global_config.brightness = 255;
global_config.screenTimeout = 5;
global_config.hotend_presets[0] = 0;
global_config.hotend_presets[1] = 200;
global_config.hotend_presets[2] = 240;
global_config.bed_presets[0] = 0;
global_config.bed_presets[1] = 60;
global_config.bed_presets[2] = 70;
VerifyVersion();
global_config.screen_timeout = 5;
global_config.printer_config[0].hotend_presets[0] = 0;
global_config.printer_config[0].hotend_presets[1] = 200;
global_config.printer_config[0].hotend_presets[2] = 240;
global_config.printer_config[0].bed_presets[0] = 0;
global_config.printer_config[0].bed_presets[1] = 60;
global_config.printer_config[0].bed_presets[2] = 70;
verify_version();
Preferences preferences;
preferences.begin("global_config", true);
preferences.getBytes("global_config", &global_config, sizeof(global_config));

View File

@@ -3,7 +3,8 @@
#include "lvgl.h"
#define CONFIG_VERSION 4
#define CONFIG_VERSION 5
#define PRINTER_CONFIG_COUNT 8
enum {
REMAINING_TIME_CALC_PERCENTAGE = 0,
@@ -11,47 +12,62 @@ enum {
REMAINING_TIME_CALC_SLICER = 2,
};
typedef struct _PRINTER_CONFIG {
union {
unsigned int raw;
struct {
// Internal
bool ip_configured : 1;
bool auth_configured : 1;
// External
bool light_mode : 1;
bool invert_colors : 1;
unsigned char remaining_time_calc_mode : 2;
};
};
char printer_name[25];
char klipper_host[65];
char klipper_auth[33];
unsigned short klipper_port;
unsigned char color_scheme;
unsigned short hotend_presets[3];
unsigned short bed_presets[3];
} PRINTER_CONFIG;
typedef struct _GLOBAL_CONFIG {
unsigned char version;
union {
unsigned int raw;
struct {
// Internal
bool screenCalibrated : 1;
bool wifiConfigured : 1;
bool ipConfigured : 1;
bool screen_calibrated : 1;
bool wifi_configured : 1;
// External
bool lightMode : 1;
bool invertColors : 1;
bool rotateScreen : 1;
bool onDuringPrint : 1;
bool autoOtaUpdate : 1;
unsigned char remaining_time_calc_mode : 2;
// Internal
bool auth_configured : 1;
bool rotate_screen : 1;
bool auto_ota_update : 1;
bool multi_printer_mode : 1;
bool on_during_print : 1;
};
};
float screenCalXOffset;
float screenCalXMult;
float screenCalYOffset;
float screenCalYMult;
char wifiSSID[32];
char wifiPassword[64];
PRINTER_CONFIG printer_config[PRINTER_CONFIG_COUNT];
char klipperHost[64];
unsigned short klipperPort;
float screen_cal_x_offset;
float screen_cal_x_mult;
float screen_cal_y_offset;
float screen_cal_y_mult;
char wifi_SSID[32];
char wifi_password[64];
unsigned char color_scheme;
unsigned char brightness;
unsigned char screenTimeout;
unsigned short hotend_presets[3];
unsigned short bed_presets[3];
char klipper_auth[33];
unsigned char screen_timeout;
unsigned char printer_index;
} GLOBAL_CONFIG;
typedef struct _COLOR_DEF {
@@ -63,8 +79,13 @@ typedef struct _COLOR_DEF {
extern GLOBAL_CONFIG global_config;
extern COLOR_DEF color_defs[];
void WriteGlobalConfig();
void VerifyVersion();
void LoadGlobalConfig();
void write_global_config();
void verify_version();
void load_global_config();
PRINTER_CONFIG* get_current_printer_config();
int get_printer_config_count();
void set_printer_config_index(int index);
int get_printer_config_free_index();
#endif // !_GLOBAL_CONFIG_INIT

View File

@@ -7,6 +7,7 @@
#include "macros_query.h"
#include <UrlEncode.h>
#include "http_client.h"
#include "../ui/ui_utils.h"
const char *printer_state_messages[] = {
"Error",
@@ -14,6 +15,7 @@ const char *printer_state_messages[] = {
"Printing"};
Printer printer = {0};
PrinterMinimal *printer_minimal;
int klipper_request_consecutive_fail_count = 0;
char filename_buff[512] = {0};
SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
@@ -49,8 +51,7 @@ void send_gcode(bool wait, const char *gcode)
SETUP_HTTP_CLIENT_FULL("/printer/gcode/script?script=" + urlEncode(gcode), false, wait ? 5000 : 750);
try
{
int result = client.GET();
Serial.printf("Send gcode result: %d\n", result);
client.GET();
}
catch (...)
{
@@ -111,7 +112,8 @@ int last_slicer_time_query = -15000;
void fetch_printer_data()
{
freeze_request_thread();
SETUP_HTTP_CLIENT("/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks&fan")
PRINTER_CONFIG *config = get_current_printer_config();
SETUP_HTTP_CLIENT("/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks&fan&display_status")
int httpCode = client.GET();
delay(10);
@@ -234,8 +236,11 @@ void fetch_printer_data()
}
}
// TODO: make a call to /server/files/metadata to get more accurate time estimates
// https://moonraker.readthedocs.io/en/latest/web_api/#server-administration
if (status.containsKey("display_status"))
{
const char* message = status["display_status"]["message"];
lv_create_popup_message(message, 10000);
}
if (printer.state == PRINTER_STATE_PRINTING && printer.print_progress > 0)
{
@@ -247,15 +252,15 @@ void fetch_printer_data()
remaining_time_s_slicer = printer.slicer_estimated_print_time_s - printer.elapsed_time_s;
}
if (remaining_time_s_slicer <= 0 || global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_PERCENTAGE)
if (remaining_time_s_slicer <= 0 || config->remaining_time_calc_mode == REMAINING_TIME_CALC_PERCENTAGE)
{
printer.remaining_time_s = remaining_time_s_percentage;
}
else if (global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_INTERPOLATED)
else if (config->remaining_time_calc_mode == REMAINING_TIME_CALC_INTERPOLATED)
{
printer.remaining_time_s = remaining_time_s_percentage * printer.print_progress + remaining_time_s_slicer * (1 - printer.print_progress);
}
else if (global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_SLICER)
else if (config->remaining_time_calc_mode == REMAINING_TIME_CALC_SLICER)
{
printer.remaining_time_s = remaining_time_s_slicer;
}
@@ -297,6 +302,92 @@ void fetch_printer_data()
}
}
void fetch_printer_data_minimal()
{
PrinterMinimal data[PRINTER_CONFIG_COUNT] = {0};
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){
PRINTER_CONFIG *config = &global_config.printer_config[i];
if (!config->ip_configured)
{
data[i].online = false;
continue;
}
delay(10);
HTTPClient client;
configure_http_client(client, get_full_url("/printer/objects/query?webhooks&print_stats&virtual_sdcard", config), true, 1000);
freeze_request_thread();
int httpCode = client.GET();
delay(10);
if (httpCode == 200)
{
data[i].online = true;
JsonDocument doc;
deserializeJson(doc, client.getStream());
auto status = doc["result"]["status"];
unfreeze_request_thread();
if (status.containsKey("webhooks"))
{
const char *state = status["webhooks"]["state"];
if (strcmp(state, "ready") == 0 && data[i].state == PRINTER_STATE_ERROR)
{
data[i].state = PRINTER_STATE_IDLE;
}
else if (strcmp(state, "shutdown") == 0 && data[i].state != PRINTER_STATE_ERROR)
{
data[i].state = PRINTER_STATE_ERROR;
}
}
if (data[i].state != PRINTER_STATE_ERROR)
{
if (status.containsKey("virtual_sdcard"))
{
data[i].print_progress = status["virtual_sdcard"]["progress"];
}
if (status.containsKey("print_stats"))
{
const char *state = status["print_stats"]["state"];
if (state == nullptr)
{
data[i].state = PRINTER_STATE_ERROR;
}
else if (strcmp(state, "printing") == 0)
{
data[i].state = PRINTER_STATE_PRINTING;
}
else if (strcmp(state, "paused") == 0)
{
data[i].state = PRINTER_STATE_PAUSED;
}
else if (strcmp(state, "complete") == 0 || strcmp(state, "cancelled") == 0 || strcmp(state, "standby") == 0)
{
data[i].state = PRINTER_STATE_IDLE;
}
}
}
}
else
{
printer_minimal->online = false;
unfreeze_request_thread();
}
}
freeze_render_thread();
memcpy(printer_minimal, data, sizeof(PrinterMinimal) * PRINTER_CONFIG_COUNT);
lv_msg_send(DATA_PRINTER_MINIMAL, NULL);
unfreeze_render_thread();
}
void data_loop()
{
// Causes other threads that are trying to lock the thread to actually lock it
@@ -307,9 +398,16 @@ void data_loop()
void data_loop_background(void * param){
esp_task_wdt_init(10, true);
int loop_iter = 20;
while (true){
delay(data_update_interval);
fetch_printer_data();
if (global_config.multi_printer_mode) {
if (loop_iter++ > 20){
fetch_printer_data_minimal();
loop_iter = 0;
}
}
}
}
@@ -317,10 +415,12 @@ TaskHandle_t background_loop;
void data_setup()
{
printer_minimal = (PrinterMinimal *)calloc(sizeof(PrinterMinimal), PRINTER_CONFIG_COUNT);
semaphore_init();
printer.print_filename = filename_buff;
fetch_printer_data();
macros_query_setup();
freeze_render_thread();
xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 0, &background_loop, 0);
xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 2, &background_loop, 0);
}

View File

@@ -37,12 +37,20 @@ typedef struct _Printer {
int slicer_estimated_print_time_s;
} Printer;
typedef struct _PrinterMinimal {
bool online;
unsigned char state;
float print_progress; // 0 -> 1
} PrinterMinimal;
extern Printer printer;
extern PrinterMinimal *printer_minimal;
extern int klipper_request_consecutive_fail_count;
#define DATA_PRINTER_STATE 1
#define DATA_PRINTER_DATA 2
#define DATA_PRINTER_TEMP_PRESET 3
#define DATA_PRINTER_MINIMAL 4
void data_loop();
void data_setup();

View File

@@ -67,14 +67,14 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
}
void set_invert_display(){
tft.invertDisplay(global_config.invertColors);
tft.invertDisplay(get_current_printer_config()->invert_colors);
}
void screen_setup()
{
touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
touchscreen.begin(touchscreen_spi);
touchscreen.setRotation(global_config.rotateScreen ? 3 : 1);
touchscreen.setRotation(global_config.rotate_screen ? 3 : 1);
lv_init();
@@ -83,7 +83,7 @@ void screen_setup()
ledcSetup(0, 5000, 12);
ledcAttachPin(21, 0);
tft.setRotation(global_config.rotateScreen ? 3 : 1);
tft.setRotation(global_config.rotate_screen ? 3 : 1);
tft.fillScreen(TFT_BLACK);
set_invert_display();
touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);

View File

@@ -65,7 +65,7 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
uint16_t magicX; // fix GT911 driver - orientation and handle rotation
uint16_t magicY;
if (!global_config.rotateScreen)
if (!global_config.rotate_screen)
{
magicY = tp.points[i].x;
magicX = TOUCH_HEIGHT - tp.points[i].y;
@@ -84,7 +84,7 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
void set_invert_display()
{
tft.invertDisplay(global_config.invertColors);
tft.invertDisplay(get_current_printer_config()->invert_colors);
}
void set_LED_color(uint8_t rgbVal[3])
@@ -114,7 +114,7 @@ void screen_setup()
tft.init();
ledcSetup(0, 5000, 12);
ledcAttachPin(TFT_BL, 0);
tft.setRotation(global_config.rotateScreen ? 3 : 1);
tft.setRotation(global_config.rotate_screen ? 3 : 1);
tft.fillScreen(TFT_BLACK);
set_invert_display();
LED_init();

View File

@@ -21,7 +21,7 @@ void set_invert_display()
void lv_screen_intercept(_lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
{
if (global_config.invertColors) {
if (get_current_printer_config()->invert_colors) {
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
@@ -61,7 +61,7 @@ void screen_setup()
}
#endif // CYD_SCREEN_DISABLE_INVERT_COLORS
lv_disp_set_rotation(lv_disp_get_default(), (global_config.rotateScreen) ? ROTATION_INVERTED : ROTATION_NORMAL);
lv_disp_set_rotation(lv_disp_get_default(), (global_config.rotate_screen) ? ROTATION_INVERTED : ROTATION_NORMAL);
}
#endif // CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY

View File

@@ -1,14 +1,17 @@
#include "http_client.h"
#include "../conf/global_config.h"
String get_full_url(String url_part, PRINTER_CONFIG * config)
{
return "http://" + String(config->klipper_host) + ":" + String(config->klipper_port) + url_part;
}
String get_full_url(String url_part)
{
return "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + url_part;
return "http://" + String(get_current_printer_config()->klipper_host) + ":" + String(get_current_printer_config()->klipper_port) + url_part;
}
void configure_http_client(HTTPClient &client, String url, bool stream, int timeout)
{
Serial.println(url);
if (stream){
client.useHTTP10(true);
}
@@ -20,7 +23,7 @@ void configure_http_client(HTTPClient &client, String url, bool stream, int time
client.begin(url);
if (global_config.auth_configured) {
client.addHeader("X-Api-Key", global_config.klipper_auth);
if (get_current_printer_config()->auth_configured) {
client.addHeader("X-Api-Key", get_current_printer_config()->klipper_auth);
}
}

View File

@@ -1,8 +1,10 @@
#pragma once
#include <HTTPClient.h>
#include "../conf/global_config.h"
String get_full_url(String url_part);
String get_full_url(String url_part, PRINTER_CONFIG * config);
void configure_http_client(HTTPClient &client, String url, bool stream = true, int timeout = 1000);

View File

@@ -54,14 +54,14 @@ void lv_touch_intercept(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
screen_timer_wake();
#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION
data->point.x = round((data->point.x * global_config.screenCalXMult) + global_config.screenCalXOffset);
data->point.y = round((data->point.y * global_config.screenCalYMult) + global_config.screenCalYOffset);
data->point.x = round((data->point.x * global_config.screen_cal_x_mult) + global_config.screen_cal_x_offset);
data->point.y = round((data->point.y * global_config.screen_cal_y_mult) + global_config.screen_cal_y_offset);
#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION
}
}
void lv_do_calibration(){
if (global_config.screenCalibrated){
if (global_config.screen_calibrated){
return;
}
@@ -149,22 +149,22 @@ void lv_do_calibration(){
int16_t yDist = CYD_SCREEN_HEIGHT_PX - 20;
#endif
global_config.screenCalXMult = (float)xDist / (float)(x2 - x1);
global_config.screenCalXOffset = 10.0 - ((float)x1 * global_config.screenCalXMult);
global_config.screen_cal_x_mult = (float)xDist / (float)(x2 - x1);
global_config.screen_cal_x_offset = 10.0 - ((float)x1 * global_config.screen_cal_x_mult);
global_config.screenCalYMult = (float)yDist / (float)(y2 - y1);
global_config.screenCalYOffset = 10.0 - ((float)y1 * global_config.screenCalYMult);
global_config.screen_cal_y_mult = (float)yDist / (float)(y2 - y1);
global_config.screen_cal_y_offset = 10.0 - ((float)y1 * global_config.screen_cal_y_mult);
if (global_config.screenCalXMult == std::numeric_limits<float>::infinity() || global_config.screenCalYMult == std::numeric_limits<float>::infinity()){
if (global_config.screen_cal_x_mult == std::numeric_limits<float>::infinity() || global_config.screen_cal_y_mult == std::numeric_limits<float>::infinity()){
Serial.println("Calibration failed, please try again");
ESP.restart();
}
global_config.screenCalibrated = true;
WriteGlobalConfig();
global_config.screen_calibrated = true;
write_global_config();
lv_obj_clean(lv_scr_act());
Serial.printf("Calibration done: X*%.2f + %.2f, Y*%.2f + %.2f\n", global_config.screenCalXMult, global_config.screenCalXOffset, global_config.screenCalYMult, global_config.screenCalYOffset);
Serial.printf("Calibration done: X*%.2f + %.2f, Y*%.2f + %.2f\n", global_config.screen_cal_x_mult, global_config.screen_cal_x_offset, global_config.screen_cal_y_mult, global_config.screen_cal_y_offset);
}
void set_screen_brightness()
@@ -207,7 +207,7 @@ void screen_timer_sleep(lv_timer_t *timer)
void screen_timer_setup()
{
screen_sleep_timer = lv_timer_create(screen_timer_sleep, global_config.screenTimeout * 1000 * 60, NULL);
screen_sleep_timer = lv_timer_create(screen_timer_sleep, global_config.screen_timeout * 1000 * 60, NULL);
lv_timer_pause(screen_sleep_timer);
}
@@ -228,26 +228,27 @@ void screen_timer_period(unsigned int period)
void set_screen_timer_period()
{
screen_timer_period(global_config.screenTimeout * 1000 * 60);
screen_timer_period(global_config.screen_timeout * 1000 * 60);
}
void set_color_scheme()
{
PRINTER_CONFIG *config = get_current_printer_config();
lv_disp_t *dispp = lv_disp_get_default();
lv_color_t main_color = {0};
COLOR_DEF color_def = color_defs[global_config.color_scheme];
COLOR_DEF color_def = color_defs[config->color_scheme];
if (color_defs[global_config.color_scheme].primary_color_light > 0){
if (color_defs[config->color_scheme].primary_color_light > 0){
main_color = lv_palette_lighten(color_def.primary_color, color_def.primary_color_light);
}
else if (color_defs[global_config.color_scheme].primary_color_light < 0) {
else if (color_defs[config->color_scheme].primary_color_light < 0) {
main_color = lv_palette_darken(color_def.primary_color, color_def.primary_color_light * -1);
}
else {
main_color = lv_palette_main(color_defs[global_config.color_scheme].primary_color);
main_color = lv_palette_main(color_defs[config->color_scheme].primary_color);
}
lv_theme_t *theme = lv_theme_default_init(dispp, main_color, lv_palette_main(color_def.secondary_color), !global_config.lightMode, &CYD_SCREEN_FONT);
lv_theme_t *theme = lv_theme_default_init(dispp, main_color, lv_palette_main(color_def.secondary_color), !config->light_mode, &CYD_SCREEN_FONT);
lv_disp_set_theme(dispp, theme);
}

View File

@@ -13,7 +13,7 @@ static char* power_devices[16] = {0};
static bool power_device_states[16] = {0};
static int power_devices_count = 0;
static void _macros_query_internal(){
void _macros_query_internal(){
SETUP_HTTP_CLIENT("/printer/gcode/help")
int httpCode = client.GET();
@@ -52,13 +52,16 @@ void _power_devices_query_internal(){
SETUP_HTTP_CLIENT("/machine/device_power/devices")
int httpCode = client.GET();
if (httpCode == 200 || httpCode == 404 || httpCode == 500){
power_devices_clear();
}
if (httpCode == 200){
JsonDocument doc;
deserializeJson(doc, client.getStream());
auto result = doc["result"]["devices"].as<JsonArray>();
power_devices_clear();
for (auto i : result){
const char * device_name = i["device"];
const char * device_state = i["status"];

View File

@@ -16,4 +16,5 @@ POWERQUERY power_devices_query();
void macros_query_setup();
bool set_power_state(const char* device_name, bool state);
void _power_devices_query_internal();
void _macros_query_internal();
void power_devices_clear();

View File

@@ -13,7 +13,7 @@
void setup() {
Serial.begin(115200);
Serial.println("Hello World");
LoadGlobalConfig();
load_global_config();
screen_setup();
lv_setup();
Serial.println("Screen init done");

View File

@@ -7,6 +7,7 @@
#include "../core/macros_query.h"
#include "panels/panel.h"
#include "../core/http_client.h"
#include "switch_printer.h"
bool connect_ok = false;
lv_obj_t * hostEntry;
@@ -69,21 +70,21 @@ static void ta_event_cb(lv_event_t * e) {
}
else if (code == LV_EVENT_READY)
{
strcpy(global_config.klipperHost, lv_textarea_get_text(hostEntry));
global_config.klipperPort = atoi(lv_textarea_get_text(portEntry));
strcpy(get_current_printer_config()->klipper_host, lv_textarea_get_text(hostEntry));
get_current_printer_config()->klipper_port = atoi(lv_textarea_get_text(portEntry));
connection_status_t status = verify_ip();
if (status == CONNECT_OK)
{
global_config.ipConfigured = true;
WriteGlobalConfig();
get_current_printer_config()->ip_configured = true;
write_global_config();
connect_ok = true;
}
else if (status == CONNECT_AUTH_REQUIRED)
{
label = NULL;
global_config.ipConfigured = true;
WriteGlobalConfig();
get_current_printer_config()->ip_configured = true;
write_global_config();
}
else
{
@@ -109,7 +110,7 @@ static void reset_btn_event_handler(lv_event_t * e){
lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_CLICKED) {
global_config.ipConfigured = false;
get_current_printer_config()->ip_configured = false;
ip_init_inner();
}
}
@@ -161,6 +162,8 @@ void redraw_connect_screen(){
lv_label_set_text(btn_label, "Power Devices");
lv_obj_center(btn_label);
}
draw_switch_printer_button();
}
static bool auth_entry_done = false;
@@ -176,9 +179,9 @@ static void keyboard_event_auth_entry(lv_event_t * e) {
int len = strlen(txt);
if (len > 0)
{
global_config.auth_configured = true;
strcpy(global_config.klipper_auth, txt);
WriteGlobalConfig();
get_current_printer_config()->auth_configured = true;
strcpy(get_current_printer_config()->klipper_auth, txt);
write_global_config();
auth_entry_done = true;
}
}
@@ -190,7 +193,7 @@ static void keyboard_event_auth_entry(lv_event_t * e) {
void handle_auth_entry(){
auth_entry_done = false;
global_config.klipper_auth[32] = 0;
get_current_printer_config()->klipper_auth[32] = 0;
lv_obj_clean(lv_scr_act());
lv_obj_t * root = lv_create_empty_panel(lv_scr_act());
@@ -212,8 +215,8 @@ void handle_auth_entry(){
lv_textarea_set_max_length(passEntry, 32);
lv_textarea_set_one_line(passEntry, true);
if (global_config.auth_configured)
lv_textarea_set_text(passEntry, global_config.klipper_auth);
if (get_current_printer_config()->auth_configured)
lv_textarea_set_text(passEntry, get_current_printer_config()->klipper_auth);
else
lv_textarea_set_text(passEntry, "");
@@ -235,7 +238,7 @@ void handle_auth_entry(){
}
void ip_init_inner(){
if (global_config.ipConfigured) {
if (get_current_printer_config()->ip_configured) {
redraw_connect_screen();
return;
}
@@ -298,7 +301,7 @@ void ip_init(){
lv_timer_handler();
lv_task_handler();
if (!connect_ok && global_config.ipConfigured && (millis() - last_data_update_ip) > data_update_interval_ip){
if (!connect_ok && get_current_printer_config()->ip_configured && (millis() - last_data_update_ip) > data_update_interval_ip){
connection_status_t status = verify_ip();
connect_ok = status == CONNECT_OK;

View File

@@ -8,6 +8,7 @@
#include "panels/panel.h"
#include "../core/macros_query.h"
#include "../core/lv_setup.h"
#include "switch_printer.h"
char extruder_temp_buff[20];
char bed_temp_buff[20];
@@ -90,10 +91,12 @@ void error_ui(){
lv_label_set_text(label, "Devices");
lv_obj_center(label);
}
draw_switch_printer_button();
}
void check_if_screen_needs_to_be_disabled(){
if (global_config.onDuringPrint && printer.state == PRINTER_STATE_PRINTING){
if (global_config.on_during_print && printer.state == PRINTER_STATE_PRINTING){
screen_timer_wake();
screen_timer_stop();
}

View File

@@ -4,6 +4,7 @@
#include "nav_buttons.h"
#include "ui_utils.h"
#include <stdio.h>
#include "../conf/global_config.h"
static lv_style_t nav_button_style;
@@ -76,6 +77,10 @@ static void btn_click_macros(lv_event_t * e){
nav_buttons_setup(4);
}
static void btn_click_printer(lv_event_t * e){
nav_buttons_setup(6);
}
void create_button(const char* icon, const char* name, lv_event_cb_t button_click, lv_event_cb_t label_update, lv_obj_t * root){
lv_obj_t* btn = lv_btn_create(root);
lv_obj_set_flex_grow(btn, 1);
@@ -131,6 +136,11 @@ void nav_buttons_setup(unsigned char active_panel){
// Macros
create_button(LV_SYMBOL_GPS, "Macro", btn_click_macros, NULL, root_panel);
if (global_config.multi_printer_mode)
{
create_button(LV_SYMBOL_HOME, "Printer", btn_click_printer, NULL, root_panel);
}
lv_obj_t * panel = lv_create_empty_panel(lv_scr_act());
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX);
lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0);
@@ -154,6 +164,9 @@ void nav_buttons_setup(unsigned char active_panel){
case 5:
stats_panel_init(panel);
break;
case 6:
printer_panel_init(panel);
break;
}
lv_msg_send(DATA_PRINTER_DATA, &printer);

View File

@@ -85,7 +85,7 @@ void ota_init()
Serial.printf("OTA Update Result: %d\n", result);
update_available = result == ESP32OTAPull::UPDATE_AVAILABLE;
if (global_config.autoOtaUpdate && update_available)
if (global_config.auto_ota_update && update_available)
{
ota_do_update(true);
}

View File

@@ -23,28 +23,7 @@ static void btn_goto_settings(lv_event_t * e){
void macros_panel_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query){
for (int i = 0; i < query.count; i++){
const char* macro = query.macros[i];
lv_obj_t * panel = lv_create_empty_panel(root_panel);
lv_layout_flex_row(panel, LV_FLEX_ALIGN_END);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, macro);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_flex_grow(label, 1);
lv_obj_t * btn = lv_btn_create(panel);
lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
label = lv_label_create(btn);
lv_label_set_text(label, "Run");
lv_obj_center(label);
lv_obj_t * line = lv_line_create(root_panel);
lv_line_set_points(line, line_points, 2);
lv_obj_set_style_line_width(line, 1, 0);
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
lv_create_custom_menu_button(macro, root_panel, btn_press, "Run", (void*)macro);
}
}
@@ -61,26 +40,7 @@ void macros_panel_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY q
for (int i = 0; i < query.count; i++){
const char* power_device_name = query.power_devices[i];
const bool power_device_state = query.power_states[i];
lv_obj_t * panel = lv_create_empty_panel(root_panel);
lv_layout_flex_row(panel, LV_FLEX_ALIGN_END);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, power_device_name);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_flex_grow(label, 1);
lv_obj_t * toggle = lv_switch_create(panel);
lv_obj_add_event_cb(toggle, power_device_toggle, LV_EVENT_VALUE_CHANGED, (void*)power_device_name);
lv_obj_set_size(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
if (power_device_state)
lv_obj_add_state(toggle, LV_STATE_CHECKED);
lv_obj_t * line = lv_line_create(root_panel);
lv_line_set_points(line, line_points, 2);
lv_obj_set_style_line_width(line, 1, 0);
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)power_device_name);
}
}

View File

@@ -10,4 +10,5 @@ void move_panel_init(lv_obj_t* panel);
void progress_panel_init(lv_obj_t* panel);
void macros_panel_init(lv_obj_t* panel);
void stats_panel_init(lv_obj_t* panel);
void printer_panel_init(lv_obj_t* panel);
void macros_panel_add_power_devices_to_panel(lv_obj_t * panel, POWERQUERY query);

View File

@@ -0,0 +1,268 @@
#include "panel.h"
#include "../../conf/global_config.h"
#include "../../core/data_setup.h"
#include "../ui_utils.h"
#include "../../core/lv_setup.h"
#include <stdio.h>
#include "../nav_buttons.h"
#include "../../core/macros_query.h"
#include "../switch_printer.h"
const char * printer_status[] = {
"Error",
"Idle",
"Printing",
"Paused"
};
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
static void update_printer_name_text(lv_event_t * e)
{
lv_obj_t * label = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
int index = config - global_config.printer_config;
PrinterMinimal * printer = &printer_minimal[index];
lv_label_set_text(label, config->printer_name[0] == 0 ? config->klipper_host : config->printer_name);
}
static void update_printer_status_text(lv_event_t * e)
{
lv_obj_t * label = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
int index = config - global_config.printer_config;
PrinterMinimal * printer = &printer_minimal[index];
if (config == get_current_printer_config())
{
lv_label_set_text(label, "In Control");
return;
}
if (!printer->online)
{
lv_label_set_text(label, "Offline");
return;
}
lv_label_set_text(label, printer_status[printer->state]);
}
static void update_printer_percentage_bar(lv_event_t * e)
{
lv_obj_t * percentage = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
int index = config - global_config.printer_config;
PrinterMinimal * printer = &printer_minimal[index];
if (printer->online && (printer->state == PRINTER_STATE_PRINTING || printer->state == PRINTER_STATE_PAUSED)){
lv_bar_set_value(percentage, printer->print_progress * 100, LV_ANIM_OFF);
}
else {
lv_bar_set_value(percentage, 0, LV_ANIM_OFF);
}
}
static void update_printer_percentage_text(lv_event_t * e)
{
lv_obj_t * label = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
int index = config - global_config.printer_config;
PrinterMinimal * printer = &printer_minimal[index];
if (printer->online && (printer->state == PRINTER_STATE_PRINTING || printer->state == PRINTER_STATE_PAUSED))
{
char percentage_buffer[12];
sprintf(percentage_buffer, "%.2f%%", printer->print_progress * 100);
lv_label_set_text(label, percentage_buffer);
}
else
{
lv_label_set_text(label, "-%");
}
}
static void btn_disable_if_controlled(lv_event_t * e)
{
lv_obj_t * btn = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
if (config == get_current_printer_config())
{
lv_obj_add_state(btn, LV_STATE_DISABLED);
}
else
{
lv_obj_clear_state(btn, LV_STATE_DISABLED);
}
}
static void btn_disable_if_controlled_or_offline(lv_event_t * e)
{
lv_obj_t * btn = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
int index = config - global_config.printer_config;
PrinterMinimal * printer = &printer_minimal[index];
if (config == get_current_printer_config() || !printer->online)
{
lv_obj_add_state(btn, LV_STATE_DISABLED);
}
else
{
lv_obj_clear_state(btn, LV_STATE_DISABLED);
}
}
PRINTER_CONFIG * keyboard_config = NULL;
static void keyboard_callback(lv_event_t * e){
lv_obj_t * ta = lv_event_get_target(e);
lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e);
const char * text = lv_textarea_get_text(ta);
strcpy(keyboard_config->printer_name, text);
write_global_config();
lv_msg_send(DATA_PRINTER_MINIMAL, NULL);
}
static void btn_printer_delete(lv_event_t * e)
{
lv_obj_t * btn = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
if (config == get_current_printer_config())
{
return;
}
config->ip_configured = false;
write_global_config();
nav_buttons_setup(6);
}
// TODO: Extract this from temp/print panel and combine
static void btn_printer_rename(lv_event_t * e)
{
keyboard_config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
lv_create_keyboard_text_entry(keyboard_callback, LV_KEYBOARD_MODE_TEXT_LOWER, CYD_SCREEN_WIDTH_PX * 0.75, 24, keyboard_config->printer_name, false);
}
static void btn_printer_activate(lv_event_t * e)
{
lv_obj_t * label = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
int index = config - global_config.printer_config;
switch_printer(index);
lv_msg_send(DATA_PRINTER_MINIMAL, NULL);
}
static void btn_printer_add(lv_event_t * e)
{
set_printer_config_index(get_printer_config_free_index());
}
void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root)
{
int index = config - global_config.printer_config;
auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2;
lv_obj_t * data_row_name = lv_create_empty_panel(root);
lv_layout_flex_row(data_row_name, LV_FLEX_ALIGN_SPACE_BETWEEN);
lv_obj_set_size(data_row_name, width, LV_SIZE_CONTENT);
lv_obj_t * label = lv_label_create(data_row_name);
lv_obj_add_event_cb(label, update_printer_name_text, LV_EVENT_MSG_RECEIVED, config);
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config);
label = lv_label_create(data_row_name);
lv_obj_add_event_cb(label, update_printer_status_text, LV_EVENT_MSG_RECEIVED, config);
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config);
lv_obj_t * progress_row = lv_create_empty_panel(root);
lv_layout_flex_row(progress_row);
lv_obj_set_size(progress_row, width, LV_SIZE_CONTENT);
lv_obj_t * progress_bar = lv_bar_create(progress_row);
lv_obj_set_flex_grow(progress_bar, 1);
lv_obj_add_event_cb(progress_bar, update_printer_percentage_bar, LV_EVENT_MSG_RECEIVED, config);
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, progress_bar, config);
label = lv_label_create(progress_row);
lv_obj_set_style_text_font(label, &CYD_SCREEN_FONT_SMALL, 0);
lv_obj_add_event_cb(label, update_printer_percentage_text, LV_EVENT_MSG_RECEIVED, config);
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config);
lv_obj_t * button_row = lv_create_empty_panel(root);
lv_layout_flex_row(button_row);
lv_obj_set_size(button_row, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t * btn = lv_btn_create(button_row);
lv_obj_set_flex_grow(btn, 1);
lv_obj_add_event_cb(btn, btn_printer_delete, LV_EVENT_CLICKED, config);
lv_obj_add_event_cb(btn, btn_disable_if_controlled, LV_EVENT_MSG_RECEIVED, config);
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_TRASH);
lv_obj_center(label);
btn = lv_btn_create(button_row);
lv_obj_set_flex_grow(btn, 2);
lv_obj_add_event_cb(btn, btn_printer_rename, LV_EVENT_CLICKED, config);
label = lv_label_create(btn);
lv_label_set_text(label, "Rename");
lv_obj_center(label);
btn = lv_btn_create(button_row);
lv_obj_set_flex_grow(btn, 2);
lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, config);
lv_obj_add_event_cb(btn, btn_disable_if_controlled_or_offline, LV_EVENT_MSG_RECEIVED, config);
lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config);
label = lv_label_create(btn);
lv_label_set_text(label, "Control");
lv_obj_center(label);
lv_obj_t * line = lv_line_create(root);
lv_line_set_points(line, line_points, 2);
lv_obj_set_style_line_width(line, 1, 0);
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
}
void printer_panel_init(lv_obj_t* panel)
{
lv_obj_t * inner_panel = lv_create_empty_panel(panel);
lv_obj_align(inner_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX, 0);
lv_obj_set_size(inner_panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_PANEL_HEIGHT_PX);
lv_layout_flex_column(inner_panel);
lv_obj_set_scrollbar_mode(inner_panel, LV_SCROLLBAR_MODE_OFF);
lv_obj_set_size(lv_create_empty_panel(inner_panel), 0, 0);
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){
PRINTER_CONFIG * config = &global_config.printer_config[i];
if (config->ip_configured) {
create_printer_ui(&global_config.printer_config[i], inner_panel);
}
}
// Add Printer Button
if (get_printer_config_free_index() != -1){
lv_obj_t * btn = lv_btn_create(inner_panel);
lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, btn_printer_add, LV_EVENT_CLICKED, NULL);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, "Add Printer");
lv_obj_center(label);
}
lv_obj_set_size(lv_create_empty_panel(inner_panel), 0, 0);
lv_msg_send(DATA_PRINTER_MINIMAL, NULL);
}

View File

@@ -7,6 +7,7 @@
#include <Esp.h>
#include "../../core/lv_setup.h"
#include "../ota_setup.h"
#include "../nav_buttons.h"
#ifndef REPO_VERSION
#define REPO_VERSION "Unknown"
@@ -15,50 +16,55 @@
static void invert_color_switch(lv_event_t * e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
global_config.invertColors = checked;
WriteGlobalConfig();
get_current_printer_config()->invert_colors = checked;
write_global_config();
set_invert_display();
}
static void reset_calibration_click(lv_event_t * e){
global_config.screenCalibrated = false;
WriteGlobalConfig();
global_config.screen_calibrated = false;
write_global_config();
ESP.restart();
}
static void reset_wifi_click(lv_event_t * e){
global_config.wifiConfigured = false;
global_config.ipConfigured = false;
global_config.auth_configured = false;
WriteGlobalConfig();
global_config.wifi_configured = false;
write_global_config();
ESP.restart();
}
static void reset_ip_click(lv_event_t * e){
get_current_printer_config()->ip_configured = false;
get_current_printer_config()->auth_configured = false;
write_global_config();
ESP.restart();
}
static void light_mode_switch(lv_event_t * e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
global_config.lightMode = checked;
WriteGlobalConfig();
get_current_printer_config()->light_mode = checked;
write_global_config();
set_color_scheme();
}
static void theme_dropdown(lv_event_t * e){
lv_obj_t * dropdown = lv_event_get_target(e);
auto selected = lv_dropdown_get_selected(dropdown);
global_config.color_scheme = selected;
get_current_printer_config()->color_scheme = selected;
set_color_scheme();
WriteGlobalConfig();
write_global_config();
}
const char* brightness_options = "100%\n75%\n50%\n25%";
const char brightness_options_values[] = { 255, 192, 128, 64 };
const unsigned char brightness_options_values[] = { 255, 192, 128, 64 };
static void brightness_dropdown(lv_event_t * e){
lv_obj_t * dropdown = lv_event_get_target(e);
auto selected = lv_dropdown_get_selected(dropdown);
global_config.brightness = brightness_options_values[selected];
set_screen_brightness();
WriteGlobalConfig();
write_global_config();
}
const char* wake_timeout_options = "1m\n2m\n5m\n10m\n15m\n30m\n1h\n2h\n4h";
@@ -67,26 +73,26 @@ const char wake_timeout_options_values[] = { 1, 2, 5, 10, 15, 30, 60, 120, 240
static void wake_timeout_dropdown(lv_event_t * e){
lv_obj_t * dropdown = lv_event_get_target(e);
auto selected = lv_dropdown_get_selected(dropdown);
global_config.screenTimeout = wake_timeout_options_values[selected];
global_config.screen_timeout = wake_timeout_options_values[selected];
set_screen_timer_period();
WriteGlobalConfig();
write_global_config();
}
static void rotate_screen_switch(lv_event_t* e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
global_config.rotateScreen = checked;
global_config.screenCalibrated = false;
WriteGlobalConfig();
global_config.rotate_screen = checked;
global_config.screen_calibrated = false;
write_global_config();
ESP.restart();
}
static void on_during_print_switch(lv_event_t* e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
global_config.onDuringPrint = checked;
global_config.on_during_print = checked;
check_if_screen_needs_to_be_disabled();
WriteGlobalConfig();
write_global_config();
}
static void btn_ota_do_update(lv_event_t * e){
@@ -96,187 +102,101 @@ static void btn_ota_do_update(lv_event_t * e){
static void auto_ota_update_switch(lv_event_t* e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
global_config.autoOtaUpdate = checked;
WriteGlobalConfig();
global_config.auto_ota_update = checked;
write_global_config();
}
static void multi_printer_switch(lv_event_t* e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
global_config.multi_printer_mode = checked;
write_global_config();
nav_buttons_setup(3);
}
const char* estimated_time_options = "Percentage\nInterpolated\nSlicer";
static void estimated_time_dropdown(lv_event_t * e){
lv_obj_t * dropdown = lv_event_get_target(e);
global_config.remaining_time_calc_mode = lv_dropdown_get_selected(dropdown);
WriteGlobalConfig();
get_current_printer_config()->remaining_time_calc_mode = lv_dropdown_get_selected(dropdown);
write_global_config();
}
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true){
lv_obj_t * panel = lv_create_empty_panel(root_panel);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, label_text);
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0);
lv_obj_set_parent(object, panel);
lv_obj_align(object, LV_ALIGN_RIGHT_MID, 0, 0);
if (set_height)
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t * line = lv_line_create(root_panel);
lv_line_set_points(line, line_points, 2);
lv_obj_set_style_line_width(line, 1, 0);
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
}
#define DROPDOWN_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 3.75
#define TOGGLE_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2
void settings_panel_init(lv_obj_t* panel){
lv_obj_t * toggle = NULL;
lv_obj_t * btn = NULL;
lv_obj_t * label = NULL;
lv_obj_t * dropdown = NULL;
lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0);
lv_layout_flex_column(panel);
lv_obj_set_scrollbar_mode(panel, LV_SCROLLBAR_MODE_OFF);
btn = lv_btn_create(panel);
lv_obj_add_event_cb(btn, reset_wifi_click, LV_EVENT_CLICKED, NULL);
if (global_config.multi_printer_mode)
{
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, "Printer Specific Settings");
}
label = lv_label_create(btn);
lv_label_set_text(label, "Restart");
lv_obj_center(label);
create_settings_widget("Configure WiFi", btn, panel);
#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION
btn = lv_btn_create(panel);
lv_obj_add_event_cb(btn, reset_calibration_click, LV_EVENT_CLICKED, NULL);
label = lv_label_create(btn);
lv_label_set_text(label, "Restart");
lv_obj_center(label);
create_settings_widget("Calibrate Touch", btn, panel);
#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION
lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode);
lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme);
#ifndef CYD_SCREEN_DISABLE_INVERT_COLORS
toggle = lv_switch_create(panel);
lv_obj_set_width(toggle, TOGGLE_WIDTH);
lv_obj_add_event_cb(toggle, invert_color_switch, LV_EVENT_VALUE_CHANGED, NULL);
if (global_config.invertColors)
lv_obj_add_state(toggle, LV_STATE_CHECKED);
create_settings_widget("Invert Colors", toggle, panel);
lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer_config()->invert_colors);
#endif // CYD_SCREEN_DISABLE_INVERT_COLORS
toggle = lv_switch_create(panel);
lv_obj_set_width(toggle, TOGGLE_WIDTH);
lv_obj_add_event_cb(toggle, light_mode_switch, LV_EVENT_VALUE_CHANGED, NULL);
lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer_config()->light_mode);
lv_create_custom_menu_button("Configure IP", panel, reset_ip_click, "Restart");
if (global_config.lightMode)
lv_obj_add_state(toggle, LV_STATE_CHECKED);
if (global_config.multi_printer_mode)
{
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, "\nGlobal Settings");
}
create_settings_widget("Light Mode", toggle, panel);
dropdown = lv_dropdown_create(panel);
lv_dropdown_set_options(dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple");
lv_dropdown_set_selected(dropdown, global_config.color_scheme);
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
lv_obj_add_event_cb(dropdown, theme_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
create_settings_widget("Theme", dropdown, panel);
dropdown = lv_dropdown_create(panel);
lv_dropdown_set_options(dropdown, brightness_options);
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
lv_obj_add_event_cb(dropdown, brightness_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
#ifndef CYD_SCREEN_DISABLE_TIMEOUT
lv_create_custom_menu_switch("Screen On During Print", panel, on_during_print_switch, global_config.on_during_print);
#endif
int brightness_settings_index = 0;
for (int i = 0; i < SIZEOF(brightness_options_values); i++){
if (brightness_options_values[i] == global_config.brightness){
lv_dropdown_set_selected(dropdown, i);
brightness_settings_index = i;
break;
}
}
create_settings_widget("Brightness", dropdown, panel);
lv_create_custom_menu_dropdown("Brightness", panel, brightness_dropdown, brightness_options, brightness_settings_index);
#ifndef CYD_SCREEN_DISABLE_TIMEOUT
dropdown = lv_dropdown_create(panel);
lv_dropdown_set_options(dropdown, wake_timeout_options);
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
lv_obj_add_event_cb(dropdown, wake_timeout_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
int wake_timeout_settings_index = 0;
for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){
if (wake_timeout_options_values[i] == global_config.screenTimeout){
lv_dropdown_set_selected(dropdown, i);
if (wake_timeout_options_values[i] == global_config.screen_timeout){
wake_timeout_settings_index = i;
break;
}
}
create_settings_widget("Wake Timeout", dropdown, panel);
lv_create_custom_menu_dropdown("Wake Timeout", panel, wake_timeout_dropdown, wake_timeout_options, wake_timeout_settings_index);
#endif
dropdown = lv_dropdown_create(panel);
lv_dropdown_set_options(dropdown, estimated_time_options);
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
lv_obj_add_event_cb(dropdown, estimated_time_dropdown, LV_EVENT_VALUE_CHANGED, NULL);
lv_dropdown_set_selected(dropdown, global_config.remaining_time_calc_mode);
create_settings_widget("Estimated Time", dropdown, panel);
toggle = lv_switch_create(panel);
lv_obj_set_width(toggle, TOGGLE_WIDTH);
lv_obj_add_event_cb(toggle, rotate_screen_switch, LV_EVENT_VALUE_CHANGED, NULL);
if (global_config.rotateScreen)
lv_obj_add_state(toggle, LV_STATE_CHECKED);
create_settings_widget("Rotate Screen", toggle, panel);
#ifndef CYD_SCREEN_DISABLE_TIMEOUT
toggle = lv_switch_create(panel);
lv_obj_set_width(toggle, TOGGLE_WIDTH);
lv_obj_add_event_cb(toggle, on_during_print_switch, LV_EVENT_VALUE_CHANGED, NULL);
if (global_config.onDuringPrint)
lv_obj_add_state(toggle, LV_STATE_CHECKED);
create_settings_widget("Screen On During Print", toggle, panel);
#endif
toggle = lv_switch_create(panel);
lv_obj_set_width(toggle, TOGGLE_WIDTH);
lv_obj_add_event_cb(toggle, auto_ota_update_switch, LV_EVENT_VALUE_CHANGED, NULL);
if (global_config.autoOtaUpdate)
lv_obj_add_state(toggle, LV_STATE_CHECKED);
create_settings_widget("Auto Update", toggle, panel);
label = lv_label_create(panel);
lv_label_set_text(label, REPO_VERSION " ");
create_settings_widget("Version", label, panel, false);
lv_create_custom_menu_switch("Rotate Screen", panel, rotate_screen_switch, global_config.rotate_screen);
lv_create_custom_menu_switch("Multi Printer Mode", panel, multi_printer_switch, global_config.multi_printer_mode);
lv_create_custom_menu_switch("Auto Update", panel, auto_ota_update_switch, global_config.auto_ota_update);
lv_create_custom_menu_label("Version", panel, REPO_VERSION " ");
if (ota_has_update()){
btn = lv_btn_create(panel);
lv_obj_t *btn = lv_btn_create(panel);
lv_obj_add_event_cb(btn, btn_ota_do_update, LV_EVENT_CLICKED, NULL);
label = lv_label_create(btn);
lv_obj_t *label = lv_label_create(btn);
lv_label_set_text_fmt(label, "Update to %s", ota_new_version_name().c_str());
lv_obj_center(label);
create_settings_widget("Device", btn, panel);
lv_create_custom_menu_entry("Device", btn, panel);
}
else {
label = lv_label_create(panel);
lv_label_set_text(label, ARDUINO_BOARD " ");
create_settings_widget("Device", label, panel, false);
lv_create_custom_menu_label("Device", panel, ARDUINO_BOARD " ");
}
#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION
lv_create_custom_menu_button("Calibrate Touch", panel, reset_calibration_click, "Restart");
#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION
lv_create_custom_menu_button("Configure WiFi", panel, reset_wifi_click, "Restart");
}

View File

@@ -36,17 +36,17 @@ static void update_printer_data_bed_temp(lv_event_t * e){
static short get_temp_preset(int target){
switch (target){
case TARGET_HOTEND_CONFIG_1:
return global_config.hotend_presets[0];
return get_current_printer_config()->hotend_presets[0];
case TARGET_HOTEND_CONFIG_2:
return global_config.hotend_presets[1];
return get_current_printer_config()->hotend_presets[1];
case TARGET_HOTEND_CONFIG_3:
return global_config.hotend_presets[2];
return get_current_printer_config()->hotend_presets[2];
case TARGET_BED_CONFIG_1:
return global_config.bed_presets[0];
return get_current_printer_config()->bed_presets[0];
case TARGET_BED_CONFIG_2:
return global_config.bed_presets[1];
return get_current_printer_config()->bed_presets[1];
case TARGET_BED_CONFIG_3:
return global_config.bed_presets[2];
return get_current_printer_config()->bed_presets[2];
default:
return -1;
}
@@ -62,97 +62,67 @@ static void update_temp_preset_label(lv_event_t * e){
}
void UpdateConfig(){
WriteGlobalConfig();
write_global_config();
lv_msg_send(DATA_PRINTER_TEMP_PRESET, &printer);
}
static void keyboard_callback(lv_event_t * e){
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * ta = lv_event_get_target(e);
lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e);
if (code == LV_EVENT_READY) {
const char * text = lv_textarea_get_text(ta);
const char * text = lv_textarea_get_text(ta);
int temp = atoi(text);
if (temp < 0 || temp > 500){
return;
}
int temp = atoi(text);
if (temp < 0 || temp > 500){
return;
}
char gcode[64];
char gcode[64];
switch (keyboard_target){
case TARGET_HOTEND:
sprintf(gcode, "M104 S%d", temp);
send_gcode(true, gcode);
break;
case TARGET_BED:
sprintf(gcode, "M140 S%d", temp);
send_gcode(true, gcode);
break;
case TARGET_HOTEND_CONFIG_1:
global_config.hotend_presets[0] = temp;
UpdateConfig();
break;
case TARGET_HOTEND_CONFIG_2:
global_config.hotend_presets[1] = temp;
UpdateConfig();
break;
case TARGET_HOTEND_CONFIG_3:
global_config.hotend_presets[2] = temp;
UpdateConfig();
break;
case TARGET_BED_CONFIG_1:
global_config.bed_presets[0] = temp;
UpdateConfig();
break;
case TARGET_BED_CONFIG_2:
global_config.bed_presets[1] = temp;
UpdateConfig();
break;
case TARGET_BED_CONFIG_3:
global_config.bed_presets[2] = temp;
UpdateConfig();
break;
}
switch (keyboard_target){
case TARGET_HOTEND:
sprintf(gcode, "M104 S%d", temp);
send_gcode(true, gcode);
break;
case TARGET_BED:
sprintf(gcode, "M140 S%d", temp);
send_gcode(true, gcode);
break;
case TARGET_HOTEND_CONFIG_1:
get_current_printer_config()->hotend_presets[0] = temp;
UpdateConfig();
break;
case TARGET_HOTEND_CONFIG_2:
get_current_printer_config()->hotend_presets[1] = temp;
UpdateConfig();
break;
case TARGET_HOTEND_CONFIG_3:
get_current_printer_config()->hotend_presets[2] = temp;
UpdateConfig();
break;
case TARGET_BED_CONFIG_1:
get_current_printer_config()->bed_presets[0] = temp;
UpdateConfig();
break;
case TARGET_BED_CONFIG_2:
get_current_printer_config()->bed_presets[1] = temp;
UpdateConfig();
break;
case TARGET_BED_CONFIG_3:
get_current_printer_config()->bed_presets[2] = temp;
UpdateConfig();
break;
}
if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY) {
lv_keyboard_set_textarea(kb, NULL);
lv_obj_del(lv_obj_get_parent(kb));
}
}
static void show_keyboard(lv_event_t * e){
lv_obj_t * parent = lv_create_empty_panel(root_panel);
lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0);
lv_obj_set_size(parent, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX);
lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN);
lv_obj_t * empty_panel = lv_create_empty_panel(parent);
lv_obj_set_flex_grow(empty_panel, 1);
lv_obj_t * ta = lv_textarea_create(parent);
lv_obj_t * keyboard = lv_keyboard_create(parent);
lv_obj_set_width(ta, CYD_SCREEN_PANEL_WIDTH_PX / 2);
lv_textarea_set_max_length(ta, 3);
lv_textarea_set_one_line(ta, true);
lv_textarea_set_text(ta, "");
lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_ALL, keyboard);
lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_NUMBER);
lv_keyboard_set_textarea(keyboard, ta);
}
static void show_keyboard_with_hotend(lv_event_t * e){
keyboard_target = TARGET_HOTEND;
show_keyboard(e);
lv_create_keyboard_text_entry(keyboard_callback);
}
static void show_keyboard_with_bed(lv_event_t * e){
keyboard_target = TARGET_BED;
show_keyboard(e);
lv_create_keyboard_text_entry(keyboard_callback);
}
static void cooldown_temp(lv_event_t * e){
@@ -179,7 +149,7 @@ static void set_temp_via_preset(lv_event_t * e){
if (edit_mode) {
keyboard_target = (temp_target)target;
show_keyboard(e);
lv_create_keyboard_text_entry(keyboard_callback);
return;
}

View File

@@ -0,0 +1,95 @@
#include "switch_printer.h"
#include "lvgl.h"
#include "../conf/global_config.h"
#include "ui_utils.h"
#include "../core/http_client.h"
#include "../core/lv_setup.h"
#include "../core/macros_query.h"
#include "../core/screen_driver.h"
void switch_printer(int index)
{
set_printer_config_index(index);
set_color_scheme();
set_invert_display();
_macros_query_internal();
_power_devices_query_internal();
}
static void btn_switch_printer(lv_event_t *e){
lv_obj_t *btn = lv_event_get_target(e);
PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e);
int index = config - global_config.printer_config;
switch_printer(index);
lv_obj_del(lv_obj_get_parent(lv_obj_get_parent(btn)));
}
void switch_printer_init() {
lv_obj_t * parent = lv_create_empty_panel(lv_scr_act());
lv_obj_set_style_bg_opa(parent, LV_OPA_100, 0);
lv_obj_align(parent, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
lv_layout_flex_column(parent);
lv_obj_set_size(lv_create_empty_panel(parent), 0, 0);
auto width = CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2;
lv_obj_t * btn = lv_btn_create(parent);
lv_obj_set_size(btn, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, parent);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_CLOSE " Close");
lv_obj_center(label);
for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){
PRINTER_CONFIG * config = &global_config.printer_config[i];
const char* printer_name = (config->printer_name[0] == 0) ? config->klipper_host : config->printer_name;
if (config == get_current_printer_config())
{
lv_create_custom_menu_label(printer_name, parent, "Active");
continue;
}
if (config->ip_configured) {
HTTPClient client;
configure_http_client(client, get_full_url("/printer/objects/query?webhooks&print_stats&virtual_sdcard", config), true, 1000);
int httpCode = client.GET();
if (httpCode == 200)
{
lv_create_custom_menu_button(printer_name, parent, btn_switch_printer, "Switch", config);
}
else
{
lv_create_custom_menu_label(printer_name, parent, "Offline");
}
}
}
}
static void show_switch_printer_screen(lv_event_t * e){
switch_printer_init();
}
void draw_switch_printer_button()
{
if (!global_config.multi_printer_mode)
{
return;
}
lv_obj_t * btn = lv_btn_create(lv_scr_act());
lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_align(btn, LV_ALIGN_TOP_RIGHT, -CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX);
lv_obj_add_event_cb(btn, show_switch_printer_screen, LV_EVENT_CLICKED, NULL);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_HOME);
lv_obj_center(label);
}

View File

@@ -0,0 +1,5 @@
#pragma once
void switch_printer(int index);
void switch_printer_init();
void draw_switch_printer_button();

View File

@@ -2,6 +2,7 @@
#include "ui_utils.h"
#include "../core/data_setup.h"
#include "../core/lv_setup.h"
#include <ErriezCRC32.h>
lv_obj_t* lv_create_empty_panel(lv_obj_t* root) {
lv_obj_t* panel = lv_obj_create(root);
@@ -85,4 +86,165 @@ void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t tit
lv_obj_center(label);
}
}
}
void lv_keyboard_text_entry_close(lv_event_t * e){
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * ta = lv_event_get_target(e);
lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e);
if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY)
{
lv_keyboard_set_textarea(kb, NULL);
lv_obj_del(lv_obj_get_parent(kb));
}
}
void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_mode_t keyboard_mode, lv_coord_t width, uint8_t max_length, const char* fill_text, bool contain_in_panel)
{
lv_obj_t * parent = lv_create_empty_panel(lv_scr_act());
lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0);
lv_obj_align(parent, LV_ALIGN_TOP_RIGHT, 0, 0);
lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN);
if (contain_in_panel)
{
lv_obj_set_size(parent, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX);
}
else
{
lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
}
lv_obj_t * empty_panel = lv_create_empty_panel(parent);
lv_obj_set_flex_grow(empty_panel, 1);
lv_obj_t * ta = lv_textarea_create(parent);
lv_obj_t * keyboard = lv_keyboard_create(parent);
lv_obj_set_width(ta, width);
lv_textarea_set_max_length(ta, max_length);
lv_textarea_set_one_line(ta, true);
lv_textarea_set_text(ta, fill_text);
lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_READY, keyboard);
lv_obj_add_event_cb(ta, lv_keyboard_text_entry_close, LV_EVENT_ALL, keyboard);
lv_keyboard_set_mode(keyboard, keyboard_mode);
lv_keyboard_set_textarea(keyboard, ta);
}
const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} };
void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height)
{
lv_obj_t * panel = lv_create_empty_panel(root_panel);
lv_layout_flex_row(panel, LV_FLEX_ALIGN_END);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, label_text);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_flex_grow(label, 1);
lv_obj_set_parent(object, panel);
if (set_height)
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t * line = lv_line_create(root_panel);
lv_line_set_points(line, line_points, 2);
lv_obj_set_style_line_width(line, 1, 0);
lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0);
}
#define DROPDOWN_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 3.75
#define TOGGLE_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2
void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data)
{
lv_obj_t * btn = lv_btn_create(lv_scr_act());
lv_obj_add_event_cb(btn, on_click, LV_EVENT_CLICKED, user_data);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, btn_text);
lv_obj_center(label);
lv_create_custom_menu_entry(label_text, btn, root_panel, true);
}
void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data)
{
lv_obj_t * toggle = lv_switch_create(lv_scr_act());
lv_obj_add_event_cb(toggle, on_toggle, LV_EVENT_VALUE_CHANGED, user_data);
lv_obj_set_width(toggle, TOGGLE_WIDTH);
if (state)
lv_obj_add_state(toggle, LV_STATE_CHECKED);
lv_create_custom_menu_entry(label_text, toggle, root_panel, true);
}
void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data)
{
lv_obj_t * dropdown = lv_dropdown_create(lv_scr_act());
lv_dropdown_set_options(dropdown, options);
lv_dropdown_set_selected(dropdown, index);
lv_obj_set_width(dropdown, DROPDOWN_WIDTH);
lv_obj_add_event_cb(dropdown, on_change, LV_EVENT_VALUE_CHANGED, user_data);
lv_create_custom_menu_entry(label_text, dropdown, root_panel, true);
}
void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text)
{
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_label_set_text(label, text);
lv_create_custom_menu_entry(label_text, label, root_panel, false);
}
uint32_t message_hash = 0;
lv_timer_t* timer = NULL;
void on_timer_destroy(lv_event_t * e)
{
lv_timer_del(timer);
timer = NULL;
}
void timer_callback(lv_timer_t *timer)
{
lv_obj_t * panel = (lv_obj_t *)timer->user_data;
lv_obj_del(panel);
}
void lv_create_popup_message(const char* message, uint16_t timeout_ms)
{
if (message == nullptr || timer != NULL)
{
return;
}
uint32_t new_hash = crc32String(message);
if (new_hash == message_hash)
{
return;
}
message_hash = new_hash;
lv_obj_t* panel = lv_obj_create(lv_scr_act());
lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX);
lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, LV_SIZE_CONTENT);
lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER);
lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, -CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX);
lv_obj_add_event_cb(panel, on_timer_destroy, LV_EVENT_DELETE, NULL);
lv_obj_set_style_border_color(panel, lv_color_hex(0xFF0000), 0);
lv_obj_t* label = lv_label_create(panel);
lv_label_set_text_fmt(label, "%s", message);
lv_obj_set_size(label, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 6, LV_SIZE_CONTENT);
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
timer = lv_timer_create(timer_callback, timeout_ms, panel);
}

View File

@@ -37,4 +37,11 @@ lv_obj_t* lv_create_empty_panel(lv_obj_t* root);
void lv_layout_flex_column(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN_START, lv_coord_t pad_column = CYD_SCREEN_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_GAP_PX);
void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN_START, lv_coord_t pad_column = CYD_SCREEN_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_GAP_PX);
void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count);
void destroy_event_user_data(lv_event_t * e);
void destroy_event_user_data(lv_event_t * e);
void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_mode_t keyboard_mode = LV_KEYBOARD_MODE_NUMBER, lv_coord_t width = CYD_SCREEN_PANEL_WIDTH_PX / 2, uint8_t max_length = 3, const char* fill_text = "", bool contain_in_panel= true);
void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true);
void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL);
void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data = NULL);
void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL);
void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text);
void lv_create_popup_message(const char* message, uint16_t timeout_ms);

View File

@@ -10,7 +10,7 @@ static void reset_btn_event_handler(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
if(code == LV_EVENT_CLICKED) {
global_config.wifiConfigured = false;
global_config.wifi_configured = false;
wifi_init_inner();
}
}
@@ -33,9 +33,9 @@ static void ta_event_cb(lv_event_t * e) {
int len = strlen(txt);
if (len > 0)
{
global_config.wifiConfigured = true;
strcpy(global_config.wifiPassword, txt);
WriteGlobalConfig();
global_config.wifi_configured = true;
strcpy(global_config.wifi_password, txt);
write_global_config();
wifi_init_inner();
}
}
@@ -79,7 +79,7 @@ static void wifi_btn_event_handler(lv_event_t * e){
if(code == LV_EVENT_CLICKED) {
delay(100);
char* ssid = (char*)e->user_data;
strcpy(global_config.wifiSSID, ssid);
strcpy(global_config.wifi_SSID, ssid);
Serial.println(ssid);
wifi_pass_entry(ssid);
}
@@ -89,8 +89,8 @@ void wifi_init_inner(){
WiFi.disconnect();
lv_obj_clean(lv_scr_act());
if (global_config.wifiConfigured){
WiFi.begin(global_config.wifiSSID, global_config.wifiPassword);
if (global_config.wifi_configured){
WiFi.begin(global_config.wifi_SSID, global_config.wifi_password);
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "Connecting to WiFi");
@@ -180,7 +180,7 @@ void wifi_init(){
WiFi.mode(WIFI_STA);
wifi_init_inner();
while (!global_config.wifiConfigured || WiFi.status() != WL_CONNECTED){
while (!global_config.wifi_configured || WiFi.status() != WL_CONNECTED){
if (millis() - print_timer > print_freq){
print_timer = millis();
Serial.printf("WiFi Status: %s\n", errs[WiFi.status()]);