Skip to content

Commit

Permalink
Clean up, optimize ExtUI/TFT code (MarlinFirmware#21333)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored Mar 12, 2021
1 parent 9dc2712 commit 1affbe2
Show file tree
Hide file tree
Showing 20 changed files with 321 additions and 334 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/bedlevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ TemporaryBedLevelingState::TemporaryBedLevelingState(const bool enable) : saved(

#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)

void set_z_fade_height(const float zfh, const bool do_report/*=true*/) {
void set_z_fade_height(const float &zfh, const bool do_report/*=true*/) {

if (planner.z_fade_height == zfh) return;

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/bedlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void set_bed_leveling_enabled(const bool enable=true);
void reset_bed_level();

#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
void set_z_fade_height(const float zfh, const bool do_report=true);
void set_z_fade_height(const float &zfh, const bool do_report=true);
#endif

#if EITHER(MESH_BED_LEVELING, PROBE_MANUALLY)
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace ExtUI {
// into buff.

// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// static_assert(sizeof(myDataStruct) <= eeprom_data_size);
// memcpy(buff, &myDataStruct, sizeof(myDataStruct));
}

Expand All @@ -84,7 +84,7 @@ namespace ExtUI {
// from buff

// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// static_assert(sizeof(myDataStruct) <= eeprom_data_size);
// memcpy(&myDataStruct, buff, sizeof(myDataStruct));
}

Expand All @@ -101,12 +101,12 @@ namespace ExtUI {
#if HAS_MESH
void onMeshLevelingStart() {}

void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float &zval) {
// Called when any mesh points are updated
//SERIAL_ECHOLNPAIR("onMeshUpdate() x:", xpos, " y:", ypos, " z:", zval);
}

void onMeshUpdate(const int8_t xpos, const int8_t ypos, const ExtUI::probe_state_t state) {
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const probe_state_t state) {
// Called to indicate a special condition
//SERIAL_ECHOLNPAIR("onMeshUpdate() x:", xpos, " y:", ypos, " state:", state);
}
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/anycubic_i3mega_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace ExtUI {
// into buff.

// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// static_assert(sizeof(myDataStruct) <= eeprom_data_size);
// memcpy(buff, &myDataStruct, sizeof(myDataStruct));
}

Expand All @@ -75,7 +75,7 @@ namespace ExtUI {
// from buff

// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// static_assert(sizeof(myDataStruct) <= eeprom_data_size);
// memcpy(&myDataStruct, buff, sizeof(myDataStruct));
}

Expand All @@ -93,7 +93,7 @@ namespace ExtUI {

void onMeshLevelingStart() {}

void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float &zval) {
// Called when any mesh points are updated
}
#endif
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/lcd/extui/dgus_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace ExtUI {
void onUserConfirmRequired(const char * const msg) {
if (msg) {
ScreenHandler.sendinfoscreen(PSTR("Please confirm."), nullptr, msg, nullptr, true, true, false, true);
ScreenHandler.SetupConfirmAction(ExtUI::setUserConfirmed);
ScreenHandler.SetupConfirmAction(setUserConfirmed);
ScreenHandler.GotoScreen(DGUSLCD_SCREEN_POPUP);
}
else if (ScreenHandler.getCurrentScreen() == DGUSLCD_SCREEN_POPUP ) {
Expand All @@ -84,7 +84,7 @@ namespace ExtUI {
// into buff.

// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// static_assert(sizeof(myDataStruct) <= eeprom_data_size);
// memcpy(buff, &myDataStruct, sizeof(myDataStruct));
}

Expand All @@ -94,7 +94,7 @@ namespace ExtUI {
// from buff

// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// static_assert(sizeof(myDataStruct) <= eeprom_data_size);
// memcpy(&myDataStruct, buff, sizeof(myDataStruct));
}

Expand All @@ -111,11 +111,11 @@ namespace ExtUI {
#if HAS_MESH
void onMeshLevelingStart() {}

void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float &zval) {
// Called when any mesh points are updated
}

void onMeshUpdate(const int8_t xpos, const int8_t ypos, const ExtUI::probe_state_t state) {
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const probe_state_t state) {
// Called to indicate a special condition
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/lcd/extui/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace ExtUI {
// into buff.

// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// static_assert(sizeof(myDataStruct) <= eeprom_data_size);
// memcpy(buff, &myDataStruct, sizeof(myDataStruct));
}

Expand All @@ -80,7 +80,7 @@ namespace ExtUI {
// from buff

// Example:
// static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
// static_assert(sizeof(myDataStruct) <= eeprom_data_size);
// memcpy(&myDataStruct, buff, sizeof(myDataStruct));
}

Expand All @@ -97,11 +97,11 @@ namespace ExtUI {
#if HAS_MESH
void onMeshLevelingStart() {}

void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float &zval) {
// Called when any mesh points are updated
}

void onMeshUpdate(const int8_t xpos, const int8_t ypos, const ExtUI::probe_state_t state) {
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const probe_state_t state) {
// Called to indicate a special condition
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/extui/lib/anycubic_chiron/FileNavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace Anycubic {
// Each time we change folder we reset the file index to 0 and keep track
// of the current position as the TFT panel isnt aware of folders trees.
if (index > 0) {
--currentindex; // go back a file to take account off the .. we added to the root.
--currentindex; // go back a file to take account of the .. added to the root.
if (index > lastindex)
currentindex += files;
else
Expand Down
5 changes: 3 additions & 2 deletions Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace Anycubic {
SERIAL_ECHOLNPGM("Select SD file then press resume");
}

void ChironTFT::SendtoTFT(PGM_P str) { // A helper to print PROGMEN string to the panel
void ChironTFT::SendtoTFT(PGM_P str) { // A helper to print PROGMEM string to the panel
#if ACDEBUG(AC_SOME)
SERIAL_ECHOPGM_P(str);
#endif
Expand Down Expand Up @@ -880,6 +880,7 @@ namespace Anycubic {
} break;
}
}
} // namespace

} // Anycubic

#endif // ANYCUBIC_LCD_CHIRON
67 changes: 35 additions & 32 deletions Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,49 @@
#include "chiron_tft_defs.h"
#include "../../../../inc/MarlinConfigPre.h"
#include "../../ui_api.h"

namespace Anycubic {

class ChironTFT {
static printer_state_t printer_state;
static paused_state_t pause_state;
static heater_state_t hotend_state;
static heater_state_t hotbed_state;
static xy_uint8_t selectedmeshpoint;
static char panel_command[MAX_CMND_LEN];
static uint8_t command_len;
static char selectedfile[MAX_PATH_LEN];
static float live_Zoffset;
static file_menu_t file_menu;
private:
static printer_state_t printer_state;
static paused_state_t pause_state;
static heater_state_t hotend_state;
static heater_state_t hotbed_state;
static xy_uint8_t selectedmeshpoint;
static char panel_command[MAX_CMND_LEN];
static uint8_t command_len;
static char selectedfile[MAX_PATH_LEN];
static float live_Zoffset;
static file_menu_t file_menu;

public:
ChironTFT();
void Startup();
void IdleLoop();
void PrinterKilled(PGM_P,PGM_P);
void MediaEvent(media_event_t);
void TimerEvent(timer_event_t);
void FilamentRunout();
void ConfirmationRequest(const char * const );
void StatusChange(const char * const );
void PowerLossRecovery();
static void Startup();
static void IdleLoop();
static void PrinterKilled(PGM_P,PGM_P);
static void MediaEvent(media_event_t);
static void TimerEvent(timer_event_t);
static void FilamentRunout();
static void ConfirmationRequest(const char * const );
static void StatusChange(const char * const );
static void PowerLossRecovery();

private:
void SendtoTFT(PGM_P);
void SendtoTFTLN(PGM_P);
bool ReadTFTCommand();
int8_t Findcmndpos(const char *, char);
void CheckHeaters();
void SendFileList(int8_t);
void SelectFile();
void InjectCommandandWait(PGM_P);
void ProcessPanelRequest();
void PanelInfo(uint8_t);
void PanelAction(uint8_t);
void PanelProcess(uint8_t);
static void SendtoTFT(PGM_P);
static void SendtoTFTLN(PGM_P);
static bool ReadTFTCommand();
static int8_t Findcmndpos(const char *, char);
static void CheckHeaters();
static void SendFileList(int8_t);
static void SelectFile();
static void InjectCommandandWait(PGM_P);
static void ProcessPanelRequest();
static void PanelInfo(uint8_t);
static void PanelAction(uint8_t);
static void PanelProcess(uint8_t);
};

extern ChironTFT Chiron;

}
} // Anycubic
4 changes: 3 additions & 1 deletion Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#define AC_cmnd_power_loss_recovery PSTR("G28XYR5\nG28Z") // Lift, home X and Y then home Z when in 'safe' position

namespace Anycubic {

enum heater_state_t : uint8_t {
AC_heater_off,
AC_heater_temp_set,
Expand Down Expand Up @@ -148,4 +149,5 @@ namespace Anycubic {
AC_menu_change_to_file,
AC_menu_change_to_command
};
}

} // Anycubic
Loading

0 comments on commit 1affbe2

Please sign in to comment.