1111static u8g2_t myDisplay ;
1212
1313static char lcd_buf [20 ] = {0 };
14- static const char * seg_name = NULL ;
15- static char seg_index_str [] = {'(' , 'X' , ')' ,'\0' };
1614
1715uint8_t u8x8_gpio_and_delay (u8x8_t * u8x8 , uint8_t msg , uint8_t arg_int , void * arg_ptr )
1816{
@@ -136,20 +134,45 @@ void Display_Init(void)
136134 u8g2_ClearDisplay (& myDisplay );
137135}
138136
139- void Display_ShowCode (uint16_t code , uint8_t segment ) {
140- seg_name = POST_GetSegmentName (segment );
141- // Convert numeric index to ASCII character
142- seg_index_str [1 ] = POST_GetSegmentIndex (segment ) + '0' ;
137+ static void drawCenteredStr (int16_t y , const char * str ) {
138+ int16_t x = (64 - u8g2_GetStrWidth (& myDisplay , str )) / 2 ;
139+ if (x < 0 ) {
140+ x = 0 ;
141+ }
142+ u8g2_DrawStr (& myDisplay , x , y , str );
143+ }
143144
144- // Assemble content
145- snprintf (lcd_buf , sizeof (lcd_buf ), "%04X" , code );
145+ void Display_ShowCode (uint64_t code , const char * flavor ) {
146+ // Unpadded hex digit count, to decide layout below.
147+ uint64_t tmp = code ;
148+ int digits = 1 ;
149+ while (tmp > 0xF ) {
150+ tmp >>= 4 ;
151+ digits ++ ;
152+ }
146153
147154 u8g2_ClearDisplay (& myDisplay );
148- u8g2_SetFont (& myDisplay , u8g2_font_luBS14_tr );
149- u8g2_DrawStr (& myDisplay , 4 , 32 , lcd_buf );
150- u8g2_SetFont (& myDisplay , u8g2_font_7x13_mr );
151- u8g2_DrawStr (& myDisplay , 12 , 10 , seg_name );
152- u8g2_DrawStr (& myDisplay , 40 , 10 , seg_index_str );
155+
156+ u8g2_SetFont (& myDisplay , u8g2_font_5x7_mr );
157+ u8g2_DrawStr (& myDisplay , 2 , 7 , flavor );
158+
159+ if (digits <= 8 ) {
160+ // Fits in 32 bits: single, bigger line.
161+ char buf [9 ];
162+ snprintf (buf , sizeof (buf ), "%lX" , (unsigned long )code );
163+ u8g2_SetFont (& myDisplay , u8g2_font_7x13_mr );
164+ drawCenteredStr (30 , buf );
165+ } else {
166+ // Longer code: split across two lines, one 32-bit half each.
167+ char hiBuf [9 ];
168+ char loBuf [9 ];
169+ snprintf (hiBuf , sizeof (hiBuf ), "%lX" , (unsigned long )(code >> 32 ));
170+ snprintf (loBuf , sizeof (loBuf ), "%lX" , (unsigned long )code );
171+ u8g2_SetFont (& myDisplay , u8g2_font_6x10_mr );
172+ drawCenteredStr (18 , hiBuf );
173+ drawCenteredStr (29 , loBuf );
174+ }
175+
153176 u8g2_SendBuffer (& myDisplay );
154177}
155178
@@ -160,13 +183,12 @@ void Display_ShowCode(uint16_t code, uint8_t segment) {
160183 */
161184void Display_Tick (void )
162185{
186+ PostCode postCode ;
187+
163188 if (Slave_HardError ()) {
164189 Display_Print ("BUS ERROR" );
165- } else if (Slave_IsNewSegmentAvailable ()) {
166- Display_ShowCode (
167- POST_ReadCode (),
168- POST_ReadSegment ()
169- );
190+ } else if (Slave_IsNewSegmentAvailable () && POST_ProcessSegment (& postCode )) {
191+ Display_ShowCode (postCode .code , POST_GetSegmentName (postCode .flavor ));
170192 } else if (Button_IsPressed ()) {
171193 Display_Print ("BtnPress" );
172194 }
0 commit comments