feat: add display UI with splash screen, dashboard, and RSSI sparkline
Implement full SSD1306 OLED display support: - Splash screen on boot (1.5s) with project name, version, board - Dashboard showing radio state, config, counters, RSSI/SNR - RSSI history sparkline (64-sample ring buffer, 2px-wide bars) - DisplayOn/DisplayOff host commands routed via dedicated channel - Pure render functions against generic DrawTarget (no hardware coupling) - Display on/off control bypasses radio task entirely Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
17624 files changed
+4564928
-38
No files matched your search
+76
@@ -0,0 +1,76 @@
|
||||
extern crate embedded_graphics;
|
||||
|
||||
use embedded_graphics::{
|
||||
prelude::*,
|
||||
primitives::{Circle, Line, Primitive, PrimitiveStyle, Rectangle},
|
||||
};
|
||||
|
||||
struct FakeDisplay {}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub struct TestPixelColor(pub bool);
|
||||
|
||||
impl PixelColor for TestPixelColor {
|
||||
type Raw = ();
|
||||
}
|
||||
|
||||
impl From<u8> for TestPixelColor {
|
||||
fn from(other: u8) -> Self {
|
||||
TestPixelColor(other != 0)
|
||||
}
|
||||
}
|
||||
|
||||
impl DrawTarget for FakeDisplay {
|
||||
type Color = TestPixelColor;
|
||||
type Error = core::convert::Infallible;
|
||||
|
||||
fn draw_iter<I>(&mut self, _pixels: I) -> Result<(), Self::Error>
|
||||
where
|
||||
I: IntoIterator<Item = Pixel<Self::Color>>,
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl OriginDimensions for FakeDisplay {
|
||||
fn size(&self) -> Size {
|
||||
Size::zero()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_supports_chaining() -> Result<(), core::convert::Infallible> {
|
||||
let mut display = FakeDisplay {};
|
||||
|
||||
let chained = Rectangle::new(Point::new(0, 0), Size::new(1, 1))
|
||||
.into_styled(PrimitiveStyle::default())
|
||||
.pixels()
|
||||
.chain(
|
||||
Circle::new(Point::new(1, 1), 3)
|
||||
.into_styled(PrimitiveStyle::default())
|
||||
.pixels(),
|
||||
);
|
||||
|
||||
chained.draw(&mut display)
|
||||
}
|
||||
|
||||
fn multi() -> impl Iterator<Item = Pixel<TestPixelColor>> {
|
||||
let line = Line::new(Point::new(0, 1), Point::new(2, 3))
|
||||
.into_styled(PrimitiveStyle::with_stroke(1u8.into(), 1))
|
||||
.pixels();
|
||||
|
||||
let circle = Circle::new(Point::new(2, 2), 7)
|
||||
.into_styled(PrimitiveStyle::with_stroke(1u8.into(), 1))
|
||||
.pixels();
|
||||
|
||||
line.chain(circle)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_from_fn() -> Result<(), core::convert::Infallible> {
|
||||
let mut display = FakeDisplay {};
|
||||
|
||||
let chained = multi();
|
||||
|
||||
chained.draw(&mut display)
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
use embedded_graphics::{
|
||||
mock_display::MockDisplay,
|
||||
pixelcolor::Rgb888,
|
||||
prelude::*,
|
||||
primitives::{PrimitiveStyle, Rectangle, StyledDimensions, StyledDrawable},
|
||||
};
|
||||
|
||||
struct Square {
|
||||
top_left: Point,
|
||||
size: u32,
|
||||
}
|
||||
|
||||
impl Square {
|
||||
fn new(top_left: Point, size: u32) -> Self {
|
||||
Self { top_left, size }
|
||||
}
|
||||
|
||||
fn to_rectangle(&self) -> Rectangle {
|
||||
Rectangle::new(self.top_left, Size::new_equal(self.size))
|
||||
}
|
||||
}
|
||||
|
||||
impl Primitive for Square {}
|
||||
|
||||
impl Dimensions for Square {
|
||||
fn bounding_box(&self) -> Rectangle {
|
||||
self.to_rectangle()
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: PixelColor> StyledDrawable<PrimitiveStyle<C>> for Square {
|
||||
type Color = C;
|
||||
type Output = ();
|
||||
|
||||
fn draw_styled<D>(
|
||||
&self,
|
||||
style: &PrimitiveStyle<C>,
|
||||
target: &mut D,
|
||||
) -> Result<Self::Output, D::Error>
|
||||
where
|
||||
D: DrawTarget<Color = Self::Color>,
|
||||
{
|
||||
self.to_rectangle().draw_styled(style, target)
|
||||
}
|
||||
}
|
||||
|
||||
impl<C: PixelColor> StyledDimensions<PrimitiveStyle<C>> for Square {
|
||||
fn styled_bounding_box(&self, style: &PrimitiveStyle<C>) -> Rectangle {
|
||||
self.to_rectangle().styled_bounding_box(style)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draw_custom_primitive() {
|
||||
let mut display = MockDisplay::new();
|
||||
Square::new(Point::new(1, 0), 2)
|
||||
.into_styled(PrimitiveStyle::with_fill(Rgb888::RED))
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
display.assert_pattern(&[
|
||||
" RR", //
|
||||
" RR", //
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_primitive_dimensions() {
|
||||
let styled_square =
|
||||
Square::new(Point::new(1, 0), 2).into_styled(PrimitiveStyle::with_stroke(Rgb888::RED, 2));
|
||||
|
||||
assert_eq!(
|
||||
styled_square.bounding_box(),
|
||||
Rectangle::new(Point::new(1, 0), Size::new_equal(2)).offset(1)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
use embedded_graphics::{
|
||||
mock_display::MockDisplay,
|
||||
pixelcolor::Rgb888,
|
||||
prelude::*,
|
||||
primitives::{Rectangle, StyledDrawable},
|
||||
};
|
||||
|
||||
struct CheckerboardStyle<C>(C, C);
|
||||
|
||||
impl<C: PixelColor> StyledDrawable<CheckerboardStyle<C>> for Rectangle {
|
||||
type Color = C;
|
||||
type Output = ();
|
||||
|
||||
fn draw_styled<D>(
|
||||
&self,
|
||||
style: &CheckerboardStyle<C>,
|
||||
target: &mut D,
|
||||
) -> Result<Self::Output, D::Error>
|
||||
where
|
||||
D: DrawTarget<Color = Self::Color>,
|
||||
{
|
||||
target.fill_contiguous(
|
||||
self,
|
||||
self.points().map(|p| {
|
||||
if (p.x % 2 == 0) ^ (p.y % 2 == 0) {
|
||||
style.1
|
||||
} else {
|
||||
style.0
|
||||
}
|
||||
}),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_primitive_style() {
|
||||
let style = CheckerboardStyle(Rgb888::RED, Rgb888::GREEN);
|
||||
|
||||
let mut display = MockDisplay::new();
|
||||
Rectangle::new(Point::zero(), Size::new(4, 3))
|
||||
.into_styled(style)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
display.assert_pattern(&[
|
||||
"RGRG", //
|
||||
"GRGR", //
|
||||
"RGRG", //
|
||||
]);
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
use embedded_graphics::{
|
||||
image::ImageRaw,
|
||||
mock_display::MockDisplay,
|
||||
mono_font::{mapping::StrGlyphMapping, DecorationDimensions, MonoFont, MonoTextStyle},
|
||||
pixelcolor::BinaryColor,
|
||||
prelude::*,
|
||||
text::{Baseline, Text},
|
||||
};
|
||||
|
||||
const DATA: &[u8] = &[0xAA, 0x55];
|
||||
|
||||
#[test]
|
||||
fn custom_font() {
|
||||
let mapping = StrGlyphMapping::new("01", 0);
|
||||
|
||||
let font = MonoFont {
|
||||
image: ImageRaw::new(DATA, 8),
|
||||
character_size: Size::new(2, 2),
|
||||
character_spacing: 0,
|
||||
baseline: 0,
|
||||
strikethrough: DecorationDimensions::default_strikethrough(2),
|
||||
underline: DecorationDimensions::default_underline(2),
|
||||
glyph_mapping: &mapping,
|
||||
};
|
||||
|
||||
let character_style = MonoTextStyle::new(&font, BinaryColor::On);
|
||||
|
||||
let mut display = MockDisplay::new();
|
||||
Text::with_baseline("01", Point::zero(), character_style, Baseline::Top)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
display.assert_pattern(&[
|
||||
"# # ", //
|
||||
" # #", //
|
||||
]);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
use embedded_graphics::{
|
||||
mock_display::MockDisplay,
|
||||
pixelcolor::Rgb888,
|
||||
prelude::*,
|
||||
primitives::Rectangle,
|
||||
text::{
|
||||
renderer::{TextMetrics, TextRenderer},
|
||||
Baseline, Text,
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
struct GenericTextStyle<C>(C);
|
||||
|
||||
impl<C: PixelColor> TextRenderer for GenericTextStyle<C> {
|
||||
type Color = C;
|
||||
|
||||
fn draw_string<D>(
|
||||
&self,
|
||||
text: &str,
|
||||
position: Point,
|
||||
baseline: Baseline,
|
||||
target: &mut D,
|
||||
) -> Result<Point, D::Error>
|
||||
where
|
||||
D: DrawTarget<Color = Self::Color>,
|
||||
{
|
||||
let metrics = self.measure_string(text, position, baseline);
|
||||
|
||||
target.fill_solid(&metrics.bounding_box, self.0)?;
|
||||
|
||||
Ok(metrics.next_position)
|
||||
}
|
||||
|
||||
fn draw_whitespace<D>(
|
||||
&self,
|
||||
_width: u32,
|
||||
_position: Point,
|
||||
_baseline: Baseline,
|
||||
_target: &mut D,
|
||||
) -> Result<Point, D::Error>
|
||||
where
|
||||
D: DrawTarget<Color = Self::Color>,
|
||||
{
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn measure_string(&self, text: &str, position: Point, _baseline: Baseline) -> TextMetrics {
|
||||
// TODO: use baseline
|
||||
|
||||
let width = text.len() as u32 * 4;
|
||||
|
||||
TextMetrics {
|
||||
bounding_box: Rectangle::new(position, Size::new(width, 4)),
|
||||
next_position: position + Size::new(width, 0),
|
||||
}
|
||||
}
|
||||
|
||||
fn line_height(&self) -> u32 {
|
||||
5
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generic_text_renderer() {
|
||||
let mut target = MockDisplay::new();
|
||||
|
||||
Text::new("ab\nc", Point::zero(), GenericTextStyle(Rgb888::RED))
|
||||
.draw(&mut target)
|
||||
.unwrap();
|
||||
|
||||
target.assert_pattern(&[
|
||||
"RRRRRRRR", //
|
||||
"RRRRRRRR", //
|
||||
"RRRRRRRR", //
|
||||
"RRRRRRRR", //
|
||||
" ", //
|
||||
"RRRR ", //
|
||||
"RRRR ", //
|
||||
"RRRR ", //
|
||||
"RRRR ", //
|
||||
]);
|
||||
}
|
||||
Reference in new issue
Block a user