]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
tests for dig in, an in, an out, dig out all passing
authorbrentru <brent@adafruit.com>
Mon, 20 May 2024 20:30:07 +0000 (16:30 -0400)
committerbrentru <brent@adafruit.com>
Mon, 20 May 2024 20:30:07 +0000 (16:30 -0400)
examples/generic_aio.py
src/adafruit_blinka/board/generic_agnostic_board.py
src/adafruit_blinka/microcontroller/generic_agnostic_board/analogio.py
src/adafruit_blinka/microcontroller/generic_agnostic_board/pin.py

index aa1df376e872691bfce1c8d6a4bf131914be3da2..9a8cf77d0704011821854e4bd66d29e3898a4bde 100644 (file)
@@ -2,6 +2,23 @@ import pytest
 import board
 import analogio
 
 import board
 import analogio
 
+# Analog Outputs
+
+def test_Ax_OUTPUT():
+    """Test analog output pin functionality."""
+    assert board.board_id == "GENERIC_AGNOSTIC_BOARD"
+    pin_out = analogio.AnalogOut(board.Ax_OUTPUT)
+
+    # Test boundaries of setting the value and reading it back
+    pin_out.value = 0
+    assert pin_out.value == 0
+    pin_out.value = 65535
+    assert pin_out.value == 65535
+
+    pin_out.deinit()
+
+# Analog Inputs
+
 # Values for sine wave
 # (data points = 20, amplitude=100, frequency=1)
 sine_wave = [
 # Values for sine wave
 # (data points = 20, amplitude=100, frequency=1)
 sine_wave = [
@@ -52,7 +69,6 @@ sawtooth_wave = [
     80,
 ]
 
     80,
 ]
 
-
 def test_Ax_INPUT_RAND_INT():
     """Test random integer from pin Ax_INPUT_RAND_INT"""
     assert board.board_id == "GENERIC_AGNOSTIC_BOARD"
 def test_Ax_INPUT_RAND_INT():
     """Test random integer from pin Ax_INPUT_RAND_INT"""
     assert board.board_id == "GENERIC_AGNOSTIC_BOARD"
index 4530b607f4577d39c204ef56ba71134aa742ef5e..925e7baf936d1055db6dd86e6a42ca2a124b892d 100644 (file)
@@ -20,6 +20,7 @@ Ax_INPUT_RAND_INT = pin.A0
 Ax_INPUT_FIXED_INT_PI = pin.A1
 Ax_INPUT_WAVE_SINE = pin.A2
 Ax_INPUT_WAVE_SAW = pin.A3
 Ax_INPUT_FIXED_INT_PI = pin.A1
 Ax_INPUT_WAVE_SINE = pin.A2
 Ax_INPUT_WAVE_SAW = pin.A3
+Ax_OUTPUT = pin.A4
 
 # I2C pins
 SDA = pin.SDA
 
 # I2C pins
 SDA = pin.SDA
index 52aea1033a468c7d5a856cc9cbae1f0512826c05..cdaa18878fc34e242d090bb01db50d86237a1602 100644 (file)
@@ -45,9 +45,8 @@ class AnalogOut(ContextManaged):
 
     @property
     def value(self):
 
     @property
     def value(self):
-        """Return an error. This is output only."""
-        # emulate what CircuitPython does
-        raise AttributeError("unreadable attribute")
+        """Fake the output."""
+        return self._pin.value()
 
     @value.setter
     def value(self, value):
 
     @value.setter
     def value(self, value):
index b04e71de7196aa2d8abb8f19eb74856bd666e649..c52775926518aeed1e60e5ac1f3c4f135c55b7ce 100644 (file)
@@ -178,8 +178,8 @@ class Pin:
         # Analog Out
         if self._mode == Pin.DAC:
             if val is None:
         # Analog Out
         if self._mode == Pin.DAC:
             if val is None:
-                # write only
-                raise AttributeError("unreadable attribute")
+                self.previous_value = self.current_value
+                return self.current_value
             self.write(val)
             return None
         raise RuntimeError(
             self.write(val)
             return None
         raise RuntimeError(
@@ -200,6 +200,7 @@ A0 = Pin(7)
 A1 = Pin(8)
 A2 = Pin(9)
 A3 = Pin(10)
 A1 = Pin(8)
 A2 = Pin(9)
 A3 = Pin(10)
+A4 = Pin(12)
 
 D7 = Pin(11)
 
 
 D7 = Pin(11)