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

Serial console #117

Merged
merged 19 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
if: (github.event_name == 'release' && github.event.action == 'created') || (github.event_name != 'pull_request' && github.ref == 'refs/heads/master')
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Print GitHub event name
run: |
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_site/out/
_site/OTA.json
_site/esp32-*.json

pyvenv.cfg
bin/
out/
lib
lib64

9 changes: 7 additions & 2 deletions CYD-Klipper/src/conf/global_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "lvgl.h"

GLOBAL_CONFIG global_config = {0};
TEMPORARY_CONFIG temporary_config = {0};

COLOR_DEF color_defs[] = {
{LV_PALETTE_BLUE, 0, LV_PALETTE_RED},
Expand Down Expand Up @@ -31,9 +32,9 @@ void verify_version()

GLOBAL_CONFIG config = {0};
preferences.getBytes("global_config", &config, sizeof(config));
Serial.printf("Config version: %d\n", config.version);
LOG_LN(("Config version: %d\n", config.version))
if (config.version != CONFIG_VERSION) {
Serial.println("Clearing Global Config");
LOG_LN("Clearing Global Config");
preferences.clear();
}

Expand Down Expand Up @@ -131,4 +132,8 @@ void load_global_config()
preferences.begin("global_config", true);
preferences.getBytes("global_config", &global_config, sizeof(global_config));
preferences.end();

temporary_config.debug = (bool) REPO_DEVELOPMENT;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this will go wrong when a release happens. REPO_DEVELOPMENT is undefined if it's a release build

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

    #if defined REPO_DEVELOPMENT  &&  REPO_DEVELOPMENT == 1
        temporary_config.debug = true;
    #else
        temporary_config.debug = false;
    #endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow during search&replace a bunch of Serial.printf got swapped for LOG_LN (Serial.println wrapper) instead of LOG_F while retaining the ((...)) syntax of LOG_F
Due to the ((...)) syntax, the inner paren was interpreted as comma expression, ("A=%d B=%d\n",A,B) evaluating to B which Serial.println() was perfectly happy with.

temporary_config.remote_echo = true;

}
14 changes: 14 additions & 0 deletions CYD-Klipper/src/conf/global_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#define CONFIG_VERSION 6
#define PRINTER_CONFIG_COUNT 8
#define DISPLAY_SECRETS 0

enum {
REMAINING_TIME_CALC_PERCENTAGE = 0,
Expand Down Expand Up @@ -68,6 +69,7 @@ typedef struct _GLOBAL_CONFIG {
bool on_during_print : 1;
bool display_mode : 1; // Driver specifc usage. Currently only used on ESP32-2432S028R to fix the screen on the usb-c model
bool disable_m117_messaging : 1;
bool sort_macros : 1;
};
};

Expand All @@ -85,16 +87,28 @@ typedef struct _GLOBAL_CONFIG {
unsigned char screen_timeout;
unsigned char printer_index;
} GLOBAL_CONFIG;

// Volatile/temporary config that doesn't survive a reset
typedef struct _TEMPORARY_CONFIG {
bool debug : 1;
bool remote_echo : 1;
} TEMPORARY_CONFIG;


typedef struct _COLOR_DEF {
lv_palette_t primary_color;
short primary_color_light;
lv_palette_t secondary_color;
} COLOR_DEF;

extern GLOBAL_CONFIG global_config;
extern TEMPORARY_CONFIG temporary_config;
extern COLOR_DEF color_defs[];

#define LOG(x) if(temporary_config.debug){ Serial.print(x);}
#define LOG_LN(x) if(temporary_config.debug){ Serial.println(x);}
#define LOG_F(x) if(temporary_config.debug){ Serial.printf x ;} // use with double braces, LOF_F(("x=%d\n",x));

void write_global_config();
void verify_version();
void load_global_config();
Expand Down
8 changes: 4 additions & 4 deletions CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void unfreeze_render_thread(){

void send_gcode(bool wait, const char *gcode)
{
Serial.printf("Sending gcode: %s\n", gcode);
LOG_LN(("Sending gcode: %s\n", gcode))

SETUP_HTTP_CLIENT_FULL("/printer/gcode/script?script=" + urlEncode(gcode), false, wait ? 5000 : 750);
try
Expand All @@ -52,7 +52,7 @@ void send_gcode(bool wait, const char *gcode)
}
catch (...)
{
Serial.println("Failed to send gcode");
LOG_LN("Failed to send gcode");
}
}

Expand All @@ -73,7 +73,7 @@ int get_slicer_time_estimate_s()
JsonDocument doc;
deserializeJson(doc, client.getStream());
int time_estimate_s = doc["result"]["estimated_time"];
Serial.printf("Got slicer time estimate: %ds\n", time_estimate_s);
LOG_LN(("Got slicer time estimate: %ds\n", time_estimate_s))
return time_estimate_s;
}

Expand Down Expand Up @@ -330,7 +330,7 @@ void fetch_printer_data()
unfreeze_render_thread();
}

Serial.printf("Failed to fetch printer data: %d\n", httpCode);
LOG_LN(("Failed to fetch printer data: %d\n", httpCode))
}
}

Expand Down
12 changes: 6 additions & 6 deletions CYD-Klipper/src/core/files_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ FILESYSTEM_FILE* get_files(int limit)
freeze_request_thread();
clear_files();

