Skip to content

Commit

Permalink
feat: auto-committing
Browse files Browse the repository at this point in the history
  • Loading branch information
GetPsyched committed Jan 16, 2024
1 parent 6383227 commit e4f1fbc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions charachorder/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,14 @@ def get_parameter(self, code: ParameterCode) -> int:
# TODO: enforce checking device-specific codes
return int(self.execute("VAR", "B1", code.value)[0])

def set_parameter(self, code: ParameterCode, value: int) -> bool:
def set_parameter(
self, code: ParameterCode, value: int, commit: bool = False
) -> bool:
# TODO: validate value
return self.execute("VAR", "B2", code.value, value)[0] == "0"
success = self.execute("VAR", "B2", code.value, value)[0] == "0"
if success and commit:
return self.commit()
return success

def get_keymap(self, code: KeymapCode, index: int) -> int:
if issubclass(self.__class__, CharaChorderOne) and index not in range(90):
Expand All @@ -202,15 +207,20 @@ def get_keymap(self, code: KeymapCode, index: int) -> int:

return int(self.execute("VAR", "B3", code.value, index)[0])

def set_keymap(self, code: KeymapCode, index: int, action_id: int) -> bool:
def set_keymap(
self, code: KeymapCode, index: int, action_id: int, commit: bool = False
) -> bool:
if issubclass(self.__class__, CharaChorderOne) and index not in range(90):
raise IndexError("Keymap index out of range. Must be between 0-89")
if issubclass(self.__class__, CharaChorderLite) and index not in range(67):
raise IndexError("Keymap index out of range. Must be between 0-66")
if action_id not in range(8, 2048):
raise IndexError("Action id out of range. Must be between 8-2047")

return self.execute("VAR", "B4", code.value, index, action_id)[0] == "0"
success = self.execute("VAR", "B4", code.value, index, action_id)[0] == "0"
if success and commit:
return self.commit()
return success

def restart(self):
self.execute("RST")
Expand Down

0 comments on commit e4f1fbc

Please sign in to comment.