Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.1.1 #6

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CYD-Klipper/src/core/screen_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,20 @@ void screen_timer_wake()
lv_timer_reset(screenSleepTimer);
isScreenInSleep = false;
set_screen_brightness();

// Reset cpu freq
setCpuFrequencyMhz(CPU_FREQ_HIGH);
Serial.printf("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz());
}

void screen_timer_sleep(lv_timer_t *timer)
{
screen_setBrightness(0);
isScreenInSleep = true;

// Screen is off, no need to make the cpu run fast, the user won't notice ;)
setCpuFrequencyMhz(CPU_FREQ_LOW);
Serial.printf("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz());
}

void screen_timer_setup()
Expand Down
3 changes: 3 additions & 0 deletions CYD-Klipper/src/core/screen_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#ifndef _SCREEN_DRIVER_INIT
#define _SCREEN_DRIVER_INIT

#define CPU_FREQ_HIGH 240
#define CPU_FREQ_LOW 80

#include <XPT2046_Touchscreen.h>
#include <TFT_eSPI.h>

Expand Down
2 changes: 1 addition & 1 deletion CYD-Klipper/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void setup() {
Serial.println("Screen init done");

wifi_init();
ip_setup();
ip_init();
data_setup();

nav_style_setup();
Expand Down
64 changes: 44 additions & 20 deletions CYD-Klipper/src/ui/ip_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ lv_obj_t * ipEntry;
lv_obj_t * portEntry;
lv_obj_t * label = NULL;

void ip_init_inner();

bool verify_ip(){
HTTPClient client;
String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/printer/info";
int httpCode;
try {
Serial.println(url);
client.setTimeout(500);
client.begin(url.c_str());
httpCode = client.GET();
return httpCode == 200;
Expand All @@ -25,17 +28,6 @@ bool verify_ip(){
}
}

bool retry_ip_verify(){
for (int i = 0; i < 5; i++){
if (verify_ip()){
return true;
}
delay(1000);
}

return false;
}

static void ta_event_cb(lv_event_t * e) {
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * ta = lv_event_get_target(e);
Expand All @@ -53,8 +45,8 @@ static void ta_event_cb(lv_event_t * e) {
{
strcpy(global_config.klipperHost, lv_textarea_get_text(ipEntry));
global_config.klipperPort = atoi(lv_textarea_get_text(portEntry));
bool result = verify_ip();
if (result)

if (verify_ip())
{
global_config.ipConfigured = true;
WriteGlobalConfig();
Expand All @@ -67,9 +59,33 @@ static void ta_event_cb(lv_event_t * e) {
}
}

void ip_setup_inner(){
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;
ip_init_inner();
}
}

void ip_init_inner(){
lv_obj_clean(lv_scr_act());

if (global_config.ipConfigured) {
label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "Connecting to Klipper");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

lv_obj_t * resetBtn = lv_btn_create(lv_scr_act());
lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL);
lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, 40);

lv_obj_t * btnLabel = lv_label_create(resetBtn);
lv_label_set_text(btnLabel, "Reset");
lv_obj_center(btnLabel);
return;
}

lv_obj_t * keyboard = lv_keyboard_create(lv_scr_act());
label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "Enter Klipper IP and Port");
Expand All @@ -95,18 +111,26 @@ void ip_setup_inner(){
lv_keyboard_set_textarea(keyboard, ipEntry);
}

void ip_setup(){
connect_ok = false;
long last_data_update_ip = -10000;
const long data_update_interval_ip = 10000;
int retry_count = 0;

if (global_config.ipConfigured && retry_ip_verify()){
return;
}
void ip_init(){
connect_ok = false;

ip_setup_inner();
ip_init_inner();

while (!connect_ok)
{
lv_timer_handler();
lv_task_handler();

if (!connect_ok && global_config.ipConfigured && (millis() - last_data_update_ip) > data_update_interval_ip){
connect_ok = verify_ip();
last_data_update_ip = millis();
retry_count++;
String retry_count_text = "Connecting to Klipper (Try " + String(retry_count + 1) + ")";
lv_label_set_text(label, retry_count_text.c_str());
}
}
}
2 changes: 1 addition & 1 deletion CYD-Klipper/src/ui/ip_setup.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
void ip_setup();
void ip_init();
5 changes: 1 addition & 4 deletions CYD-Klipper/src/ui/wifi_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ static void wifi_btn_event_handler(lv_event_t * e){

void wifi_init_inner(){
WiFi.disconnect();
lv_obj_clean(lv_scr_act());

if (global_config.wifiConfigured){
WiFi.begin(global_config.wifiSSID, global_config.wifiPassword);

lv_obj_clean(lv_scr_act());

lv_obj_t * label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "Connecting to WiFi");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
Expand All @@ -98,8 +97,6 @@ void wifi_init_inner(){
return;
}

lv_obj_clean(lv_scr_act());

lv_obj_t * label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "Scanning for networks...");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
Expand Down