18 Commits

Author SHA1 Message Date
suchmememanyskill
d9d6789a21 TODO 2025-07-10 15:15:04 +02:00
suchmememanyskill
5df709e083 Don't set padding on root panel 2025-03-04 21:08:38 +01:00
suchmememanyskill
664862100f Feedback from almighty atomique 2025-03-04 21:04:16 +01:00
suchmememanyskill
3f5e02e8f7 Null check in printer state 2025-03-01 13:31:56 +01:00
suchmememanyskill
bbb65725fa New move screen 2025-03-01 13:29:17 +01:00
suchmememanyskill
04a3b78b21 Add crowpanel 3.5 inch to html 2025-02-09 02:37:37 +01:00
suchmememanyskill
5c0ee08135 Hopefully fix webflash for s3 2025-02-09 01:14:07 +01:00
suchmememanyskill
d8a9b13fe1 Fix compile 2025-02-01 17:37:06 +01:00
suchmememanyskill
fbc2964ad8 Make serial script work with both sudo and not sudo 2025-02-01 17:20:06 +01:00
suchmememanyskill
d616ef5a6d Allow running service under root 2025-01-28 21:50:21 +01:00
suchmememanyskill
9bfbb1cb0e Change keyboard for bambu setup (#161) 2025-01-28 21:23:02 +01:00
suchmememanyskill
8d8e36fde9 Merge #152 2025-01-28 21:20:22 +01:00
Kire Dyfvelsten
4e3cd69b63 Sunton esp32 2.2" c (#151)
* Update readme

* Update README.md

* driver definition? for a vertical 2.2" with touch

* Update platformio.ini

* Update esp32-2432S022C-vertical.json

* Update esp32-2432S022C-vertical.json

---------

Co-authored-by: Sims <38142618+suchmememanyskill@users.noreply.github.com>
2025-01-28 21:19:36 +01:00
Sims
3aeb67cfdd esp32-CROWPANEL-35C (#159)
* :)

* Correct screen rotation

* Remove brightness adjustment

* Silence buzzer

* Fixes from atomique
2025-01-28 21:16:46 +01:00
suchmememanyskill
0992f466cf Fix Klipper params being non-blocking 2025-01-12 00:13:26 +01:00
suchmememanyskill
f8ed3afd06 Don't ignore first popup message (Klipper) 2025-01-11 23:50:58 +01:00
suchmememanyskill
fdfa2d014f Properly clear input buffer for serial 2025-01-11 17:15:26 +01:00
suchmememanyskill
1efaa616e1 Add 2x scale gcode preview option 2025-01-10 22:28:35 +01:00
31 changed files with 901 additions and 143 deletions

View File

@@ -20,7 +20,7 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
@@ -31,7 +31,7 @@ jobs:
# ~/.platformio/.cache
# key: ${{ runner.os }}-pio-cyd-klipper
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
@@ -43,13 +43,13 @@ jobs:
python3 ci.py
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: firmware
path: ./out
- name: Upload GitHub Page Artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
deploy:
environment:
@@ -65,5 +65,5 @@ jobs:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4

View File

@@ -48,7 +48,8 @@
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
"typeinfo": "cpp",
"lv_group.h": "c"
},
"cmake.configureOnOpen": false
}

View File

