From 99e660ce712eb9479e96392f40581a82b8c2e0cc Mon Sep 17 00:00:00 2001 From: Andrew Kay Date: Sun, 22 Dec 2019 15:12:37 -0600 Subject: [PATCH] Implement LOAD_SECONDARY_CONTROL --- pycoax/coax/__init__.py | 1 + pycoax/coax/protocol.py | 19 +++++++++++++++++-- pycoax/tests/test_protocol.py | 8 +++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pycoax/coax/__init__.py b/pycoax/coax/__init__.py index e16f132..31433d0 100644 --- a/pycoax/coax/__init__.py +++ b/pycoax/coax/__init__.py @@ -8,6 +8,7 @@ from .protocol import ( PowerOnResetCompletePollResponse, KeystrokePollResponse, Control, + SecondaryControl, poll, poll_ack, read_status, diff --git a/pycoax/coax/protocol.py b/pycoax/coax/protocol.py index 3fb32de..55b6516 100644 --- a/pycoax/coax/protocol.py +++ b/pycoax/coax/protocol.py @@ -152,6 +152,19 @@ class Control: f'cursor_reverse={self.cursor_reverse}, ' f'cursor_blink={self.cursor_blink}>') +class SecondaryControl: + """Terminal secondary control register.""" + + def __init__(self, big=False): + self.big = big + + @property + def value(self): + return bool(self.big) | 0 + + def __repr__(self): + return f'' + def poll(interface, action=PollAction.NONE, **kwargs): """Execute a POLL command.""" command_word = (action.value << 8) | _pack_command_word(Command.POLL) @@ -233,9 +246,11 @@ def load_control_register(interface, control, **kwargs): _execute_write_command(interface, command_word, bytes([control.value]), **kwargs) -def load_secondary_control(interface): +def load_secondary_control(interface, control, **kwargs): """Execute a LOAD_SECONDARY_CONTROL command.""" - raise NotImplementedError + command_word = _pack_command_word(Command.LOAD_SECONDARY_CONTROL) + + _execute_write_command(interface, command_word, bytes([control.value]), **kwargs) def load_mask(interface): """Execute a LOAD_MASK command.""" diff --git a/pycoax/tests/test_protocol.py b/pycoax/tests/test_protocol.py index 8a732f4..ceab9d2 100644 --- a/pycoax/tests/test_protocol.py +++ b/pycoax/tests/test_protocol.py @@ -4,7 +4,7 @@ from unittest.mock import Mock import context from coax import PollResponse, KeystrokePollResponse, ProtocolError -from coax.protocol import Command, Status, TerminalId, Control, _execute_read_command, _execute_write_command, _pack_command_word, _unpack_command_word, _unpack_data_words, _unpack_data_word +from coax.protocol import Command, Status, TerminalId, Control, SecondaryControl, _execute_read_command, _execute_write_command, _pack_command_word, _unpack_command_word, _unpack_data_words, _unpack_data_word class PollResponseTestCase(unittest.TestCase): def test_is_power_on_reset_complete(self): @@ -89,6 +89,12 @@ class ControlTestCase(unittest.TestCase): self.assertEqual(control.value, 0b00000001) +class SecondaryControlTestCase(unittest.TestCase): + def test_big(self): + control = SecondaryControl(big=True) + + self.assertEqual(control.value, 0b00000001) + class ExecuteReadCommandTestCase(unittest.TestCase): def setUp(self): self.interface = Mock()