mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-28 16:25:33 +00:00
working on binary selection
This commit is contained in:
@@ -3,9 +3,10 @@ use crate::{
|
||||
display::{FRAMEBUFFER, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
format,
|
||||
peripherals::keyboard,
|
||||
usb::RESTART_USB,
|
||||
};
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use core::fmt::Debug;
|
||||
use core::{fmt::Debug, str::FromStr, sync::atomic::Ordering};
|
||||
use defmt::info;
|
||||
use embassy_rp::{
|
||||
gpio::{Level, Output},
|
||||
@@ -23,10 +24,10 @@ use embedded_graphics::{
|
||||
draw_target::DrawTarget,
|
||||
mono_font::{
|
||||
MonoTextStyle,
|
||||
ascii::{FONT_6X10, FONT_9X15, FONT_10X20},
|
||||
ascii::{FONT_6X9, FONT_6X10, FONT_9X15, FONT_10X20},
|
||||
},
|
||||
pixelcolor::Rgb565,
|
||||
prelude::{Dimensions, Point, RgbColor, Size},
|
||||
prelude::{Dimensions, Point, Primitive, RgbColor, Size},
|
||||
primitives::{PrimitiveStyle, Rectangle, StyledDrawable},
|
||||
text::Text,
|
||||
};
|
||||
@@ -38,22 +39,29 @@ use embedded_layout::{
|
||||
object_chain::Chain,
|
||||
prelude::*,
|
||||
};
|
||||
use shared::keyboard::KeyCode;
|
||||
use embedded_text::TextBox;
|
||||
use shared::keyboard::{KeyCode, KeyState};
|
||||
|
||||
static SELECTIONS: Mutex<CriticalSectionRawMutex, SelectionList> =
|
||||
pub static SELECTIONS: Mutex<CriticalSectionRawMutex, SelectionList> =
|
||||
Mutex::new(SelectionList::new(Vec::new()));
|
||||
|
||||
pub async fn ui_handler() {
|
||||
loop {
|
||||
let state = TASK_STATE.lock().await;
|
||||
if let TaskState::Ui = *state {
|
||||
let mut selections = SELECTIONS.lock().await;
|
||||
if let TaskState::Ui = *TASK_STATE.lock().await {
|
||||
if let Some(event) = keyboard::read_keyboard_fifo().await {
|
||||
match event.key {
|
||||
KeyCode::JoyUp => selections.up(),
|
||||
KeyCode::JoyDown => selections.down(),
|
||||
KeyCode::Enter | KeyCode::JoyRight => (),
|
||||
_ => (),
|
||||
if let KeyState::Pressed = event.state {
|
||||
match event.key {
|
||||
KeyCode::JoyUp => {
|
||||
let mut selections = SELECTIONS.lock().await;
|
||||
selections.up();
|
||||
}
|
||||
KeyCode::JoyDown => {
|
||||
let mut selections = SELECTIONS.lock().await;
|
||||
selections.down();
|
||||
}
|
||||
KeyCode::Enter | KeyCode::JoyRight => (),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,38 +71,62 @@ pub async fn ui_handler() {
|
||||
}
|
||||
|
||||
async fn draw_selection() {
|
||||
let file_names: Vec<String> = {
|
||||
let guard = SELECTIONS.lock().await;
|
||||
guard.selections.clone()
|
||||
};
|
||||
|
||||
let mut fb_lock = FRAMEBUFFER.lock().await;
|
||||
if let Some(fb) = fb_lock.as_mut() {
|
||||
info!("UIINg");
|
||||
let text_style = MonoTextStyle::new(&FONT_9X15, Rgb565::WHITE);
|
||||
let display_area = fb.bounding_box();
|
||||
|
||||
let guard = SELECTIONS.lock().await;
|
||||
let mut file_names = guard.selections.iter();
|
||||
const NO_BINS: &str = "No Programs found on SD Card. Ensure programs end with '.bin', and are located in the root directory";
|
||||
let no_bins = String::from_str(NO_BINS).unwrap();
|
||||
|
||||
let Some(first) = file_names.next() else {
|
||||
Text::new("No Programs found on SD Card\nEnsure programs end with '.bin',\nand are located in the root directory",
|
||||
if file_names.is_empty() {
|
||||
TextBox::new(
|
||||
&no_bins,
|
||||
Rectangle::new(
|
||||
Point::new(25, 25),
|
||||
Size::new(display_area.size.width - 50, display_area.size.width - 50),
|
||||
),
|
||||
text_style,
|
||||
)
|
||||
.draw(*fb)
|
||||
.unwrap();
|
||||
} else {
|
||||
let mut file_names = file_names.iter();
|
||||
let Some(first) = file_names.next() else {
|
||||
Text::new("No Programs found on SD Card\nEnsure programs end with '.bin',\nand are located in the root directory",
|
||||
Point::zero(), text_style).draw(*fb).unwrap();
|
||||
|
||||
return;
|
||||
};
|
||||
return;
|
||||
};
|
||||
|
||||
let chain = Chain::new(Text::new(first, Point::zero(), text_style));
|
||||
let chain = Chain::new(Text::new(first, Point::zero(), text_style));
|
||||
|
||||
// for _ in 0..file_names.len() {
|
||||
// let chain = chain.append(Text::new(
|
||||
// file_names.next().unwrap(),
|
||||
// Point::zero(),
|
||||
// text_style,
|
||||
// ));
|
||||
// }
|
||||
|
||||
for _ in 0..10 {
|
||||
LinearLayout::vertical(chain)
|
||||
.with_alignment(horizontal::Center)
|
||||
.arrange()
|
||||
.align_to(&fb.bounding_box(), horizontal::Center, vertical::Center)
|
||||
.align_to(&display_area, horizontal::Center, vertical::Center)
|
||||
.draw(*fb)
|
||||
.unwrap();
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SelectionList {
|
||||
current_selection: u16,
|
||||
selections: Vec<String>,
|
||||
pub selections: Vec<String>,
|
||||
}
|
||||
|
||||
impl SelectionList {
|
||||
@@ -105,13 +137,17 @@ impl SelectionList {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn down(&mut self) {
|
||||
pub fn reset(&mut self) {
|
||||
self.current_selection = 1
|
||||
}
|
||||
|
||||
fn down(&mut self) {
|
||||
if self.current_selection + 1 < self.selections.len() as u16 {
|
||||
self.current_selection += 1
|
||||
}
|
||||
}
|
||||
|
||||
pub fn up(&mut self) {
|
||||
fn up(&mut self) {
|
||||
if self.current_selection > self.selections.len() as u16 {
|
||||
self.current_selection -= 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user