@@ -6,8 +6,12 @@ use roccat_vulcan_api_rs::layout::{
66 Layout ,
77 layout_fr_ch:: LayoutFrCh
88} ;
9- use roccat_vulcan_api_rs:: color:: ColorBuffer ;
10- use roccat_vulcan_api_rs:: color:: ColorRgb ;
9+ use roccat_vulcan_api_rs:: color:: {
10+ ColorRgb ,
11+ ColorBuffer ,
12+ Color ,
13+ } ;
14+ use roccat_vulcan_api_rs:: constants;
1115use std:: {
1216 thread:: sleep,
1317 time:: { Duration , Instant } ,
@@ -16,37 +20,59 @@ use std::{
1620fn main ( ) {
1721
1822 let api = hidapi:: HidApi :: new ( ) . unwrap ( ) ;
19- for device in api. device_list ( ) {
20- let product_id_list = roccat_vulcan_api_rs:: config:: get_products_id_default ( ) ;
21- if product_id_list. contains ( & ( device. product_id ( ) ) ) {
22- println ! { "vendor : {}, usage page : {}, usage : {}, intreface : {}" , device. vendor_id( ) , device. usage_page( ) , device. usage( ) , device. interface_number( ) }
23- }
24- }
25-
2623
24+ let mut key_press_mask: [ bool ; constants:: NUMBER_KEY_LED_BUFFER ] = [ false ; constants:: NUMBER_KEY_LED_BUFFER ] ;
2725 let keyboard = KeyboardApi :: get_api_from_hidapi ( & api) . unwrap ( ) ;
28-
29- let mut buffer = ColorBuffer :: < ColorRgb > :: new ( ColorRgb :: new ( 0 , 255 , 255 ) ) ;
26+ let base_color = ColorRgb :: new ( 255 , 255 , 255 ) ;
27+ let press_color = vec ! [ ColorRgb :: new( 255 , 0 , 255 ) , ColorRgb :: new( 0 , 0 , 255 ) , ColorRgb :: new( 255 , 0 , 0 ) , ColorRgb :: new( 0 , 255 , 255 ) ] ;
28+ let mut press_count: usize = 0 ;
29+ let mut buffer = ColorBuffer :: < ColorRgb > :: new ( base_color) ;
3030 let layout = LayoutFrCh :: new ( ) ;
31- loop {
32- keyboard . render ( & buffer ) . unwrap ( ) ;
33- let result = keyboard. wait_for_key_press ( ) ;
31+ keyboard . render ( & buffer ) . unwrap ( ) ;
32+ ' mainloop : loop {
33+ let result = keyboard. read_key_press ( Duration :: from_millis ( 62 ) ) ;
3434 if let Ok ( val) = result {
35- let a = layout. find_key_info_from_press_code ( & val. key_code ( ) ) ;
36- if let Some ( key) = a {
37- let index_key = * key. key_code_light ( ) as usize ;
38- if index_key < buffer. buffer ( ) . len ( ) {
39- if !val. is_pressed ( ) {
40- if let Key :: Escape = key. key ( ) {
41- break ;
42- }
43- buffer. buffer_mut ( ) [ index_key] = ColorRgb :: new ( 0 , 255 , 255 )
35+ for keypress in val {
36+ let a = layout. find_key_info_from_press_code ( & keypress. key_code ( ) ) ;
37+ if let Some ( key) = a {
38+ if * key. key ( ) == Key :: Escape {
39+ break ' mainloop;
4440 }
45- else {
46- buffer. buffer_mut ( ) [ index_key] = ColorRgb :: new ( 0 , 0 , 255 )
41+ let index_key = * key. key_code_light ( ) as usize ;
42+ if index_key < buffer. buffer ( ) . len ( ) {
43+ if keypress. is_pressed ( ) {
44+ buffer. buffer_mut ( ) [ index_key] = press_color[ press_count % press_color. len ( ) ] ;
45+ press_count += 1 ;
46+ }
47+ key_press_mask[ index_key] = keypress. is_pressed ( ) ;
48+
4749 }
4850 }
4951 }
5052 }
53+ keyboard. render ( & buffer) . unwrap ( ) ;
54+ for index in 0 ..buffer. buffer ( ) . len ( ) {
55+ let el = & mut buffer. buffer_mut ( ) [ index] ;
56+ if * el != base_color && !key_press_mask[ index] {
57+ if el. r ( ) > base_color. r ( ) {
58+ * el. r_mut ( ) -= 5 . min ( el. r ( ) - base_color. r ( ) ) ;
59+ }
60+ else {
61+ * el. r_mut ( ) += 5 . min ( base_color. r ( ) - el. r ( ) ) ;
62+ }
63+ if el. g ( ) > base_color. g ( ) {
64+ * el. g_mut ( ) -= 5 . min ( el. g ( ) - base_color. g ( ) ) ;
65+ }
66+ else {
67+ * el. g_mut ( ) += 5 . min ( base_color. g ( ) - el. g ( ) ) ;
68+ }
69+ if el. b ( ) > base_color. b ( ) {
70+ * el. b_mut ( ) -= 5 . min ( el. b ( ) - base_color. b ( ) ) ;
71+ }
72+ else {
73+ * el. b_mut ( ) += 5 . min ( base_color. b ( ) - el. b ( ) ) ;
74+ }
75+ }
76+ }
5177 }
5278}
0 commit comments