Skip to content
Snippets Groups Projects
Commit 3837306a authored by Stephen D's avatar Stephen D
Browse files

wire up more settings

parent 2738a981
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,6 @@ const BACKOFF_FACTOR: u32 = 1;
const RX_LIGHT_TIME_MS: u64 = 100; // milliseconds
const BACKLIGHT_DELAY_TIME_SECS: u64 = 5;
const BACKLIGHT_FADE_TIME_SECS: u64 = 2;
const LCD_DELAY_TIME_SECS: u64 = 15;
const LCD_FADE_TIME_SECS: u64 = 2;
const TOUCHPAD_THRESHOLD: i16 = 3;
......@@ -224,7 +223,13 @@ impl View {
None
}
fn touchpad_scroll(&mut self, x: i16, y: i16, brightness: &mut u8) {
fn touchpad_scroll(
&mut self,
x: i16,
y: i16,
display_brightness: &mut u8,
keyboard_brightness: &mut u8,
) {
match self {
View::MainMenu(m) => m.touchpad_scroll(x, y),
View::Contacts(c) => c.touchpad_scroll(x, y),
......@@ -235,7 +240,7 @@ impl View {
View::Packets(p) => p.touchpad_scroll(x, y),
View::Digipeater(d) => d.touchpad_scroll(x, y),
View::Gps(_) => {}
View::Settings(s) => s.touchpad_scroll(x, y, brightness),
View::Settings(s) => s.touchpad_scroll(x, y, display_brightness, keyboard_brightness),
}
}
}
......@@ -262,6 +267,7 @@ pub struct Controller {
display_bl: DisplayBl,
last_key_press: Instant,
display_brightness: u8,
keyboard_brightness: u8,
sleepy: bool,
sleeping: bool,
gps_data: GpsData,
......@@ -285,7 +291,9 @@ impl Controller {
keyboard_bl: KeyboardBl,
display_bl: DisplayBl,
) -> Self {
let display_brightness = storage.settings().display_brightness();
let settings = storage.settings();
let display_brightness = settings.display_brightness();
let keyboard_brightness = settings.keyboard_brightness();
Self {
status: StatusBar::new(volt_meter),
......@@ -297,6 +305,7 @@ impl Controller {
display_bl,
last_key_press: monotonics::now(),
display_brightness,
keyboard_brightness,
sleepy: false,
sleeping: false,
gps_data: GpsData::default(),
......@@ -433,12 +442,15 @@ impl Controller {
}
}
pub fn new_unread_message(&mut self) -> bool {
let ret = self.new_unread;
// first bool is for the LED
// second is for the vibrator
pub fn new_unread_message(&mut self) -> (bool, bool) {
let led = self.new_unread;
let vibrator = led && self.storage.settings().vibrate();
self.new_unread = false;
ret
(led, vibrator)
}
pub fn green_led_on(&self) -> bool {
......@@ -605,9 +617,9 @@ impl Controller {
u32::from(self.display_bl.get_max_duty()) * u32::from(self.display_brightness) / 100,
)
.unwrap();
// using display brightness for keyboard as well
let keyboard_max_duty = u16::try_from(
u32::from(self.keyboard_bl.get_max_duty()) * u32::from(self.display_brightness) / 100,
u32::from(self.keyboard_bl.get_max_duty()) * u32::from(self.keyboard_brightness) / 100,
)
.unwrap();
......@@ -626,20 +638,21 @@ impl Controller {
// lcd backlight logic
// sleepy = screen is turning off or is fully off
// sleeping = screen is fully off
(self.sleepy, self.sleeping) =
if let Some(fade_delta) = delta.checked_sub(LCD_DELAY_TIME_SECS.secs::<1, 1>()) {
let fade_delta = fade_delta.to_millis();
let fade_time_ms = LCD_FADE_TIME_SECS * 1000;
let frac = u64::from(display_max_duty) * (fade_time_ms.saturating_sub(fade_delta))
/ fade_time_ms;
self.display_bl.set_duty(frac.try_into().unwrap());
(true, frac == 0)
} else {
self.display_bl.set_duty(display_max_duty);
(self.sleepy, self.sleeping) = if let Some(fade_delta) =
delta.checked_sub(u64::from(self.storage.settings().sleep_time()).secs::<1, 1>())
{
let fade_delta = fade_delta.to_millis();
let fade_time_ms = LCD_FADE_TIME_SECS * 1000;
let frac = u64::from(display_max_duty) * (fade_time_ms.saturating_sub(fade_delta))
/ fade_time_ms;
self.display_bl.set_duty(frac.try_into().unwrap());
(false, false)
};
(true, frac == 0)
} else {
self.display_bl.set_duty(display_max_duty);
(false, false)
};
}
pub fn render<E, DT: DrawTarget<Color = Rgb565, Error = E>>(
......@@ -827,8 +840,12 @@ impl Controller {
x = 0;
}
self.cur_view
.touchpad_scroll(x, y, &mut self.display_brightness);
self.cur_view.touchpad_scroll(
x,
y,
&mut self.display_brightness,
&mut self.keyboard_brightness,
);
}
}
}
......@@ -244,7 +244,13 @@ impl Device {
// updating brightness here
// probably not perfect but whatever. At least we only update it when we scroll
pub fn touchpad_scroll(&mut self, x: i16, y: i16, display_brightness: &mut u8) {
pub fn touchpad_scroll(
&mut self,
x: i16,
y: i16,
display_brightness: &mut u8,
keyboard_brightness: &mut u8,
) {
match self.selected {
0 => self.display_brightness.touchpad_scroll(x, y),
1 => self.keyboard_brightness.touchpad_scroll(x, y),
......@@ -271,6 +277,7 @@ impl Device {
ScrollAction::None => {}
}
*display_brightness = self.display_brightness.value().value()
*display_brightness = self.display_brightness.value().value();
*keyboard_brightness = self.keyboard_brightness.value().value();
}
}
......@@ -110,12 +110,18 @@ impl SettingsView {
// updating brightness here
// probably not perfect but whatever. At least we only update it when we scroll
pub fn touchpad_scroll(&mut self, x: i16, y: i16, brightness: &mut u8) {
pub fn touchpad_scroll(
&mut self,
x: i16,
y: i16,
display_brightness: &mut u8,
keyboard_brightness: &mut u8,
) {
match &mut self.view {
View::Selector(s) => s.touchpad_scroll(x, y),
View::General(g) => g.touchpad_scroll(x, y),
View::Radio(r) => r.touchpad_scroll(x, y),
View::Device(d) => d.touchpad_scroll(x, y, brightness),
View::Device(d) => d.touchpad_scroll(x, y, display_brightness, keyboard_brightness),
View::Beacon(b) => b.touchpad_scroll(x, y),
View::BlackHole(b) => b.touchpad_scroll(x, y),
View::About(a) => a.touchpad_scroll(x, y),
......
......@@ -357,8 +357,11 @@ mod app {
});
});
if g.new_unread_message() {
let (led, vibrator) = g.new_unread_message();
if led {
let _ = notif_light_on::spawn();
}
if vibrator {
let _ = vibrate_activate::spawn();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment