Skip to content

Commit

Permalink
[pyseabreeze] initial testing implementation for gpio (QEPro)
Browse files Browse the repository at this point in the history
  • Loading branch information
ap-- committed Sep 19, 2021
1 parent b3b6c61 commit 3d0d32b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/seabreeze/pyseabreeze/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ class QEPRO(SeaBreezeDevice):

# features
feature_classes = (
sbf.gpio.SeaBreezeGPIOFeatureOBP,
sbf.spectrometer.SeaBreezeSpectrometerFeatureQEPRO,
sbf.rawusb.SeaBreezeRawUSBBusAccessFeature,
)
Expand Down
50 changes: 50 additions & 0 deletions src/seabreeze/pyseabreeze/features/gpio.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import struct

from seabreeze.pyseabreeze.features._base import SeaBreezeFeature


Expand Down Expand Up @@ -56,3 +58,51 @@ def get_egpio_value(self, pin_number):

def set_egpio_value(self, pin_number, value):
raise NotImplementedError("implement in derived class")


class SeaBreezeGPIOFeatureOBP(SeaBreezeGPIOFeature):
def get_number_of_gpio_pins(self):
"""output is the I/O pin count"""
ret = self.protocol.query(0x00200000)
return struct.unpack("B", ret)[0]

def get_output_enable_vector(self):
"""output is the data direction definition"""
ret = self.protocol.query(0x00200100)
# maybe we could return a list of bool here?
return struct.unpack("<H", ret)[0]

def set_gpio_output_enable_vector(self, output_enable_vector, bit_mask):
"""set the data direction"""
# we could allow lists of bool (or strings "001010101...") here too
if not (
isinstance(output_enable_vector, int)
and 0 <= output_enable_vector < 2 ** 16
):
raise ValueError(
"expecting a 16bit integer representing the output enable bits"
)
if not (isinstance(bit_mask, int) and 0 <= bit_mask < 2 ** 16):
raise ValueError(
"expecting a 16bit integer representing the output enable mask"
)
self.protocol.send(0x00200110, payload=(output_enable_vector, bit_mask))

def get_gpio_value_vector(self):
"""return the value vector of the gpio registers"""
ret = self.protocol.query(0x00200300)
# maybe we could return a list of bool here?
return struct.unpack("<H", ret)[0]

def set_gpio_value_vector(self, value_vector, bit_mask):
"""set the gpio value vector"""
# we could allow lists of bool (or strings "001010101...") here too
if not (isinstance(value_vector, int) and 0 <= value_vector < 2 ** 16):
raise ValueError(
"expecting a 16bit integer representing the output enable bits"
)
if not (isinstance(bit_mask, int) and 0 <= bit_mask < 2 ** 16):
raise ValueError(
"expecting a 16bit integer representing the output enable mask"
)
self.protocol.send(0x00200310, payload=(value_vector, bit_mask))
6 changes: 5 additions & 1 deletion src/seabreeze/pyseabreeze/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from seabreeze.pyseabreeze.exceptions import SeaBreezeError



class ProtocolInterface:
def __init__(self, transport):
if not (
Expand Down Expand Up @@ -165,6 +164,11 @@ class OBPProtocol(ProtocolInterface):
0x00180101: "<B", # GET_WL_COEFF
0x00181100: "", # GET_NL_COEFF_COUNT
0x00181101: "<B", # GET_NL_COEFF
0x00200000: "",
0x00200100: "",
0x00200110: "<LL",
0x00200300: "",
0x00200310: "<LL",
0x00420004: "", # GET_TE_TEMPERATURE
0x00420010: "<B", # SET_TE_ENABLE
0x00420011: "<f", # SET_TE_SETPOINT
Expand Down

0 comments on commit 3d0d32b

Please sign in to comment.