diff --git a/__init__.py b/__init__.py index 5ca6294..feba204 100644 --- a/__init__.py +++ b/__init__.py @@ -11,6 +11,6 @@ from flink.subdevices.flink_wdt import FlinkWDT from flink.subdevices.flink_analogin import FlinkAnalogIn from flink.subdevices.flink_analogout import FlinkAnalogOut -from flink.subdevices.flink_reflective_sensor import FlinkRefelectiveSensor +from flink.subdevices.flink_reflective_sensor import FlinkReflectiveSensor from flink.subdevices.flink_interrupt import FlinkInterrupt from flink.subdevices.flink_steppermotor import FlinkStepperMotor diff --git a/flink_definitions.py b/flink_definitions.py index ad2b1af..80c080a 100644 --- a/flink_definitions.py +++ b/flink_definitions.py @@ -17,9 +17,9 @@ # # -__author__ = Urs Graf, Patrick Good -__license__ = http://www.apache.org/licenses/LICENSE-2.0 -__version__ = 1.0 +__author__ = "Urs Graf, Patrick Good" +__license__ = "http://www.apache.org/licenses/LICENSE-2.0" +__version__ = "1.0" REGISTER_WIDTH = 4 # in byte REGISTER_WIDTH_BIT = REGISTER_WIDTH * 8 diff --git a/flink_device.py b/flink_device.py index 0af7ea1..5b07f5c 100644 --- a/flink_device.py +++ b/flink_device.py @@ -274,7 +274,7 @@ class FlinkDevice: _instance = None - def __init__(self, devFileName: str = "/dev/flink0", libPath: str = "/usr/lib/libflink.so.1.0.2.13"): + def __init__(self, devFileName: str = "/dev/flink0", libPath: str = "/usr/lib/libflink.so.1.0.2.33"): """ Creates a FlinkDevice. This is a Singleton! If the FlinkDevice already exists, it will simply return the already existing instance. @@ -423,6 +423,8 @@ def getSubdeviceByType(self, type: int, subType: int = 0) -> ct.c_void_p: subDev = self.getSubDeviceById(i) if self.lib.flink_subdevice_get_function(subDev) == type and self.lib.flink_subdevice_get_subfunction(subDev) == subType: return subDev + errString = "Failed to get subdevice with type" + str(type) + " and subtype" + str(subType) + raise FlinkException(errString, -1) return # type: ignore #TODO: replace with id2str @@ -433,9 +435,12 @@ def __idToCharArray(self, id: int) -> str: elif id == flink.Definitions.WD_INTERFACE_ID: return "WATCHDOG" elif id == flink.Definitions.UART_INTERFACE_ID: return "UART" elif id == flink.Definitions.PPWA_INTERFACE_ID: return "PPWA" + elif id == flink.Definitions.STEPPER_MOTOR_INTERFACE_ID: return "STEPPER MOTOR" + elif id == flink.Definitions.SENSOR_INTERFACE_ID: return "SENSOR" + elif id == flink.Definitions.IRQ_MULTIPLEXER_INTERFACE_ID: return "IRQ MULTIPLEXER" elif id == flink.Definitions.ANALOG_INPUT_INTERFACE_ID: return "ANALOG INPUT" elif id == flink.Definitions.ANALOG_OUTPUT_INTERFACE_ID: return "ANALOG OUTPUT" - elif id == flink.Definitions.INFO_INTERFACE_ID: return "INFO DEVICE" + elif id == flink.Definitions.INFO_DEVICE_ID: return "INFO DEVICE" else: return str(id) def lsflink(self): diff --git a/subdevices/flink_info.py b/subdevices/flink_info.py index d398fff..6681eb4 100644 --- a/subdevices/flink_info.py +++ b/subdevices/flink_info.py @@ -13,7 +13,7 @@ class FlinkInfo(flink.FlinkSubDevice): def __init__(self): dev = flink.FlinkDevice() - subDev = dev.getSubdeviceByType(flink.Definitions.INFO_INTERFACE_ID) + subDev = dev.getSubdeviceByType(flink.Definitions.INFO_DEVICE_ID) super().__init__(dev, subDev) dev.lib.flink_info_get_description.argtypes = [ct.c_void_p, ct.c_char_p] dev.lib.flink_info_get_description.restype = ct.c_int diff --git a/subdevices/flink_reflective_sensor.py b/subdevices/flink_reflective_sensor.py index 704ef2c..06bd1a9 100644 --- a/subdevices/flink_reflective_sensor.py +++ b/subdevices/flink_reflective_sensor.py @@ -28,15 +28,15 @@ __license__ = "http://www.apache.org/licenses/LICENSE-2.0" __version__ = "1.0" -class FlinkRefelectiveSensor(flink.FlinkSubDevice): +class FlinkReflectiveSensor(flink.FlinkSubDevice): """ The flinkreflectivesensor subdevice realizes an reflective sensor within a flink device. - It offers several channels. Each channel has it's own sensor value and a hysteresis for IRQ generating. + It offers several channels. Each channel has it's own sensor value and a level for IRQ generating. For IRQ: - - Each channel has two IRQ lines. one line when the sensor value exceeds the upper bound of the - hysteresis and one line when the sensor value goes below the lower bound of the hysteresis. - - The configuration of the histeresis is done through this module, but to connect the IRQ to a + - Each channel has two IRQ lines. one line when the sensor value exceeds the upper level + and one line when the sensor value decreases below the lower level. + - The configuration of the levels is done here, but to configure the IRQ with a function use the FlinkInterrupt class. """ @@ -52,20 +52,20 @@ def __init__(self): the object """ dev = flink.FlinkDevice() - subDev = dev.getSubdeviceByType(flink.Definitions.SENSOR_INTERFACE_ID, flink.Definitions.REFELCTIV_SENSOR_SUBTYP) + subDev = dev.getSubdeviceByType(flink.Definitions.SENSOR_INTERFACE_ID, flink.Definitions.REFLECTIVE_SENSOR_SUBTYP) super().__init__(dev, subDev) dev.lib.flink_reflectivesensor_get_resolution.argtypes = [ct.c_void_p, ct.POINTER(ct.c_uint32)] dev.lib.flink_reflectivesensor_get_resolution.restype = ct.c_int dev.lib.flink_reflectivesensor_get_value.argtypes = [ct.c_void_p, ct.c_uint32, ct.POINTER(ct.c_uint32)] dev.lib.flink_reflectivesensor_get_value.restype = ct.c_int - dev.lib.flink_reflectivesensor_set_upper_hysterese.argtypes = [ct.c_void_p, ct.c_uint32, ct.c_uint32] - dev.lib.flink_reflectivesensor_set_upper_hysterese.restype = ct.c_int - dev.lib.flink_reflectivesensor_get_upper_hysterese.argtypes = [ct.c_void_p, ct.c_uint32, ct.POINTER(ct.c_uint32)] - dev.lib.flink_reflectivesensor_get_upper_hysterese.restype = ct.c_int - dev.lib.flink_reflectivesensor_set_lower_hysterese.argtypes = [ct.c_void_p, ct.c_uint32, ct.c_uint32] - dev.lib.flink_reflectivesensor_set_lower_hysterese.restype = ct.c_int - dev.lib.flink_reflectivesensor_get_lower_hysterese.argtypes = [ct.c_void_p, ct.c_uint32, ct.POINTER(ct.c_uint32)] - dev.lib.flink_reflectivesensor_get_lower_hysterese.restype = ct.c_int + dev.lib.flink_reflectivesensor_set_upper_level_int.argtypes = [ct.c_void_p, ct.c_uint32, ct.c_uint32] + dev.lib.flink_reflectivesensor_set_upper_level_int.restype = ct.c_int + dev.lib.flink_reflectivesensor_get_upper_level_int.argtypes = [ct.c_void_p, ct.c_uint32, ct.POINTER(ct.c_uint32)] + dev.lib.flink_reflectivesensor_get_upper_level_int.restype = ct.c_int + dev.lib.flink_reflectivesensor_set_lower_level_int.argtypes = [ct.c_void_p, ct.c_uint32, ct.c_uint32] + dev.lib.flink_reflectivesensor_set_lower_level_int.restype = ct.c_int + dev.lib.flink_reflectivesensor_get_lower_level_int.argtypes = [ct.c_void_p, ct.c_uint32, ct.POINTER(ct.c_uint32)] + dev.lib.flink_reflectivesensor_get_lower_level_int.restype = ct.c_int self._RESOLUTION = self._getResolution() ################################################################################## @@ -129,34 +129,34 @@ def getValue(self, channel: int) -> int: raise flink.FlinkException("Failed to read value from reflective sensor channel", error, self.subDev) return int(val.value) - def setHysteresis(self, channel: int, upperBound: int, lowerBound: int) -> None: + def setLevel(self, channel: int, upperBound: int, lowerBound: int) -> None: """ - Writes the hysteresis of a single channel within a reflective sensor subdevice. + Writes the upper and lower level of a single channel. Channel number must be 0 <= channel < nof available channels. - Bounds must be 0 <= upperBound,lowerBound <= resolution + Bounds must be 0 <= upperBound, lowerBound <= resolution Parameters ---------- channel : channel number - upperBound : The upper limit of the hysteresis for the IRQ - lowerBound : The lower limit of the hysteresis for the IRQ + upperBound : The upper level + lowerBound : The lower level Returns ------- None """ - error = self.dev.lib.flink_reflectivesensor_set_upper_hysterese(self.subDev, channel, upperBound) + error = self.dev.lib.flink_reflectivesensor_set_upper_level_int(self.subDev, channel, upperBound) if error < 0: - raise flink.FlinkException("Failed to write hysteresis upper bound to reflective sensor channel", error, self.subDev) - error = self.dev.lib.flink_reflectivesensor_set_lower_hysterese(self.subDev, channel, lowerBound) + raise flink.FlinkException("Failed to write upper level to channel", error, self.subDev) + error = self.dev.lib.flink_reflectivesensor_set_lower_level_int(self.subDev, channel, lowerBound) if error < 0: - raise flink.FlinkException("Failed to write hysteresis lower bound to reflective sensor channel", error, self.subDev) + raise flink.FlinkException("Failed to write lower level to channel", error, self.subDev) - def getHysteresis(self, channel: int) -> Tuple[int]: + def getLevel(self, channel: int) -> Tuple[int, int]: """ - Writes the hysteresis of a single channel within a reflective sensor subdevice. + Reads the upper and lower level of a single channel. Channel number must be 0 <= channel < nof available channels. - Bounds must be 0 <= upperBound,lowerBound <= resolution + Bounds must be 0 <= upperBound, lowerBound <= resolution Parameters ---------- @@ -165,17 +165,17 @@ def getHysteresis(self, channel: int) -> Tuple[int]: Returns ------- (lowerBound, upperBound) - lowerBound : The lower limit of the hysteresis for the IRQ - upperBound : The upper limit of the hysteresis for the IRQ + lowerBound : The lower level + upperBound : The upper level """ upperBound = ct.c_uint32() lowerBound = ct.c_uint32() - error = self.dev.lib.flink_reflectivesensor_get_upper_hysterese(self.subDev, channel, upperBound) + error = self.dev.lib.flink_reflectivesensor_get_upper_level_int(self.subDev, channel, upperBound) if error < 0: - raise flink.FlinkException("Failed to read hysteresis upper bound to reflective sensor channel", error, self.subDev) - error = self.dev.lib.flink_reflectivesensor_get_lower_hysterese(self.subDev, channel, ct.byref(lowerBound)) + raise flink.FlinkException("Failed to read upper level of channel", error, self.subDev) + error = self.dev.lib.flink_reflectivesensor_get_lower_level_int(self.subDev, channel, ct.byref(lowerBound)) if error < 0: - raise flink.FlinkException("Failed to read hysteresis lower bound to reflective sensor channel", error, self.subDev) + raise flink.FlinkException("Failed to read lower level of channel", error, self.subDev) return (int(lowerBound.value), int(upperBound.value)) \ No newline at end of file diff --git a/subdevices/flink_wdt.py b/subdevices/flink_wdt.py index 61495ae..161190b 100644 --- a/subdevices/flink_wdt.py +++ b/subdevices/flink_wdt.py @@ -12,7 +12,7 @@ class FlinkWDT(flink.FlinkSubDevice): def __init__(self): dev = flink.FlinkDevice() - subDev = dev.getSubdeviceByType(flink.Definitions.PWM_INTERFACE_ID) + subDev = dev.getSubdeviceByType(flink.Definitions.WD_INTERFACE_ID) super().__init__(dev, subDev) dev.lib.flink_wd_get_baseclock.argtypes = [ct.c_void_p, ct.POINTER(ct.c_uint32)] dev.lib.flink_wd_get_baseclock.restype = ct.c_int @@ -36,7 +36,7 @@ def getBaseClock(self) -> int: if error < 0: raise flink.FlinkException("Failed to get baseclock from watchdog subdevice", error, self.subDev) return clk.value - + def getStatus(self) -> int: """ Reads the status register and returns the state of the status bit within. @@ -58,7 +58,7 @@ def setCounter(self, value: int) -> None: Parameters ---------- - value : counter value + value : counter value Returns ------- @@ -79,5 +79,3 @@ def arm(self) -> None: error = self.dev.lib.flink_wd_arm(self.subDev) if error < 0: raise flink.FlinkException("Faild to arm the watchdog timer", error, self.subDev) - -