]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/analogio.py
removed hidapi altogether
[Adafruit_Blinka-hackapet.git] / src / analogio.py
1 """
2 `analogio` - Analog input and output control
3 =================================================
4 See `CircuitPython:analogio` in CircuitPython for more details.
5 * Author(s): Carter Nelson
6 """
7
8 from adafruit_blinka.agnostic import board_id, detector
9
10 # pylint: disable=ungrouped-imports,wrong-import-position
11
12 if detector.board.microchip_mcp2221:
13     from adafruit_blinka.microcontroller.mcp2221.pin import Pin
14 else:
15     raise NotImplementedError("analogio not supported for this board.")
16
17 from adafruit_blinka import ContextManaged
18
19 class AnalogIn(ContextManaged):
20
21     def __init__(self, pin):
22         self._pin = Pin(pin.id)
23         self._pin.init(mode=Pin.ADC)
24
25     @property
26     def value(self):
27         return self._pin.value()
28
29     @value.setter
30     def value(self, value):
31         # emulate what CircuitPython does
32         raise AttributeError("'AnalogIn' object has no attribute 'value'")
33
34     def deinit(self):
35         del self._pin
36
37 class AnalogOut(ContextManaged):
38     def __init__(self, pin):
39         self._pin = Pin(pin.id)
40         self._pin.init(mode=Pin.DAC)
41
42     @property
43     def value(self):
44         # emulate what CircuitPython does
45         raise AttributeError("unreadable attribute")
46
47     @value.setter
48     def value(self, value):
49         self._pin.value(value)
50
51     def deinit(self):
52         del self._pin