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,
|
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)]
|
#[derive(Clone, Copy)]
|
||||||
|
|
@ -295,27 +305,27 @@ impl App {
|
||||||
if self.timers.led0_timer.need_service() {
|
if self.timers.led0_timer.need_service() {
|
||||||
self.timers.led0_timer.service();
|
self.timers.led0_timer.service();
|
||||||
self.sequences.led0.next();
|
self.sequences.led0.next();
|
||||||
self.services
|
self.services.led0.set_amplitude(
|
||||||
.led0
|
self.sequences.led0.get_value() / self.settings.brightness.as_brightness_divisor(),
|
||||||
.set_amplitude(self.sequences.led0.get_value());
|
);
|
||||||
// #[cfg(feature = "enable_print")]
|
// #[cfg(feature = "enable_print")]
|
||||||
// println!("led0 sevice {}", self.sequences.led0.get_value());
|
// println!("led0 sevice {}", self.sequences.led0.get_value());
|
||||||
}
|
}
|
||||||
if self.timers.led1_timer.need_service() {
|
if self.timers.led1_timer.need_service() {
|
||||||
self.timers.led1_timer.service();
|
self.timers.led1_timer.service();
|
||||||
self.sequences.led1.next();
|
self.sequences.led1.next();
|
||||||
self.services
|
self.services.led1.set_amplitude(
|
||||||
.led1
|
self.sequences.led1.get_value() / self.settings.brightness.as_brightness_divisor(),
|
||||||
.set_amplitude(self.sequences.led1.get_value());
|
);
|
||||||
// #[cfg(feature = "enable_print")]
|
// #[cfg(feature = "enable_print")]
|
||||||
// println!("led1 service");
|
// println!("led1 service");
|
||||||
}
|
}
|
||||||
if self.timers.led2_timer.need_service() {
|
if self.timers.led2_timer.need_service() {
|
||||||
self.timers.led2_timer.service();
|
self.timers.led2_timer.service();
|
||||||
self.sequences.led2.next();
|
self.sequences.led2.next();
|
||||||
self.services
|
self.services.led2.set_amplitude(
|
||||||
.led2
|
self.sequences.led2.get_value() / self.settings.brightness.as_brightness_divisor(),
|
||||||
.set_amplitude(self.sequences.led2.get_value());
|
);
|
||||||
// #[cfg(feature = "enable_print")]
|
// #[cfg(feature = "enable_print")]
|
||||||
// println!("led2 service");
|
// println!("led2 service");
|
||||||
}
|
}
|
||||||
|
|
@ -357,9 +367,9 @@ impl App {
|
||||||
println!("new volume: {:?}", self.settings.volume);
|
println!("new volume: {:?}", self.settings.volume);
|
||||||
}
|
}
|
||||||
pub fn brightness_button(&mut self) {
|
pub fn brightness_button(&mut self) {
|
||||||
|
self.settings.brightness.next();
|
||||||
#[cfg(feature = "enable_print")]
|
#[cfg(feature = "enable_print")]
|
||||||
println!("brightness button app handler");
|
println!("new brightness: {:?}", self.settings.brightness);
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
pub fn main_button(&mut self) {
|
pub fn main_button(&mut self) {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
@ -376,7 +386,6 @@ impl App {
|
||||||
// 3. amp_en control
|
// 3. amp_en control
|
||||||
//
|
//
|
||||||
// LED:
|
// LED:
|
||||||
// 1. brightness control
|
|
||||||
//
|
//
|
||||||
// INTERFACE:
|
// INTERFACE:
|
||||||
// 1. short press handling
|
// 1. short press handling
|
||||||
|
|
@ -391,3 +400,4 @@ impl App {
|
||||||
//
|
//
|
||||||
// STRETCH TODO LIST
|
// STRETCH TODO LIST
|
||||||
// 1. clean up edge detector
|
// 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();
|
app.init();
|
||||||
loop {
|
loop {
|
||||||
// system servicing
|
// system servicing
|
||||||
//
|
|
||||||
// edge detector
|
// volume edge detector
|
||||||
if !volume_btn_input.active() {
|
if !volume_btn_input.active() {
|
||||||
let volume_btn_curr = volume_btn_input.is_high_immediate();
|
let volume_btn_curr = volume_btn_input.is_high_immediate();
|
||||||
if volume_btn_prev != volume_btn_curr {
|
if volume_btn_prev != volume_btn_curr {
|
||||||
|
|
@ -349,6 +349,25 @@ fn app_main(mut p: hal::Peripherals) -> ! {
|
||||||
volume_btn_input.reset();
|
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
|
// systick tick
|
||||||
if unsafe {
|
if unsafe {
|
||||||
#[allow(static_mut_refs)]
|
#[allow(static_mut_refs)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue