feat: add Zigbee-controlled smart light
This commit is contained in:
1 parent
9793bc62af
commit
1aa6ba3c5f
10 files changed
+237
-99
No files matched your search
+8
-24
@@ -25,7 +25,6 @@ use esp_hal_smartled::WS2812B_TIMING;
|
||||
use crate::config::STEPS_PER_BRIGHTNESS_UNIT;
|
||||
use crate::encoder::EVENTS;
|
||||
use crate::encoder::EncoderEvent;
|
||||
use crate::light::Mode;
|
||||
use crate::strip::Strip;
|
||||
|
||||
esp_bootloader_esp_idf::esp_app_desc!();
|
||||
@@ -33,12 +32,6 @@ esp_bootloader_esp_idf::esp_app_desc!();
|
||||
/// Brightness units per detent.
|
||||
const BRIGHTNESS_STEP: i16 = 8;
|
||||
|
||||
/// Hue per detent, in 1/256ths of the colour circle (~5.6 degrees).
|
||||
const HUE_STEP: i16 = 4;
|
||||
|
||||
/// Saturation units per detent; 0 is white, 255 fully coloured.
|
||||
const SATURATION_STEP: i16 = 16;
|
||||
|
||||
#[esp_rtos::main]
|
||||
async fn main(spawner: embassy_executor::Spawner) -> ! {
|
||||
esp_println::logger::init_logger_from_env();
|
||||
@@ -92,7 +85,7 @@ async fn main(spawner: embassy_executor::Spawner) -> ! {
|
||||
// the stack owns persistence: the information bases are restored here
|
||||
// and written back whenever the stack changes them
|
||||
let flash = BlockingAsync::new(FlashStorage::new(peripherals.FLASH));
|
||||
let storage = zigbee::storage::init_with_flash(flash, zigbee_stack::FLASH_RANGE).await;
|
||||
let storage = zigbee::storage::FlashStorage::new(flash, zigbee_stack::FLASH_RANGE).await;
|
||||
|
||||
let ieee802154 = Ieee802154::new(peripherals.IEEE802154);
|
||||
let mac = EspMlme::new(ieee802154, esp_radio::ieee802154::Config::default());
|
||||
@@ -106,7 +99,7 @@ async fn main(spawner: embassy_executor::Spawner) -> ! {
|
||||
));
|
||||
|
||||
spawner.spawn(zigbee_stack::stack_task(stack).expect("spawn stack_task"));
|
||||
spawner.spawn(zigbee_stack::on_off_task().expect("spawn on_off_task"));
|
||||
spawner.spawn(zigbee_stack::on_off_task(stack).expect("spawn on_off_task"));
|
||||
spawner.spawn(zigbee_stack::identify_task().expect("spawn identify_task"));
|
||||
}
|
||||
|
||||
@@ -114,25 +107,16 @@ async fn main(spawner: embassy_executor::Spawner) -> ! {
|
||||
match EVENTS.receive().await {
|
||||
EncoderEvent::Rotate(detents) => {
|
||||
let steps = i16::from(detents) * STEPS_PER_BRIGHTNESS_UNIT as i16;
|
||||
match light::mode() {
|
||||
Mode::Brightness => light::adjust_brightness(steps * BRIGHTNESS_STEP),
|
||||
Mode::Hue => light::adjust_hue(steps * HUE_STEP),
|
||||
Mode::Saturation => light::adjust_saturation(steps * SATURATION_STEP),
|
||||
}
|
||||
log::info!(
|
||||
"rotate {detents:+} -> brightness {} hue {} saturation {}",
|
||||
light::brightness(),
|
||||
light::hue(),
|
||||
light::saturation()
|
||||
);
|
||||
light::adjust_brightness(steps * BRIGHTNESS_STEP);
|
||||
log::info!("rotate {detents:+} -> brightness {}", light::brightness());
|
||||
}
|
||||
EncoderEvent::Click => {
|
||||
let on = light::toggle();
|
||||
log::info!("light {}", if on { "on" } else { "off" });
|
||||
let (kelvin, _) = light::next_temperature();
|
||||
log::info!("colour temperature {kelvin}K");
|
||||
}
|
||||
EncoderEvent::LongPress => {
|
||||
let mode = light::next_mode();
|
||||
log::info!("encoder now adjusts {mode:?}");
|
||||
let on = light::toggle();
|
||||
log::info!("light {}", if on { "on" } else { "off" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user