Skip to content

Commit

Permalink
Testing of data population complete. Added initial tool functionality…
Browse files Browse the repository at this point in the history
… and update mapping to handle the trackball values
  • Loading branch information
katie-snow committed Mar 2, 2024
1 parent 43d8aa1 commit c3a6fef
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 63 deletions.
95 changes: 41 additions & 54 deletions tests/devices/test_ultimateIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,50 +130,22 @@ def test_ultimateio_pin_optional_params(self, dev_handle_mock, lib_usb_mock):

dev.__class__ = UltimateIODevice

config_file = os.path.join(git_project_root(), 'tests/test-data/minipac/mini-pac-pin-optional.json')
valid, data = dev._create_message_(config_file)

# pin 1up values, has both optional values
self.assertTrue(data.bytes[10] == 0x52)
self.assertTrue(data.bytes[60] == 0x35)
self.assertTrue(data.bytes[110] == 0x40)

# pin 1sw2 values no optional values
self.assertTrue(data.bytes[11] == 0x72)
self.assertTrue(data.bytes[61] == 0)
self.assertTrue(data.bytes[111] == 0)

# macros
self.assertTrue(data.bytes[166] == 0)

@patch.object(USBDeviceHandle, '_get_descriptor_fields', return_value=None)
@patch('libusb.get_device', return_value='pointer')
def test_ultimateio_pin_ui_connection(self, dev_handle_mock, lib_usb_mock):
""" Test that optional parameters are handled correctly """
dev = USBDeviceHandle('test_handle', '0000:0000')
self.assertTrue(dev)

dev.__class__ = UltimateIODevice

config_file = os.path.join(git_project_root(), 'tests/test-data/minipac/mini-pac-pin-optional.json')
# Validate against the base schema.
resource_types = ['mini-pac-pins']
json_dict = dev.validate_config_base(config_file, resource_types)

valid, data = dev._create_message_dict_(json_dict)
config_file = os.path.join(git_project_root(), 'tests/test-data/ultimateIO/ultimateio-pin-optional.json')
self.assertTrue(os.path.exists(config_file))
valid, data = dev._create_device_message_(config_file)

# pin 1up values, has both optional values
self.assertTrue(data.bytes[10] == 0x52)
self.assertTrue(data.bytes[60] == 0x35)
self.assertTrue(data.bytes[110] == 0x40)
# pin 1down values, has both optional values
self.assertTrue(data.bytes[6] == 0x51)
self.assertTrue(data.bytes[56] == 0x13)
self.assertTrue(data.bytes[106] == 0x40)

# pin 1sw2 values no optional values
self.assertTrue(data.bytes[11] == 0x72)
self.assertTrue(data.bytes[61] == 0)
self.assertTrue(data.bytes[111] == 0)
# pin 1right values no optional values
self.assertTrue(data.bytes[0] == 0x4f)
self.assertTrue(data.bytes[50] == 0)
self.assertTrue(data.bytes[100] == 0x01)

# macros
self.assertTrue(data.bytes[166] == 0)
self.assertTrue(data.bytes[164] == 0)

@patch.object(USBDeviceHandle, '_get_descriptor_fields', return_value=None)
@patch('libusb.get_device', return_value='pointer')
Expand All @@ -184,13 +156,13 @@ def test_ultimateio_large_macro_entries(self, dev_handle_mock, lib_usb_mock):
self.assertTrue(dev)
dev.__class__ = UltimateIODevice

config_file = os.path.join(git_project_root(), 'tests/test-data/minipac/mini-pac-macro-large-count.json')
valid, data = dev._create_message_(config_file)
config_file = os.path.join(git_project_root(), 'tests/test-data/ultimateIO/ultimateio-macro-large-count.json')
valid, data = dev._create_device_message_(config_file)
self.assertFalse(valid)
self.assertIsNone(data)

