40 AVAILABLE =
'True if the driver is available, false otherwise' 93 raise NotImplementedMethod()
116 def map_pin(self, abstract_pin_id, physical_pin_id):
133 def _linear_interpolation(self, x, imin, imax, omin, omax):
134 return (imax * omin - imin * omax + x * (omax - omin)) / (imax - imin)
165 if type(pin)
is list:
167 args = (read_min, read_max, write_min, write_max)
172 valid_read = (read_min
is not None and read_max
is not None)
173 valid_write = (write_min
is not None and write_max
is not None)
175 if not valid_read
and not valid_write:
180 pins = [pin
for pin
in self.
available_pins()
if pin_id == pin[
'id']]
181 read = pins[0][
'analog'][
'read_range']
182 write = pins[0][
'analog'][
'write_range']
183 valid_read = valid_read
and read
184 valid_write = valid_write
and write
186 'read': (*read, read_min, read_max)
if valid_read
else None,
187 'write': (write_min, write_max, *write)
if valid_write
else None 208 if type(pin)
is list:
214 if pin_id
and type(direction)
is ahio.Direction:
215 self._set_pin_direction(pin_id, direction)
217 raise KeyError(
'Requested pin is not mapped: %s' % pin)
230 if type(pin)
is list:
235 return self._pin_direction(pin_id)
237 raise KeyError(
'Requested pin is not mapped: %s' % pin)
257 if type(pin)
is list:
263 if type(ptype)
is not ahio.PortType:
264 raise KeyError(
'ptype must be of type ahio.PortType')
266 self._set_pin_type(pin_id, ptype)
268 raise KeyError(
'Requested pin is not mapped: %s' % pin)
281 if type(pin)
is list:
282 return [self.
pin_type(p)
for p
in pin]
286 return self._pin_type(pin_id)
288 raise KeyError(
'Requested pin is not mapped: %s' % pin)
315 def write(self, pin, value, pwm=False):
316 if type(pin)
is list:
318 self.
write(p, value, pwm)
321 if pwm
and type(value)
is not int
and type(value)
is not float:
322 raise TypeError(
'pwm is set, but value is not a float or int')
327 if lpin
and type(lpin[
'write'])
is tuple:
328 write_range = lpin[
'write']
330 self._write(pin_id, value, pwm)
332 raise KeyError(
'Requested pin is not mapped: %s' % pin)
349 if type(pin)
is list:
350 return [self.
read(p)
for p
in pin]
354 value = self._read(pin_id)
356 if lpin
and type(lpin[
'read'])
is tuple:
357 read_range = lpin[
'read']
361 raise KeyError(
'Requested pin is not mapped: %s' % pin)
372 raise NotImplementedMethod()
397 self._set_analog_reference(reference,
None)
401 self._set_analog_reference(reference, pin_id)
403 raise KeyError(
'Requested pin is not mapped: %s' % pin)
426 return self._analog_reference(
None)
430 return self._analog_reference(pin_id)
432 raise KeyError(
'Requested pin is not mapped: %s' % pin)
455 self._set_pwm_frequency(frequency,
None)
459 self._set_pwm_frequency(frequency, pin_id)
461 raise KeyError(
'Requested pin is not mapped: %s' % pin)
def map_pin(self, abstract_pin_id, physical_pin_id)
Maps a pin number to a physical device pin.
def set_pin_interpolation(self, pin, read_min, read_max, write_min, write_max)
Interpolates input and output values for pin.
def available_pins(self)
Returns available pins.
def set_pwm_frequency(self, frequency, pin=None)
Sets PWM frequency, if supported by hardware.
def _linear_interpolation(self, x, imin, imax, omin, omax)
def analog_references(self)
Possible values for analog reference.
def pin_direction(self, pin)
Gets the ahio.Direction this pin was set to.
def mapped_pins(self)
Returns a dictionary containing the mapped pins.
def set_pin_type(self, pin, ptype)
Sets pin pin to type.
def set_analog_reference(self, reference, pin=None)
Sets the analog reference to reference
Abstract class containing information about the driver.
def pin_type(self, pin)
Gets the ahio.PortType this pin was set to.
def write(self, pin, value, pwm=False)
Sets the output to the given value.
def analog_reference(self, pin=None)
Returns the analog reference.
def read(self, pin)
Reads value from pin pin.
def set_pin_direction(self, pin, direction)
Sets pin pin to direction.