moved shared types to common crate
This commit is contained in:
parent
cffa942ac9
commit
9b15d4509c
10 changed files with 196 additions and 39 deletions
1
common/.gitignore
vendored
Normal file
1
common/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
target
|
65
common/Cargo.lock
generated
Normal file
65
common/Cargo.lock
generated
Normal file
|
@ -0,0 +1,65 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.215"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.215"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.90"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
7
common/Cargo.toml
Normal file
7
common/Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
|
30
common/src/lib.rs
Normal file
30
common/src/lib.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
#![no_std]
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum Request {
|
||||
RecentBadge,
|
||||
SetRecentBadge(Name),
|
||||
SetVolume(u8),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
pub enum Name {
|
||||
Andy,
|
||||
Evan,
|
||||
Felix,
|
||||
Phil,
|
||||
Tess,
|
||||
Amaia,
|
||||
Prueky,
|
||||
David,
|
||||
Nathaniel,
|
||||
Thia,
|
||||
Michael,
|
||||
Zoey,
|
||||
Coke,
|
||||
Unknown,
|
||||
}
|
||||
|
8
outside/Cargo.lock
generated
8
outside/Cargo.lock
generated
|
@ -260,6 +260,13 @@ dependencies = [
|
|||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const-oid"
|
||||
version = "0.9.6"
|
||||
|
@ -1556,6 +1563,7 @@ dependencies = [
|
|||
"assign-resources",
|
||||
"bt-hci",
|
||||
"byte-slice-cast 1.2.2",
|
||||
"common",
|
||||
"cortex-m",
|
||||
"cortex-m-rt",
|
||||
"critical-section",
|
||||
|
|
|
@ -62,6 +62,7 @@ bt-hci = { version = "0.1.0", default-features = false, features = ["defmt"] }
|
|||
hex = { version = "0.4.3", default-features=false}
|
||||
itoa = "1.0.14"
|
||||
postcard = "1.0.0"
|
||||
common = {path = "../common"}
|
||||
|
||||
[profile.release]
|
||||
debug = 2
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use crate::music::{MusicCommand, Name, COMMANDS};
|
||||
use crate::music::{MusicCommand, COMMANDS};
|
||||
use crate::server::NAMES;
|
||||
|
||||
use common::Name;
|
||||
use embassy_net::{IpEndpoint, Ipv4Address};
|
||||
use embassy_time::Duration;
|
||||
|
||||
|
@ -16,6 +18,7 @@ use log::*;
|
|||
trait Authorized {
|
||||
/// allowed to open door
|
||||
fn authorized(&self) -> bool;
|
||||
async fn from_badge(badge: u64) -> Self;
|
||||
}
|
||||
|
||||
impl Authorized for Name {
|
||||
|
@ -27,6 +30,17 @@ impl Authorized for Name {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
async fn from_badge(badge: u64) -> Self {
|
||||
match badge {
|
||||
badge => {
|
||||
if let Some(name) = NAMES.lock().await.borrow().get(badge) {
|
||||
*name
|
||||
} else {
|
||||
Name::Unknown
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
|
|
62
outside/src/lib.rs
Normal file
62
outside/src/lib.rs
Normal file
|
@ -0,0 +1,62 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
#![allow(async_fn_in_trait)]
|
||||
|
||||
use core::array;
|
||||
use core::borrow::BorrowMut;
|
||||
use core::cell::RefCell;
|
||||
use core::fmt::Formatter;
|
||||
use core::marker::PhantomData;
|
||||
use core::mem::MaybeUninit;
|
||||
use core::panic::PanicInfo;
|
||||
use core::str::from_utf8;
|
||||
use core::sync::atomic::{AtomicU8};
|
||||
|
||||
use auth::send_badge;
|
||||
use bt_hci::cmd::info;
|
||||
use critical_section::Mutex;
|
||||
use cyw43::JoinOptions;
|
||||
use cyw43_pio::PioSpi;
|
||||
use embassy_futures::join::join;
|
||||
use embassy_futures::yield_now;
|
||||
use embassy_rp::interrupt::typelevel::{Handler, Interrupt, IO_IRQ_BANK0};
|
||||
use embassy_rp::multicore::{spawn_core1, Stack};
|
||||
use embassy_rp::pwm::{self};
|
||||
use embassy_rp::uart::{BufferedInterruptHandler};
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
use embassy_sync::channel::{Channel};
|
||||
use fixed::FixedU16;
|
||||
use log::*;
|
||||
//use embassy_rp::i2c::InterruptHandler;
|
||||
use embassy_executor::{InterruptExecutor, Spawner};
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Config, IpEndpoint, Ipv4Address, StackResources};
|
||||
use embassy_rp::{bind_interrupts, interrupt};
|
||||
use embassy_rp::clocks::RoscRng;
|
||||
use embassy_rp::gpio::{AnyPin, Input, InterruptTrigger, Level, Output};
|
||||
use embassy_rp::peripherals::{DMA_CH0, PIN_22, PIO0, UART1, USB};
|
||||
use embassy_rp::pio::{InterruptHandler, Pio};
|
||||
use embassy_rp::usb::Driver;
|
||||
use embassy_time::{Timer};
|
||||
use embedded_io_async::{Read, ReadReady, Write};
|
||||
use music::{music_manager, COMMANDS};
|
||||
use rand::RngCore;
|
||||
use reqwless::response;
|
||||
use scanner::{data_extractor, spawn_poller};
|
||||
use server::server_task;
|
||||
use static_cell::StaticCell;
|
||||
use defmt_rtt as _;
|
||||
use wiggle::wiggle_manager;
|
||||
pub mod wiggle;
|
||||
pub mod music;
|
||||
pub mod scanner;
|
||||
pub mod auth;
|
||||
pub mod arraymap;
|
||||
pub mod server;
|
||||
|
||||
bind_interrupts!(pub struct Irqs {
|
||||
PIO0_IRQ_0 => InterruptHandler<PIO0>;
|
||||
USBCTRL_IRQ => embassy_rp::usb::InterruptHandler<USB>;
|
||||
UART1_IRQ => BufferedInterruptHandler<UART1>;
|
||||
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
use common::Name;
|
||||
use embassy_rp::clocks::RoscRng;
|
||||
use embassy_rp::uart;
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
|
@ -26,26 +27,12 @@ use log::*;
|
|||
|
||||
pub static COMMANDS: Channel<CriticalSectionRawMutex, MusicCommand, 3> = Channel::new();
|
||||
|
||||
#[derive(Clone, Copy, Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
pub enum Name {
|
||||
Andy,
|
||||
Evan,
|
||||
Felix,
|
||||
Phil,
|
||||
Tess,
|
||||
Amaia,
|
||||
Prueky,
|
||||
David,
|
||||
Nathaniel,
|
||||
Thia,
|
||||
Michael,
|
||||
Zoey,
|
||||
Coke,
|
||||
Unknown,
|
||||
pub trait Tracks {
|
||||
fn tracks(&self) -> u8;
|
||||
fn prefix(&self) -> &'static str;
|
||||
}
|
||||
|
||||
impl Name {
|
||||
impl Tracks for Name {
|
||||
fn tracks(&self) -> u8 {
|
||||
match self {
|
||||
Name::Andy => 7,
|
||||
|
@ -84,17 +71,6 @@ impl Name {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn from_badge(badge: u64) -> Self {
|
||||
match badge {
|
||||
badge => {
|
||||
if let Some(name) = NAMES.lock().await.borrow().get(badge) {
|
||||
*name
|
||||
} else {
|
||||
Name::Unknown
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ACCEPTED_SUFFIXABLE: [bool; 6] = [false, false, false, false, false, true];
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use core::{cell::RefCell, str::from_utf8};
|
||||
|
||||
use common::{Name, Request};
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
|
||||
use embedded_io_async::Write;
|
||||
|
@ -7,19 +8,11 @@ use log::*;
|
|||
use postcard::from_bytes;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{arraymap::ArrayMap, music::{Name, COMMANDS}, scanner::READ_CARD};
|
||||
use crate::{arraymap::ArrayMap, music::{COMMANDS}, scanner::READ_CARD};
|
||||
|
||||
pub static NAMES: Mutex<CriticalSectionRawMutex, RefCell<ArrayMap<64, u64, Name>>> =
|
||||
Mutex::new(RefCell::new(ArrayMap::new()));
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum Request {
|
||||
RecentBadge,
|
||||
SetRecentBadge(Name),
|
||||
SetVolume(u8),
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn server_task(stack: embassy_net::Stack<'static>) {
|
||||
let mut rx_buffer = [0; 4096];
|
||||
|
|
Loading…
Reference in a new issue