Skip to content

Commit

Permalink
refactor: rename and move CML functions
Browse files Browse the repository at this point in the history
  • Loading branch information
GetPsyched committed Jan 15, 2024
1 parent d474bc7 commit 8be3ee1
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions charachorder/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,12 @@ def execute(self, *args: int | str) -> tuple[str, ...]:

return actual_output

# ID
def get_id(self) -> str:
return " ".join(self.execute("ID"))

# VERSION
def get_version(self) -> str:
return self.execute("VERSION")[0]

# CML

def get_chordmap_count(self) -> int:
return int(self.execute("CML", "C0")[0])

Expand All @@ -138,17 +134,25 @@ def get_chordmap(self, index: int) -> tuple[Chord, ChordPhrase]:
chord, phrase, success = self.execute("CML", "C1", index)
return Chord(chord), ChordPhrase(phrase)

def get_chordmaps(self) -> Generator[tuple[Chord, ChordPhrase], None, None]:
chordmap_count = self.get_chordmap_count()
return (self.get_chordmap(i) for i in range(chordmap_count))

def get_chord_phrase(self, chord: str) -> ChordPhrase | None:
phrase = self.execute("CML", "C2", chord)[0]
return ChordPhrase(phrase) if phrase != "0" else None

def set_chordmap_by_chord(self, chord: Chord, phrase: ChordPhrase) -> bool:
def set_chordmap(self, chord: Chord, phrase: ChordPhrase) -> bool:
return self.execute("CML", "C3", chord.raw, phrase.raw)[0] == "0"

def del_chordmap_by_chord(self, chord: Chord) -> bool:
def delete_chordmap(self, chord: Chord) -> bool:
return self.execute("CML", "C4", chord.raw)[0] == "0"

# VAR
def delete_chordmaps(self):
self.execute("RST", "CLEARCML")

def upgrade_chordmaps(self):
self.execute("RST", "UPGRADECML")

def commit(self) -> bool:
return self.execute("VAR", "B0")[0] == "0"
Expand Down Expand Up @@ -179,8 +183,6 @@ def set_keymap(self, code: KeymapCode, index: int, action_id: int) -> bool:

return self.execute("VAR", "B4", code.value, index, action_id)[0] == "0"

# RST

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

Expand All @@ -199,29 +201,15 @@ def reset_keymaps(self):
def append_starter_chords(self):
self.execute("RST", "STARTER")

def nuke_chordmaps(self):
self.execute("RST", "CLEARCML")

def upgrade_chordmaps(self):
self.execute("RST", "UPGRADECML")

def append_functional_chords(self):
self.execute("RST", "FUNC")

# RAM
def get_available_ram(self) -> int:
return int(self.execute("RAM")[0])

# SIM
def sim(self, subcommand: str, value: str) -> str:
return self.execute("SIM", subcommand, value)[0]

# Misc. custom abstractions

def get_chordmaps(self) -> Generator[tuple[Chord, ChordPhrase], None, None]:
chordmap_count = self.get_chordmap_count()
return (self.get_chordmap(i) for i in range(chordmap_count))


@allowed_product_ids(0x800F) # M0
class CharaChorderOne(CharaChorder):
Expand Down

0 comments on commit 8be3ee1

Please sign in to comment.