Serial.printf("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size());
LOG_LN(("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size()))
std::list<FILESYSTEM_FILE> files;

auto timer_request = millis();
Expand All @@ -41,7 +41,7 @@ FILESYSTEM_FILE* get_files(int limit)
if (httpCode == 200){
JsonDocument doc;
auto parseResult = deserializeJson(doc, client.getStream());
Serial.printf("Json parse: %s\n", parseResult.c_str());
LOG_LN(("Json parse: %s\n", parseResult.c_str()))
auto result = doc["result"].as<JsonArray>();

for (auto file : result){
Expand All @@ -62,7 +62,7 @@ FILESYSTEM_FILE* get_files(int limit)

f.name = (char*)malloc(strlen(path) + 1);
if (f.name == NULL){
Serial.println("Failed to allocate memory");
LOG_LN("Failed to allocate memory");
continue;
}
strcpy(f.name, path);
Expand All @@ -88,7 +88,7 @@ FILESYSTEM_FILE* get_files(int limit)
FILESYSTEM_FILE* result = (FILESYSTEM_FILE*)malloc(size);

if (result == NULL){
Serial.println("Failed to allocate memory");
LOG_LN("Failed to allocate memory");

for (auto file : files){
free(file.name);
Expand All @@ -106,8 +106,8 @@ FILESYSTEM_FILE* get_files(int limit)
result += 1;
}

Serial.printf("Heap space post-file-parse: %d bytes\n", esp_get_free_heap_size());
Serial.printf("Got %d files. Request took %dms, parsing took %dms\n", files.size(), timer_parse - timer_request, millis() - timer_parse);
LOG_LN(("Heap space post-file-parse: %d bytes\n", esp_get_free_heap_size()))
LOG_LN(("Got %d files. Request took %dms, parsing took %dms\n", files.size(), timer_parse - timer_request, millis() - timer_parse))
unfreeze_request_thread();
return last_query;
}
10 changes: 6 additions & 4 deletions CYD-Klipper/src/core/lv_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "lvgl.h"
#include "../ui/ui_utils.h"
#include <Esp.h>
#include "../ui/serial/serial_console.h"

#ifndef CPU_FREQ_HIGH
#define CPU_FREQ_HIGH 240
Expand Down Expand Up @@ -117,6 +118,7 @@ void lv_do_calibration(){

while (true){
lv_handler();
serial_console::run();

if (point[0] != 0 && point[1] != 0){
break;
Expand Down Expand Up @@ -175,15 +177,15 @@ void lv_do_calibration(){
global_config.screen_cal_y_offset = 10.0 - ((float)y1 * global_config.screen_cal_y_mult);

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");
LOG_LN("Calibration failed, please try again");
ESP.restart();
}

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.screen_cal_x_mult, global_config.screen_cal_x_offset, global_config.screen_cal_y_mult, global_config.screen_cal_y_offset);
LOG_LN(("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()
Expand All @@ -208,7 +210,7 @@ void screen_timer_wake()

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

Expand All @@ -220,7 +222,7 @@ void screen_timer_sleep(lv_timer_t *timer)

// 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());
LOG_LN(("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz()))
#endif
}

Expand Down
7 changes: 7 additions & 0 deletions CYD-Klipper/src/core/macros_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ MACROSQUERY macros_query(PRINTER_CONFIG * config)
}
}

if (global_config.sort_macros)
{
std::sort(macros, macros + macros_count, [](const char* a, const char* b) {
return strcmp(a, b) < 0;
});
}

return {(const char**)macros, (unsigned int)macros_count};
}
else {
Expand Down
6 changes: 3 additions & 3 deletions CYD-Klipper/src/lib/ESP32OTAPull.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ESP32OTAPull
size_t bytes_written = Update.write(buff, bytes_read);
if (bytes_read != bytes_written)
{
// Serial.printf("Unexpected error in OTA: %d %d %d\n", bytes_to_read, bytes_read, bytes_written);
// LOG_LN(("Unexpected error in OTA: %d %d %d\n", bytes_to_read, bytes_read, bytes_written))
break;
}
offset += bytes_written;
Expand Down Expand Up @@ -212,8 +212,8 @@ class ESP32OTAPull
String CDevice = config["Device"].isNull() ? "" : (const char *)config["Device"];
CVersion = config["Version"].isNull() ? "" : (const char *)config["Version"];
String CConfig = config["Config"].isNull() ? "" : (const char *)config["Config"];
//Serial.printf("Checking %s %s %s %s\n", CBoard.c_str(), CDevice.c_str(), CVersion.c_str(), CConfig.c_str());
//Serial.printf("Against %s %s %s %s\n", BoardName.c_str(), DeviceName.c_str(), CurrentVersion, ConfigName.c_str());
//LOG_LN(("Checking %s %s %s %s\n", CBoard.c_str(), CDevice.c_str(), CVersion.c_str(), CConfig.c_str()))
//LOG_LN(("Against %s %s %s %s\n", BoardName.c_str(), DeviceName.c_str(), CurrentVersion, ConfigName.c_str()))
if ((CBoard.isEmpty() || CBoard == BoardName) &&
(CDevice.isEmpty() || CDevice == DeviceName) &&
(CConfig.isEmpty() || CConfig == ConfigName))
Expand Down
6 changes: 4 additions & 2 deletions CYD-Klipper/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "core/screen_driver.h"
#include "ui/wifi_setup.h"
#include "ui/ip_setup.h"
#include "ui/serial/serial_console.h"
#include "lvgl.h"
#include "core/data_setup.h"
#include "ui/main_ui.h"
Expand All @@ -12,11 +13,11 @@

void setup() {
Serial.begin(115200);
Serial.println("Hello World");
serial_console::greet();
load_global_config();
screen_setup();
lv_setup();
Serial.println("Screen init done");
LOG_LN("Screen init done");

wifi_init();
ota_init();
Expand All @@ -31,6 +32,7 @@ void loop(){
wifi_ok();
data_loop();
lv_handler();
serial_console::run();

if (is_ready_for_ota_update())
{
Expand Down
Loading
Loading