X-Git-Url: https://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=src%2Fsettings.rs;h=511cb8cf0c45be548e22b0c144185232c53b8835;hb=HEAD;hp=993917855d42237c2b90f17488c4c2ef7d416bb1;hpb=cbe5e6d643cafbb36dc0e2019651900a0623938a;p=temp2RGB.git diff --git a/src/settings.rs b/src/settings.rs index 9939178..feaa201 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,59 +1,65 @@ -use std::fs::File; - -use ron::{ - de::from_reader, - ser::{to_writer_pretty, PrettyConfig}, -}; -use serde::{Deserialize, Serialize}; - -use crate::rgb::RGB; - -#[derive(Debug, Deserialize, Serialize)] -pub enum MachineName { - Jiji, - LyssMetal, -} - -#[derive(Debug, Deserialize, Serialize)] -pub struct Settings { - pub machine_name: MachineName, - pub cold_color: RGB, - pub hot_color: RGB, - // Average temperature between CPU and GPU. - pub cold_temperature: f32, - pub hot_temperature: f32, -} - -type Result = std::result::Result>; - -impl Settings { - fn default() -> Self { - Settings { - machine_name: MachineName::Jiji, - cold_color: RGB { - red: 0, - green: 255, - blue: 40, - }, - hot_color: RGB { - red: 255, - green: 0, - blue: 0, - }, - cold_temperature: 55., - hot_temperature: 75., - } - } - - pub fn read(file_path: &str) -> Result { - match File::open(file_path) { - Ok(file) => from_reader(file).map_err(|e| e.into()), - Err(_) => { - let file = File::create(file_path)?; - let default_config = Settings::default(); - to_writer_pretty(file, &default_config, PrettyConfig::new())?; - Ok(default_config) - } - } - } -} +use std::fs::File; + +use ron::{ + de::from_reader, + ser::{PrettyConfig, to_writer_pretty}, +}; +use serde::{Deserialize, Serialize}; + +use crate::rgb::Rgb; + +#[derive(Debug, Deserialize, Serialize)] +pub enum MachineName { + Jiji, + LyssMetal, + LyssMetal2, + Mshroom, +} + +#[derive(Debug, Deserialize, Serialize)] +pub struct Settings { + pub machine_name: MachineName, + pub cold_color_1: Rgb, + pub hot_color_1: Rgb, + pub cold_color_2: Option, + pub hot_color_2: Option, + // Average temperature between CPU and GPU. + pub cold_temperature: f32, + pub hot_temperature: f32, +} + +type Result = std::result::Result>; + +impl Settings { + fn default() -> Self { + Settings { + machine_name: MachineName::Mshroom, + cold_color_1: Rgb { + red: 0, + green: 255, + blue: 40, + }, + hot_color_1: Rgb { + red: 255, + green: 0, + blue: 0, + }, + cold_color_2: None, + hot_color_2: None, + cold_temperature: 55., + hot_temperature: 75., + } + } + + pub fn read(file_path: &str) -> Result { + match File::open(file_path) { + Ok(file) => from_reader(file).map_err(|e| e.into()), + Err(_) => { + let file = File::create(file_path)?; + let default_config = Settings::default(); + to_writer_pretty(file, &default_config, PrettyConfig::new())?; + Ok(default_config) + } + } + } +}