🎨 Misc. DGUS cleanup

This commit is contained in:
Scott Lahteine 2022-02-10 16:03:48 -06:00
parent 9f57f6f36f
commit 2a584cea96
11 changed files with 48 additions and 36 deletions

View file

@ -46,6 +46,12 @@
DGUSDisplay dgusdisplay;
#ifdef DEBUG_DGUSLCD_COMM
#define DEBUGLCDCOMM_ECHOPGM DEBUG_ECHOPGM
#else
#define DEBUGLCDCOMM_ECHOPGM(...) NOOP
#endif
// Preamble... 2 Bytes, usually 0x5A 0xA5, but configurable
constexpr uint8_t DGUS_HEADER1 = 0x5A;
constexpr uint8_t DGUS_HEADER2 = 0xA5;
@ -154,19 +160,19 @@ void DGUSDisplay::ProcessRx() {
case DGUS_IDLE: // Waiting for the first header byte
receivedbyte = LCD_SERIAL.read();
//DEBUG_ECHOPGM("< ",x);
//DEBUGLCDCOMM_ECHOPGM("< ", receivedbyte);
if (DGUS_HEADER1 == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN;
break;
case DGUS_HEADER1_SEEN: // Waiting for the second header byte
receivedbyte = LCD_SERIAL.read();
//DEBUG_ECHOPGM(" ",x);
//DEBUGLCDCOMM_ECHOPGM(" ", receivedbyte);
rx_datagram_state = (DGUS_HEADER2 == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE;
break;
case DGUS_HEADER2_SEEN: // Waiting for the length byte
rx_datagram_len = LCD_SERIAL.read();
DEBUG_ECHOPGM(" (", rx_datagram_len, ") ");
//DEBUGLCDCOMM_ECHOPGM(" (", rx_datagram_len, ") ");
// Telegram min len is 3 (command and one word of payload)
rx_datagram_state = WITHIN(rx_datagram_len, 3, DGUS_RX_BUFFER_SIZE) ? DGUS_WAIT_TELEGRAM : DGUS_IDLE;
@ -178,20 +184,20 @@ void DGUSDisplay::ProcessRx() {
Initialized = true; // We've talked to it, so we defined it as initialized.
uint8_t command = LCD_SERIAL.read();
DEBUG_ECHOPGM("# ", command);
//DEBUGLCDCOMM_ECHOPGM("# ", command);
uint8_t readlen = rx_datagram_len - 1; // command is part of len.
unsigned char tmp[rx_datagram_len - 1];
unsigned char *ptmp = tmp;
while (readlen--) {
receivedbyte = LCD_SERIAL.read();
DEBUG_ECHOPGM(" ", receivedbyte);
//DEBUGLCDCOMM_ECHOPGM(" ", receivedbyte);
*ptmp++ = receivedbyte;
}
DEBUG_ECHOPGM(" # ");
//DEBUGLCDCOMM_ECHOPGM(" # ");
// mostly we'll get this: 5A A5 03 82 4F 4B -- ACK on 0x82, so discard it.
if (command == DGUS_CMD_WRITEVAR && 'O' == tmp[0] && 'K' == tmp[1]) {
DEBUG_ECHOLNPGM(">");
//DEBUGLCDCOMM_ECHOPGM(">");
rx_datagram_state = DGUS_IDLE;
break;
}
@ -253,16 +259,16 @@ void DGUSDisplay::loop() {
rx_datagram_state_t DGUSDisplay::rx_datagram_state = DGUS_IDLE;
uint8_t DGUSDisplay::rx_datagram_len = 0;
bool DGUSDisplay::Initialized = false;
bool DGUSDisplay::no_reentrance = false;
bool DGUSDisplay::Initialized = false,
DGUSDisplay::no_reentrance = false;
// A SW memory barrier, to ensure GCC does not overoptimize loops
#define sw_barrier() asm volatile("": : :"memory");
bool populate_VPVar(const uint16_t VP, DGUS_VP_Variable * const ramcopy) {
// DEBUG_ECHOPGM("populate_VPVar ", VP);
//DEBUG_ECHOPGM("populate_VPVar ", VP);
const DGUS_VP_Variable *pvp = DGUSLCD_FindVPVar(VP);
// DEBUG_ECHOLNPGM(" pvp ", (uint16_t )pvp);
//DEBUG_ECHOLNPGM(" pvp ", (uint16_t )pvp);
if (!pvp) return false;
memcpy_P(ramcopy, pvp, sizeof(DGUS_VP_Variable));
return true;

View file

@ -29,6 +29,9 @@
#include <stdlib.h> // size_t
//#define DEBUG_DGUSLCD
//#define DEBUG_DGUSLCD_COMM
#if HAS_BED_PROBE
#include "../../../module/probe.h"
#endif

View file

@ -55,14 +55,14 @@ void (*DGUSScreenHandler::confirm_action_cb)() = nullptr;
#if ENABLED(SDSUPPORT)
int16_t DGUSScreenHandler::top_file = 0,
DGUSScreenHandler::file_to_print = 0;
static ExtUI::FileList filelist;
ExtUI::FileList filelist;
#endif
#if ENABLED(DGUS_FILAMENT_LOADUNLOAD)
filament_data_t filament_data;
#endif
void DGUSScreenHandler::sendinfoscreen(const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool l4inflash) {
void DGUSScreenHandler::sendinfoscreen(PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool l4inflash) {
DGUS_VP_Variable ramcopy;
if (populate_VPVar(VP_MSGSTR1, &ramcopy)) {
ramcopy.memadr = (void*) line1;
@ -76,13 +76,15 @@ void DGUSScreenHandler::sendinfoscreen(const char *line1, const char *line2, con
ramcopy.memadr = (void*) line3;
l3inflash ? DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(ramcopy) : DGUSScreenHandler::DGUSLCD_SendStringToDisplay(ramcopy);
}
#ifdef VP_MSGSTR4
if (populate_VPVar(VP_MSGSTR4, &ramcopy)) {
ramcopy.memadr = (void*) line4;
l4inflash ? DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(ramcopy) : DGUSScreenHandler::DGUSLCD_SendStringToDisplay(ramcopy);
}
#endif
}
void DGUSScreenHandler::HandleUserConfirmationPopUp(uint16_t VP, const char *line1, const char *line2, const char *line3, const char *line4, bool l1, bool l2, bool l3, bool l4) {
void DGUSScreenHandler::HandleUserConfirmationPopUp(uint16_t VP, PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1, bool l2, bool l3, bool l4) {
if (current_screen == DGUSLCD_SCREEN_CONFIRM) // Already showing a pop up, so we need to cancel that first.
PopToOldScreen();
@ -344,6 +346,7 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var)
SetupConfirmAction(nullptr);
GotoScreen(DGUSLCD_SCREEN_POPUP);
}
#endif // SDSUPPORT
void DGUSScreenHandler::ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr) {

View file

@ -42,7 +42,7 @@
#if ENABLED(SDSUPPORT)
static ExtUI::FileList filelist;
extern ExtUI::FileList filelist;
void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file;

View file

@ -37,15 +37,15 @@ public:
// Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen
// The bools specifying whether the strings are in RAM or FLASH.
static void sendinfoscreen(const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
static void sendinfoscreen(PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
sendinfoscreen(FTOP(line1), FTOP(line2), line3, line4, l1inflash, l2inflash, l3inflash, liinflash);
}
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, FSTR_P const line3, FSTR_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
sendinfoscreen(FTOP(line1), FTOP(line2), FTOP(line3), FTOP(line4), l1inflash, l2inflash, l3inflash, liinflash);
}
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
// "M117" Message -- msg is a RAM ptr.
static void setstatusmessage(const char *msg);

View file

@ -42,7 +42,7 @@
#if ENABLED(SDSUPPORT)
static ExtUI::FileList filelist;
extern ExtUI::FileList filelist;
void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file;

View file

@ -37,15 +37,15 @@ public:
// Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen
// The bools specifying whether the strings are in RAM or FLASH.
static void sendinfoscreen(const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
static void sendinfoscreen(PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
sendinfoscreen(FTOP(line1), FTOP(line2), line3, line4, l1inflash, l2inflash, l3inflash, liinflash);
}
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, FSTR_P const line3, FSTR_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
sendinfoscreen(FTOP(line1), FTOP(line2), FTOP(line3), FTOP(line4), l1inflash, l2inflash, l3inflash, liinflash);
}
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
// "M117" Message -- msg is a RAM ptr.
static void setstatusmessage(const char *msg);

View file

@ -48,7 +48,7 @@
#endif
#if ENABLED(SDSUPPORT)
static ExtUI::FileList filelist;
extern ExtUI::FileList filelist;
#endif
bool DGUSAutoTurnOff = false;
@ -65,7 +65,7 @@ void DGUSScreenHandler::sendinfoscreen_ch_mks(const uint16_t *line1, const uint1
dgusdisplay.WriteVariable(VP_MSGSTR4, line4, 32, true);
}
void DGUSScreenHandler::sendinfoscreen_en_mks(const char *line1, const char *line2, const char *line3, const char *line4) {
void DGUSScreenHandler::sendinfoscreen_en_mks(PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4) {
dgusdisplay.WriteVariable(VP_MSGSTR1, line1, 32, true);
dgusdisplay.WriteVariable(VP_MSGSTR2, line2, 32, true);
dgusdisplay.WriteVariable(VP_MSGSTR3, line3, 32, true);

View file

@ -37,19 +37,19 @@ public:
// Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen
// The bools specifying whether the strings are in RAM or FLASH.
static void sendinfoscreen(const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
static void sendinfoscreen(PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
sendinfoscreen(FTOP(line1), FTOP(line2), line3, line4, l1inflash, l2inflash, l3inflash, liinflash);
}
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, FSTR_P const line3, FSTR_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
sendinfoscreen(FTOP(line1), FTOP(line2), FTOP(line3), FTOP(line4), l1inflash, l2inflash, l3inflash, liinflash);
}
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
#if 0
static void sendinfoscreen_ch_mks(const uint16_t *line1, const uint16_t *line2, const uint16_t *line3, const uint16_t *line4);
static void sendinfoscreen_en_mks(const char *line1, const char *line2, const char *line3, const char *line4) ;
static void sendinfoscreen_en_mks(PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4);
static void sendinfoscreen_mks(const void *line1, const void *line2, const void *line3, const void *line4, uint16_t language);
#endif

View file

@ -42,7 +42,7 @@
#if ENABLED(SDSUPPORT)
static ExtUI::FileList filelist;
extern ExtUI::FileList filelist;
void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) {
uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file;

View file

@ -37,15 +37,15 @@ public:
// Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen
// The bools specifying whether the strings are in RAM or FLASH.
static void sendinfoscreen(const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
static void sendinfoscreen(PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
sendinfoscreen(FTOP(line1), FTOP(line2), line3, line4, l1inflash, l2inflash, l3inflash, liinflash);
}
static void sendinfoscreen(FSTR_P const line1, FSTR_P const line2, FSTR_P const line3, FSTR_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash) {
sendinfoscreen(FTOP(line1), FTOP(line2), FTOP(line3), FTOP(line4), l1inflash, l2inflash, l3inflash, liinflash);
}
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char *line1, const char *line2, const char *line3, const char *line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, PGM_P const line1, PGM_P const line2, PGM_P const line3, PGM_P const line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
// "M117" Message -- msg is a RAM ptr.
static void setstatusmessage(const char *msg);