Skip to content

Commit

Permalink
vinscant: tried to get leds working
Browse files Browse the repository at this point in the history
  • Loading branch information
draxaris1010 committed Sep 12, 2024
1 parent 4d17b43 commit d52948d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions vinscant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ anyhow = "1.0.86"
embedded-svc = "0.28.0"
mfrc522 = "0.7.0"
hex = "0.4.3"
ws2812-esp32-rmt-driver = { version = "0.9.0", features = ["smart-leds-trait"] }

[build-dependencies]
embuild = "0.32.0"
Expand Down
47 changes: 41 additions & 6 deletions vinscant/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use anyhow::{bail, Result};
use ws2812_esp32_rmt_driver::{driver::color::LedPixelColorGrb24, LedPixelEsp32Rmt, RGB8};
use core::str;
use embedded_svc::{
http::{client::Client, Method},
io::Read,
};
use embedded_svc::http::{client::Client, Method};
use esp_idf_svc::{
eventloop::EspSystemEventLoop, hal::{
gpio::{InputPin, OutputPin},
Expand All @@ -12,7 +9,9 @@ use esp_idf_svc::{
self, SpiSingleDeviceDriver
//config::{DriverConfig, Config},
},
}, http::client::{Configuration, EspHttpConnection}, sys::esp_task_wdt_deinit
},
http::client::{Configuration, EspHttpConnection},
sys::esp_task_wdt_deinit
};

use mfrc522::{
Expand All @@ -32,6 +31,26 @@ pub struct Config {
auth_key: &'static str,
}

#[derive(Debug)]
struct StatusNotifier<'a> {
led_strip: LedPixelEsp32Rmt::<'a, RGB8, LedPixelColorGrb24>,
leds: usize,
}
impl StatusNotifier<'_> {
fn idle(&mut self) {
let pixels = std::iter::repeat(RGB8::new(0xff, 0xff, 0x00)).take(self.leds);
self.led_strip.write_nocopy(pixels);
}
fn good(&mut self) {
let pixels = std::iter::repeat(RGB8::new(0x00, 0xff, 0x00)).take(self.leds);
self.led_strip.write_nocopy(pixels);
}
fn bad(&mut self) {
let pixels = std::iter::repeat(RGB8::new(0xff, 0x00, 0x00)).take(self.leds);
self.led_strip.write_nocopy(pixels);
}
}

fn main() {
unsafe {
esp_task_wdt_deinit();
Expand Down Expand Up @@ -77,6 +96,17 @@ fn main() {
let scan_interface = SpiInterface::new(scan_spi_device);
let mut scanner = Mfrc522::new(scan_interface).init().unwrap();

let led_pin = pins.gpio5;
let channel = peripherals.rmt.channel0;
let mut led_strip = LedPixelEsp32Rmt::<RGB8, LedPixelColorGrb24>::new(channel, led_pin).unwrap();

let mut status_notifier = StatusNotifier {
led_strip,
leds: 8
};

status_notifier.idle();

loop {
if let Ok(answer) = scanner.reqa() {
if let Ok(uid) = scanner.select(&answer) {
Expand All @@ -91,6 +121,11 @@ fn main() {
request.write(format!("{};{}", hex::encode(uid.as_bytes()), app_config.auth_key).as_bytes());
if let Ok(response) = request.submit() {
log::info!("response code: {}", response.status());
if response.status() == 200 {
status_notifier.good();
}
} else {

}
}
}
Expand Down

0 comments on commit d52948d

Please sign in to comment.