config_file = os.path.join(git_project_root(), 'tests/test-data/minipac/mini-pac-macro-large-action-count.json')
valid, data = dev._create_message_(config_file)
config_file = os.path.join(git_project_root(), 'tests/test-data/ultimateIO/ultimateio-macro-large-action-count.json')
valid, data = dev._create_device_message_(config_file)
self.assertFalse(valid)
self.assertIsNone(data)

Expand All @@ -217,25 +189,40 @@ def test_header_byte_4_multiple_entries(self, dev_handle_mock, lib_usb_mock):

dev.__class__ = UltimateIODevice

config_file = os.path.join(git_project_root(), 'tests/test-data/minipac/mini-pac-good.json')
valid, data = dev._create_message_(config_file)
config_file = os.path.join(git_project_root(), 'tests/test-data/ultimateIO/ultimateio-pin-optional.json')
valid, data = dev._create_device_message_(config_file)

header = PacConfigUnion()
header.asByte = data.header.byte_4
# paclink is True
self.assertTrue(header.config.paclink == 0x01)

# high current output
self.assertTrue(header.config.high_current_output == 0x01)

# accelerometer
self.assertTrue(header.config.accelerometer == 0x01)

# paclink is 0x0, not available on UltimateIO board
self.assertTrue(header.config.paclink == 0x00)

# debounce is short (0x02)
self.assertTrue(header.config.debounce == 0x02)

config_file = os.path.join(git_project_root(), 'tests/test-data/minipac/mini-pac-pin-optional.json')
valid, data = dev._create_message_(config_file)
config_file = os.path.join(git_project_root(), 'ultimarc/examples/ultimateIO/ultimateio-pin.json')
valid, data = dev._create_device_message_(config_file)

header = PacConfigUnion()
header.asByte = data.header.byte_4
# paclink is False
self.assertTrue(header.config.paclink == 0)
# debounce is short (0x02)
self.assertTrue(header.config.debounce == 0x02)
# high current output
self.assertTrue(header.config.high_current_output == 0x00)

# accelerometer
self.assertTrue(header.config.accelerometer == 0x00)

# paclink is 0x0, not available on UltimateIO board
self.assertTrue(header.config.paclink == 0x00)

# debounce is short (0x00)
self.assertTrue(header.config.debounce == 0x00)

