tests/pyb: Add test for pyb.ADCAll class.

This commit is contained in:
Damien George 2018-04-11 17:12:13 +10:00
parent 3d5d76fb73
commit d12483d936
2 changed files with 63 additions and 0 deletions

31
tests/pyb/adcall.py Normal file
View File

@ -0,0 +1,31 @@
from pyb import Pin, ADCAll
pins = [Pin.cpu.A0, Pin.cpu.A1, Pin.cpu.A2, Pin.cpu.A3]
# set pins to IN mode, init ADCAll, then check pins are ANALOG
for p in pins:
p.init(p.IN)
adc = pyb.ADCAll(12)
for p in pins:
print(p)
# set pins to IN mode, init ADCAll with mask, then check some pins are ANALOG
for p in pins:
p.init(p.IN)
adc = pyb.ADCAll(12, 0x70003)
for p in pins:
print(p)
# init all pins to ANALOG
adc = pyb.ADCAll(12)
print(adc)
# read all channels
for c in range(19):
print(type(adc.read_channel(c)))
# call special reading functions
print(0 < adc.read_core_temp() < 100)
print(0 < adc.read_core_vbat() < 4)
print(0 < adc.read_core_vref() < 2)
print(0 < adc.read_vref() < 4)

32
tests/pyb/adcall.py.exp Normal file
View File

@ -0,0 +1,32 @@
Pin(Pin.cpu.A0, mode=Pin.ANALOG)
Pin(Pin.cpu.A1, mode=Pin.ANALOG)
Pin(Pin.cpu.A2, mode=Pin.ANALOG)
Pin(Pin.cpu.A3, mode=Pin.ANALOG)
Pin(Pin.cpu.A0, mode=Pin.ANALOG)
Pin(Pin.cpu.A1, mode=Pin.ANALOG)
Pin(Pin.cpu.A2, mode=Pin.IN)
Pin(Pin.cpu.A3, mode=Pin.IN)
<ADCAll>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
<class 'int'>
True
True
True
True