@@ -0,0 +1,127 @@
{
"build": {
"arduino": {
"ldscript": "esp32_out.ld"
},
"core": "esp32",
"extra_flags": [
"'-D ARDUINO_ESP32_DEV'",
"'-D ESP32_2432S022C'",
"'-D LCD_WIDTH=240'",
"'-D LCD_HEIGHT=320'",
"'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/8)'",
"'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'",
"'-D GPIO_BCKL=0'",
"'-D LCD_ST7789_I80'",
"'-D ST7789_I80_BUS_CONFIG_CLK_SRC=LCD_CLK_SRC_PLL160M'",
"'-D ST7789_I80_BUS_CONFIG_DC=16'",
"'-D ST7789_I80_BUS_CONFIG_WR=4'",
"'-D ST7789_I80_BUS_CONFIG_DATA_GPIO_D8=15'",
"'-D ST7789_I80_BUS_CONFIG_DATA_GPIO_D9=13'",
"'-D ST7789_I80_BUS_CONFIG_DATA_GPIO_D10=12'",
"'-D ST7789_I80_BUS_CONFIG_DATA_GPIO_D11=14'",
"'-D ST7789_I80_BUS_CONFIG_DATA_GPIO_D12=27'",
"'-D ST7789_I80_BUS_CONFIG_DATA_GPIO_D13=25'",
"'-D ST7789_I80_BUS_CONFIG_DATA_GPIO_D14=33'",
"'-D ST7789_I80_BUS_CONFIG_DATA_GPIO_D15=32'",
"'-D ST7789_I80_BUS_CONFIG_BUS_WIDTH=8'",
"'-D ST7789_I80_BUS_CONFIG_MAX_TRANSFER_BYTES=(LVGL_BUFFER_PIXELS * sizeof(lv_color_t))'",
"'-D ST7789_I80_BUS_CONFIG_PSRAM_TRANS_ALIGN=64'",
"'-D ST7789_I80_BUS_CONFIG_SRAM_TRANS_ALIGN=4'",
"'-D ST7789_IO_I80_CONFIG_CS_GPIO_NUM=17'",
"'-D ST7789_IO_I80_CONFIG_PCLK_HZ=12000000'",
"'-D ST7789_IO_I80_CONFIG_TRANS_QUEUE_DEPTH=10'",
"'-D ST7789_IO_I80_CONFIG_LCD_CMD_BITS=8'",
"'-D ST7789_IO_I80_CONFIG_LCD_PARAM_BITS=8'",
"'-D ST7789_IO_I80_CONFIG_DC_LEVELS_DC_IDLE_LEVEL=0'",
"'-D ST7789_IO_I80_CONFIG_DC_LEVELS_DC_CMD_LEVEL=0'",
"'-D ST7789_IO_I80_CONFIG_DC_LEVELS_DC_DUMMY_LEVEL=0'",
"'-D ST7789_IO_I80_CONFIG_DC_LEVELS_DC_DATA_LEVEL=1'",
"'-D ST7789_IO_I80_CONFIG_FLAGS_CS_ACTIVE_HIGH=0'",
"'-D ST7789_IO_I80_CONFIG_FLAGS_REVERSE_COLOR_BITS=0'",
"'-D ST7789_IO_I80_CONFIG_FLAGS_SWAP_COLOR_BYTES=0'",
"'-D ST7789_IO_I80_CONFIG_FLAGS_PCLK_ACTIVE_NEG=0'",
"'-D ST7789_IO_I80_CONFIG_FLAGS_PCLK_IDLE_LOW=0'",
"'-D ST7789_DEV_CONFIG_RESET_GPIO_NUM=GPIO_NUM_NC'",
"'-D ST7789_DEV_CONFIG_COLOR_SPACE=ESP_LCD_COLOR_SPACE_RGB'",
"'-D ST7789_DEV_CONFIG_BITS_PER_PIXEL=16'",
"'-D ST7789_DEV_CONFIG_FLAGS_RESET_ACTIVE_HIGH=false'",
"'-D ST7789_DEV_CONFIG_VENDOR_CONFIG=NULL'",
"'-D ST7789_RD_GPIO=2'",
"'-D LCD_SWAP_XY=false'",
"'-D LCD_MIRROR_X=false'",
"'-D LCD_MIRROR_Y=false'",
"'-D BOARD_HAS_TOUCH'",
"'-D TOUCH_CST816S_I2C'",
"'-D CST816S_I2C_HOST=I2C_NUM_0'",
"'-D CST816S_I2C_CONFIG_SDA_IO_NUM=21'",
"'-D CST816S_I2C_CONFIG_SCL_IO_NUM=22'",
"'-D CST816S_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'",
"'-D CST816S_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'",
"'-D CST816S_I2C_CONFIG_MASTER_CLK_SPEED=400000'",
"'-D CST816S_I2C_CONFIG_CLK_FLAGS=0'",
"'-D CST816S_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_CST816S_ADDRESS'",
"'-D CST816S_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'",
"'-D CST816S_IO_I2C_CONFIG_DC_BIT_OFFSET=0'",
"'-D CST816S_IO_I2C_CONFIG_LCD_CMD_BITS=8'",
"'-D CST816S_IO_I2C_CONFIG_LCD_PARAM_BITS=0'",
"'-D CST816S_IO_I2C_CONFIG_FLAGS_DC_LOW_ON_DATA=false'",
"'-D CST816S_IO_I2C_CONFIG_FLAGS_DISABLE_CONTROL_PHASE=true'",
"'-D CST816S_TOUCH_CONFIG_X_MAX=LCD_WIDTH'",
"'-D CST816S_TOUCH_CONFIG_Y_MAX=LCD_HEIGHT'",
"'-D CST816S_TOUCH_CONFIG_RST_GPIO_NUM=GPIO_NUM_NC'",
"'-D CST816S_TOUCH_CONFIG_INT_GPIO_NUM=GPIO_NUM_NC'",
"'-D CST816S_TOUCH_CONFIG_LEVELS_RESET=0'",
"'-D CST816S_TOUCH_CONFIG_LEVELS_INTERRUPT=0'",
"'-D TOUCH_SWAP_XY=false'",
"'-D TOUCH_SWAP_X=false'",
"'-D TOUCH_SWAP_Y=false'",
"'-D BOARD_HAS_TF'",
"'-D TF_CS=5'",
"'-D TF_SPI_MOSI=23'",
"'-D TF_SPI_SCLK=18'",
"'-D TF_SPI_MISO=19'",
"'-D BOARD_HAS_SPEAK'",
"'-D SPEAK=26'",
"-DCYD_SCREEN_GAP_PX=8",
"-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35",
"-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35",
"-DCYD_SCREEN_VERTICAL=1",
"-DCYD_SCREEN_FONT=lv_font_montserrat_14",
"-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10",
"-DCYD_SCREEN_SIDEBAR_SIZE_PX=40",
"-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1",
"-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1",
"-DCYD_SCREEN_DISABLE_INVERT_COLORS=1"
],
"f_cpu": "240000000L",
"f_flash": "40000000L",
"flash_mode": "dio",
"mcu": "esp32",
"variant": "esp32"
},
"connectivity": [
"wifi",
"bluetooth",
"ethernet",
"can"
],
"debug": {
"openocd_board": "esp-wroom-32.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"name": "esp32-2432S022C-V",
"upload": {
"flash_size": "4MB",
"maximum_ram_size": 327680,
"maximum_size": 4194304,
"require_upload_port": true,
"speed": 460800
},
"url": "https://www.aliexpress.com/item/1005006284154750.html",
"vendor": "Sunton"
}

View File

@@ -0,0 +1,55 @@
{
"build": {
"arduino": {
"ldscript": "esp32s3_out.ld",
"partitions": "default_16MB.csv",
"memory_type": "qio_opi"
},
"core": "esp32",
"extra_flags": [
"-DCYD_SCREEN_HEIGHT_PX=320",
"-DCYD_SCREEN_WIDTH_PX=480",
"-DCYD_SCREEN_GAP_PX=10",
"-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_CROWPANEL_35C=1",
"-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1"
],
"f_cpu": "240000000L",
"f_flash": "80000000L",
"flash_mode": "qio",
"hwids": [
[
"0x303A",
"0x1001"
]
],
"mcu": "esp32s3",
"variant": "esp32s3"
},
"connectivity": [
"wifi"
],
"debug": {
"openocd_target": "esp32s3.cfg"
},
"frameworks": [
"arduino",
"espidf"
],
"name": "esp32-8048S043C-SD",
"upload": {
"flash_size": "16MB",
"maximum_ram_size": 327680,
"maximum_size": 16777216,
"use_1200bps_touch": true,
"wait_for_upload_port": true,
"require_upload_port": true,
"speed": 460800
},
"url": "https://www.elecrow.com/esp-terminal-with-esp32-3-5-inch-parallel-480x320-tft-capacitive-touch-display-rgb-by-chip-ili9488.html",
"vendor": "CROWPANEL"
}

View File

@@ -84,7 +84,7 @@ board = esp32-3248S035C-smartdisplay
board = esp32-4827S043C-smartdisplay
[env:esp32-4827S043R-SD]
board = esp32-4827S043C-smartdisplay
board = esp32-4827S043R-smartdisplay
[env:esp32-8048S043C-SD]
board = esp32-8048S043C-smartdisplay
@@ -92,6 +92,9 @@ board = esp32-8048S043C-smartdisplay
[env:esp32-8048S043C-SD-alt]
board = esp32-8048S043C-smartdisplay-alt
[env:esp32-2432S022C-SD-V]
board = esp32-2432S022C-vertical
[env:esp32-CROWPANEL-28R]
board = esp32-CROWPANEL-28R
lib_deps =
@@ -102,3 +105,15 @@ lib_deps =
plageoj/UrlEncode@^1.0.1
knolleary/PubSubClient@^2.8
WiFiClientSecure
[env:esp32-CROWPANEL-35C]
board = esp32-CROWPANEL-35C
lib_deps =
SPI
https://github.com/suchmememanyskill/lvgl
https://github.com/lovyan03/LovyanGFX@1.2.0
bblanchon/ArduinoJson@^7.0.0
plageoj/UrlEncode@^1.0.1
knolleary/PubSubClient@^2.8
WiFiClientSecure

View File

@@ -83,6 +83,7 @@ typedef struct {
bool sort_macros : 1;
bool show_estop : 1;
bool full_filenames : 1;
bool double_size_gcode_img : 1;
};
};

View File

