@@ -31,9 +31,12 @@ fn main() -> Result<()> {
3131 }
3232
3333 match cli. op {
34- Op :: GetBrightnexs => {
34+ Op :: GetBrightness { bus } => {
3535 let list = DisplayList :: probe ( true ) ?;
36- for dinfo in list. iter ( ) {
36+ for dinfo in list. iter ( ) . filter ( |info| {
37+ bus. map ( |bus| info. io_path ( ) == IOPath :: I2C ( bus as i32 ) )
38+ . unwrap_or ( true )
39+ } ) {
3740 tracing:: info!( "Found display: {}" , dinfo. model( ) ) ;
3841 let display = dinfo. open ( ) ?;
3942 let backlight = display. backlight_get ( ) ?;
@@ -45,9 +48,12 @@ fn main() -> Result<()> {
4548 ) ;
4649 }
4750 }
48- Op :: SetBrightness { brightness } => {
51+ Op :: SetBrightness { brightness, bus } => {
4952 let list = DisplayList :: probe ( true ) ?;
50- for dinfo in list. iter ( ) {
53+ for dinfo in list. iter ( ) . filter ( |info| {
54+ bus. map ( |bus| info. io_path ( ) == IOPath :: I2C ( bus as i32 ) )
55+ . unwrap_or ( true )
56+ } ) {
5157 tracing:: info!( "Found display: {}" , dinfo. model( ) ) ;
5258 let display = dinfo. open ( ) ?;
5359 display. backlight_set ( brightness. into ( ) ) ?;
@@ -60,6 +66,48 @@ fn main() -> Result<()> {
6066 ) ;
6167 }
6268 }
69+ Op :: IncreaseBrightness { amount, bus } => {
70+ let list = DisplayList :: probe ( true ) ?;
71+ for dinfo in list. iter ( ) . filter ( |info| {
72+ bus. map ( |bus| info. io_path ( ) == IOPath :: I2C ( bus as i32 ) )
73+ . unwrap_or ( true )
74+ } ) {
75+ tracing:: info!( "Found display: {}" , dinfo. model( ) ) ;
76+ let display = dinfo. open ( ) ?;
77+ let current_backlight = display. backlight_get ( ) ?;
78+ let new_brightness = std:: cmp:: min ( 100 , current_backlight. current + amount as u16 ) ;
79+ display. backlight_set ( new_brightness) ?;
80+ let backlight = display. backlight_get ( ) ?;
81+ println ! (
82+ "{}: {}/{} (increased by {})" ,
83+ dinfo. model( ) . blue( ) ,
84+ backlight. current,
85+ backlight. max,
86+ amount
87+ ) ;
88+ }
89+ }
90+ Op :: DecreaseBrightness { amount, bus } => {
91+ let list = DisplayList :: probe ( true ) ?;
92+ for dinfo in list. iter ( ) . filter ( |info| {
93+ bus. map ( |bus| info. io_path ( ) == IOPath :: I2C ( bus as i32 ) )
94+ . unwrap_or ( true )
95+ } ) {
96+ tracing:: info!( "Found display: {}" , dinfo. model( ) ) ;
97+ let display = dinfo. open ( ) ?;
98+ let current_backlight = display. backlight_get ( ) ?;
99+ let new_brightness = current_backlight. current . saturating_sub ( amount as u16 ) ;
100+ display. backlight_set ( new_brightness) ?;
101+ let backlight = display. backlight_get ( ) ?;
102+ println ! (
103+ "{}: {}/{} (decreased by {})" ,
104+ dinfo. model( ) . blue( ) ,
105+ backlight. current,
106+ backlight. max,
107+ amount
108+ ) ;
109+ }
110+ }
63111 Op :: GetInput { bus } => {
64112 let list = DisplayList :: probe ( true ) ?;
65113 for dinfo in list. iter ( ) . filter ( |info| {
0 commit comments