Skip to content

Commit

Permalink
Lower CPU speed if screen is off
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Dec 2, 2023
1 parent e15c7e3 commit 1e3f0ab
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
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
2 changes: 1 addition & 1 deletion CYD-Klipper/src/ui/ip_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void ip_setup_inner(){
lv_keyboard_set_textarea(keyboard, ipEntry);
}

void ip_setup(){
void ip_init(){
connect_ok = false;

if (global_config.ipConfigured && retry_ip_verify()){
Expand Down
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();

0 comments on commit 1e3f0ab

Please sign in to comment.