Skip to content

Commit

Permalink
release all keys before changing device
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongyihui committed Sep 24, 2020
1 parent 536ff67 commit f16fac9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion keyboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(self, keymap=(), pairs=(), verbose=True):
self.pair_delay = 10

self._connection = ""
self.adv_timeout = None

self.data = array.array("L", microcontroller.nvm[:272])
if self.data[0] != 0x424B5950:
Expand Down Expand Up @@ -193,7 +194,6 @@ def setup(self):
for pair in self.pairs:
for key in pair:
self.pair_keys.add(key)
self.update_connection()

def start_advertising(self):
self.ble.start_advertising(self.advertisement)
Expand Down Expand Up @@ -292,6 +292,10 @@ def is_tapping_key(self, key):

def change_bt(self, n):
if self.ble.connected:
try:
self.ble_hid.release_all()
except Exception as e:
print(e)
for c in self.ble.connections:
c.disconnect()
if self.ble._adapter.advertising:
Expand All @@ -315,10 +319,15 @@ def change_bt(self, n):
except Exception as e:
print(e)
self.log(self.ble._adapter.address)

self.start_advertising()

def toggle_bt(self):
if self.ble.connected:
try:
self.ble_hid.release_all()
except Exception as e:
print(e)
for c in self.ble.connections:
c.disconnect()
elif self.ble._adapter.advertising:
Expand All @@ -333,6 +342,10 @@ def toggle_usb(self):
self.usb_status = 3
else:
self.usb_status = 1
try:
self.usb_hid.release_all()
except Exception as e:
print(e)
self.update_connection()

def action_code(self, position):
Expand Down

0 comments on commit f16fac9

Please sign in to comment.