]> Repositories - Adafruit_Blinka-hackapet.git/blob - src/adafruit_blinka/microcontroller/mcp2221/analogio.py
Set executable flag on libgpiod_pulsein64 so pip installs it
[Adafruit_Blinka-hackapet.git] / src / adafruit_blinka / microcontroller / mcp2221 / 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.microcontroller.mcp2221.pin import Pin
9 from adafruit_blinka import ContextManaged
10
11
12 class AnalogIn(ContextManaged):
13     """Analog Input Class"""
14
15     def __init__(self, pin):
16         self._pin = Pin(pin.id)
17         self._pin.init(mode=Pin.ADC)
18
19     @property
20     def value(self):
21         """Read the ADC and return the value"""
22         return self._pin.value()
23
24     # pylint: disable=no-self-use
25     @value.setter
26     def value(self, value):
27         # emulate what CircuitPython does
28         raise AttributeError("'AnalogIn' object has no attribute 'value'")
29
30     # pylint: enable=no-self-use
31
32     def deinit(self):
33         del self._pin
34
35
36 class AnalogOut(ContextManaged):
37     """Analog Output Class"""
38
39     def __init__(self, pin):
40         self._pin = Pin(pin.id)
41         self._pin.init(mode=Pin.DAC)
42
43     @property
44     def value(self):
45         """Return an error. This is output only."""
46         # emulate what CircuitPython does
47         raise AttributeError("unreadable attribute")
48
49     @value.setter
50     def value(self, value):
51         self._pin.value(value)
52
53     def deinit(self):
54         del self._pin