32
32
(
33
33
ESC , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 0 , '-' , '=' , BACKSPACE ,
34
34
TAB , Q , W , E , R , T , Y , U , I , O , P , '[' , ']' , '|' ,
35
- CAPS , A , S , L2D , F , G , H , J , K , L , SCC , '"' , ENTER ,
35
+ CAPS , A , S , D , F , G , H , J , K , L , SCC , '"' , ENTER ,
36
36
LSHIFT ,Z , X , C , V , L3B , N , M , ',' , '.' , '/' , RSHIFT ,
37
37
LCTRL , LGUI , LALT , SPACE , RALT , MENU , L1 , RCTRL
38
38
),
@@ -136,6 +136,7 @@ def send_text(self, text):
136
136
class Keyboard :
137
137
def __init__ (self , keymap = KEYMAP , pairs = (), verbose = True ):
138
138
self .keymap = KEYMAP
139
+ self .profiles = {}
139
140
self .pairs = pairs
140
141
self .verbose = verbose
141
142
self .pairs_handler = None
@@ -194,15 +195,23 @@ def check(self):
194
195
self .leds = leds
195
196
self .backlight .set_hid_leds (leds )
196
197
self .log ('keyboard leds {}' .format (bin (leds )))
197
-
198
+
198
199
def setup (self ):
199
200
convert = lambda a : array .array ('H' , (get_action_code (k ) for k in a ))
200
201
self .actonmap = tuple (convert (layer ) for layer in self .keymap )
202
+ self .action_maps = {}
203
+ for key in self .profiles :
204
+ self .action_maps [key ] = tuple (convert (layer ) for layer in self .profiles [key ])
201
205
202
206
for pair in self .pairs :
203
207
for key in pair :
204
208
self .pair_keys .add (key )
205
209
210
+ def get_actionmap (self ):
211
+ if self .current_channel () in self .action_maps :
212
+ return self .action_maps [self .current_channel ()]
213
+ return self .actonmap
214
+
206
215
def start_advertising (self ):
207
216
self .ble .start_advertising (self .advertisement )
208
217
self .backlight .set_bt_led (self .ble_id )
@@ -225,7 +234,7 @@ def change_bt(self, n):
225
234
226
235
if 0 > n or n > 9 :
227
236
return
228
-
237
+
229
238
uid = self .uid [n :n + 6 ]
230
239
uid [- 1 ] = uid [- 1 ] | 0xC0
231
240
address = _bleio .Address (uid , _bleio .Address .RANDOM_STATIC )
@@ -242,6 +251,7 @@ def change_bt(self, n):
242
251
print (e )
243
252
self .log (self .ble ._adapter .address )
244
253
self .start_advertising ()
254
+ print (self .current_channel ())
245
255
246
256
def toggle_bt (self ):
247
257
if self .ble .connected :
@@ -251,17 +261,24 @@ def toggle_bt(self):
251
261
self .stop_advertising ()
252
262
else :
253
263
self .start_advertising ()
264
+ print (self .current_channel ())
265
+
266
+ def current_channel (self ):
267
+ if self .ble .connected :
268
+ return "BT%d" % self .ble_id
269
+ return "USB"
254
270
255
271
def toggle_usb (self ):
256
272
if usb_is_connected ():
257
273
self .usb_status = 1 if self .usb_status == 3 else 3
274
+ print (self .current_channel ())
258
275
259
276
def action_code (self , position ):
260
277
position = COORDS [position ]
261
278
layer_mask = self .layer_mask
262
- for layer in range (len (self .actonmap ) - 1 , - 1 , - 1 ):
279
+ for layer in range (len (self .get_actionmap () ) - 1 , - 1 , - 1 ):
263
280
if (layer_mask >> layer ) & 1 :
264
- code = self .actonmap [layer ][position ]
281
+ code = self .get_actionmap () [layer ][position ]
265
282
if code == 1 : # TRANSPARENT
266
283
continue
267
284
return code
0 commit comments