Skip to content

Commit

Permalink
Merge pull request #5 from FrameworkComputer/white-backlight
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnAZoidberg authored Feb 6, 2023
2 parents 0c066f9 + a266861 commit bff059b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
42 changes: 19 additions & 23 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn find_devices(api: &HidApi, args: &ClapCli) -> Found {
}

if args.list || args.verbose {
println!("{:04x}:{:04x} Interface: {}", vid, pid, interface);
println!("{vid:04x}:{pid:04x} Interface: {interface}");
println!(" Manufacturer: {:?}", dev_info.manufacturer_string());
println!(" path: {:?}", dev_info.path());
println!(" Product: {:?}", dev_info.product_string());
Expand Down Expand Up @@ -197,8 +197,7 @@ fn find_devices(api: &HidApi, args: &ClapCli) -> Found {
RAW_USAGE_PAGE => {
if interface != QMK_INTERFACE {
println!(
"Something is wrong with {}:{}. The interface isn't {}",
vid, pid, QMK_INTERFACE
"Something is wrong with {vid}:{pid}. The interface isn't {QMK_INTERFACE}"
);
} else {
found.raw_usages.push(dev_info.clone());
Expand Down Expand Up @@ -237,7 +236,7 @@ fn main() {
}
}
Err(e) => {
eprintln!("Error: {}", e);
eprintln!("Error: {e}");
}
};
}
Expand All @@ -253,7 +252,7 @@ fn all_keycodes(device: &HidDevice) {
KC_UP, KC_DOWN, KC_RGHT,
];
for keycode in ansi {
println!("Emulating keycode: {}", keycode);
println!("Emulating keycode: {keycode}");
send_factory_command(device, 0x01, keycode).unwrap();
thread::sleep(Duration::from_millis(100));
}
Expand All @@ -265,22 +264,19 @@ fn use_device(args: &ClapCli, api: &HidApi, dev_info: &DeviceInfo) {
let interface = dev_info.interface_number();

if args.verbose {
println!(
"Connecting to {:04X}:{:04X} Interface: {}",
vid, pid, interface
);
println!("Connecting to {vid:04X}:{pid:04X} Interface: {interface}");
}

let device = dev_info.open_device(api).unwrap();

match &args.command {
Some(Commands::Factory(args)) => {
if let Some(keycode) = args.keycode {
println!("Emulating keycode: {}", keycode);
println!("Emulating keycode: {keycode}");
send_factory_command(&device, 0x01, keycode as u8).unwrap();
}
if let Some(led) = args.led {
println!("Lighting up LED: {}", led);
println!("Lighting up LED: {led}");
send_factory_command(&device, 0x02, led).unwrap();
}
if args.all_keycodes {
Expand All @@ -295,7 +291,7 @@ fn use_device(args: &ClapCli, api: &HidApi, dev_info: &DeviceInfo) {
Some(Commands::Via(args)) => {
if args.version {
let prot_ver = get_protocol_ver(&device).unwrap();
println!("Protocol Version: {:04X}", prot_ver);
println!("Protocol Version: {prot_ver:04X}");
} else if args.eeprom_reset {
eeprom_reset(&device).unwrap();
} else if args.bootloader {
Expand All @@ -310,13 +306,13 @@ fn use_device(args: &ClapCli, api: &HidApi, dev_info: &DeviceInfo) {
let fw_ver =
get_keyboard_value(&device, ViaKeyboardValueId::FirmwareVersion).unwrap();

println!("Protocol Version: {:04X}", prot_ver);
println!("Protocol Version: {prot_ver:04X}");
println!("Uptime: {:?}s", uptime / 1000);
println!("Layout Options: {:?}", layout_opts);
println!("Switch Matrix State: {:?}", matrix_state); // TODO: Decode
println!("VIA Firmware Version: {:?}", fw_ver);
println!("Layout Options: {layout_opts:?}");
println!("Switch Matrix State: {matrix_state:?}"); // TODO: Decode
println!("VIA Firmware Version: {fw_ver:?}");
} else if args.device_indication {
// TODO: Make sure it works with the single color backlight
// Works with RGB and single zone backlight keyboards
// Device indication doesn't work well with all effects
// So it's best to save the currently configured one, switch to solid color and later back.
let cur_effect = get_rgb_u8(&device, ViaRgbMatrixValue::Effect as u8).unwrap();
Expand Down Expand Up @@ -349,27 +345,27 @@ fn use_device(args: &ClapCli, api: &HidApi, dev_info: &DeviceInfo) {
set_rgb_u8(&device, ViaRgbMatrixValue::Effect as u8, effect).unwrap();
}
let effect = get_rgb_u8(&device, ViaRgbMatrixValue::Effect as u8).unwrap();
println!("Effect: {}", effect)
println!("Effect: {effect}")
} else if let Some(arg_speed) = args.rgb_effect_speed {
if let Some(speed) = arg_speed {
set_rgb_u8(&device, ViaRgbMatrixValue::EffectSpeed as u8, speed).unwrap();
}
let speed = get_rgb_u8(&device, ViaRgbMatrixValue::EffectSpeed as u8).unwrap();
println!("Effect Speed: {}", speed)
println!("Effect Speed: {speed}")
} else if let Some(arg_saturation) = &args.rgb_saturation {
if let Some(saturation) = arg_saturation {
set_rgb_color(&device, None, Some(*saturation)).unwrap();
}
let (hue, saturation) = get_rgb_color(&device).unwrap();
println!("Color Hue: {}", hue);
println!("Color Saturation: {}", saturation);
println!("Color Hue: {hue}");
println!("Color Saturation: {saturation}");
} else if let Some(arg_hue) = &args.rgb_hue {
if let Some(hue) = arg_hue {
set_rgb_color(&device, Some(*hue), None).unwrap();
}
let (hue, saturation) = get_rgb_color(&device).unwrap();
println!("Color Hue: {}", hue);
println!("Color Saturation: {}", saturation);
println!("Color Hue: {hue}");
println!("Color Saturation: {saturation}");
} else if let Some(arg_backlight) = args.backlight {
if let Some(percentage) = arg_backlight {
let brightness = (255.0 * percentage as f32) / 100.0;
Expand Down
8 changes: 4 additions & 4 deletions src/raw_hid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn send_message(
//println!("Written: {}", size);
}
Err(err) => {
println!("Write err: {:?}", err);
println!("Write err: {err:?}");
return Err(());
}
};
Expand All @@ -59,7 +59,7 @@ pub fn send_message(
Ok(buf[1..out_len + 1].to_vec())
}
Err(err) => {
println!("Read err: {:?}", err);
println!("Read err: {err:?}");
Err(())
}
}
Expand All @@ -74,10 +74,10 @@ pub fn qmk_console(dev: &HidDevice) {
match res {
Ok(_size) => {
let string = String::from_utf8_lossy(&buf);
print!("{}", string);
print!("{string}");
}
Err(err) => {
println!("Read err: {:?}", err);
println!("Read err: {err:?}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/via.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub fn get_backlight(dev: &HidDevice, value: u8) -> Result<u8, ()> {
}

pub fn set_backlight(dev: &HidDevice, value: u8, value_data: u8) -> Result<(), ()> {
let msg = vec![ViaChannelId::RgbMatrixChannel as u8, value, value_data];
let msg = vec![ViaChannelId::BacklightChannel as u8, value, value_data];
send_message(dev, ViaCommandId::CustomSetValue as u8, Some(&msg), 0)?;
Ok(())
}
Expand Down

0 comments on commit bff059b

Please sign in to comment.