Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
Frank Villaro-Dixon 2024-05-16 22:35:08 +02:00
parent f0885efd27
commit 5456c6845e
4 changed files with 25 additions and 44 deletions

View file

@ -1,5 +1,3 @@
use std::thread::current;
pub struct BeoApps { pub struct BeoApps {
pub apps: Vec<Box<dyn App>>, pub apps: Vec<Box<dyn App>>,
} }
@ -51,14 +49,6 @@ impl Menu {
self.selected_submenu = Some(self.submenus[self.current_submenu_id].clone()); self.selected_submenu = Some(self.submenus[self.current_submenu_id].clone());
} }
pub fn get_deepest_selected_submenu_mut(&mut self) -> &mut Menu {
// Use a loop to traverse to the deepest submenu
let mut current_menu = self;
while let Some(ref mut selected_submenu) = current_menu.selected_submenu {
current_menu = selected_submenu;
}
current_menu
}
pub fn get_deepest_selected_submenu(&self) -> &Menu { pub fn get_deepest_selected_submenu(&self) -> &Menu {
// Use a loop to traverse to the deepest submenu // Use a loop to traverse to the deepest submenu
let mut current_menu = self; let mut current_menu = self;

View file

@ -9,6 +9,7 @@ use std::{
const LASER_POINTER_MAX: i32 = 121; const LASER_POINTER_MAX: i32 = 121;
#[derive(Debug)] #[derive(Debug)]
#[allow(dead_code)]
pub enum Beo5Event { pub enum Beo5Event {
LaserPosition(f32), LaserPosition(f32),
SelectionWheelRel(i32), SelectionWheelRel(i32),
@ -49,10 +50,12 @@ impl Beo5Device {
nix::fcntl::fcntl(raw_fd, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)).unwrap(); nix::fcntl::fcntl(raw_fd, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)).unwrap();
// Create epoll handle and attach raw_fd // Create epoll handle and attach raw_fd
#[allow(deprecated)]
let epoll_fd = epoll::epoll_create1(epoll::EpollCreateFlags::EPOLL_CLOEXEC).ok()?; let epoll_fd = epoll::epoll_create1(epoll::EpollCreateFlags::EPOLL_CLOEXEC).ok()?;
println!("epoll_fd: {epoll_fd}."); println!("epoll_fd: {epoll_fd}.");
let epoll_fd = unsafe { OwnedFd::from_raw_fd(epoll_fd) }; let epoll_fd = unsafe { OwnedFd::from_raw_fd(epoll_fd) };
let mut event = epoll::EpollEvent::new(epoll::EpollFlags::EPOLLIN, 0); let mut event = epoll::EpollEvent::new(epoll::EpollFlags::EPOLLIN, 0);
#[allow(deprecated)]
epoll::epoll_ctl( epoll::epoll_ctl(
epoll_fd.as_raw_fd(), epoll_fd.as_raw_fd(),
epoll::EpollOp::EpollCtlAdd, epoll::EpollOp::EpollCtlAdd,
@ -61,8 +64,6 @@ impl Beo5Device {
) )
.unwrap(); .unwrap();
//loop {}
return Some(Beo5Device { return Some(Beo5Device {
device: d, device: d,
evts_in_queue: VecDeque::new(), evts_in_queue: VecDeque::new(),
@ -91,7 +92,8 @@ impl Beo5Device {
if x.kind() == std::io::ErrorKind::WouldBlock { if x.kind() == std::io::ErrorKind::WouldBlock {
// Wait forever for bytes available on raw_fd // Wait forever for bytes available on raw_fd
let mut events = [epoll::EpollEvent::empty(); 2]; let mut events = [epoll::EpollEvent::empty(); 2];
epoll::epoll_wait(8, &mut events, -1); #[allow(deprecated)]
let _ = epoll::epoll_wait(8, &mut events, -1);
} else { } else {
println!("Error getting event: {x} - {}", x.kind()); println!("Error getting event: {x} - {}", x.kind());
//panic!("Error getting event: {x}"); //panic!("Error getting event: {x}");
@ -99,15 +101,14 @@ impl Beo5Device {
} }
} }
let ev = self.evts_in_queue.pop_front(); let ev = self.evts_in_queue.pop_front();
if ev.is_some() { if let Some(e) = ev {
return Beo5Device::parse_event(ev.unwrap()); return Beo5Device::parse_event(e);
} }
None None
} }
fn parse_event(ev: evdev::InputEvent) -> Option<Beo5Event> { fn parse_event(ev: evdev::InputEvent) -> Option<Beo5Event> {
println!("Beosound event: {ev:?}"); #[allow(clippy::collapsible_match)]
// XXX What happens with the other events in the iterator?
match ev.kind() { match ev.kind() {
// Look at the beosound 5 kernel module for the correct event codes // Look at the beosound 5 kernel module for the correct event codes
evdev::InputEventKind::RelAxis(axis) => { evdev::InputEventKind::RelAxis(axis) => {
@ -123,6 +124,7 @@ impl Beo5Device {
} }
} }
evdev::InputEventKind::AbsAxis(axis) => { evdev::InputEventKind::AbsAxis(axis) => {
#[allow(clippy::single_match)]
match axis { match axis {
evdev::AbsoluteAxisType::ABS_X => { evdev::AbsoluteAxisType::ABS_X => {
let pos_pct = (ev.value() as f32 / LASER_POINTER_MAX as f32).min(1.0); let pos_pct = (ev.value() as f32 / LASER_POINTER_MAX as f32).min(1.0);

View file

@ -13,7 +13,14 @@ use winit::{
mod helpers; mod helpers;
use helpers::PerfGraph; use helpers::PerfGraph;
// XXX rename to smth else use glutin::prelude::*;
mod apps;
mod hid;
mod roundy_math;
mod ui;
#[allow(dead_code)]
struct Fonts { struct Fonts {
sans: FontId, sans: FontId,
bold: FontId, bold: FontId,
@ -26,19 +33,6 @@ struct Fonts {
fn main() { fn main() {
helpers::start(1024, 768, "Text demo"); helpers::start(1024, 768, "Text demo");
} }
use glutin::prelude::*;
mod apps;
mod hid;
mod roundy_math;
mod ui;
enum UiEvent<'e> {
WinitEvent(winit::event::Event<'e, ()>),
HardwareEvent(evdev::InputEvent),
}
fn run( fn run(
mut canvas: Canvas<OpenGl>, mut canvas: Canvas<OpenGl>,
el: EventLoop<()>, el: EventLoop<()>,
@ -112,11 +106,8 @@ fn run(
*control_flow = ControlFlow::Poll; *control_flow = ControlFlow::Poll;
let hw_event = beo_device.get_event_nonblocking(); let hw_event = beo_device.get_event_nonblocking();
match hw_event { if let Some(ev) = hw_event {
Some(ev) => { beo.accept_event(ev);
beo.accept_event(ev);
}
None => {}
} }
match event { match event {
@ -191,7 +182,6 @@ fn run(
canvas.set_size(size.width, size.height, dpi_factor as f32); canvas.set_size(size.width, size.height, dpi_factor as f32);
canvas.clear_rect(0, 0, size.width, size.height, Color::rgbf(0., 0., 0.)); canvas.clear_rect(0, 0, size.width, size.height, Color::rgbf(0., 0., 0.));
let elapsed = start.elapsed().as_secs_f32();
let now = Instant::now(); let now = Instant::now();
let dt = (now - prevt).as_secs_f32(); let dt = (now - prevt).as_secs_f32();
prevt = now; prevt = now;

View file

@ -1,8 +1,8 @@
use femtovg::{Align, Baseline, Canvas, Color, Paint, Path, Renderer}; use femtovg::{Baseline, Canvas, Color, Paint, Path, Renderer};
use crate::{hid::Beo5Event, Fonts}; use crate::{hid::Beo5Event, Fonts};
use crate::apps::{App, BeoApps, Menu}; use crate::apps::{App, BeoApps};
use crate::roundy_math; use crate::roundy_math;
pub struct BeoUi { pub struct BeoUi {
@ -227,12 +227,11 @@ impl BeoUi {
paint_selected.set_text_baseline(Baseline::Top); paint_selected.set_text_baseline(Baseline::Top);
for appid in 0..apps.len() { for appid in 0..apps.len() {
let paint; let paint = if self.current_app_id == Some(appid) {
if self.current_app_id == Some(appid) { &paint_selected
paint = &paint_selected;
} else { } else {
paint = &paint_normal; &paint_normal
} };
let app = &apps[appid]; let app = &apps[appid];
let _ = canvas.fill_text(pts[appid].x, pts[appid].y, app.base().name(), paint); let _ = canvas.fill_text(pts[appid].x, pts[appid].y, app.base().name(), paint);