This commit is contained in:
		
							parent
							
								
									8390b739da
								
							
						
					
					
						commit
						442da63c90
					
				
					 2 changed files with 22 additions and 4 deletions
				
			
		
							
								
								
									
										10
									
								
								src/cli.rs
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/cli.rs
									
										
									
									
									
								
							|  | @ -1,5 +1,5 @@ | |||
| #[derive(clap::Parser, std::fmt::Debug)] | ||||
| #[clap(version)] | ||||
| #[clap(version, arg_required_else_help = true)] | ||||
| pub struct Cli { | ||||
|     #[arg(
 | ||||
|         short, | ||||
|  | @ -19,7 +19,7 @@ pub struct Cli { | |||
|     #[clap(subcommand)] | ||||
|     pub command: Mode, | ||||
|     #[clap(short, long, help = "verbose logging")] | ||||
|     pub verbose: bool | ||||
|     pub verbose: bool, | ||||
| } | ||||
| 
 | ||||
| #[derive(clap::Parser, std::fmt::Debug)] | ||||
|  | @ -48,6 +48,12 @@ pub enum PixelCommand { | |||
| pub enum BrightnessCommand { | ||||
|     #[command(visible_alias = "r")] | ||||
|     Reset, | ||||
|     #[command(visible_alias = "s")] | ||||
|     Set { | ||||
|         brightness: u8, | ||||
|     }, | ||||
|     Min, | ||||
|     Max, | ||||
| } | ||||
| 
 | ||||
| #[derive(clap::ValueEnum, Clone, Debug)] | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| use crate::cli::{BrightnessCommand, Mode, PixelCommand}; | ||||
| use log::info; | ||||
| use servicepoint::{Brightness, Command, Connection}; | ||||
| use crate::cli::{BrightnessCommand, Mode, PixelCommand}; | ||||
| 
 | ||||
| pub fn execute_mode(mode: Mode, connection: Connection) { | ||||
|     match mode { | ||||
|  | @ -22,6 +22,11 @@ fn pixels(connection: &Connection, pixel_command: PixelCommand) { | |||
| fn brightness(connection: &Connection, brightness_command: BrightnessCommand) { | ||||
|     match brightness_command { | ||||
|         BrightnessCommand::Reset => brightness_reset(&connection), | ||||
|         BrightnessCommand::Min => brightness_set(&connection, Brightness::MIN), | ||||
|         BrightnessCommand::Max => brightness_set(&connection, Brightness::MAX), | ||||
|         BrightnessCommand::Set { brightness } => { | ||||
|             brightness_set(&connection, Brightness::saturating_from(brightness)) | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -37,4 +42,11 @@ fn brightness_reset(connection: &Connection) { | |||
|         .send(Command::Brightness(Brightness::MAX)) | ||||
|         .expect("Failed to reset brightness to maximum"); | ||||
|     info!("Reset brightness"); | ||||
| } | ||||
| } | ||||
| 
 | ||||
| fn brightness_set(connection: &&Connection, brightness: Brightness) { | ||||
|     connection | ||||
|         .send(Command::Brightness(brightness)) | ||||
|         .expect("Failed to set brightness"); | ||||
|     info!("set brightness to {brightness:?}"); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter