Created
September 12, 2016 19:42
-
-
Save benoit-pierre/84b86eb5756aa9ab9d862bfe6da1830d to your computer and use it in GitHub Desktop.
plover_italian_stentura.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
import binascii | |
import plover.machine.base | |
from plover import log | |
STENO_KEY_CHART = ( | |
None, 'S-', 'T-', 'K-', 'P-', 'W-', 'H-', 'R-', | |
None, 'A-', 'O-', '*' , '-E', '-U', '-F', '-R', | |
None, '-P', '-B', '-L', '-G', '-T', '-S', '-D', | |
None, '-Z', '#' , None, None, None, None, None, | |
) | |
def _decode(raw): | |
stroke = [] | |
mask = struct.unpack('<I', raw)[0] | |
if (mask & 1) == 0: | |
return [] | |
for n, key in enumerate(STENO_KEY_CHART): | |
if key is None: | |
continue | |
if (mask & (1 << n)) != 0: | |
stroke.append(key) | |
return stroke | |
class ItalianStentura(plover.machine.base.SerialStenotypeBase): | |
KEYMAP_MACHINE_TYPE = 'Stentura' | |
KEYS_LAYOUT = ''' | |
# # # # # # # # # # | |
S- T- P- H- * -F -P -L -T -D | |
S- K- W- R- * -R -B -G -S -Z | |
A- O- -E -U | |
^ | |
''' | |
def __init__(self, params): | |
plover.machine.base.SerialStenotypeBase.__init__(self, params) | |
def run(self): | |
settings = self.serial_port.getSettingsDict() | |
self.serial_port.applySettingsDict(settings) | |
self._ready() | |
while not self.finished.isSet(): | |
raw = self.serial_port.read(4) | |
if not raw: | |
continue | |
log.debug('raw: %s', binascii.hexlify(raw)) | |
if len(raw) != 4: | |
continue | |
keys = _decode(raw) | |
log.debug('keys: %r', keys) | |
if not keys: | |
continue | |
steno_keys = self.keymap.keys_to_actions(keys) | |
log.debug('steno keys: %r', steno_keys) | |
if not steno_keys: | |
continue | |
self._notify(steno_keys) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment