Skip to content

Commit

Permalink
Get Serial to a functional state
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Nov 8, 2024
1 parent 747ff4c commit 92b7b68
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 35 deletions.
99 changes: 99 additions & 0 deletions CYD-Klipper/src/core/current_printer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "data_setup.h"
#include "current_printer.h"

bool current_printer_move_printer(const char* axis, float amount, bool relative)
{
freeze_request_thread();
bool result = get_current_printer()->move_printer(axis, amount, relative);
unfreeze_request_thread();
return result;
}

bool current_printer_execute_feature(PrinterFeatures feature)
{
freeze_request_thread();
bool result = get_current_printer()->execute_feature(feature);
unfreeze_request_thread();
return result;
}

Macros current_printer_get_macros()
{
freeze_request_thread();
Macros macros = get_current_printer()->get_macros();
unfreeze_request_thread();
return macros;
}

int current_printer_get_macros_count()
{
freeze_request_thread();
int count = get_current_printer()->get_macros_count();
unfreeze_request_thread();
return count;
}

bool current_printer_execute_macro(const char* macro)
{
freeze_request_thread();
bool result = get_current_printer()->execute_macro(macro);
unfreeze_request_thread();
return result;
}

PowerDevices current_printer_get_power_devices()
{
freeze_request_thread();
PowerDevices power_devices = get_current_printer()->get_power_devices();
unfreeze_request_thread();
return power_devices;
}

int current_printer_get_power_devices_count()
{
freeze_request_thread();
int count = get_current_printer()->get_power_devices_count();
unfreeze_request_thread();
return count;
}

bool current_printer_set_power_device_state(const char* device_name, bool state)
{
freeze_request_thread();
bool result = get_current_printer()->set_power_device_state(device_name, state);
unfreeze_request_thread();
return result;
}

Files current_printer_get_files()
{
freeze_request_thread();
Files files = get_current_printer()->get_files();
unfreeze_request_thread();
return files;
}

bool current_printer_start_file(const char* filename)
{
freeze_request_thread();
bool result = get_current_printer()->start_file(filename);
unfreeze_request_thread();
return result;
}

Thumbnail current_printer_get_32_32_png_image_thumbnail(const char* gcode_filename)
{
freeze_request_thread();
Thumbnail thumbnail = get_current_printer()->get_32_32_png_image_thumbnail(gcode_filename);
unfreeze_request_thread();
return thumbnail;
}

bool current_printer_set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature)
{
freeze_request_thread();
bool result = get_current_printer()->set_target_temperature(device, temperature);
unfreeze_request_thread();
return result;
}

15 changes: 15 additions & 0 deletions CYD-Klipper/src/core/current_printer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include "printer_integration.hpp"

bool current_printer_move_printer(const char* axis, float amount, bool relative);
bool current_printer_execute_feature(PrinterFeatures feature);
Macros current_printer_get_macros();
int current_printer_get_macros_count();
bool current_printer_execute_macro(const char* macro);
PowerDevices current_printer_get_power_devices();
int current_printer_get_power_devices_count();
bool current_printer_set_power_device_state(const char* device_name, bool state);
Files current_printer_get_files();
bool current_printer_start_file(const char* filename);
Thumbnail current_printer_get_32_32_png_image_thumbnail(const char* gcode_filename);
bool current_printer_set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature);
5 changes: 4 additions & 1 deletion CYD-Klipper/src/ui/macros.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "macros.h"
#include "ui_utils.h"
#include <Esp.h>
#include "../core/current_printer.h"
#include "../core/data_setup.h"

typedef struct {
Expand All @@ -12,7 +13,7 @@ static void macro_run(lv_event_t * e){
lv_obj_t * btn = lv_event_get_target(e);
const char* macro = (const char*)lv_event_get_user_data(e);
LOG_F(("Macro: %s\n", macro))
get_current_printer()->execute_macro(macro);
current_printer_execute_macro(macro);
}

int macros_add_macros_to_panel(lv_obj_t * root_panel, BasePrinter* printer)
Expand Down Expand Up @@ -44,7 +45,9 @@ static void power_device_toggle(lv_event_t * e)
DoubleStorage* device = (DoubleStorage*)lv_event_get_user_data(e);
LOG_F(("Power Device: %s, State: %d -> %d\n", device->power_device_name, !checked, checked))

freeze_request_thread();
device->printer->set_power_device_state(device->power_device_name, checked);
unfreeze_request_thread();
}

