mirror of
https://github.com/IllusionMan1212/predator-ng.git
synced 2026-10-24 02:12:30 +00:00
WIP changes?
This commit is contained in:
+27
-26
@@ -105,7 +105,7 @@ fn update_dynamic(dynamic_dev: &mut File, cfg: Config) {
|
||||
dynamic_data[7] = cfg.kb.color[2];
|
||||
dynamic_data[9] = 1;
|
||||
|
||||
dynamic_dev.write(&dynamic_data).expect("Failed to write to dynamic device");
|
||||
dynamic_dev.write_all(&dynamic_data).expect("Failed to write to dynamic device");
|
||||
}
|
||||
|
||||
fn change_brightness(dynamic_dev: &mut File, cfg: Config) {
|
||||
@@ -119,7 +119,7 @@ fn change_brightness(dynamic_dev: &mut File, cfg: Config) {
|
||||
dynamic_data[7] = if cfg.kb.mode == KBLightMode::Static {0} else {cfg.kb.color[2]};
|
||||
dynamic_data[9] = 1;
|
||||
|
||||
dynamic_dev.write(&dynamic_data).expect("Failed to write to dynamic device");
|
||||
dynamic_dev.write_all(&dynamic_data).expect("Failed to write to dynamic device");
|
||||
}
|
||||
|
||||
fn switch_to_static(static_dev: &mut File, dynamic_dev: &mut File, cfg: Config) {
|
||||
@@ -130,7 +130,7 @@ fn switch_to_static(static_dev: &mut File, dynamic_dev: &mut File, cfg: Config)
|
||||
dynamic_data[2] = cfg.kb.brightness;
|
||||
dynamic_data[9] = 1; // This is needed for PT314-52s and possibly other models
|
||||
|
||||
dynamic_dev.write(&dynamic_data).expect("Failed to write to static device");
|
||||
dynamic_dev.write_all(&dynamic_data).expect("Failed to write to static device");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ fn write_to_static_dev(static_dev: &mut File, cfg: Config, zone: usize) {
|
||||
cfg.kb.zones[1].enabled as u8,
|
||||
cfg.kb.zones[2].enabled as u8
|
||||
];
|
||||
static_dev.write(&static_data).expect("Failed to write to static device");
|
||||
static_dev.write_all(&static_data).expect("Failed to write to static device");
|
||||
}
|
||||
|
||||
fn toggle_zone(static_dev: &mut File, cfg: Config, zone_num: usize) {
|
||||
@@ -165,7 +165,7 @@ fn toggle_zone(static_dev: &mut File, cfg: Config, zone_num: usize) {
|
||||
cfg.kb.zones[2].enabled as u8 // Zone 3 enabled
|
||||
];
|
||||
|
||||
static_dev.write(&static_data).expect("Failed to write to static device");
|
||||
static_dev.write_all(&static_data).expect("Failed to write to static device");
|
||||
}
|
||||
|
||||
fn show_dynamic_kb_lighting_pane(ui: &mut egui::Ui, dynamic_dev: &mut File, cfg: &mut Config, config_path: PathBuf) {
|
||||
@@ -306,7 +306,7 @@ fn show_static_kb_lighting_pane(ui: &mut egui::Ui, static_dev: &mut File, cfg: &
|
||||
});
|
||||
if !cfg.kb.zones[0].enabled {
|
||||
let pos = [egui::pos2(picker_rect.max.x - 2.0, picker_rect.max.y - 7.0)];
|
||||
ui.put(egui::Rect::from_points(&pos), egui::Image::new(&prohibit_tex).max_size(egui::Vec2::new(10.0, 10.0)));
|
||||
ui.put(egui::Rect::from_points(&pos), egui::Image::new(&prohibit_tex).max_size(egui::Vec2::new(14.0, 14.0)));
|
||||
}
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
@@ -350,7 +350,7 @@ fn show_static_kb_lighting_pane(ui: &mut egui::Ui, static_dev: &mut File, cfg: &
|
||||
});
|
||||
if !cfg.kb.zones[1].enabled {
|
||||
let pos = [egui::pos2(picker_rect.max.x - 2.0, picker_rect.max.y - 7.0)];
|
||||
ui.put(egui::Rect::from_points(&pos), egui::Image::new(&prohibit_tex).max_size(egui::Vec2::new(10.0, 10.0)));
|
||||
ui.put(egui::Rect::from_points(&pos), egui::Image::new(&prohibit_tex).max_size(egui::Vec2::new(14.0, 14.0)));
|
||||
}
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
@@ -432,25 +432,26 @@ fn check_devices(options: &eframe::NativeOptions) -> Result<(File, File), String
|
||||
.create(false)
|
||||
.open("/dev/acer-gkbbl-0");
|
||||
|
||||
if static_dev.is_err() || dynamic_dev.is_err() {
|
||||
eprintln!("[ERROR]: Could not open device files");
|
||||
match static_dev.is_err() || dynamic_dev.is_err() {
|
||||
true => {
|
||||
eprintln!("[ERROR]: Could not open device files");
|
||||
|
||||
let _ = eframe::run_simple_native("Predator-ng", options.clone(), move |ctx, _frame| {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.colored_label(egui::Color32::RED, egui::RichText::new("Error: could not open device files").heading());
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Please make sure you have the kernel module loaded, and that both");
|
||||
ui.label(egui::RichText::new("/dev/acer-gkbbl-0").code());
|
||||
ui.label("and");
|
||||
ui.label(egui::RichText::new("/dev/acer-gkbbl-static-0").code());
|
||||
ui.label("exist");
|
||||
let _ = eframe::run_simple_native("Predator-ng", options.clone(), move |ctx, _frame| {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.colored_label(egui::Color32::RED, egui::RichText::new("Error: could not open device files").heading());
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.label("Please make sure you have the kernel module loaded, and that both");
|
||||
ui.label(egui::RichText::new("/dev/acer-gkbbl-0").code());
|
||||
ui.label("and");
|
||||
ui.label(egui::RichText::new("/dev/acer-gkbbl-static-0").code());
|
||||
ui.label("exist");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return Err("Could not open device files".to_string());
|
||||
} else {
|
||||
return Ok((static_dev.unwrap(), dynamic_dev.unwrap()));
|
||||
Err("Could not open device files".to_string())
|
||||
}
|
||||
false => Ok((static_dev.unwrap(), dynamic_dev.unwrap())),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,7 +470,7 @@ fn initial_load(config_path: PathBuf, static_dev: &mut File, dynamic_dev: &mut F
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let options = eframe::NativeOptions {
|
||||
initial_window_size: Some(egui::vec2(640.0, 480.0)),
|
||||
min_window_size: Some(egui::vec2(620.0, 400.0)),
|
||||
//min_window_size: Some(egui::vec2(620.0, 400.0)),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@@ -492,16 +493,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
ui.label("Keyboard Lighting Mode: ");
|
||||
if ui.radio_value(&mut cfg.kb.mode, KBLightMode::Static, "Static").clicked() {
|
||||
switch_to_static(&mut static_dev, &mut dynamic_dev, cfg);
|
||||
let _ = confy::store_path(config_path.clone(), &cfg);
|
||||
let _ = confy::store_path(config_path.clone(), cfg);
|
||||
}
|
||||
if ui.radio_value(&mut cfg.kb.mode, KBLightMode::Dynamic, "Dynamic").clicked() {
|
||||
update_dynamic(&mut dynamic_dev, cfg);
|
||||
let _ = confy::store_path(config_path.clone(), &cfg);
|
||||
let _ = confy::store_path(config_path.clone(), cfg);
|
||||
}
|
||||
ui.label("Keyboard Brightness: ");
|
||||
if ui.add(egui::Slider::new(&mut cfg.kb.brightness, 0..=100).show_value(false).step_by(25.0)).changed() {
|
||||
change_brightness(&mut dynamic_dev, cfg);
|
||||
let _ = confy::store_path(config_path.clone(), &cfg);
|
||||
let _ = confy::store_path(config_path.clone(), cfg);
|
||||
}
|
||||
});
|
||||
ui.add_space(15.0);
|
||||
|
||||
Reference in New Issue
Block a user