Move to notam from macroquad
Some checks failed
Build project / Build (push) Failing after 2m5s

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2026-03-28 15:32:11 +02:00
parent 5656d3d424
commit 54538dcd2a
4 changed files with 2722 additions and 152 deletions

View File

@@ -4,15 +4,9 @@ use std::{
time::Duration,
};
use anyhow::{Result, anyhow};
use macroquad::{
color::*,
miniquad::{
conf::LinuxBackend,
error, info,
},
};
use anyhow::{anyhow, Result};
use midly::Smf;
use notan::{draw::*, prelude::*};
use serialport::SerialPortType;
#[derive(Clone, Copy, Debug)]
@@ -170,14 +164,15 @@ pub enum SerialStatus {
SerialDisconnected,
}
struct App {
#[derive(AppState)]
struct SingerApp {
song_state: Option<AppSongState>,
tx: Sender<SerialCommand>,
rx: Receiver<SerialStatus>,
connected: Option<String>,
}
impl App {
impl SingerApp {
pub fn new() -> Self {
let (tx_cmd, rx_cmd) = mpsc::channel();
let (tx_status, rx_status) = mpsc::channel();
@@ -198,15 +193,12 @@ impl App {
if device.is_none() {
match SerialDevice::new() {
Ok(new_device) => {
info!("Serial device connected");
let _ = tx.send(SerialStatus::SerialConnected {
name: device
.as_ref()
.unwrap()
.port
.name()
.unwrap_or("<unknown serial port>".to_string()),
});
let name = new_device
.port
.name()
.unwrap_or("<unknown serial port>".to_string());
println!("Serial device connected: {name}");
let _ = tx.send(SerialStatus::SerialConnected { name });
device = Some(new_device);
}
Err(_err) => {
@@ -222,14 +214,14 @@ impl App {
match command {
SerialCommand::Instruction(ch, instr) => {
if let Err(e) = dev.execute(ch, instr) {
error!("Disconnected: {e}");
eprintln!("Disconnected: {e}");
device = None;
let _ = tx.send(SerialStatus::SerialDisconnected);
}
}
SerialCommand::Stop => {
if let Err(e) = dev.stop() {
error!("Disconnected: {e}");
eprintln!("Disconnected: {e}");
device = None;
let _ = tx.send(SerialStatus::SerialDisconnected);
}
@@ -244,56 +236,53 @@ impl App {
});
}
pub async fn run(&mut self) {
loop {
self.update().await;
}
}
async fn update(&mut self) {
match self.rx.recv_timeout(Duration::from_millis(100)) {
Ok(status) => match status {
fn update(&mut self) {
while let Ok(status) = self.rx.try_recv() {
match status {
SerialStatus::SerialDisconnected => self.connected = None,
SerialStatus::SerialConnected { name } => self.connected = Some(name),
},
_ => {}
}
}
}
macroquad::window::clear_background(WHITE);
fn draw(&mut self, gfx: &mut Graphics) {
let mut draw = gfx.create_draw();
draw.clear(Color::WHITE);
macroquad::shapes::draw_line(40.0, 40.0, 100.0, 200.0, 15.0, BLUE);
macroquad::shapes::draw_rectangle(
macroquad::window::screen_width() / 2.0 - 60.0,
100.0,
120.0,
60.0,
GREEN,
);
draw.line((40.0, 40.0), (100.0, 200.0))
.width(15.0)
.color(Color::BLUE);
draw.rect((220.0, 100.0), (120.0, 60.0)).color(Color::GREEN);
macroquad::text::draw_text(
match &self.connected {
Some(name) => &name,
None => "Serial disconnected",
},
20.0,
20.0,
30.0,
DARKGRAY,
);
let status_color = if self.connected.is_some() {
Color::GREEN
} else {
Color::GRAY
};
draw.rect((14.0, 14.0), (20.0, 20.0)).color(status_color);
macroquad::window::next_frame().await
gfx.render(&draw);
}
}
fn window_conf() -> macroquad::prelude::Conf {
let mut conf = macroquad::prelude::Conf::default();
conf.fullscreen = true;
conf.platform.linux_backend = LinuxBackend::WaylandWithX11Fallback;
conf
fn setup(_gfx: &mut Graphics) -> SingerApp {
SingerApp::new()
}
#[macroquad::main(window_conf)]
async fn main() {
let mut app = App::new();
app.run().await;
fn update(_app: &mut notan::app::App, state: &mut SingerApp) {
state.update();
}
fn draw(gfx: &mut Graphics, state: &mut SingerApp) {
state.draw(gfx);
}
#[notan_main]
fn main() -> Result<(), String> {
notan::init_with(setup)
.add_config(WindowConfig::new().set_title("singer").set_fullscreen(true))
.add_config(DrawConfig)
.update(update)
.draw(draw)
.build()
}