application: display text on OLED
This commit is contained in:
parent
da0a440e0e
commit
e1802fcc2f
|
@ -47,6 +47,7 @@
|
|||
#include "menu.h" // menu utilities
|
||||
#include "usb_cables.h" // USB cables definition
|
||||
#include "lcd_hd44780.h" // LCD utilities
|
||||
#include "oled_text.h" // OLED utilities to display text
|
||||
|
||||
/** watchdog period in ms */
|
||||
#define WATCHDOG_PERIOD 10000
|
||||
|
@ -1420,6 +1421,13 @@ void main(void)
|
|||
printf("could not start LCD\n");
|
||||
}
|
||||
|
||||
// setup OLED display
|
||||
oled_text_setup();
|
||||
oled_text_clear();
|
||||
oled_text_line(lcd_default_line1, 0);
|
||||
oled_text_line(lcd_default_line2, 1);
|
||||
oled_text_update();
|
||||
|
||||
// setup USB connectors
|
||||
gpio_primary_remap(AFIO_MAPR_SWJ_CFG_JTAG_OFF_SW_ON, 0); // only use SWD and reuse JTAG pins
|
||||
rcc_periph_clock_enable(RCC_GPIOA); // enable clock to all GPIO port domains since we use them all
|
||||
|
@ -1470,6 +1478,10 @@ void main(void)
|
|||
lcd_hd44780_clear_display();
|
||||
lcd_hd44780_write_line(false, lcd_interactive_line1, strlen(lcd_interactive_line1));
|
||||
lcd_hd44780_write_line(true, lcd_interactive_line2, strlen(lcd_interactive_line2));
|
||||
oled_text_clear();
|
||||
oled_text_line(lcd_interactive_line1, 0);
|
||||
oled_text_line(lcd_interactive_line2, 1);
|
||||
oled_text_update();
|
||||
}
|
||||
char c = user_input_get(); // store receive character
|
||||
terminal_send(c); // send received character to terminal
|
||||
|
@ -1520,25 +1532,46 @@ void main(void)
|
|||
lcd_hd44780_clear_display(); // be sure the display is cleared
|
||||
lcd_hd44780_write_line(false, lcd_default_line1, strlen(lcd_default_line1));
|
||||
lcd_hd44780_write_line(true, lcd_default_line2, strlen(lcd_default_line2));
|
||||
oled_text_clear();
|
||||
oled_text_line(lcd_default_line1, 0);
|
||||
oled_text_line(lcd_default_line2, 1);
|
||||
oled_text_update();
|
||||
} else { // there is a new confirmed cable
|
||||
cable_load(cable_current); // check if there is a load
|
||||
cable_issues(cable_current); // get the exact issues
|
||||
lcd_hd44780_clear_display(); // clear display
|
||||
oled_text_clear();
|
||||
if (cable_current->cable_best < LENGTH(usb_cables) && cable_current->cable_best < LENGTH(cable_current->unconnected_nb) && cable_current->cable_best < LENGTH(cable_current->unspecified_nb)) {
|
||||
const struct usb_cable_t* usb_cable = &usb_cables[cable_current->cable_best];
|
||||
lcd_hd44780_write_line(false, usb_cable->name, strlen(usb_cable->name));
|
||||
oled_text_line(usb_cable->name, 0);
|
||||
char line[17] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\0'}; // line to display
|
||||
if (cable_current->load) {
|
||||
snprintf(line, LENGTH(line), "with load");
|
||||
} else {
|
||||
snprintf(line, LENGTH(line), "without load");
|
||||
}
|
||||
oled_text_line(line, 2);
|
||||
uint16_t issues = cable_current->unconnected_nb[cable_current->cable_best] + cable_current->unspecified_nb[cable_current->cable_best];
|
||||
if (0 == issues) {
|
||||
char* line2 = "perfect match";
|
||||
const char* line2 = "perfect match";
|
||||
lcd_hd44780_write_line(true, line2, strlen(line2));
|
||||
oled_text_line(line2, 1);
|
||||
} else {
|
||||
char* line2 = "closest match";
|
||||
const char* line2 = "closest match";
|
||||
lcd_hd44780_write_line(true, line2, strlen(line2));
|
||||
snprintf(line, LENGTH(line), "issues: %u", issues);
|
||||
oled_text_line(line, 3);
|
||||
}
|
||||
} else {
|
||||
lcd_hd44780_write_line(false, "no matching", 11);
|
||||
lcd_hd44780_write_line(true, "cable found", 11);
|
||||
const char* line1 = "no matching";
|
||||
const char* line2 = "cable found";
|
||||
lcd_hd44780_write_line(false, line1, strlen(line1));
|
||||
lcd_hd44780_write_line(true, line2, strlen(line2));
|
||||
oled_text_line(line1, 0);
|
||||
oled_text_line(line2, 1);
|
||||
}
|
||||
oled_text_update();
|
||||
}
|
||||
} else if (cable_current->cable_best < LENGTH(usb_cables) && cable_current->cable_best < LENGTH(cable_current->unconnected_nb) && cable_current->cable_best < LENGTH(cable_current->unspecified_nb)) { // the cable did not change, and there is a valid cable plugged in
|
||||
// fix time (RTC integer overflow is possible, but only happens after 13 years without reset)
|
||||
|
|
Loading…
Reference in New Issue