use crate::{DISPLAY_DATA_LEN, DISPLAY_HEIGHT, DISPLAY_WIDTH};
#[derive(Debug)]
pub struct FileHandle {
pub(crate) handle: u8,
pub len: u32,
}
#[derive(Debug)]
pub struct FindFileHandle {
pub(crate) handle: u8,
pub name: String,
pub len: u32,
}
#[derive(Debug)]
pub struct FwVersion {
pub prot: (u8, u8),
pub fw: (u8, u8),
}
#[derive(Debug)]
pub struct ModuleHandle {
pub(crate) handle: u8,
pub name: String,
pub id: u32,
pub len: u32,
pub iomap_len: u16,
}
#[derive(Debug)]
pub struct DeviceInfo {
pub name: String,
pub bt_addr: [u8; 6],
pub signal_strength: (u8, u8, u8, u8),
pub flash: u32,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u8)]
pub enum BufType {
Usb = 0,
HighSpeed = 1,
}
pub type DisplayRaster = [[u8; DISPLAY_WIDTH]; DISPLAY_HEIGHT];
#[must_use]
pub fn display_data_to_raster(data: &[u8; DISPLAY_DATA_LEN]) -> DisplayRaster {
let mut out = [[0u8; DISPLAY_WIDTH]; DISPLAY_HEIGHT];
for (idx, chunk) in data.iter().enumerate() {
let col = idx % DISPLAY_WIDTH;
let row_base = (idx / DISPLAY_WIDTH) * 8;
for shift in 0..8 {
let row = row_base + shift;
let bit = (chunk >> shift) & 0x01;
out[row][col] = bit;
}
}
out
}
#[must_use]
pub fn raster_to_string(raster: &DisplayRaster) -> String {
raster
.iter()
.map(|row| {
row.iter()
.map(|&pixel| if pixel == 0 { '.' } else { '#' })
.chain(std::iter::once('\n'))
.collect::<String>()
})
.collect::<String>()
}
#[cfg(test)]
mod test {
use super::*;
const DISPLAY_DATA: [u8; crate::DISPLAY_DATA_LEN] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 32, 62, 0, 46, 42, 58, 0, 62,
42, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 62, 68, 36, 0,
0, 56, 84, 84, 84, 8, 0, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 2, 4, 2, 127, 0, 156, 160, 96,
60, 0, 0, 0, 0, 0, 0, 0, 0, 127, 9, 9, 9, 1, 0, 0, 0, 125, 64, 0, 0, 0,
0, 127, 64, 0, 0, 56, 84, 84, 84, 8, 0, 8, 84, 84, 84, 32, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 128, 224, 160, 160, 160, 160,
160, 160, 224, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 2,
250, 10, 250, 74, 202, 74, 74, 74, 74, 74, 74, 74, 122, 74, 250, 66,
194, 2, 2, 2, 2, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 32, 32, 32,
224, 128, 128, 224, 32, 32, 32, 224, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 254, 1, 0, 0, 24,
24, 0, 0, 0, 0, 24, 24, 0, 0, 1, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
255, 0, 255, 0, 255, 0, 255, 2, 254, 2, 2, 2, 2, 2, 2, 2, 3, 2, 255, 2,
254, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 2, 2, 3, 0, 0, 3,
2, 130, 202, 251, 120, 120, 248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 16, 32, 32, 32, 34, 36, 36, 36,
36, 34, 32, 32, 32, 16, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0,
1, 7, 8, 63, 64, 128, 129, 249, 137, 233, 137, 137, 137, 249, 129, 128,
128, 127, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 68, 68,
68, 124, 0, 3, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
const DISPLAY_RENDERED:&str = "...............................................................................######...............
............#.#.###.###................#.................#...........................#..............
............#.#.#...#.#...............####...###...###..####.........................#.....#######..
............#.#.###.###................#....#...#.#......#....................#..##..#....#.....##..
............#.#...#.#.#................#....####...###...#....................#..##..#....#.....##..
............###.###.###................#.#..#.........#..#.#..................#......#.....#######..
........................................#....###...###....#...................#......#..............
...............................................................................######...............
....................................................................................................
####################################################################################################
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
..........................#...#.............#####...#.....#.........................................
..........................##.##.............#.............#.........................................
..........................#.#.#.#..#........#.......#.....#....###...###............................
..........................#...#.#..#........####....#.....#...#...#.#...............................
..........................#...#.#..#........#.......#.....#...####...###............................
..........................#...#..###........#.......#.....#...#.........#...........................
..........................#...#...#.........#.......##....##...###...###............................
................................##..................................................................
....................................................................................................
......................................########################......................................
......................................#......................#......................................
......................................#.###############......#......................................
......................................#.#.#.........#.#......#......................................
...............########...............#.#.#.........#.#......#..........#####..#####................
...............#......#...............#.#.###############....#..........#...#..#...#................
.............############.............#.#.#.#.........#.#....#..........#...####...###..............
............#............#............#.#.#.#.........#.#....#..........#...#..#...#................
...........#..............#...........#.#.#.###############..#..........#####..#####................
...........#..............#...........#.#.#.#.#.........#.#..#......................................
...........#...##....##...#...........#.#.#.#.#.........#.#..#....................#####.............
...........#...##....##...#...........#.#.#.#.#.........#.#..#.....................####.............
...........#..............#...........#.#.#.#.#.........#.#..#.....................####.............
...........#..............#...........#.#.#.#.#.........#.#..#....................#####.............
...........#..............#...........#.#.#.#.#.........#.#..#...................###..#.............
...........#..............#...........#..##.#..#########..#..#..................###.................
...........#....#....#....#...........#...#.#.............#..#..................##..................
...........#.....####.....#...........#...#.#.............#..#............#####.....................
...........#..............#...........#....##...#######...#..#............#...#.....................
............#............#............#.....#...#.....#...#..#............#...#.....................
.............############.............#.....#...#.#...#...#..#............#...#.....................
......................................#......#..#.#...#...#..#............#####.....................
......................................#.......############...#......................................
";
#[test]
fn display_raster() {
let raster = display_data_to_raster(&DISPLAY_DATA);
let rendered = raster_to_string(&raster);
println!("{rendered}");
assert_eq!(rendered, DISPLAY_RENDERED);
}
}