1
- use std:: {
2
- cell:: { Cell , RefCell } ,
3
- char,
4
- } ;
1
+ use std:: { cell:: Cell , char} ;
5
2
6
3
use crate :: { DaemonBoard , DaemonBoardWeak , Hs , PhysicalLayoutKey , Rect , Rgb } ;
7
4
@@ -24,11 +21,11 @@ pub struct Key {
24
21
pub leds : Vec < u8 > ,
25
22
/// LED name
26
23
pub led_name : String ,
27
- pub ( crate ) led_color : Cell < Option < Hs > > ,
24
+ led_color : Cell < Option < Hs > > ,
28
25
// Key is currently pressed
29
26
pub ( crate ) pressed : Cell < bool > ,
30
27
// Currently loaded scancodes and their names
31
- pub ( crate ) scancodes : RefCell < Vec < ( u16 , String ) > > ,
28
+ scancodes : Vec < Cell < u16 > > ,
32
29
// Background color
33
30
pub background_color : Rgb ,
34
31
}
@@ -90,14 +87,12 @@ impl Key {
90
87
}
91
88
} ;
92
89
debug ! ( " Scancode: {:04X}" , scancode) ;
90
+ debug ! (
91
+ " Scancode Name: {:?}" ,
92
+ board. layout( ) . scancode_names. get( & scancode)
93
+ ) ;
93
94
94
- let scancode_name = match board. layout ( ) . scancode_names . get ( & scancode) {
95
- Some ( some) => some. to_string ( ) ,
96
- None => String :: new ( ) ,
97
- } ;
98
- debug ! ( " Scancode Name: {}" , scancode_name) ;
99
-
100
- scancodes. push ( ( scancode, scancode_name) ) ;
95
+ scancodes. push ( Cell :: new ( scancode) ) ;
101
96
}
102
97
103
98
let mut led_color = None ;
@@ -120,7 +115,7 @@ impl Key {
120
115
led_name,
121
116
led_color : Cell :: new ( led_color) ,
122
117
pressed : Cell :: new ( false ) ,
123
- scancodes : RefCell :: new ( scancodes ) ,
118
+ scancodes,
124
119
background_color,
125
120
}
126
121
}
@@ -148,7 +143,13 @@ impl Key {
148
143
}
149
144
150
145
pub fn get_scancode ( & self , layer : usize ) -> Option < ( u16 , String ) > {
151
- self . scancodes . borrow ( ) . get ( layer) . cloned ( )
146
+ let board = self . board ( ) ;
147
+ let scancode = self . scancodes . get ( layer) ?. get ( ) ;
148
+ let scancode_name = match board. layout ( ) . scancode_names . get ( & scancode) {
149
+ Some ( some) => some. to_string ( ) ,
150
+ None => String :: new ( ) ,
151
+ } ;
152
+ Some ( ( scancode, scancode_name) )
152
153
}
153
154
154
155
pub fn set_scancode ( & self , layer : usize , scancode_name : & str ) -> Result < ( ) , String > {
@@ -165,7 +166,7 @@ impl Key {
165
166
self . electrical . 1 ,
166
167
scancode,
167
168
) ?;
168
- self . scancodes . borrow_mut ( ) [ layer] = ( scancode , scancode_name . to_string ( ) ) ;
169
+ self . scancodes [ layer] . set ( scancode ) ;
169
170
Ok ( ( ) )
170
171
}
171
172
}
0 commit comments