Make interactive slideshow
This commit is contained in:
parent
5c88cf9086
commit
a634c9230c
BIN
images/mario.qoi
Normal file
BIN
images/mario.qoi
Normal file
Binary file not shown.
BIN
images/mario.xcf
Normal file
BIN
images/mario.xcf
Normal file
Binary file not shown.
BIN
images/pikachu.qoi
Normal file
BIN
images/pikachu.qoi
Normal file
Binary file not shown.
BIN
images/press_btn.qoi
Normal file
BIN
images/press_btn.qoi
Normal file
Binary file not shown.
54
src/main.rs
54
src/main.rs
@ -20,7 +20,7 @@ use panic_halt as _;
|
|||||||
use crate::{
|
use crate::{
|
||||||
display::{Display, Position, Rgb565},
|
display::{Display, Position, Rgb565},
|
||||||
peripherals::{Button, Knob},
|
peripherals::{Button, Knob},
|
||||||
qoi::draw_image,
|
qoi::{MARIO, PIKA, PRESS_BTN, draw_image},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod display;
|
mod display;
|
||||||
@ -83,41 +83,35 @@ fn main() -> ! {
|
|||||||
adc,
|
adc,
|
||||||
};
|
};
|
||||||
|
|
||||||
let colors = [
|
|
||||||
Rgb565::red(),
|
|
||||||
Rgb565::green(),
|
|
||||||
Rgb565::blue(),
|
|
||||||
Rgb565::cyan(),
|
|
||||||
Rgb565::magenta(),
|
|
||||||
Rgb565::yellow(),
|
|
||||||
];
|
|
||||||
let mut idx = 0;
|
|
||||||
|
|
||||||
let mut delay = atmega_hal::delay::Delay::<CoreClock>::new();
|
let mut delay = atmega_hal::delay::Delay::<CoreClock>::new();
|
||||||
|
|
||||||
let mut last_input = 0f32;
|
let mut idx = 0;
|
||||||
loop {
|
let mut images = [&PIKA.as_slice(), &MARIO.as_slice()];
|
||||||
let input = knob.poll();
|
let len = images.len();
|
||||||
let button_poll = button.poll();
|
|
||||||
|
|
||||||
if button_poll {
|
match draw_image(
|
||||||
idx = (idx + 1) % colors.len();
|
&mut serial,
|
||||||
}
|
&PRESS_BTN.as_slice(),
|
||||||
|
&mut display,
|
||||||
// if last_input != input || button_poll {
|
Position { x: 0, y: 0 },
|
||||||
// last_input = input;
|
) {
|
||||||
// display.draw_rect(
|
|
||||||
// Position { x: 0, y: 0 },
|
|
||||||
// Position { x: 200, y: 200 },
|
|
||||||
// (colors[idx] * input).as_color(),
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
match draw_image(&mut serial, &mut display, Position { x: 0, y: 0 }) {
|
|
||||||
Ok(_) => ufmt::uwriteln!(serial, "Successfully read QOI").unwrap(),
|
Ok(_) => ufmt::uwriteln!(serial, "Successfully read QOI").unwrap(),
|
||||||
Err(e) => ufmt::uwriteln!(serial, "Error: {:?}", e).unwrap(),
|
Err(e) => ufmt::uwriteln!(serial, "Error: {:?}", e).unwrap(),
|
||||||
}
|
}
|
||||||
|
|
||||||
delay.delay_ms(1000);
|
loop {
|
||||||
|
if button.poll() {
|
||||||
|
idx = (idx + 1) % len;
|
||||||
|
|
||||||
|
match draw_image(
|
||||||
|
&mut serial,
|
||||||
|
&images[idx],
|
||||||
|
&mut display,
|
||||||
|
Position { x: 0, y: 0 },
|
||||||
|
) {
|
||||||
|
Ok(_) => ufmt::uwriteln!(serial, "Successfully read QOI").unwrap(),
|
||||||
|
Err(e) => ufmt::uwriteln!(serial, "Error: {:?}", e).unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
82
src/qoi.rs
82
src/qoi.rs
@ -16,58 +16,10 @@ use crate::{
|
|||||||
display::{Color, Display, Position, Rgb565, Writeable},
|
display::{Color, Display, Position, Rgb565, Writeable},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[repr(u8)]
|
|
||||||
enum NonBssByte {
|
|
||||||
V = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct NonBss<Buf> {
|
|
||||||
_hack: NonBssByte,
|
|
||||||
pub buf: Buf,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<const N: usize> NonBss<[u8; N]> {
|
|
||||||
pub const fn new(buf: [u8; N]) -> Self {
|
|
||||||
Self {
|
|
||||||
_hack: NonBssByte::V,
|
|
||||||
buf,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! non_bss_statics {(
|
|
||||||
$(
|
|
||||||
$(#$attr:tt)*
|
|
||||||
$pub:vis
|
|
||||||
static ref $NAME:ident : [$u8:ty] = *include_bytes!($($args:tt)*);
|
|
||||||
)*
|
|
||||||
) => (
|
|
||||||
$(
|
|
||||||
|
|
||||||
$(#$attr)*
|
|
||||||
$pub
|
|
||||||
const $NAME: &[u8] = {
|
|
||||||
static $NAME: NonBss<[$u8; ::core::include_bytes!($($args)*).len()]> =
|
|
||||||
NonBss::new(*::core::include_bytes!($($args)*));
|
|
||||||
&$NAME.buf
|
|
||||||
};
|
|
||||||
)*
|
|
||||||
)}
|
|
||||||
|
|
||||||
// https://qoiformat.org/qoi-specification.pdf
|
// https://qoiformat.org/qoi-specification.pdf
|
||||||
// static LARGE: [u8; 1966] = *include_bytes!("../images/large.qoi");
|
pub static MARIO: [u8; 161] = *include_bytes!("../images/mario.qoi");
|
||||||
// static SHEEP: [u8; 852] = *include_bytes!("../images/sheep.qoi");
|
pub static PIKA: [u8; 241] = *include_bytes!("../images/pikachu.qoi");
|
||||||
|
pub static PRESS_BTN: [u8; 174] = *include_bytes!("../images/press_btn.qoi");
|
||||||
// non_bss_statics! {
|
|
||||||
// static ref SHEEP: [u8] = *include_bytes!("../images/sheep.qoi");
|
|
||||||
// // static ref LARGE: [u8] = *include_bytes!("../images/large.qoi");
|
|
||||||
// }
|
|
||||||
static SHEEP: [u8; 1077] = *include_bytes!("../images/sheep.qoi");
|
|
||||||
|
|
||||||
// const LARGE_C1: [u8; 512] = LARGE.as_chunks().0[0];
|
|
||||||
// const LARGE_C2: [u8; 512] = LARGE.as_chunks().0[1];
|
|
||||||
// const LARGE_C3: [u8; 512] = LARGE.as_chunks().0[2];
|
|
||||||
// const LARGE_C4: &[u8] = LARGE.as_chunks::<512>().1;
|
|
||||||
|
|
||||||
#[derive(Debug, uDebug)]
|
#[derive(Debug, uDebug)]
|
||||||
pub enum QoiErr {
|
pub enum QoiErr {
|
||||||
@ -75,33 +27,13 @@ pub enum QoiErr {
|
|||||||
UnexpectedEOF,
|
UnexpectedEOF,
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[derive(Default)]
|
|
||||||
// struct LargeIter<const N: usize> {
|
|
||||||
// index: usize,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// impl<const N: usize> Iterator for LargeIter<N> {
|
|
||||||
// type Item = u8;
|
|
||||||
|
|
||||||
// fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
// if self.index >= N {
|
|
||||||
// return None;
|
|
||||||
// }
|
|
||||||
// let old_idx = self.index;
|
|
||||||
// self.index += 1;
|
|
||||||
// Some(SHEEP[old_idx])
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
||||||
serial: &mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
serial: &mut Usart<USART0, Pin<mode::Input, PD0>, Pin<mode::Output, PD1>, CoreClock>,
|
||||||
|
buffer: &[u8],
|
||||||
display: &mut Display<T, DCPin, RSTPin>,
|
display: &mut Display<T, DCPin, RSTPin>,
|
||||||
position: Position,
|
position: Position,
|
||||||
) -> Result<(), QoiErr> {
|
) -> Result<(), QoiErr> {
|
||||||
// let a = LARGE[black_box(50)];
|
let mut iter = buffer.iter().map(|b| *b);
|
||||||
// ufmt::uwriteln!(serial, "Successfully read QOI header {}", a).unwrap();
|
|
||||||
|
|
||||||
let mut iter = SHEEP.iter().map(|v| *v);
|
|
||||||
|
|
||||||
if let (Some(113), Some(111), Some(105), Some(102)) =
|
if let (Some(113), Some(111), Some(105), Some(102)) =
|
||||||
(iter.next(), iter.next(), iter.next(), iter.next())
|
(iter.next(), iter.next(), iter.next(), iter.next())
|
||||||
@ -127,13 +59,13 @@ pub fn draw_image<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
|||||||
|
|
||||||
ufmt::uwriteln!(serial, "Successfully read QOI header").unwrap();
|
ufmt::uwriteln!(serial, "Successfully read QOI header").unwrap();
|
||||||
|
|
||||||
let scale_factor = 10;
|
let scale_factor = 240 / width;
|
||||||
|
|
||||||
display.set_window(
|
display.set_window(
|
||||||
position,
|
position,
|
||||||
Position {
|
Position {
|
||||||
x: position.x + (width * scale_factor) - 1,
|
x: position.x + (width * scale_factor) - 1,
|
||||||
y: position.y + (width * scale_factor) - 1,
|
y: position.y + (height * scale_factor) - 1,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user