SatCat5
cfgbus_text_lcd.cc
1 // Copyright 2022 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 
6 #include <satcat5/cfgbus_text_lcd.h>
7 
10 
11 TextLcd::TextLcd(satcat5::cfg::ConfigBus* cfg, unsigned devaddr, unsigned regaddr)
12  : m_ctrl(cfg->get_register(devaddr, regaddr))
13 {
14  clear();
15 }
16 
18 {
19  // Send the "reset" opcode.
20  *m_ctrl = (1u << 31);
21 }
22 
23 void TextLcd::write(const char* msg)
24 {
25  // Copy each character until we reach a null terminator.
26  // Skip over UTF-8 codepoints outside the basic ASCII range.
27  while (*msg) {
28  u8 tmp = (unsigned char)(*msg);
29  if (tmp < 128) *m_ctrl = (u32)tmp;
30  ++msg;
31  }
32 }
33 
34 LogToLcd::LogToLcd(satcat5::cfg::TextLcd* lcd)
35  : m_lcd(lcd)
36 {
37  // Nothing else to initialize.
38 }
39 
40 void LogToLcd::log_event(s8 priority, unsigned nbytes, const char* msg)
41 {
42  // Space is limited, so use a very short label.
43  const char* lbl = 0;
44  if (priority >= satcat5::log::ERROR) lbl = "Err: ";
45  else if (priority >= satcat5::log::WARNING) lbl = "Wrn: ";
46  else if (priority >= satcat5::log::INFO) lbl = "Inf: ";
47  else lbl = "Dbg: ";
48 
49  // LCD will concatenate the message automatically.
50  m_lcd->write(lbl);
51  m_lcd->write(msg);
52  m_lcd->write("\n");
53 }
Generic ConfigBus API.
Definition: cfgbus_core.h:124
Adapter for connecting log::Log messages to a TextLcd object.
void log_event(s8 priority, unsigned nbytes, const char *msg) override
Callback for each formatted Log message.
Interface driver for the cfgbus_uart block.
void write(const char *msg)
Write a string to the display (max 32 characters).
void clear()
Reset and clear display.