Skip to content

Commit

Permalink
Correct minor errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ursgraf committed Dec 7, 2023
1 parent 0b3eeb6 commit 4970bea
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions flink_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions flink_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion subdevices/flink_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 32 additions & 32 deletions subdevices/flink_reflective_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

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

##################################################################################
Expand Down Expand Up @@ -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
----------
Expand All @@ -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))

8 changes: 3 additions & 5 deletions subdevices/flink_wdt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -58,7 +58,7 @@ def setCounter(self, value: int) -> None:
Parameters
----------
value : counter value
value : counter value
Returns
-------
Expand All @@ -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)


0 comments on commit 4970bea

Please sign in to comment.