@@ -1,5 +1,5 @@
#include "data_setup.h"
#include "current_printer.h"
#include "semaphore.h"
bool current_printer_move_printer(const char* axis, float amount, bool relative)
{

View File

@@ -1,5 +1,6 @@
#include "data_setup.h"
#include "semaphore.h"
#include <esp_task_wdt.h>
#include <UrlEncode.h>
#include "printer_integration.hpp"
@@ -8,32 +9,8 @@
#include "bambu/bambu_printer_integration.hpp"
#include "octoprint/octoprint_printer_integration.hpp"
SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
const long data_update_interval = 780;
void semaphore_init(){
freezeRenderThreadSemaphore = xSemaphoreCreateMutex();
freezeRequestThreadSemaphore = xSemaphoreCreateMutex();
xSemaphoreGive(freezeRenderThreadSemaphore);
xSemaphoreGive(freezeRequestThreadSemaphore);
}
void freeze_request_thread(){
xSemaphoreTake(freezeRequestThreadSemaphore, portMAX_DELAY);
}
void unfreeze_request_thread(){
xSemaphoreGive(freezeRequestThreadSemaphore);
}
void freeze_render_thread(){
xSemaphoreTake(freezeRenderThreadSemaphore, portMAX_DELAY);
}
void unfreeze_render_thread(){
xSemaphoreGive(freezeRenderThreadSemaphore);
}
void fetch_printer_data()
{
freeze_request_thread();

View File

@@ -1,7 +1,4 @@
#pragma once
void data_loop();
void data_setup();
void freeze_request_thread();
void unfreeze_request_thread();
void data_setup();

View File

@@ -0,0 +1,183 @@
// Adapted from https://github.com/OzInFl/Elecrow-3.5-RGB-TFT-SQUARELINE-EXAMPLE
#ifdef CYD_SCREEN_DRIVER_ESP32_CROWPANEL_35C
#include "../screen_driver.h"
#include "lvgl.h"
#include "../../conf/global_config.h"
#include <LovyanGFX.hpp>
#include <Arduino.h>
#include <Wire.h>
#ifdef CYD_SCREEN_VERTICAL
#error "Vertical screen not supported with the ESP32_CROWPANEL_28R driver"
#endif
static lv_disp_draw_buf_t draw_buf;
static lv_color_t buf[CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10];
#define BUZZER_PIN 20
#define LCD_BL 46
#define SDA_FT6236 38
#define SCL_FT6236 39
#define I2C_TOUCH_ADDR 0x38
class LGFX : public lgfx::LGFX_Device
{
lgfx::Panel_ILI9488 _panel_instance;
lgfx::Bus_Parallel16 _bus_instance;
lgfx::Touch_FT5x06 _touch_instance;
public:
LGFX()
{
auto bus_cfg = _bus_instance.config();
bus_cfg.port = 0;
bus_cfg.freq_write = 80000000;
bus_cfg.pin_wr = 18;
bus_cfg.pin_rd = 48;
bus_cfg.pin_rs = 45;
bus_cfg.pin_d0 = 47;
bus_cfg.pin_d1 = 21;
bus_cfg.pin_d2 = 14;
bus_cfg.pin_d3 = 13;
bus_cfg.pin_d4 = 12;
bus_cfg.pin_d5 = 11;
bus_cfg.pin_d6 = 10;
bus_cfg.pin_d7 = 9;
bus_cfg.pin_d8 = 3;
bus_cfg.pin_d9 = 8;
bus_cfg.pin_d10 = 16;
bus_cfg.pin_d11 = 15;
bus_cfg.pin_d12 = 7;
bus_cfg.pin_d13 = 6;
bus_cfg.pin_d14 = 5;
bus_cfg.pin_d15 = 4;
_bus_instance.config(bus_cfg);
_panel_instance.setBus(&_bus_instance);
auto panel_cfg = _panel_instance.config();
panel_cfg.pin_cs = -1;
panel_cfg.pin_rst = -1;
panel_cfg.pin_busy = -1;
panel_cfg.memory_width = 320;
panel_cfg.memory_height = 480;
panel_cfg.panel_width = 320;
panel_cfg.panel_height = 480;
panel_cfg.offset_x = 0;
panel_cfg.offset_y = 0;
panel_cfg.offset_rotation = 0;
panel_cfg.dummy_read_pixel = 8;
panel_cfg.dummy_read_bits = 1;
panel_cfg.readable = true;
panel_cfg.invert = global_config.printer_config[global_config.printer_index].invert_colors ? true : false;
panel_cfg.rgb_order = false;
panel_cfg.dlen_16bit = true;
panel_cfg.bus_shared = true;
_panel_instance.config(panel_cfg);
auto touch_cfg = _touch_instance.config();
touch_cfg.x_min = 0;
touch_cfg.x_max = 319;
touch_cfg.y_min = 0;
touch_cfg.y_max = 479;
touch_cfg.pin_int = -1;
touch_cfg.bus_shared = false;
touch_cfg.offset_rotation = 0;
touch_cfg.i2c_port = 1;
touch_cfg.i2c_addr = 0x38;
touch_cfg.pin_sda = 38;
touch_cfg.pin_scl = 39;
touch_cfg.freq = 400000;
_touch_instance.config(touch_cfg);
_panel_instance.setTouch(&_touch_instance);
setPanel(&_panel_instance);
}
};
LGFX tft;
void screen_setBrightness(unsigned char brightness)
{
// TODO
}
void set_invert_display()
{
// TODO
}
void screen_lv_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
tft.endWrite();
lv_disp_flush_ready(disp);
}
void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
{
uint16_t touchX, touchY;
bool touched = tft.getTouch(&touchX, &touchY);
if (touchX > CYD_SCREEN_WIDTH_PX || touchY > CYD_SCREEN_HEIGHT_PX)
{
LOG_LN("Y or y outside of expected parameters..");
}
else
{
data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
data->point.x = touchX;
data->point.y = touchY;
}
}
void screen_setup()
{
pinMode(BUZZER_PIN, OUTPUT);
ledcSetup(4, 5000, 8);
ledcAttachPin(BUZZER_PIN, 4);
tft.begin();
tft.setRotation(global_config.rotate_screen ? 3 : 1);
delay(500);
pinMode(LCD_BL, OUTPUT);
digitalWrite(LCD_BL, HIGH);
/*
ledcSetup(0, 5000, 12);
ledcAttachPin(LCD_BL, 0);
*/
lv_init();
lv_disp_draw_buf_init(&draw_buf, buf, NULL, CYD_SCREEN_WIDTH_PX * CYD_SCREEN_HEIGHT_PX / 10);
/*Initialize the display*/
static lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = CYD_SCREEN_WIDTH_PX;
disp_drv.ver_res = CYD_SCREEN_HEIGHT_PX;
disp_drv.flush_cb = screen_lv_flush;
disp_drv.draw_buf = &draw_buf;
lv_disp_drv_register(&disp_drv);
/*Initialize the (dummy) input device driver*/
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = screen_lv_touchRead;
lv_indev_drv_register(&indev_drv);
}
#endif

View File

@@ -3,12 +3,23 @@
#include <UrlEncode.h>
#include "../../ui/serial/serial_console.h"
void clear_serial_buffer()
void clear_serial_buffer(bool can_rely_on_newline_terminator = true)
{
while (Serial.available())
if (can_rely_on_newline_terminator)
{
Serial.read();
};
if (Serial.available())
{
while (Serial.read() != '\n')
;
}
}
else
{
while (Serial.available())
{
Serial.read();
}
}
}
// Request: {timeout} {method} {endpoint}
@@ -46,7 +57,7 @@ bool make_serial_request(JsonDocument &out, int timeout_ms, HttpRequestType requ
if (buff[0] < '0' || buff[0] > '9')
{
Serial.println("Invalid error code");
Serial.printf("Invalid error code, got char '%c'\n", buff[0]);
clear_serial_buffer();
return false;
@@ -108,7 +119,7 @@ bool make_binary_request(BinaryResponse* data, int timeout_ms, HttpRequestType r
if (buff[0] < '0' || buff[0] > '9')
{
Serial.println("Invalid length");
clear_serial_buffer();
clear_serial_buffer(false);
return false;
}
@@ -118,7 +129,7 @@ bool make_binary_request(BinaryResponse* data, int timeout_ms, HttpRequestType r
if (data_length <= 0)
{
Serial.println("0 Length");
clear_serial_buffer();
clear_serial_buffer(false);
return false;
}
@@ -129,7 +140,7 @@ bool make_binary_request(BinaryResponse* data, int timeout_ms, HttpRequestType r
if (data->data == NULL)
{
Serial.println("Failed to allocate memory");
clear_serial_buffer();
clear_serial_buffer(false);
return false;
}

View File

@@ -3,6 +3,27 @@
#include "../../ui/ui_utils.h"
#include "../common/constants.h"
#include <stdio.h>
#include "../semaphore.h"
bool send_gcode_blocking(const char *gcode, bool wait = true)
{
freeze_request_thread();
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
bool result = printer->send_gcode(gcode);
unfreeze_request_thread();
return result;
}
bool move_printer_blocking(const char* axis, float amount, bool relative)
{
freeze_request_thread();
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
bool result = printer->move_printer(axis, amount, relative);
unfreeze_request_thread();
return result;
}
static void set_fan_speed_text(lv_event_t * e) {
lv_obj_t * label = lv_event_get_target(e);
@@ -14,10 +35,9 @@ static void set_fan_speed_text(lv_event_t * e) {
static void set_fan_speed(lv_event_t * e){
int speed = (int)lv_event_get_user_data(e);
int actual_speed = fan_percent_to_byte(speed);
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
char gcode[16];
sprintf(gcode, "M106 S%d", actual_speed);
printer->send_gcode(gcode);
send_gcode_blocking(gcode);
}
FAN_SPEED_COLUMN(set_fan_speed, klipper_fan_speed_columns)
@@ -40,24 +60,21 @@ static void set_zoffset_text_ex(lv_event_t * e) {
static void set_zoffset(lv_event_t * e){
char* offset = (char*)lv_event_get_user_data(e);
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
char gcode[48];
sprintf(gcode, "SET_GCODE_OFFSET Z_ADJUST=%s MOVE=1", offset);
printer->send_gcode(gcode);
send_gcode_blocking(gcode);
}
static void set_z(lv_event_t * e){
void* ptr = lv_event_get_user_data(e);
float value = *(float *)(&ptr);
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
if (value < 0) {
printer->send_gcode("SET_GCODE_OFFSET Z=0 MOVE=1");
send_gcode_blocking("SET_GCODE_OFFSET Z=0 MOVE=1");
return;
}
printer->move_printer("Z", value, false);
move_printer_blocking("Z", value, false);
}
const char* zoffsets[] = { "-0.01", "-0.025", "-0.05", "-0.2" };
@@ -80,20 +97,18 @@ static void set_speed_mult_text(lv_event_t * e){
static void set_speed_mult(lv_event_t * e){
int speed = (int)lv_event_get_user_data(e);
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
char gcode[16];
sprintf(gcode, "M220 S%d", speed);
printer->send_gcode(gcode);
send_gcode_blocking(gcode);
}
static void set_speed_mult_offset(lv_event_t * e){
int speed = (int)lv_event_get_user_data(e);
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
float result = get_current_printer_data()->speed_mult * 100 + speed;
get_current_printer_data()->speed_mult = result / 100;
char gcode[16];
sprintf(gcode, "M220 S%.0f", result);
printer->send_gcode(gcode);
send_gcode_blocking(gcode);
}
const char* speed_presets[] = { "50%", "100%", "150%", "200%" };
@@ -118,20 +133,19 @@ static void set_extrude_mult_text(lv_event_t * e){
static void set_extrude_mult(lv_event_t * e){
int speed = (int)lv_event_get_user_data(e);
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
char gcode[16];
sprintf(gcode, "M221 S%d", speed);
printer->send_gcode(gcode);
send_gcode_blocking(gcode);
}
static void set_extrude_mult_offset(lv_event_t * e){
int speed = (int)lv_event_get_user_data(e);
KlipperPrinter* printer = (KlipperPrinter*)get_current_printer(); // TODO: pass by ref
float result = get_current_printer_data()->extrude_mult * 100 + speed;
get_current_printer_data()->extrude_mult = result / 100;
char gcode[16];
sprintf(gcode, "M221 S%.0f", result);
printer->send_gcode(gcode);
send_gcode_blocking(gcode);
}
const char* extrude_presets[] = { "95%", "100%", "105%", "110%" };
@@ -145,7 +159,7 @@ lv_button_column_t extrude_mult_columns[] = {
};
static void open_fan_speed_panel(lv_event_t * e){
lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_fan_speed_text, klipper_fan_speed_columns, 2);
lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_fan_speed_text, klipper_fan_speed_columns, 3);
}
static void open_zoffset_panel(lv_event_t * e){

View File

@@ -18,13 +18,16 @@ void KlipperPrinter::parse_state(JsonDocument &in)
const char *state = status["webhooks"]["state"];
const char *message = status["webhooks"]["state_message"];
if (strcmp(state, "ready") == 0 && printer_data.state == PrinterStateError)
if (state != NULL)
{
printer_data.state = PrinterStateIdle;
}
else if ((strcmp(state, "shutdown") == 0 || strcmp(state, "error") == 0) && printer_data.state != PrinterStateError)
{
printer_data.state = PrinterStateError;
if (strcmp(state, "ready") == 0 && printer_data.state == PrinterStateError)
{
printer_data.state = PrinterStateIdle;
}
else if ((strcmp(state, "shutdown") == 0 || strcmp(state, "error") == 0) && printer_data.state != PrinterStateError)
{
printer_data.state = PrinterStateError;
}
}
if (message != NULL && (printer_data.state_message == NULL || strcmp(printer_data.state_message, message)))
@@ -56,6 +59,12 @@ void KlipperPrinter::parse_state(JsonDocument &in)
{
const char *homed_axis = status["toolhead"]["homed_axes"];
printer_data.homed_axis = strcmp(homed_axis, "xyz") == 0;
for (int i = 0; i < 3; i++)
{
printer_data.position_min[i] = status["toolhead"]["axis_minimum"][i];
printer_data.position_max[i] = status["toolhead"]["axis_maximum"][i];
}
}
if (status.containsKey("gcode_move"))

View File

@@ -62,11 +62,18 @@ PrinterData* BasePrinter::AnnouncePrinterData()
lv_msg_send(DATA_PRINTER_STATE, get_current_printer());
}
if (old_popup_message != printer_data_copy->popup_message && old_popup_message != NULL && old_popup_message != blank && !no_free)
if (old_popup_message != printer_data_copy->popup_message)
{
LOG_F(("Freeing popup message '%s' (%x)\n", old_popup_message, old_popup_message));
free(old_popup_message);
lv_msg_send(DATA_PRINTER_POPUP, get_current_printer());
if (old_popup_message != NULL && old_popup_message != blank && !no_free)
{
LOG_F(("Freeing popup message '%s' (%x)\n", old_popup_message, old_popup_message));
free(old_popup_message);
}
if (printer_data_copy->popup_message != NULL && printer_data_copy->popup_message != blank)
{
lv_msg_send(DATA_PRINTER_POPUP, get_current_printer());
}
}
lv_msg_send(DATA_PRINTER_DATA, get_current_printer());

View File

@@ -82,6 +82,8 @@ typedef struct _PrinterData {
float temperatures[10];
float target_temperatures[10];
float position[3];
float position_min[3];
float position_max[3];
float elapsed_time_s;
float printed_time_s;
float remaining_time_s;

View File

@@ -0,0 +1,28 @@
#include "semaphore.h"
#include <UrlEncode.h>
#include <esp_task_wdt.h>
SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore;
void semaphore_init(){
freezeRenderThreadSemaphore = xSemaphoreCreateMutex();
freezeRequestThreadSemaphore = xSemaphoreCreateMutex();
xSemaphoreGive(freezeRenderThreadSemaphore);
xSemaphoreGive(freezeRequestThreadSemaphore);
}
void freeze_request_thread(){
xSemaphoreTake(freezeRequestThreadSemaphore, portMAX_DELAY);
}
void unfreeze_request_thread(){
xSemaphoreGive(freezeRequestThreadSemaphore);
}
void freeze_render_thread(){
xSemaphoreTake(freezeRenderThreadSemaphore, portMAX_DELAY);
}
void unfreeze_render_thread(){
xSemaphoreGive(freezeRenderThreadSemaphore);
}

View File

@@ -0,0 +1,11 @@
#pragma once
void semaphore_init();
void freeze_request_thread();
void unfreeze_request_thread();
// Don't use unless you want trouble
void freeze_render_thread();
// Don't use unless you want trouble
void unfreeze_render_thread();

View File

@@ -375,6 +375,8 @@ void show_ip_entry()
lv_textarea_set_placeholder_text(host_entry, "Printer IP");
lv_textarea_set_placeholder_text(port_entry, "Access code");
lv_textarea_set_placeholder_text(auth_entry, "Printer serial number");
lv_obj_clear_flag(auth_entry, LV_OBJ_FLAG_USER_2);
lv_obj_add_flag(auth_entry, LV_OBJ_FLAG_USER_3);
break;
case PrinterType::PrinterTypeOctoprint:
lv_obj_clear_flag(auth_entry, LV_OBJ_FLAG_USER_2);

View File

@@ -3,6 +3,7 @@
#include <Esp.h>
#include "../core/current_printer.h"
#include "../core/data_setup.h"
#include "../core/semaphore.h"
typedef struct {
const char* power_device_name;

View File

@@ -5,6 +5,7 @@
#include "../core/data_setup.h"
#include "../conf/global_config.h"
#include "ota_setup.h"
#include "../core/semaphore.h"
//const char *ota_url = "https://gist.githubusercontent.com/suchmememanyskill/ece418fe199e155340de6c224a0badf2/raw/0d6762d68bc807cbecc71e40d55b76692397a7b3/update.json"; // Test url
const char *ota_url = "https://suchmememanyskill.github.io/CYD-Klipper/OTA.json"; // Prod url

View File

@@ -32,43 +32,22 @@ static void btn_print_file_verify(lv_event_t * e)
return;
}
const auto button_size_mult = 1.3f;
lv_obj_t * btn = lv_event_get_target(e);
selected_file = (char*)lv_event_get_user_data(e);
lv_obj_t * panel = lv_obj_create(lv_scr_act());
lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX * 2, 0);
lv_obj_set_style_pad_hor(panel, CYD_SCREEN_GAP_PX * 2, 0);
lv_obj_set_style_pad_ver(panel, CYD_SCREEN_GAP_PX, 0);
lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 4, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 3);
lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0);
lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER);
lv_obj_t * label_print_file = lv_label_create(panel);
lv_label_set_text(label_print_file, "Print File");
lv_obj_align(label_print_file, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, selected_file);
lv_obj_align(label, LV_ALIGN_CENTER, 0, -20);
lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 10);
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
btn = lv_btn_create(panel);
lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 0, 0);
lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult);
lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_CLOSE);
lv_obj_center(label);
btn = lv_btn_create(panel);
lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult);
lv_obj_add_event_cb(btn, btn_print_file, LV_EVENT_CLICKED, panel);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_OK);
lv_obj_center(label);
lv_obj_t * top_panel = lv_create_empty_panel(panel);
lv_obj_set_width(top_panel, LV_PCT(100));
lv_obj_set_flex_grow(top_panel, 1);
lv_layout_flex_row(top_panel, LV_FLEX_ALIGN_CENTER);
Thumbnail thumbnail = current_printer_get_32_32_png_image_thumbnail(selected_file);
lv_obj_t * img = NULL;
@@ -85,17 +64,45 @@ static void btn_print_file_verify(lv_event_t * e)
img_header->header.cf = LV_IMG_CF_RAW_ALPHA;
img_header->data = thumbnail.png;
img = lv_img_create(panel);
img = lv_img_create(top_panel);
lv_img_set_src(img, img_header);
lv_obj_align(img, LV_ALIGN_TOP_LEFT, 0, 0);
lv_obj_t * text_center_panel = lv_create_empty_panel(panel);
lv_obj_set_size(text_center_panel, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2, 32);
lv_obj_align(text_center_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX + 32, 0);
lv_obj_set_parent(label_print_file, text_center_panel);
lv_obj_align(label_print_file, LV_ALIGN_LEFT_MID, 0, 0);
lv_img_set_antialias(img, true);
lv_img_set_size_mode(img, LV_IMG_SIZE_MODE_REAL);
if (global_config.double_size_gcode_img)
{
lv_img_set_zoom(img, LV_IMG_ZOOM_NONE * 2);
}
}
lv_obj_t * label = lv_label_create(top_panel);
lv_label_set_text(label, selected_file);
lv_obj_set_height(label, LV_SIZE_CONTENT);
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
lv_obj_set_flex_grow(label, 1);
lv_obj_t* buttons_panel = lv_create_empty_panel(panel);
lv_layout_flex_row(buttons_panel);
lv_obj_set_size(buttons_panel, LV_PCT(100), CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_t* btn = lv_btn_create(buttons_panel);
lv_obj_set_flex_grow(btn, 1);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_CLOSE " Cancel");
lv_obj_center(label);
btn = lv_btn_create(buttons_panel);
lv_obj_set_flex_grow(btn, 1);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, btn_print_file, LV_EVENT_CLICKED, panel);
lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_OK " Print");
lv_obj_center(label);
}
void files_panel_init(lv_obj_t* panel){

View File

@@ -344,18 +344,24 @@ static void root_panel_state_update(lv_event_t * e){
if (last_homing_state == get_current_printer_data()->homed_axis)
return;
PrinterType printer_type = get_current_printer()->printer_config->printer_type;
bool is_klipper = printer_type == PrinterTypeKlipper || printer_type == PrinterTypeKlipperSerial;
lv_obj_t * panel = lv_event_get_target(e);
last_homing_state = get_current_printer_data()->homed_axis;
lv_obj_clean(panel);
if (get_current_printer_data()->homed_axis)
if (get_current_printer_data()->homed_axis && is_klipper)
move_panel_slider_init(panel);
else if (get_current_printer_data()->homed_axis)
root_panel_steppers_locked(panel);
else
else
root_panel_steppers_unlocked(panel);
}
void move_panel_init(lv_obj_t* panel){
void move_panel_init(lv_obj_t* panel)
{
if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting){
stats_panel_init(panel);
return;

View File

@@ -0,0 +1,257 @@
#include "panel.h"
#include "lvgl.h"
#include "../../core/data_setup.h"
#include "../nav_buttons.h"
#include "../ui_utils.h"
#include "../../core/printer_integration.hpp"
#include "../../core/current_printer.h"
static void line_custom_set(const char * axis, const char *text)
{
float pos = atof(text);
if (pos < 0 || pos > 500)
return;
current_printer_move_printer(axis, pos, false);
}
static void x_line_custom_callback(lv_event_t * e)
{
const char * text = lv_textarea_get_text(lv_event_get_target(e));
line_custom_set("X", text);
}
static void y_line_custom_callback(lv_event_t * e)
{
const char * text = lv_textarea_get_text(lv_event_get_target(e));
line_custom_set("Y", text);
}
static void z_line_custom_callback(lv_event_t * e)
{
const char * text = lv_textarea_get_text(lv_event_get_target(e));
line_custom_set("Z", text);
}
static void x_line_custom(lv_event_t * e)
{
lv_create_keyboard_text_entry(x_line_custom_callback, "Set X position", LV_KEYBOARD_MODE_NUMBER, LV_PCT(75), 6);
}
static void y_line_custom(lv_event_t * e)
{
lv_create_keyboard_text_entry(y_line_custom_callback, "Set Y position", LV_KEYBOARD_MODE_NUMBER, LV_PCT(75), 6);
}
static void z_line_custom(lv_event_t * e)
{
lv_create_keyboard_text_entry(z_line_custom_callback, "Set Z position", LV_KEYBOARD_MODE_NUMBER, LV_PCT(75), 6);
}
static void pos_update(lv_event_t * e, const char* target_template, float target)
{
lv_obj_t* obj = lv_event_get_target(e);
lv_obj_t* slider = (lv_obj_t*)lv_event_get_user_data(e);
if (lv_slider_is_dragged(slider))
{
return;
}
if (lv_obj_check_type(obj, &lv_label_class))
{
char pos_buff[12];
sprintf(pos_buff, target_template, target);
lv_label_set_text(obj, pos_buff);
}
else
{
lv_slider_set_value(obj, target, LV_ANIM_ON);
}
}
static void x_pos_update(lv_event_t * e)
{
pos_update(e, "%.1f " LV_SYMBOL_EDIT, get_current_printer_data()->position[0]);
}
static void y_pos_update(lv_event_t * e)
{
pos_update(e, "%.1f", get_current_printer_data()->position[1]);
}
static void z_pos_update(lv_event_t * e)
{
pos_update(e, "%.2f", get_current_printer_data()->position[2]);
}
static void x_slider_update(lv_event_t * e)
{
current_printer_move_printer("X", lv_slider_get_value(lv_event_get_target(e)), false);
}
static void y_slider_update(lv_event_t * e)
{
current_printer_move_printer("Y", lv_slider_get_value(lv_event_get_target(e)), false);
}
static void z_slider_update(lv_event_t * e)
{
current_printer_move_printer("Z", lv_slider_get_value(lv_event_get_target(e)), false);
}
static void home_button_click(lv_event_t * e)
{
current_printer_execute_feature(PrinterFeatures::PrinterFeatureHome);
}
static void disable_steppers_button_click(lv_event_t * e)
{
current_printer_execute_feature(PrinterFeatures::PrinterFeatureDisableSteppers);
}
static void set_label_slider_position(lv_event_t * e)
{
lv_obj_t* slider = lv_event_get_target(e);
lv_obj_t* label = (lv_obj_t*)lv_event_get_user_data(e);
if (lv_slider_is_dragged(slider))
{
lv_label_set_text_fmt(label, "%d", lv_slider_get_value(slider));
}
}
static void switch_to_params_panel_button_click(lv_event_t * e)
{
lv_obj_t * panel = lv_event_get_target(e);
nav_buttons_setup(PANEL_STATS);
}
static void make_vertical_slider(
lv_obj_t* parent,
const char* axis,
lv_event_cb_t position_change,
lv_event_cb_t on_slider_change,
lv_event_cb_t on_edit,
float min,
float max)
{
lv_obj_t* root = lv_create_empty_panel(parent);
lv_layout_flex_column(root);
lv_obj_set_size(root, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 1.5, LV_PCT(100));
lv_obj_set_style_pad_column(root, 10, 0);
lv_obj_clear_flag(root, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_t* sub_root = lv_create_empty_panel(root);
lv_layout_flex_column(sub_root);
lv_obj_set_height(sub_root, LV_SIZE_CONTENT);
lv_obj_add_flag(sub_root, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_event_cb(sub_root, on_edit, LV_EVENT_CLICKED, NULL);
lv_obj_t* top_label = lv_label_create(sub_root);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, top_label, NULL);
lv_obj_t* one_below_label = lv_label_create(sub_root);
lv_label_set_text(one_below_label, LV_SYMBOL_EDIT);
lv_obj_t* two_below_label = lv_label_create(sub_root);
lv_label_set_text_fmt(two_below_label, "%s+", axis);
lv_obj_t* slider = lv_slider_create(root);
lv_obj_set_flex_grow(slider, 1);
lv_obj_set_width(slider, CYD_SCREEN_MIN_BUTTON_WIDTH_PX / 2);
lv_slider_set_range(slider, min, max);
lv_obj_add_event_cb(slider, on_slider_change, LV_EVENT_RELEASED, NULL);
lv_obj_add_event_cb(slider, position_change, LV_EVENT_MSG_RECEIVED, slider);
lv_obj_add_event_cb(slider, set_label_slider_position, LV_EVENT_VALUE_CHANGED, top_label);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, slider, NULL);
lv_obj_t* last_label = lv_label_create(root);
lv_label_set_text_fmt(last_label, "%s-", axis);
lv_obj_add_event_cb(top_label, position_change, LV_EVENT_MSG_RECEIVED, slider);
}
/* TODO: Make vertical button row with +1, +0.1, -0.1, -1, maybe with MAX - 30 */
static void make_horizontal_slider(
lv_obj_t* parent,
const char* axis,
lv_event_cb_t position_change,
lv_event_cb_t on_slider_change,
lv_event_cb_t on_edit,
float min,
float max)
{
lv_obj_t* root = lv_create_empty_panel(parent);
lv_layout_flex_column(root);
lv_obj_set_size(root, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_t* upper = lv_create_empty_panel(root);
lv_layout_flex_row(upper, LV_FLEX_ALIGN_SPACE_BETWEEN);
lv_obj_set_size(upper, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_add_flag(upper, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_event_cb(upper, on_edit, LV_EVENT_CLICKED, NULL);
lv_obj_t* left_label = lv_label_create(upper);
lv_label_set_text_fmt(left_label, "%s-", axis);
lv_obj_t* position_label = lv_label_create(upper);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, position_label, NULL);
lv_obj_t* right_label = lv_label_create(upper);
lv_label_set_text_fmt(right_label, "%s+", axis);
lv_obj_t* slider = lv_slider_create(root);
lv_obj_set_size(slider, LV_PCT(100), CYD_SCREEN_MIN_BUTTON_HEIGHT_PX / 2);
lv_slider_set_range(slider, min, max);
lv_obj_add_event_cb(slider, on_slider_change, LV_EVENT_RELEASED, NULL);
lv_obj_add_event_cb(slider, position_change, LV_EVENT_MSG_RECEIVED, slider);
lv_obj_add_event_cb(slider, set_label_slider_position, LV_EVENT_VALUE_CHANGED, position_label);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, slider, NULL);
lv_obj_set_style_pad_bottom(root, 10, 0);
lv_obj_set_style_pad_bottom(upper, 10, 0);
lv_obj_set_style_pad_column(upper, 10, 0);
lv_obj_add_event_cb(position_label, position_change, LV_EVENT_MSG_RECEIVED, slider);
}
static void create_button(lv_obj_t* parent, lv_event_cb_t on_click, const char* text)
{
lv_obj_t* btn = lv_btn_create(parent);
lv_obj_set_width(btn, LV_PCT(100));
lv_obj_set_flex_grow(btn, 1);
lv_obj_add_event_cb(btn, on_click, LV_EVENT_CLICKED, NULL);
lv_obj_t* label = lv_label_create(btn);
lv_obj_center(label);
lv_label_set_text(label, text);
}
void move_panel_slider_init(lv_obj_t* panel)
{
lv_obj_t * sub_panel = lv_create_empty_panel(panel);
lv_obj_set_size(sub_panel, LV_PCT(100), LV_PCT(100));
lv_layout_flex_row(sub_panel);
lv_obj_t* left = lv_create_empty_panel(sub_panel);
lv_layout_flex_column(left);
lv_obj_set_flex_grow(left, 1);
lv_obj_set_height(left, LV_PCT(100));
float* position_min = get_current_printer_data()->position_min;
float* position_max = get_current_printer_data()->position_max;
make_horizontal_slider(left, "X", x_pos_update, x_slider_update, x_line_custom, position_min[0], position_max[0]);
make_vertical_slider(sub_panel, "Y", y_pos_update, y_slider_update, y_line_custom, position_min[1], position_max[1]);
make_vertical_slider(sub_panel, "Z", z_pos_update, z_slider_update, z_line_custom, position_min[2], position_max[2]);
create_button(left, home_button_click, LV_SYMBOL_HOME " Home XYZ");
create_button(left, disable_steppers_button_click, LV_SYMBOL_EYE_CLOSE " Free Motors");
create_button(left, switch_to_params_panel_button_click, LV_SYMBOL_SETTINGS " Parameters");
lv_obj_set_style_pad_right(left, 10, 0);
lv_obj_set_style_pad_all(sub_panel, 10, 0);
}

View File

@@ -12,5 +12,6 @@ void stats_panel_init(lv_obj_t* panel);
void printer_panel_init(lv_obj_t* panel);
void error_panel_init(lv_obj_t* panel);
void connecting_panel_init(lv_obj_t* panel);
void move_panel_slider_init(lv_obj_t* panel);
void settings_section_device(lv_obj_t* panel);

View File

@@ -132,6 +132,13 @@ static void full_filenames_switch(lv_event_t* e){
write_global_config();
}
static void double_size_gcode_img_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.double_size_gcode_img = checked;
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);
@@ -239,6 +246,7 @@ void settings_section_behaviour(lv_obj_t* panel)
lv_create_custom_menu_switch("Sort Macros A->Z", panel, sort_macros_switch, global_config.sort_macros);
lv_create_custom_menu_switch("Show Full Filenames", panel, full_filenames_switch, global_config.full_filenames);
lv_create_custom_menu_switch("2X Size Gcode Image", panel, double_size_gcode_img_switch, global_config.double_size_gcode_img);
lv_create_custom_menu_button("Configure Printer Host", panel, reset_ip_click, "Restart");
}

View File

@@ -7,6 +7,7 @@
#include "../core/lv_setup.h"
#include "serial/serial_console.h"
#include "panels/panel.h"
#include "../core/semaphore.h"
void wifi_init_inner();
void wifi_pass_entry(const char* ssid);

View File

@@ -2,9 +2,10 @@
[![Donations](https://img.shields.io/badge/Support%20on-Ko--Fi-red)](https://ko-fi.com/suchmememanyskill)
# CYD-Klipper
An implementation of a wireless Klipper status display on an ESP32 + screen. Uses Moonraker to fetch data.
An implementation of a wireless Klipper, Bambu and Octoprint status display on an ESP32 + screen. Uses Moonraker to fetch data.
A simple and cheap solution to use a dedicated screen with Klipper, a 3d printing Firmware.
Also now with Bambu Lab and Octoprint printers!
![showcase_image](readme/PXL_20231113_171629383.jpg)
@@ -24,6 +25,8 @@ A ESP32-2432S028R is required to run this project. You can find out where to buy
- Toggle Moonraker power devices
- OTA updates
- Serial console over USB (115200 8n1, echo off, LF/LF)
- Control Klipper, Octoprint and Bambu printers.
- Wired Serial/Usb Klipper connection
### Install

View File

@@ -71,7 +71,7 @@
<body>
<section class="main">
<h2>CYD-Klipper <span class="iconify" data-icon="mdi-printer-3d" style="color: #F44;"></span></h2>
<p>An implementation of a Klipper status display on an ESP32 + screen.<br>Uses Moonraker to fetch data.<br><a href="https://github.com/suchmememanyskill/CYD-Klipper">Source code is available on GitHub</a>.</p>
<p>An implementation of a wireless Klipper, Bambu and Octoprint status display on an ESP32 + screen.<br>Uses Moonraker to fetch data.<br><a href="https://github.com/suchmememanyskill/CYD-Klipper">Source code is available on GitHub</a>.</p>
<section class="changelog">
<h3 id="changelog-header"><span class="iconify" data-icon="mdi-hammer-wrench" style="color: lightgray;"></span> Changelog <span id="changelog-header-version"></span></h3>
@@ -101,6 +101,7 @@
<option value="esp32-8048S043C-SD">ESP32-8048S043 (4.3" 800x480 Capacitive)</option>
<option value="esp32-8048S043C-SD-alt">ESP32-8048S043 Alt (4.3" 800x480 Capacitive)</option>
<option value="esp32-CROWPANEL-28R">ESP32-CROWPANEL-28R (2.8" Resistive)</option>
<option value="esp32-CROWPANEL-35C">ESP32-CROWPANEL-35C (3.5" Capacitive)</option>
</select>
<span id="install-btn"></span>
</section>

15
ci.py
View File

@@ -11,12 +11,14 @@ CYD_PORTS = [
"esp32-3248S035C-V",
#"esp32-4827S043R-SD",
"esp32-CROWPANEL-28R",
"esp32-CROWPANEL-35C",
]
ESP_S3_CHIPS = [
"esp32-8048S043C-SD",
"esp32-8048S043C-SD-alt",
"esp32-4827S043C-SD",
"esp32-CROWPANEL-35C",
]
BASE_DIR = os.getcwd()
@@ -32,19 +34,19 @@ def get_manifest(base_path : str, device_name : str):
"parts": [
{
"path": f"{base_path}/bootloader.bin",
"offset": 4096
"offset": 0 if device_name in ESP_S3_CHIPS else 0x1000
},
{
"path": f"{base_path}/partitions.bin",
"offset": 32768
"offset": 0x8000
},
{
"path": f"{base_path}/boot_app0.bin",
"offset": 57344
"offset": 0xe000
},
{
"path": f"{base_path}/firmware.bin",
"offset": 65536
"offset": 0x10000
}
]
}
@@ -80,7 +82,10 @@ for port in CYD_PORTS:
shutil.copy(os.path.join(os.path.expanduser("~"), ".platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin"), f"{port_path}/boot_app0.bin")
os.chdir(port_path)
subprocess.run(["python3", "-m", "esptool", "--chip", "esp32", "merge_bin", "-o", "merged_firmware.bin", "--flash_mode", "dio", "--flash_freq", "40m", "--flash_size", "4MB", "0x1000", "bootloader.bin", "0x8000", "partitions.bin", "0xe000", "boot_app0.bin", "0x10000", "firmware.bin"], check=True)
if (port in ESP_S3_CHIPS):
subprocess.run(["python3", "-m", "esptool", "--chip", "esp32s3", "merge_bin", "-o", "merged_firmware.bin", "--flash_mode", "dio", "--flash_freq", "80m", "--flash_size", "16MB", "0x0000", "bootloader.bin", "0x8000", "partitions.bin", "0xe000", "boot_app0.bin", "0x10000", "firmware.bin"], check=True)
else:
subprocess.run(["python3", "-m", "esptool", "--chip", "esp32", "merge_bin", "-o", "merged_firmware.bin", "--flash_mode", "dio", "--flash_freq", "40m", "--flash_size", "4MB", "0x1000", "bootloader.bin", "0x8000", "partitions.bin", "0xe000", "boot_app0.bin", "0x10000", "firmware.bin"], check=True)
os.chdir(BASE_DIR)

View File

@@ -1,8 +1,21 @@
#!/bin/bash
if [ "$EUID" -eq 0 ]; then
echo "Please do not run as root"
exit
read -r -p "Are you sure you want to run this service as root? [y/N] " response
response=${response,,} # tolower
if ! [[ "$response" =~ ^(yes|y)$ ]]; then
exit
fi
SERVICE_PATH="/etc/systemd/system/cyd-klipper-serial.service"
else
echo "Are you sure you want to run this service as the current user?"
read -r -p "Make sure this user is logged in at boot! [y/N] " response
response=${response,,} # tolower
if ! [[ "$response" =~ ^(yes|y)$ ]]; then
exit
fi
mkdir -p ~/.config/systemd/user
SERVICE_PATH="$HOME/.config/systemd/user/cyd-klipper-serial.service"
fi
set -e
@@ -15,20 +28,26 @@ source ./env/bin/activate
pip3 install -r requirements.txt
# Create systemd unit file
mkdir -p ~/.config/systemd/user
echo "[Unit]" > ~/.config/systemd/user/cyd-klipper-serial.service
echo "Description=CYD Klipper serial server" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "After=network.target" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "[Service]" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "ExecStart=$(pwd)/run.sh" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "WorkingDirectory=$(pwd)" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "Restart=always" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "[Install]" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "WantedBy=multi-user.target" >> ~/.config/systemd/user/cyd-klipper-serial.service
echo "[Unit]" > $SERVICE_PATH
echo "Description=CYD Klipper serial server" >> $SERVICE_PATH
echo "After=network.target" >> $SERVICE_PATH
echo "" >> $SERVICE_PATH
echo "[Service]" >> $SERVICE_PATH
echo "ExecStart=$(pwd)/run.sh" >> $SERVICE_PATH
echo "WorkingDirectory=$(pwd)" >> $SERVICE_PATH
echo "Restart=always" >> $SERVICE_PATH
echo "" >> $SERVICE_PATH
echo "[Install]" >> $SERVICE_PATH
echo "WantedBy=multi-user.target" >> $SERVICE_PATH
# Start the service
systemctl --user daemon-reload
systemctl --user enable cyd-klipper-serial
systemctl --user start cyd-klipper-serial
if [ "$EUID" -eq 0 ]; then
systemctl daemon-reload
systemctl enable cyd-klipper-serial
systemctl start cyd-klipper-serial
else
systemctl --user daemon-reload
systemctl --user enable cyd-klipper-serial
systemctl --user start cyd-klipper-serial
fi

View File

@@ -1,13 +1,21 @@
#!/bin/bash
set -e
if [ "$EUID" -eq 0 ]; then
echo "Please do not run as root"
exit
systemctl stop cyd-klipper-serial
systemctl disable cyd-klipper-serial
rm /etc/systemd/system/cyd-klipper-serial.service
systemctl daemon-reload
else
systemctl --user stop cyd-klipper-serial
systemctl --user disable cyd-klipper-serial
rm ~/.config/systemd/user/cyd-klipper-serial.service
systemctl --user daemon-reload
fi
systemctl --user stop cyd-klipper-serial
systemctl --user disable cyd-klipper-serial
rm ~/.config/systemd/user/cyd-klipper-serial.service
systemctl --user daemon-reload
rm -rf ./env