Implement LOAD_SECONDARY_CONTROL

This commit is contained in:
Andrew Kay
2019-12-22 15:12:37 -06:00
parent 8243620083
commit 99e660ce71
3 changed files with 25 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ from .protocol import (
PowerOnResetCompletePollResponse,
KeystrokePollResponse,
Control,
SecondaryControl,
poll,
poll_ack,
read_status,

View File

@@ -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'<SecondaryControl big={self.big}>'
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."""

View File

@@ -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()