mirror of
https://github.com/lowobservable/coax.git
synced 2026-03-04 10:45:36 +00:00
Implemented READ_STATUS
This commit is contained in:
@@ -73,6 +73,22 @@ class KeystrokePollResponse(PollResponse):
|
||||
|
||||
self.scan_code = (value >> 2) & 0xff
|
||||
|
||||
class Status:
|
||||
"""Terminal status."""
|
||||
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
self.monocase = bool(value & 0x80)
|
||||
self.busy = not bool(value & 0x20)
|
||||
self.feature_error = bool(value & 0x04)
|
||||
self.operation_complete = bool(value & 0x02)
|
||||
|
||||
def __repr__(self):
|
||||
return (f'<Status monocase={self.monocase}, busy={self.busy}, '
|
||||
f'feature_error={self.feature_error}, '
|
||||
f'operation_complete={self.operation_complete}>')
|
||||
|
||||
class TerminalId:
|
||||
"""Terminal model and keyboard."""
|
||||
|
||||
@@ -122,9 +138,11 @@ def poll_ack(interface, **kwargs):
|
||||
"""Execute a POLL_ACK command."""
|
||||
_execute_write_command(interface, Command.POLL_ACK, **kwargs)
|
||||
|
||||
def read_status(interface):
|
||||
def read_status(interface, **kwargs):
|
||||
"""Execute a READ_STATUS command."""
|
||||
raise NotImplementedError
|
||||
response = _execute_read_command(interface, Command.READ_STATUS, **kwargs)
|
||||
|
||||
return Status(response[0])
|
||||
|
||||
def read_terminal_id(interface, **kwargs):
|
||||
"""Execute a READ_TERMINAL_ID command."""
|
||||
|
||||
30
pycoax/examples/07_read_status.py
Executable file
30
pycoax/examples/07_read_status.py
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import time
|
||||
from serial import Serial
|
||||
|
||||
sys.path.append('..')
|
||||
|
||||
from coax import Interface1, read_status
|
||||
|
||||
print('Opening serial port...')
|
||||
|
||||
with Serial('/dev/ttyUSB0', 115200) as serial:
|
||||
print('Sleeping to allow interface time to wake up...')
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
interface = Interface1(serial)
|
||||
|
||||
print('Resetting interface...')
|
||||
|
||||
version = interface.reset()
|
||||
|
||||
print(f'Firmware version is {version}')
|
||||
|
||||
print('READ_STATUS...')
|
||||
|
||||
status = read_status(interface)
|
||||
|
||||
print(status)
|
||||
@@ -4,7 +4,7 @@ from unittest.mock import Mock
|
||||
import context
|
||||
|
||||
from coax import PollResponse, KeystrokePollResponse, ProtocolError
|
||||
from coax.protocol import Command, TerminalId, _execute_read_command, _execute_write_command, _pack_command_word, _unpack_data_words, _unpack_data_word
|
||||
from coax.protocol import Command, Status, TerminalId, _execute_read_command, _execute_write_command, _pack_command_word, _unpack_data_words, _unpack_data_word
|
||||
|
||||
class PollResponseTestCase(unittest.TestCase):
|
||||
def test_is_power_on_reset_complete(self):
|
||||
@@ -25,6 +25,15 @@ class KeystrokePollResponseTestCase(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'Invalid keystroke poll response'):
|
||||
response = KeystrokePollResponse(0b0000001000)
|
||||
|
||||
class StatusTestCase(unittest.TestCase):
|
||||
def test(self):
|
||||
status = Status(0b10000110)
|
||||
|
||||
self.assertTrue(status.monocase)
|
||||
self.assertTrue(status.busy)
|
||||
self.assertTrue(status.feature_error)
|
||||
self.assertTrue(status.operation_complete)
|
||||
|
||||
class TerminalIdTestCase(unittest.TestCase):
|
||||
def test_model_2(self):
|
||||
terminal_id = TerminalId(0b00000100)
|
||||
|
||||
Reference in New Issue
Block a user