int macros_add_power_devices_to_panel(lv_obj_t * root_panel, BasePrinter* printer)
Expand Down
12 changes: 6 additions & 6 deletions CYD-Klipper/src/ui/panels/error_panel.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#include "panel.h"
#include "../../core/data_setup.h"
#include "../../core/current_printer.h"
#include "../ui_utils.h"
#include "../../core/printer_integration.hpp"

static void btn_click_restart(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatureRestart);
current_printer_execute_feature(PrinterFeatureRestart);
}

static void btn_click_firmware_restart(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatureFirmwareRestart);
current_printer_execute_feature(PrinterFeatureFirmwareRestart);
}

static void btn_click_error_ignore(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatureIgnoreError);
current_printer_execute_feature(PrinterFeatureIgnoreError);
}

static void btn_click_error_continue(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatureContinueError);
current_printer_execute_feature(PrinterFeatureContinueError);
}

static void btn_click_error_retry(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatureRetryError);
current_printer_execute_feature(PrinterFeatureRetryError);
}

static void set_state_message_text(lv_event_t * e) {
Expand Down
13 changes: 4 additions & 9 deletions CYD-Klipper/src/ui/panels/files_panel.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "lvgl.h"
#include "panel.h"

#include "../../core/data_setup.h"
#include "../../core/current_printer.h"
#include "../../conf/global_config.h"
#include <HardwareSerial.h>
#include "../ui_utils.h"
Expand All @@ -15,7 +15,7 @@ static void btn_print_file(lv_event_t * e){
lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e);
lv_obj_del(panel);

get_current_printer()->start_file(selected_file);
current_printer_start_file(selected_file);
}

static void btn_print_file_verify(lv_event_t * e){
Expand Down Expand Up @@ -61,10 +61,7 @@ static void btn_print_file_verify(lv_event_t * e){
lv_label_set_text(label, LV_SYMBOL_OK);
lv_obj_center(label);

freeze_request_thread();
Thumbnail thumbnail = get_current_printer()->get_32_32_png_image_thumbnail(selected_file);
unfreeze_request_thread();

Thumbnail thumbnail = current_printer_get_32_32_png_image_thumbnail(selected_file);
lv_obj_t * img = NULL;

if (thumbnail.success)
Expand Down Expand Up @@ -93,9 +90,7 @@ static void btn_print_file_verify(lv_event_t * e){
}

void files_panel_init(lv_obj_t* panel){
freeze_request_thread();
Files files = get_current_printer()->get_files();
unfreeze_request_thread();
Files files = current_printer_get_files();

if (!files.success || files.count <= 0){
lv_obj_t * label = lv_label_create(panel);
Expand Down
1 change: 0 additions & 1 deletion CYD-Klipper/src/ui/panels/macros_panel.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "../macros.h"
#include "panel.h"
#include "../nav_buttons.h"
#include "../../core/data_setup.h"
#include "../../conf/global_config.h"
#include "../ui_utils.h"
#include <HardwareSerial.h>
Expand Down
15 changes: 7 additions & 8 deletions CYD-Klipper/src/ui/panels/move_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdio.h>
#include <Esp.h>
#include "../../core/printer_integration.hpp"
#include "../../core/current_printer.h"

static bool last_homing_state = false;
static bool move_edit_mode = false;
Expand Down Expand Up @@ -110,7 +111,7 @@ static void x_line_button_press(lv_event_t * e) {
}

float data = *data_pointer;
get_current_printer()->move_printer("X", data, true);
current_printer_move_printer("X", data, true);
}

static void y_line_button_press(lv_event_t * e) {
Expand All @@ -123,7 +124,7 @@ static void y_line_button_press(lv_event_t * e) {
}

float data = *data_pointer;
get_current_printer()->move_printer("Y", data, true);
current_printer_move_printer("Y", data, true);
}

static void z_line_button_press(lv_event_t * e) {
Expand All @@ -136,7 +137,7 @@ static void z_line_button_press(lv_event_t * e) {
}

float data = *data_pointer;
get_current_printer()->move_printer("Z", data, true);
current_printer_move_printer("Z", data, true);
}

static void x_pos_update(lv_event_t * e){
Expand Down Expand Up @@ -167,16 +168,14 @@ static void home_button_click(lv_event_t * e) {
if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting)
return;

freeze_request_thread();
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureHome);
unfreeze_request_thread();
current_printer_execute_feature(PrinterFeatures::PrinterFeatureHome);
}

static void disable_steppers_click(lv_event_t * e) {
if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting)
return;

get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureDisableSteppers);
current_printer_execute_feature(PrinterFeatures::PrinterFeatureDisableSteppers);
}

