forked from adafruit/Adafruit_Blinka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_generic_agnostic_board_analogio.py
126 lines (100 loc) · 2.6 KB
/
test_generic_agnostic_board_analogio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# SPDX-FileCopyrightText: 2024 Brent Rubell for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import pytest # pylint: disable=unused-import
import board
import analogio
# Analog Outputs
def test_Ax_OUTPUT():
"""Test analog output pin functionality."""
assert board.board_id == "OS_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 = [
0,
31,
59,
81,
95,
100,
95,
81,
59,
31,
0,
-31,
-59,
-81,
-95,
-100,
-95,
-81,
-59,
-31,
]
# Values for a sawtooth wave
# (data points = 20, amplitude=100)
sawtooth_wave = [
-100,
-80,
-60,
-40,
-20,
0,
20,
40,
60,
80,
-100,
-80,
-60,
-40,
-20,
0,
20,
40,
60,
80,
]
def test_Ax_INPUT_RAND_INT():
"""Test random integer from pin Ax_INPUT_RAND_INT"""
assert board.board_id == "OS_AGNOSTIC_BOARD"
pin_random = analogio.AnalogIn(board.Ax_INPUT_RAND_INT)
assert isinstance(pin_random.value, int)
pin_random.deinit()
def test_Ax_INPUT_FIXED_INT_PI():
"""Test fixed integer from pin Ax_INPUT_FIXED_INT_PI"""
assert board.board_id == "OS_AGNOSTIC_BOARD"
pin_pi = analogio.AnalogIn(board.Ax_INPUT_FIXED_INT_PI)
assert pin_pi.value == 31415
pin_pi.deinit()
def test_Ax_INPUT_WAVE_SINE():
"""Test sine wave from pin Ax_INPUT_WAVE_SINE"""
assert board.board_id == "OS_AGNOSTIC_BOARD"
pin_sine_wave = analogio.AnalogIn(board.Ax_INPUT_WAVE_SINE)
# Run through the sine wave once
for expected_value in sine_wave:
assert pin_sine_wave.value == expected_value
# Run through the sine wave again to ensure it loops back correctly
for expected_value in sine_wave:
assert pin_sine_wave.value == expected_value
pin_sine_wave.deinit()
def test_Ax_INPUT_WAVE_SAW():
"""Test sawtooth wave from pin Ax_INPUT_WAVE_SAW"""
assert board.board_id == "OS_AGNOSTIC_BOARD"
pin_saw_wave = analogio.AnalogIn(board.Ax_INPUT_WAVE_SAW)
# Run through the sine wave once
for expected_value in sawtooth_wave:
assert pin_saw_wave.value == expected_value
# Run through the sine wave again to ensure it loops back correctly
for expected_value in sawtooth_wave:
assert pin_saw_wave.value == expected_value
pin_saw_wave.deinit()