@ -59,23 +59,13 @@ constexpr uint8_t DGUS_CMD_READVAR = 0x83;
bool dguslcd_local_debug ; // = false;
bool dguslcd_local_debug ; // = false;
# endif
# endif
# define dgusserial DGUS_SERIAL
void DGUSDisplay : : InitDisplay ( ) {
void DGUSDisplay : : InitDisplay ( ) {
dgusserial . begin ( DGUS_BAUDRATE ) ;
# ifndef LCD_BAUDRATE
# define LCD_BAUDRATE 115200
if ( true
# endif
# if ENABLED(POWER_LOSS_RECOVERY)
LCD_SERIAL . begin ( LCD_BAUDRATE ) ;
& & ! recovery . valid ( )
if ( TERN1 ( POWER_LOSS_RECOVERY , ! recovery . valid ( ) ) )
# endif
RequestScreen ( TERN ( SHOW_BOOTSCREEN , DGUSLCD_SCREEN_BOOT , DGUSLCD_SCREEN_MAIN ) ) ;
)
RequestScreen (
# if ENABLED(SHOW_BOOTSCREEN)
DGUSLCD_SCREEN_BOOT
# else
DGUSLCD_SCREEN_MAIN
# endif
) ;
}
}
void DGUSDisplay : : WriteVariable ( uint16_t adr , const void * values , uint8_t valueslen , bool isstr ) {
void DGUSDisplay : : WriteVariable ( uint16_t adr , const void * values , uint8_t valueslen , bool isstr ) {
@ -89,7 +79,7 @@ void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t values
strend = true ;
strend = true ;
x = ' ' ;
x = ' ' ;
}
}
dgusserial . write ( x ) ;
LCD_SERIAL . write ( x ) ;
}
}
}
}
@ -133,41 +123,41 @@ void DGUSDisplay::WriteVariablePGM(uint16_t adr, const void* values, uint8_t val
strend = true ;
strend = true ;
x = ' ' ;
x = ' ' ;
}
}
dgusserial . write ( x ) ;
LCD_SERIAL . write ( x ) ;
}
}
}
}
void DGUSDisplay : : ProcessRx ( ) {
void DGUSDisplay : : ProcessRx ( ) {
# if ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS)
# if ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS)
if ( ! dgusserial. available ( ) & & dgusserial . buffer_overruns ( ) ) {
if ( ! LCD_SERIAL. available ( ) & & LCD_SERIAL . buffer_overruns ( ) ) {
// Overrun, but reset the flag only when the buffer is empty
// Overrun, but reset the flag only when the buffer is empty
// We want to extract as many as valid datagrams possible...
// We want to extract as many as valid datagrams possible...
DEBUG_ECHOPGM ( " OVFL " ) ;
DEBUG_ECHOPGM ( " OVFL " ) ;
rx_datagram_state = DGUS_IDLE ;
rx_datagram_state = DGUS_IDLE ;
// dgusserial .reset_rx_overun();
// LCD_SERIAL .reset_rx_overun();
dgusserial . flush ( ) ;
LCD_SERIAL . flush ( ) ;
}
}
# endif
# endif
uint8_t receivedbyte ;
uint8_t receivedbyte ;
while ( dgusserial . available ( ) ) {
while ( LCD_SERIAL . available ( ) ) {
switch ( rx_datagram_state ) {
switch ( rx_datagram_state ) {
case DGUS_IDLE : // Waiting for the first header byte
case DGUS_IDLE : // Waiting for the first header byte
receivedbyte = dgusserial . read ( ) ;
receivedbyte = LCD_SERIAL . read ( ) ;
//DEBUG_ECHOPAIR("< ",x);
//DEBUG_ECHOPAIR("< ",x);
if ( DGUS_HEADER1 = = receivedbyte ) rx_datagram_state = DGUS_HEADER1_SEEN ;
if ( DGUS_HEADER1 = = receivedbyte ) rx_datagram_state = DGUS_HEADER1_SEEN ;
break ;
break ;
case DGUS_HEADER1_SEEN : // Waiting for the second header byte
case DGUS_HEADER1_SEEN : // Waiting for the second header byte
receivedbyte = dgusserial . read ( ) ;
receivedbyte = LCD_SERIAL . read ( ) ;
//DEBUG_ECHOPAIR(" ",x);
//DEBUG_ECHOPAIR(" ",x);
rx_datagram_state = ( DGUS_HEADER2 = = receivedbyte ) ? DGUS_HEADER2_SEEN : DGUS_IDLE ;
rx_datagram_state = ( DGUS_HEADER2 = = receivedbyte ) ? DGUS_HEADER2_SEEN : DGUS_IDLE ;
break ;
break ;
case DGUS_HEADER2_SEEN : // Waiting for the length byte
case DGUS_HEADER2_SEEN : // Waiting for the length byte
rx_datagram_len = dgusserial . read ( ) ;
rx_datagram_len = LCD_SERIAL . read ( ) ;
DEBUG_ECHOPAIR ( " ( " , rx_datagram_len , " ) " ) ;
DEBUG_ECHOPAIR ( " ( " , rx_datagram_len , " ) " ) ;
// Telegram min len is 3 (command and one word of payload)
// Telegram min len is 3 (command and one word of payload)
@ -175,10 +165,10 @@ void DGUSDisplay::ProcessRx() {
break ;
break ;
case DGUS_WAIT_TELEGRAM : // wait for complete datagram to arrive.
case DGUS_WAIT_TELEGRAM : // wait for complete datagram to arrive.
if ( dgusserial . available ( ) < rx_datagram_len ) return ;
if ( LCD_SERIAL . available ( ) < rx_datagram_len ) return ;
Initialized = true ; // We've talked to it, so we defined it as initialized.
Initialized = true ; // We've talked to it, so we defined it as initialized.
uint8_t command = dgusserial . read ( ) ;
uint8_t command = LCD_SERIAL . read ( ) ;
DEBUG_ECHOPAIR ( " # " , command ) ;
DEBUG_ECHOPAIR ( " # " , command ) ;
@ -186,7 +176,7 @@ void DGUSDisplay::ProcessRx() {
unsigned char tmp [ rx_datagram_len - 1 ] ;
unsigned char tmp [ rx_datagram_len - 1 ] ;
unsigned char * ptmp = tmp ;
unsigned char * ptmp = tmp ;
while ( readlen - - ) {
while ( readlen - - ) {
receivedbyte = dgusserial . read ( ) ;
receivedbyte = LCD_SERIAL . read ( ) ;
DEBUG_ECHOPAIR ( " " , receivedbyte ) ;
DEBUG_ECHOPAIR ( " " , receivedbyte ) ;
* ptmp + + = receivedbyte ;
* ptmp + + = receivedbyte ;
}
}
@ -229,19 +219,19 @@ void DGUSDisplay::ProcessRx() {
}
}
}
}
size_t DGUSDisplay : : GetFreeTxBuffer ( ) { return DGUS_ SERIAL_GET_TX_BUFFER_FREE( ) ; }
size_t DGUSDisplay : : GetFreeTxBuffer ( ) { return SERIAL_GET_TX_BUFFER_FREE( ) ; }
void DGUSDisplay : : WriteHeader ( uint16_t adr , uint8_t cmd , uint8_t payloadlen ) {
void DGUSDisplay : : WriteHeader ( uint16_t adr , uint8_t cmd , uint8_t payloadlen ) {
dgusserial . write ( DGUS_HEADER1 ) ;
LCD_SERIAL . write ( DGUS_HEADER1 ) ;
dgusserial . write ( DGUS_HEADER2 ) ;
LCD_SERIAL . write ( DGUS_HEADER2 ) ;
dgusserial . write ( payloadlen + 3 ) ;
LCD_SERIAL . write ( payloadlen + 3 ) ;
dgusserial . write ( cmd ) ;
LCD_SERIAL . write ( cmd ) ;
dgusserial . write ( adr > > 8 ) ;
LCD_SERIAL . write ( adr > > 8 ) ;
dgusserial . write ( adr & 0xFF ) ;
LCD_SERIAL . write ( adr & 0xFF ) ;
}
}
void DGUSDisplay : : WritePGM ( const char str [ ] , uint8_t len ) {
void DGUSDisplay : : WritePGM ( const char str [ ] , uint8_t len ) {
while ( len - - ) dgusserial . write ( pgm_read_byte ( str + + ) ) ;
while ( len - - ) LCD_SERIAL . write ( pgm_read_byte ( str + + ) ) ;
}
}
void DGUSDisplay : : loop ( ) {
void DGUSDisplay : : loop ( ) {