static void switch_to_stat_panel(lv_event_t * e) {
Expand All @@ -197,7 +196,7 @@ static void line_custom_set(const char * axis, const char *text)
if (pos < 0 || pos > 500)
return;

get_current_printer()->move_printer(axis, pos, false);
current_printer_move_printer(axis, pos, false);
}

static void x_line_custom_callback(lv_event_t * e) {
Expand Down
9 changes: 5 additions & 4 deletions CYD-Klipper/src/ui/panels/progress_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdio.h>
#include "../ui_utils.h"
#include "../../core/printer_integration.hpp"
#include "../../core/current_printer.h"

char time_buffer[12];

Expand Down Expand Up @@ -58,19 +59,19 @@ static void update_printer_data_percentage(lv_event_t * e){
}

static void btn_click_stop(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureStop);
current_printer_execute_feature(PrinterFeatures::PrinterFeatureStop);
}

static void btn_click_pause(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeaturePause);
current_printer_execute_feature(PrinterFeatures::PrinterFeaturePause);
}

static void btn_click_resume(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureResume);
current_printer_execute_feature(PrinterFeatures::PrinterFeatureResume);
}

static void btn_click_estop(lv_event_t * e){
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureEmergencyStop);
current_printer_execute_feature(PrinterFeatures::PrinterFeatureEmergencyStop);
}

void progress_panel_init(lv_obj_t* panel){
Expand Down
13 changes: 7 additions & 6 deletions CYD-Klipper/src/ui/panels/temp_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <HardwareSerial.h>
#include "../ui_utils.h"
#include "../../core/printer_integration.hpp"
#include "../../core/current_printer.h"

enum temp_target{
TARGET_HOTEND,
Expand Down Expand Up @@ -85,10 +86,10 @@ static void keyboard_callback(lv_event_t * e){

switch (keyboard_target){
case TARGET_HOTEND:
get_current_printer()->set_target_temperature(PrinterTemperatureDevice::PrinterTemperatureDeviceNozzle1, temp);
current_printer_set_target_temperature(PrinterTemperatureDevice::PrinterTemperatureDeviceNozzle1, temp);
break;
case TARGET_BED:
get_current_printer()->set_target_temperature(PrinterTemperatureDevice::PrinterTemperatureDeviceBed, temp);
current_printer_set_target_temperature(PrinterTemperatureDevice::PrinterTemperatureDeviceBed, temp);
break;
case TARGET_HOTEND_CONFIG_1:
get_current_printer()->printer_config->hotend_presets[0] = temp;
Expand Down Expand Up @@ -132,15 +133,15 @@ static void cooldown_temp(lv_event_t * e){
return;
}

get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureCooldown);
current_printer_execute_feature(PrinterFeatures::PrinterFeatureCooldown);
}

static void btn_extrude(lv_event_t * e){
if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting){
return;
}

get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureExtrude);
current_printer_execute_feature(PrinterFeatures::PrinterFeatureExtrude);
}

static void set_temp_via_preset(lv_event_t * e){
Expand All @@ -153,7 +154,7 @@ static void set_temp_via_preset(lv_event_t * e){
return;
}

get_current_printer()->set_target_temperature(TARGET_HOTEND_CONFIG_3
current_printer_set_target_temperature(TARGET_HOTEND_CONFIG_3
? PrinterTemperatureDevice::PrinterTemperatureDeviceNozzle1
: PrinterTemperatureDevice::PrinterTemperatureDeviceBed
, value);
Expand All @@ -170,7 +171,7 @@ static void btn_retract(lv_event_t * e){
return;
}

get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureRetract);
current_printer_execute_feature(PrinterFeatures::PrinterFeatureRetract);
}

static void set_chart_range(lv_event_t * e) {
Expand Down
Loading

0 comments on commit 92b7b68

Please sign in to comment.