use std::path::PathBuf;
use crate::device::battery;
use crate::device::bt::{self as bt_mod, set_bt_bus};
use crate::device::clock;
use crate::device::config::SocFamily;
use crate::device::fb::Fb;
use crate::device::power;
use crate::device::traits::{FrontlightPaths, *};
use crate::device::wifi;
pub struct SysFrontlight {
brightness_path: PathBuf,
}
impl SysFrontlight {
pub fn new(paths: &FrontlightPaths) -> Self {
SysFrontlight {
brightness_path: paths.brightness.clone(),
}
}
pub fn from_path(path: PathBuf) -> Self {
SysFrontlight {
brightness_path: path,
}
}
}
impl Frontlight for SysFrontlight {
fn get(&self) -> u32 {
power::frontlight_get(&self.brightness_path).unwrap_or(0)
}
fn set(&self, brightness: u32) {
power::frontlight_set(&self.brightness_path, brightness);
}
fn restore(&self, brightness: u32) {
power::restore_frontlight(&self.brightness_path, brightness);
}
}
pub struct SysBattery;
impl Battery for SysBattery {
fn pct(&self) -> i32 {
battery::battery_pct()
}
}
pub struct SysWifi;
impl Wifi for SysWifi {
fn connected(&self) -> bool {
wifi::wifi_status()
}
fn ssid(&self) -> Option<String> {
wifi::wifi_name()
}
fn toggle(&self, on: bool) {
wifi::wifi_toggle(on);
}
}
pub struct SysBluetooth;
impl SysBluetooth {
pub fn init(soc: SocFamily) -> Self {
set_bt_bus(soc);
SysBluetooth
}
}
impl Bluetooth for SysBluetooth {
fn connected(&self) -> bool {
bt_mod::bt_status()
}
fn name(&self) -> Option<String> {
bt_mod::bt_name()
}
fn toggle(&self, on: bool) {
bt_mod::bt_toggle(on);
}
}
pub struct SysSystemControl;
impl SystemControl for SysSystemControl {
fn suspend(&self, state: &str) {
power::kernel_suspend(state);
}
fn clock(&self) -> String {
clock::current_clock()
}
}
pub struct SysFramebuffer<'a> {
fb: &'a Fb,
}
impl<'a> SysFramebuffer<'a> {
pub fn new(fb: &'a Fb) -> Self {
SysFramebuffer { fb }
}
}
impl<'a> Framebuffer for SysFramebuffer<'a> {
fn resolution(&self) -> (usize, usize) {
(self.fb.xres, self.fb.yres)
}
fn present(
&self,
buf: &[u8],
w: usize,
h: usize,
full: bool,
top: usize,
rh: usize,
waveform: u32,
) {
self.fb.present(buf, w, h, full, top, rh, waveform);
}
}
pub fn resolve_frontlight_paths(
fl_cfg: &crate::device::config::FrontlightConfig,
) -> FrontlightPaths {
FrontlightPaths {
brightness: power::known_brightness_path(fl_cfg),
mixer: power::frontlight_path(fl_cfg),
}
}