11use std:: time:: Duration ;
22
3- #[ cfg( feature = "color_compatibility" ) ]
4- pub use bevy:: color:: { Color , LinearRgba } ;
5- #[ cfg( feature = "image_compatibility" ) ]
6- use bevy:: image:: Image ;
7- use bevy:: {
8- app:: { App , AppExit , Plugin } ,
9- color:: ColorToComponents ,
10- ecs:: {
11- event:: { EventReader , EventWriter } ,
12- system:: { Commands , Res , ResMut } ,
13- } ,
14- input:: ButtonInput ,
15- log:: debug,
16- prelude:: { Event , Last , PreStartup , PreUpdate , Resource } ,
17- tasks:: IoTaskPool ,
3+ use bevy_app:: { App , AppExit , Last , Plugin , PreStartup , PreUpdate } ;
4+ pub use bevy_color:: { Color , ColorToComponents , LinearRgba } ;
5+ use bevy_ecs:: {
6+ event:: { Event , EventReader , EventWriter } ,
7+ resource:: Resource ,
8+ system:: { Commands , Res , ResMut } ,
189} ;
10+ #[ cfg( feature = "image_compatibility" ) ]
11+ use bevy_image:: Image ;
12+ use bevy_input:: ButtonInput ;
13+ use bevy_tasks:: IoTaskPool ;
1914use crossbeam_channel:: { bounded, Receiver , Sender } ;
2015#[ cfg( feature = "images" ) ]
2116use image:: { imageops:: FilterType , DynamicImage , ImageBuffer , Pixel , Rgba } ;
17+ use log:: debug;
2218pub use streamdeck:: Kind ;
2319use streamdeck:: { Colour , Error } ;
2420
@@ -52,30 +48,6 @@ enum StreamDeckEvent {
5248 KeyPressed ( Vec < u8 > ) ,
5349}
5450
55- #[ cfg( not( feature = "color_compatibility" ) ) ]
56- #[ derive( Default ) ]
57- pub struct Color {
58- pub r : f32 ,
59- pub g : f32 ,
60- pub b : f32 ,
61- }
62- #[ cfg( not( feature = "color_compatibility" ) ) ]
63- impl Color {
64- const BLACK : Color = Color {
65- r : 0.0 ,
66- g : 0.0 ,
67- b : 0.0 ,
68- } ;
69-
70- pub const fn rgb ( r : f32 , g : f32 , b : f32 ) -> Color {
71- Color { r, g, b }
72- }
73-
74- fn as_rgba_f32 ( & self ) -> [ f32 ; 4 ] {
75- [ self . r , self . g , self . b , 1.0 ]
76- }
77- }
78-
7951enum StreamDeckOrder {
8052 Reset ,
8153 Color ( u8 , Color ) ,
@@ -177,22 +149,22 @@ fn receiver(
177149 match from_stream {
178150 StreamDeckEvent :: LostConnection => {
179151 streamdeck. kind = None ;
180- input_events. send ( StreamDeckInput :: Disconnected ) ;
152+ input_events. write ( StreamDeckInput :: Disconnected ) ;
181153 }
182154 StreamDeckEvent :: Connected ( kind) => {
183155 streamdeck. kind = Some ( kind) ;
184- input_events. send ( StreamDeckInput :: Connected ( kind) ) ;
156+ input_events. write ( StreamDeckInput :: Connected ( kind) ) ;
185157 }
186158 StreamDeckEvent :: KeyPressed ( keys) => {
187159 for ( k, s) in keys. iter ( ) . enumerate ( ) {
188160 if * s == 1 && !inputs. pressed ( StreamDeckKey ( k as u8 ) ) {
189161 inputs. press ( StreamDeckKey ( k as u8 ) ) ;
190- input_events. send ( StreamDeckInput :: Press ( k as u8 ) ) ;
162+ input_events. write ( StreamDeckInput :: Press ( k as u8 ) ) ;
191163 }
192164
193165 if * s == 0 && inputs. pressed ( StreamDeckKey ( k as u8 ) ) {
194166 inputs. release ( StreamDeckKey ( k as u8 ) ) ;
195- input_events. send ( StreamDeckInput :: Release ( k as u8 ) ) ;
167+ input_events. write ( StreamDeckInput :: Release ( k as u8 ) ) ;
196168 }
197169 }
198170 }
@@ -230,11 +202,11 @@ impl StreamDeck {
230202 if let Some ( kind) = self . kind {
231203 // Convert the texture to an image
232204 let mut dynamic_image = match image. texture_descriptor . format {
233- bevy :: render :: render_resource:: TextureFormat :: Rgba8UnormSrgb => {
205+ bevy_render :: render_resource:: TextureFormat :: Rgba8UnormSrgb => {
234206 ImageBuffer :: from_raw (
235207 image. texture_descriptor . size . width ,
236208 image. texture_descriptor . size . height ,
237- image. data . clone ( ) ,
209+ image. data . as_ref ( ) . unwrap ( ) . clone ( ) ,
238210 )
239211 . map ( DynamicImage :: ImageRgba8 )
240212 }
@@ -258,7 +230,7 @@ impl StreamDeck {
258230
259231 // Apply a background
260232 if let Some ( background) = image_mode. background {
261- let LinearRgba {
233+ let bevy_color :: LinearRgba {
262234 red, green, blue, ..
263235 } = background. to_linear ( ) ;
264236
0 commit comments