add basic brightness control
This commit is contained in:
parent
95b55f88a8
commit
930d10218f
2 changed files with 43 additions and 14 deletions
|
|
@ -44,6 +44,16 @@ mod settings {
|
|||
Self::Maximum => 1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_brightness_divisor(&self) -> u8 {
|
||||
match self {
|
||||
Self::Off => u8::MAX,
|
||||
Self::Low => 4,
|
||||
Self::Medium => 3,
|
||||
Self::High => 2,
|
||||
Self::Maximum => 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
|
@ -295,27 +305,27 @@ impl App {
|
|||
if self.timers.led0_timer.need_service() {
|
||||
self.timers.led0_timer.service();
|
||||
self.sequences.led0.next();
|
||||
self.services
|
||||
.led0
|
||||
.set_amplitude(self.sequences.led0.get_value());
|
||||
self.services.led0.set_amplitude(
|
||||
self.sequences.led0.get_value() / self.settings.brightness.as_brightness_divisor(),
|
||||
);
|
||||
// #[cfg(feature = "enable_print")]
|
||||
// println!("led0 sevice {}", self.sequences.led0.get_value());
|
||||
}
|
||||
if self.timers.led1_timer.need_service() {
|
||||
self.timers.led1_timer.service();
|
||||
self.sequences.led1.next();
|
||||
self.services
|
||||
.led1
|
||||
.set_amplitude(self.sequences.led1.get_value());
|
||||
self.services.led1.set_amplitude(
|
||||
self.sequences.led1.get_value() / self.settings.brightness.as_brightness_divisor(),
|
||||
);
|
||||
// #[cfg(feature = "enable_print")]
|
||||
// println!("led1 service");
|
||||
}
|
||||
if self.timers.led2_timer.need_service() {
|
||||
self.timers.led2_timer.service();
|
||||
self.sequences.led2.next();
|
||||
self.services
|
||||
.led2
|
||||
.set_amplitude(self.sequences.led2.get_value());
|
||||
self.services.led2.set_amplitude(
|
||||
self.sequences.led2.get_value() / self.settings.brightness.as_brightness_divisor(),
|
||||
);
|
||||
// #[cfg(feature = "enable_print")]
|
||||
// println!("led2 service");
|
||||
}
|
||||
|
|
@ -357,9 +367,9 @@ impl App {
|
|||
println!("new volume: {:?}", self.settings.volume);
|
||||
}
|
||||
pub fn brightness_button(&mut self) {
|
||||
self.settings.brightness.next();
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("brightness button app handler");
|
||||
// TODO
|
||||
println!("new brightness: {:?}", self.settings.brightness);
|
||||
}
|
||||
pub fn main_button(&mut self) {
|
||||
// TODO
|
||||
|
|
@ -376,7 +386,6 @@ impl App {
|
|||
// 3. amp_en control
|
||||
//
|
||||
// LED:
|
||||
// 1. brightness control
|
||||
//
|
||||
// INTERFACE:
|
||||
// 1. short press handling
|
||||
|
|
@ -391,3 +400,4 @@ impl App {
|
|||
//
|
||||
// STRETCH TODO LIST
|
||||
// 1. clean up edge detector
|
||||
// 2. better handling for pwm scaling (brightness / volume)
|
||||
|
|
|
|||
|
|
@ -329,8 +329,8 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
|||
app.init();
|
||||
loop {
|
||||
// system servicing
|
||||
//
|
||||
// edge detector
|
||||
|
||||
// volume edge detector
|
||||
if !volume_btn_input.active() {
|
||||
let volume_btn_curr = volume_btn_input.is_high_immediate();
|
||||
if volume_btn_prev != volume_btn_curr {
|
||||
|
|
@ -349,6 +349,25 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
|||
volume_btn_input.reset();
|
||||
}
|
||||
|
||||
// brightness edge detector
|
||||
if !light_ctrl_btn_input.active() {
|
||||
let light_ctrl_btn_curr = light_ctrl_btn_input.is_high_immediate();
|
||||
if light_ctrl_btn_prev != light_ctrl_btn_curr {
|
||||
light_ctrl_btn_input.begin();
|
||||
light_ctrl_btn_prev = light_ctrl_btn_curr;
|
||||
}
|
||||
}
|
||||
|
||||
light_ctrl_btn_input.service();
|
||||
if light_ctrl_btn_input.ready() {
|
||||
#[cfg(feature = "enable_print")]
|
||||
println!("brightness btn value: {}", light_ctrl_btn_input.value());
|
||||
if !light_ctrl_btn_input.value() {
|
||||
app.brightness_button();
|
||||
}
|
||||
light_ctrl_btn_input.reset();
|
||||
}
|
||||
|
||||
// systick tick
|
||||
if unsafe {
|
||||
#[allow(static_mut_refs)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue