Skip to content

Commit

Permalink
vinscant: cool led effects
Browse files Browse the repository at this point in the history
  • Loading branch information
draxaris1010 committed Sep 12, 2024
1 parent 90bccd2 commit 2ec7f9d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions vinscant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ 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"] }
smart_led_effects = "0.1.7"
palette = "0.7.6"
rgb = "0.8.50"

[build-dependencies]
embuild = "0.32.0"
Expand Down
17 changes: 13 additions & 4 deletions vinscant/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use smart_led_effects::strip::{Bounce, EffectIterator};
use ws2812_esp32_rmt_driver::{driver::color::LedPixelColorGrb24, LedPixelEsp32Rmt, RGB8};
use core::str;
use std::time::Duration;
Expand All @@ -9,7 +10,6 @@ use esp_idf_svc::{
prelude::Peripherals,
spi::{
self, SpiSingleDeviceDriver
//config::{DriverConfig, Config},
},
},
http::client::{Configuration, EspHttpConnection},
Expand All @@ -20,6 +20,8 @@ use mfrc522::{
comm::blocking::spi::SpiInterface,
Mfrc522,
};
use palette::{self, Srgb};
use rgb;

use lib::wifi;

Expand All @@ -33,14 +35,20 @@ pub struct Config {
auth_key: &'static str,
}

fn from_palette_rgb_to_rgb_rgb(value: &palette::rgb::Rgb<palette::encoding::Srgb, u8>) -> RGB8 {
let [red, green, blue] = [value.red, value.green, value.blue];
RGB8::new(red, green, blue)
}

struct StatusNotifier<'a> {
led_strip: LedPixelEsp32Rmt::<'a, RGB8, LedPixelColorGrb24>,
leds: usize,
idle_effect: Box<dyn EffectIterator>,
}
impl StatusNotifier<'_> {
fn idle(&mut self) {
let pixels = std::iter::repeat(RGB8::new(0x00, 0x00, 0x00)).take(self.leds);
self.led_strip.write_nocopy(pixels);
let pixels = self.idle_effect.next().unwrap();
self.led_strip.write_nocopy(pixels.iter().map(|color| from_palette_rgb_to_rgb_rgb(color)));
}
fn processing(&mut self) {
let pixels = std::iter::repeat(RGB8::new(0xff, 0xff, 0x00)).take(self.leds);
Expand Down Expand Up @@ -112,7 +120,8 @@ fn main() {

let mut status_notifier = StatusNotifier {
led_strip,
leds: 8
leds: 8,
idle_effect: Box::new(Bounce::new(8, Some(Srgb::new(1.0, 1.0, 1.0)), Some(1), None, None, None)),
};

status_notifier.idle();
Expand Down

0 comments on commit 2ec7f9d

Please sign in to comment.