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
8
using
satcat5::cfg::TextLcd
;
9
using
satcat5::cfg::LogToLcd
;
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
17
void
TextLcd::clear
()
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
}
satcat5::cfg::ConfigBus
Generic ConfigBus API.
Definition:
cfgbus_core.h:124
satcat5::cfg::LogToLcd
Adapter for connecting log::Log messages to a TextLcd object.
Definition:
cfgbus_text_lcd.h:33
satcat5::cfg::LogToLcd::log_event
void log_event(s8 priority, unsigned nbytes, const char *msg) override
Callback for each formatted Log message.
Definition:
cfgbus_text_lcd.cc:40
satcat5::cfg::TextLcd
Interface driver for the cfgbus_uart block.
Definition:
cfgbus_text_lcd.h:16
satcat5::cfg::TextLcd::write
void write(const char *msg)
Write a string to the display (max 32 characters).
Definition:
cfgbus_text_lcd.cc:23
satcat5::cfg::TextLcd::clear
void clear()
Reset and clear display.
Definition:
cfgbus_text_lcd.cc:17
src
cpp
satcat5
cfgbus_text_lcd.cc
Generated by
1.9.1
Copyright 2024 The Aerospace Corporation. This documentation is a part of SatCat5, licensed under CERN-OHL-W v2 or later.