keyboard_comm: error out if unsupported protocol
parent
c384fb87c3
commit
b717c58d68
|
|
@ -12,6 +12,9 @@ from macro_action import SS_TAP_CODE, SS_DOWN_CODE, SS_UP_CODE, ActionText, Acti
|
|||
from unlocker import Unlocker
|
||||
from util import MSG_LEN, hid_send, chunks
|
||||
|
||||
SUPPORTED_VIA_PROTOCOL = [-1, 9]
|
||||
SUPPORTED_VIAL_PROTOCOL = [-1, 0, 1, 2, 3]
|
||||
|
||||
CMD_VIA_GET_PROTOCOL_VERSION = 0x01
|
||||
CMD_VIA_GET_KEYBOARD_VALUE = 0x02
|
||||
CMD_VIA_SET_KEYBOARD_VALUE = 0x03
|
||||
|
|
@ -53,6 +56,10 @@ CMD_VIAL_LOCK = 0x08
|
|||
BUFFER_FETCH_CHUNK = 28
|
||||
|
||||
|
||||
class ProtocolError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def macro_deserialize_v1(data):
|
||||
"""
|
||||
Deserialize a single macro, protocol version 1
|
||||
|
|
@ -205,6 +212,10 @@ class Keyboard:
|
|||
data = self.usb_send(self.dev, struct.pack("B", CMD_VIA_GET_PROTOCOL_VERSION), retries=20)
|
||||
self.via_protocol = struct.unpack(">H", data[1:3])[0]
|
||||
|
||||
def check_protocol_version(self):
|
||||
if self.via_protocol not in SUPPORTED_VIA_PROTOCOL or self.vial_protocol not in SUPPORTED_VIAL_PROTOCOL:
|
||||
raise ProtocolError()
|
||||
|
||||
def reload_layout(self, sideload_json=None):
|
||||
""" Requests layout data from the current device """
|
||||
|
||||
|
|
@ -235,6 +246,8 @@ class Keyboard:
|
|||
|
||||
payload = json.loads(lzma.decompress(payload))
|
||||
|
||||
self.check_protocol_version()
|
||||
|
||||
self.definition = payload
|
||||
|
||||
if "vial" in payload:
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from urllib.request import urlopen
|
|||
|
||||
from editor_container import EditorContainer
|
||||
from firmware_flasher import FirmwareFlasher
|
||||
from keyboard_comm import ProtocolError
|
||||
from keymap_editor import KeymapEditor
|
||||
from keymaps import KEYMAPS
|
||||
from layout_editor import LayoutEditor
|
||||
|
|
@ -216,12 +217,16 @@ class MainWindow(QMainWindow):
|
|||
self.current_device = self.devices[idx]
|
||||
|
||||
if self.current_device is not None:
|
||||
if self.current_device.sideload:
|
||||
self.current_device.open(self.sideload_json)
|
||||
elif self.current_device.via_stack:
|
||||
self.current_device.open(self.via_stack_json["definitions"][self.current_device.via_id])
|
||||
else:
|
||||
self.current_device.open(None)
|
||||
try:
|
||||
if self.current_device.sideload:
|
||||
self.current_device.open(self.sideload_json)
|
||||
elif self.current_device.via_stack:
|
||||
self.current_device.open(self.via_stack_json["definitions"][self.current_device.via_id])
|
||||
else:
|
||||
self.current_device.open(None)
|
||||
except ProtocolError:
|
||||
QMessageBox.warning(self, "", "Unsupported protocol version!\n"
|
||||
"Please download latest Vial from https://get.vial.today/")
|
||||
|
||||
if isinstance(self.current_device, VialKeyboard) \
|
||||
and self.current_device.keyboard.keyboard_id in EXAMPLE_KEYBOARDS:
|
||||
|
|
|
|||
Loading…
Reference in New Issue