@patch.object(USBDeviceHandle, '_get_descriptor_fields', return_value=None)
@patch('libusb.get_device', return_value='pointer')
Expand Down
2 changes: 2 additions & 0 deletions tests/test-data/ultimateIO/ultimateio-debounce-bad.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"resourceType" : "ultimateIO-pin",
"deviceClass" : "ultimateIO",
"debounce" : "invalid debounce value",
"highCurrentOutput": false,
"accelerometer": false,
"macros": [
{"name": "macro #1", "action": ["s", "a", "b"]},
{"name": "macro #2", "action": ["m", "2", "2"]},
Expand Down
2 changes: 2 additions & 0 deletions tests/test-data/ultimateIO/ultimateio-macro-bad.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"resourceType": "ultimateIO-pin",
"deviceClass": "ultimateIO",
"debounce": "standard",
"highCurrentOutput": false,
"accelerometer": false,
"xThreshold": 15,
"yThreshold": 127,
"macros": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"schemaVersion" : 2.0,
"resourceType" : "ultimateIO-pin",
"deviceClass" : "ultimateIO",
"debounce" : "short",
"highCurrentOutput": false,
"accelerometer": false,
"macros": [
{"name": "macro #1", "action": ["m"]},
{"name": "macro #2", "action": ["m", "2", "2"]},
{"name": "macro #3", "action": ["m", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1"]},
{"name": "macro #4", "action": ["m", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1"]},
{"name": "macro #5", "action": ["m", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1"]},
{"name": "macro #6", "action": ["m", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1"]},
{"name": "macro #7", "action": ["m", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1"]},
{"name": "macro #8", "action": ["m", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1"]},
{"name": "macro #9", "action": ["m", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1", "3", "m", "3", "2", "1"]}
],
"pins" : [
{
"name": "1right",
"action": "right",
"alternate_action": "tab"
}
]
}
48 changes: 48 additions & 0 deletions tests/test-data/ultimateIO/ultimateio-macro-large-count.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"schemaVersion" : 2.0,
"resourceType" : "ultimateIO-pin",
"deviceClass" : "ultimateIO",
"debounce" : "short",
"highCurrentOutput": false,
"accelerometer": false,
"macros": [
{"name": "macro #1", "action": ["1", "2"]},
{"name": "macro #2", "action": ["m", "2", "2"]},
{"name": "macro #3", "action": ["m", "3", "m", "3", "2", "1"]},
{"name": "macro #4", "action": ["m"]},
{"name": "macro #5", "action": ["m", "1"]},
{"name": "macro #6", "action": ["m", "1"]},
{"name": "macro #7", "action": ["m", "1"]},
{"name": "macro #8", "action": ["m", "1"]},
{"name": "macro #9", "action": ["m", "1"]},
{"name": "macro #10", "action": ["m", "1"]},
{"name": "macro #11", "action": ["m", "1"]},
{"name": "macro #12", "action": ["m", "1"]},
{"name": "macro #13", "action": ["m", "1"]},
{"name": "macro #14", "action": ["m", "1"]},
{"name": "macro #15", "action": ["m", "1"]},
{"name": "macro #16", "action": ["m", "1"]},
{"name": "macro #17", "action": ["m", "1"]},
{"name": "macro #18", "action": ["m", "1"]},
{"name": "macro #19", "action": ["m", "1"]},
{"name": "macro #20", "action": ["m", "1"]},
{"name": "macro #21", "action": ["m", "1"]},
{"name": "macro #22", "action": ["m", "1"]},
{"name": "macro #23", "action": ["m", "1"]},
{"name": "macro #24", "action": ["m", "1"]},
{"name": "macro #25", "action": ["m", "1"]},
{"name": "macro #26", "action": ["m", "1"]},
{"name": "macro #27", "action": ["m", "1"]},
{"name": "macro #28", "action": ["m", "1"]},
{"name": "macro #29", "action": ["m", "1"]},
{"name": "macro #30", "action": ["m", "1"]},
{"name": "macro #31", "action": ["m", "1"]}
],
"pins" : [
{
"name": "1right",
"action": "right",
"alternate_action": "tab"
}
]
}
2 changes: 2 additions & 0 deletions tests/test-data/ultimateIO/ultimateio-pin-bad.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"resourceType" : "ultimateIO-pin",
"deviceClass" : "ultimateIO",
"debounce" : "short",
"highCurrentOutput": false,
"accelerometer": false,
"macros": [
{"name": "macro #1", "action": ["s", "a", "b"]},
{"name": "macro #2", "action": ["m", "2", "2"]},
Expand Down
21 changes: 21 additions & 0 deletions tests/test-data/ultimateIO/ultimateio-pin-optional.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"schemaVersion" : 2.0,
"resourceType" : "ultimateIO-pin",
"deviceClass" : "ultimateIO",
"debounce" : "short",
"highCurrentOutput": true,
"accelerometer": true,

"pins" : [
{
"name": "1right",
"action": "right"
},
{
"name": "1down",
"action": "down",
"alternate_action": "p",
"shift": true
}
]
}
32 changes: 23 additions & 9 deletions ultimarc/devices/ultimateIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class UltimateIODevice(USBDeviceHandle):
# overall total macro characters is 56
MACRO_MAX_COUNT = 30

# These two values need to add up to 252
MACRO_MAX_SIZE = 88
# These two values need to add up to 251
MACRO_MAX_SIZE = 87
MACRO_START_INDEX = 164

def get_device_config(self, indent=None, file=None):
Expand Down Expand Up @@ -115,6 +115,10 @@ def to_json_str(self, ultimate_struct):
# header configuration
header = PacConfigUnion()
header.asByte = ultimate_struct.header.byte_4
json_obj['highCurrentOutput'] = True if header.config.high_current_output == 0x01 else False

json_obj['accelerometer'] = True if header.config.accelerometer == 0x01 else False

json_obj['debounce'] = get_ipac_series_debounce_key(header.config.debounce)

# X Threshold
Expand Down Expand Up @@ -210,7 +214,7 @@ def set_config(self, config_file, use_current):
if res else False

def set_pin(self, pin_config):
""" Write a pin to the current ipac4 device """
""" Write a pin to the current ultimateIO device """
pin = pin_config[0]
# Get the current configuration from the device
cur_config = self.read_device()
Expand Down Expand Up @@ -263,7 +267,7 @@ def set_pin(self, pin_config):
cur_config, ct.sizeof(cur_config))

def set_debounce(self, debounce):
""" Set debounce value to the current ipac4 device """
""" Set debounce value to the current ultimateIO device """
val = debounce.lower()
if val in IPACSeriesDebounce:
# Get the current configuration from the device
Expand All @@ -288,7 +292,7 @@ def set_debounce(self, debounce):
cur_config, ct.sizeof(cur_config))

def set_config_ui(self, config_dict: dict):
""" Write a new configuration from UI to the current ipac4 device """
""" Write a new configuration from UI to the current ultimateIO device """

# Insert the new configuration into the PacStruct data object
res, data = self._create_device_struct_(config_dict)
Expand Down Expand Up @@ -356,11 +360,21 @@ def _create_device_struct_(self, json_config: dict, cur_device_config=None):
_logger.info(_(f'"{config.debounce}" is not a valid debounce value'))
return False, None

header.config.high_current_output = 0x01 if config.highCurrentOutput is True else 0
header.config.accelerometer = 0x01 if config.accelerometer is True else 0
data.header.byte_4 = header.asByte

# X Threshold
data.bytes[156] = config.xThreshold
try:
data.bytes[156] = config.xThreshold
except AttributeError:
pass

# Y Threshold
data.bytes[163] = config.yThreshold
try:
data.bytes[163] = config.yThreshold
except AttributeError:
pass

# bug: Current limitation, macros are not kept between configurations. To prevent lingering macro
# values in pac structure
Expand Down Expand Up @@ -402,7 +416,7 @@ def _create_device_struct_(self, json_config: dict, cur_device_config=None):

if cur_size_count > self.MACRO_MAX_SIZE:
_logger.debug(_(f'There are more than {self.MACRO_MAX_SIZE} '
f'macro values defined for the ipac4 device'))
f'macro values defined for the ultimateIO device'))
return False, None
except AttributeError:
pass
Expand Down Expand Up @@ -440,7 +454,7 @@ def _create_device_struct_(self, json_config: dict, cur_device_config=None):
pass

except KeyError:
_logger.debug(_(f'Pin {pin.name} does not exists in ipac4 device'))
_logger.debug(_(f'Pin {pin.name} does not exists in ultimateIO device'))

return True, data

Expand Down
2 changes: 2 additions & 0 deletions ultimarc/examples/ultimateIO/ultimateio-pin.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"resourceType": "ultimateIO-pin",
"deviceClass": "ultimateIO",
"debounce": "standard",
"highCurrentOutput": false,
"accelerometer": false,
"xThreshold": 17,
"yThreshold": 17,
"macros": [
Expand Down
15 changes: 15 additions & 0 deletions ultimarc/schemas/ultimateio-pin.schema
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"schemaVersion",
"resourceType",
"deviceClass",
"debounce",
"highCurrentOutput",
"accelerometer",
"pins"
],
"properties": {
Expand All @@ -25,6 +28,18 @@
"type": "string",
"const": "ultimateIO"
},
"highCurrentOutput": {
"$id": "#root/highCurrentOutput",
"title": "HighCurrentOutput",
"type": "boolean",
"default": false
},
"acelerometer": {
"$id": "#root/accelerometer",
"title": "accelerometer",
"type": "boolean",
"default": false
},
"debounce": {
"$id": "#root/debounce",
"title": "Debounce",
Expand Down

0 comments on commit c3a6fef

Please sign in to comment.