Janky config save/load. Fine for builtin modes

This commit is contained in:
Luke
2020-04-16 21:55:49 +12:00
parent 0a88b5b20a
commit 5f8ea365ef
7 changed files with 106 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
use crate::{core::RogCore, DBUS_IFACE, DBUS_PATH};
use crate::{config::Config, core::RogCore, DBUS_IFACE, DBUS_PATH};
use dbus::{
blocking::Connection,
tree::{Factory, MethodErr},
@@ -7,12 +7,18 @@ use std::error::Error;
use std::time::Duration;
pub fn start_daemon() -> Result<(), Box<dyn Error>> {
let mut config = Config::default().read();
let mut core = RogCore::new()?;
core.aura_set_mode(&config.builtin)?;
let bright = RogCore::aura_brightness_bytes(config.brightness)?;
core.aura_set_mode(&bright)?;
let mut c = Connection::new_system()?;
c.request_name(DBUS_IFACE, false, true, false)?;
// The choice of factory tells us what type of tree we want,
// and if we want any extra data inside. We pick the simplest variant.
let f = Factory::new_fn::<()>();
let f = Factory::new_fnmut::<()>();
// We create a tree with one object path inside and make that path introspectable.
let tree = f.tree(()).add(
@@ -30,6 +36,13 @@ pub fn start_daemon() -> Result<(), Box<dyn Error>> {
if let Ok(mut core) = RogCore::new() {
match core.aura_set_mode(&bytes[..]) {
Ok(_) => {
// TODO: create statics out of header bytes
if bytes[0] == 0x5a && bytes[1] == 0xba {
config.brightness = bytes[4];
} else if bytes[0] == 0x5d && bytes[1] == 0xb3 {
config.builtin = bytes;
}
config.write();
let mret = m.msg.method_return().append1(s);
Ok(vec![mret])
}