badge -> sound
This commit is contained in:
parent
d513a25258
commit
6b80c49a59
3 changed files with 117 additions and 17 deletions
4
inside/Cargo.lock
generated
4
inside/Cargo.lock
generated
|
|
@ -4,9 +4,9 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.93"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
|
||||
checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
|
|
|
|||
69
inside/src/lib.rs
Normal file
69
inside/src/lib.rs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(const_trait_impl)]
|
||||
|
||||
use core::sync::atomic::AtomicU32;
|
||||
|
||||
use blocking_network_stack::Socket;
|
||||
use embedded_hal::pwm::SetDutyCycle;
|
||||
use embedded_io::Write;
|
||||
use esp_hal::{delay::Delay, gpio::GpioPin, ledc::{channel::Channel, LowSpeed}, };
|
||||
use esp_println::println;
|
||||
use esp_wifi::wifi::{WifiDevice, WifiStaDevice};
|
||||
|
||||
|
||||
//pub fn handle<T,U,const V: u8>(slice: &[u8], motor: PwmPin<T,U, V,true>) {
|
||||
pub fn handle(slice: &[u8], motor: &mut Channel<LowSpeed, GpioPin<15>>, socket: &mut Socket<WifiDevice<WifiStaDevice>>) {
|
||||
println!("dat: {:?}", slice);
|
||||
let mut command = slice.trim_ascii().split(|c| *c == b' ');
|
||||
|
||||
// hate hate hate
|
||||
static LAST_BADGE_LOW: AtomicU32 = AtomicU32::new(0);
|
||||
static LAST_BADGE_HIG: AtomicU32 = AtomicU32::new(0);
|
||||
|
||||
match char::from_u32(command.next().unwrap()[0] as u32).unwrap() {
|
||||
'D' => {
|
||||
let hex = command.next().unwrap();
|
||||
println!("{hex:#?}");
|
||||
let buf: [u8;2] = hex::FromHex::from_hex(hex).unwrap();
|
||||
let power: u16 = u16::from_be_bytes(buf);
|
||||
println!("{power}");
|
||||
motor.set_duty_cycle(power).unwrap();
|
||||
},
|
||||
'O' => {
|
||||
open_door(motor);
|
||||
}
|
||||
'B' => {
|
||||
let buf: [u8;8] = hex::FromHex::from_hex(command.next().unwrap()).unwrap();
|
||||
let card: u64 = u64::from_ne_bytes(buf);
|
||||
println!("card {card:#16x}");
|
||||
|
||||
LAST_BADGE_LOW.store(card as u32, core::sync::atomic::Ordering::SeqCst);
|
||||
LAST_BADGE_HIG.store((card >> 32) as u32, core::sync::atomic::Ordering::SeqCst);
|
||||
|
||||
open_door(motor);
|
||||
},
|
||||
'G' => {
|
||||
|
||||
let mut last_badge: u64 = LAST_BADGE_LOW.load(core::sync::atomic::Ordering::SeqCst) as u64;
|
||||
last_badge += (LAST_BADGE_HIG.load(core::sync::atomic::Ordering::SeqCst) as u64) << 32;
|
||||
|
||||
let _ = socket.write_fmt(
|
||||
format_args!("B{last_badge}\r\n")
|
||||
);
|
||||
},
|
||||
_ => {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn open_door(motor: &mut Channel<LowSpeed, GpioPin<15>>) {
|
||||
let delay = Delay::new();
|
||||
let _ = motor.set_duty_cycle(0x533);
|
||||
delay.delay_millis(3000);
|
||||
//Timer::after_millis(3000).await;
|
||||
let _ = motor.set_duty_cycle(0x4c8);
|
||||
delay.delay_millis(750);
|
||||
let _ = motor.set_duty_cycle(0x4CD);
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
use embedded_io::{Read, ReadReady, Write};
|
||||
use embedded_hal::pwm::SetDutyCycle;
|
||||
use esp_backtrace as _;
|
||||
use esp_hal::{gpio::Io, ledc::{channel, timer, LSGlobalClkSource, Ledc, LowSpeed}, prelude::*, rng::Rng, time::{self, Duration}};
|
||||
use esp_hal::{gpio::Io, ledc::{channel, timer, LSGlobalClkSource, Ledc, LowSpeed}, prelude::*, reset::software_reset, rng::Rng, time::{self, Duration}};
|
||||
use esp_println::{print, println};
|
||||
use esp_wifi::wifi::{utils::create_network_interface, AccessPointInfo, ClientConfiguration, Configuration, WifiError, WifiStaDevice};
|
||||
use smoltcp::iface::SocketStorage;
|
||||
|
|
@ -72,8 +72,8 @@ fn main() -> ! {
|
|||
let mut stack = Stack::new(iface, device, socket_set, now, rng.random());
|
||||
|
||||
let client_config = Configuration::Client(ClientConfiguration {
|
||||
ssid: include_str!("../../ssid").try_into().unwrap(),
|
||||
password: include_str!("../../password").try_into().unwrap(),
|
||||
ssid: "🐟".try_into().unwrap(),
|
||||
password: "ilcougars1234".try_into().unwrap(),
|
||||
..Default::default()
|
||||
});
|
||||
let res = controller.set_configuration(&client_config);
|
||||
|
|
@ -125,6 +125,17 @@ fn main() -> ! {
|
|||
socket.listen(4595).unwrap();
|
||||
|
||||
loop {
|
||||
loop {
|
||||
match controller.is_connected() {
|
||||
Ok(true) => break,
|
||||
Ok(false) => {}
|
||||
Err(err) => {
|
||||
log::error!("{:?}", err);
|
||||
log::info!("connecting: {:?}", controller.connect());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
socket.work();
|
||||
|
||||
if !socket.is_open() {
|
||||
|
|
@ -148,6 +159,7 @@ fn main() -> ! {
|
|||
if let Ok(len) = socket.read(&mut buffer[pos..]) {
|
||||
let to_print = unsafe { core::str::from_utf8_unchecked(&buffer[..(pos + len)]) };
|
||||
|
||||
println!("recv {}", to_print);
|
||||
if to_print.contains("\r\n") {
|
||||
print!("{}", to_print);
|
||||
println!();
|
||||
|
|
@ -167,14 +179,7 @@ fn main() -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
let mut command = buffer[..pos].trim_ascii().split(|c| *c == b' ');
|
||||
let buf: [u8;2] = hex::FromHex::from_hex(command.next().unwrap()).unwrap();
|
||||
let card: u16 = u16::from_be_bytes(buf);
|
||||
println!("{card}");
|
||||
motor.set_duty_cycle(card).unwrap();
|
||||
|
||||
|
||||
handle(&buffer[..pos], &mut motor);
|
||||
handle(&buffer[..pos], &mut motor, &mut socket);
|
||||
|
||||
if !time_out {
|
||||
let _ = socket.write_all(
|
||||
|
|
|
|||
Loading…
Reference in a new issue