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 f0a9e2d
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 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,22 @@ 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 commit(self) -> bool:
return self.execute("VAR", "B0")[0] == "0"
Expand Down Expand Up @@ -179,8 +180,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 +198,18 @@ 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 f0a9e2d

Please sign in to comment.