From 57fec7d26f89a41d824f884ad4eb35b77da0dfee Mon Sep 17 00:00:00 2001 From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com> Date: Fri, 19 Apr 2024 19:22:31 +0200 Subject: [PATCH] Limit brightness of completely on --- src/main.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index a7b0798..b2fc409 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,23 +20,27 @@ fn main() { let on_cmd = "HX\x02\x02\x00".as_bytes(); let off_cmd = "HX\x02\x02\x01".as_bytes(); - let son1_cmd = "HX\x03\x02\x02\x01".as_bytes(); - let son2_cmd = "HX\x03\x02\x02\x00".as_bytes(); + let toggle0_cmd = "HX\x03\x02\x02\x00".as_bytes(); + let toggle1_cmd = "HX\x03\x02\x02\x01".as_bytes(); + let toggle2_cmd = "HX\x03\x02\x02\x02".as_bytes(); + let toggle3_cmd = "HX\x03\x02\x02\x03".as_bytes(); + let increase0_cmd = "HX\x03\x02\x03\x00".as_bytes(); + let increase1_cmd = "HX\x03\x02\x03\x01".as_bytes(); + let increase2_cmd = "HX\x03\x02\x03\x02".as_bytes(); + let increase3_cmd = "HX\x03\x02\x03\x03".as_bytes(); match args.mode.as_str() { - "on" => { - println!("Turning on..."); - port.write(on_cmd).expect("Write failed!"); - } "off" => { println!("Turning off..."); port.write(off_cmd).expect("Write failed!"); } - "son" => { + "on" | "son" => { println!("Turning semi-on..."); - port.write(on_cmd).expect("Write failed!"); - port.write(son1_cmd).expect("Write failed!"); - port.write(son2_cmd).expect("Write failed!"); + port.write(off_cmd).expect("Write failed!"); + for _ in 0..20 { + port.write(increase1_cmd).expect("Write failed!"); + port.write(increase2_cmd).expect("Write failed!"); + } } _ => { eprintln!("Invalid mode value");