diff options
| author | Damien George <damien.p.george@gmail.com> | 2015-03-13 22:11:50 +0000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2015-03-13 22:11:50 +0000 |
| commit | ac4f6b804fc7fd298aef420195f773f830ace422 (patch) | |
| tree | 817155701295fe15e0da5a79bc1234d19acb4eb4 /tests/pyb | |
| parent | 1129de5ac09ac5b41a952021cbc7a9752c8c253f (diff) | |
stmhal: Fix adc.read_timed so buffer store respects element size.
Addresses issue #1154.
Diffstat (limited to 'tests/pyb')
| -rw-r--r-- | tests/pyb/adc.py | 24 | ||||
| -rw-r--r-- | tests/pyb/adc.py.exp | 3 |
2 files changed, 25 insertions, 2 deletions
diff --git a/tests/pyb/adc.py b/tests/pyb/adc.py index 7bed54e9f..6508d7e24 100644 --- a/tests/pyb/adc.py +++ b/tests/pyb/adc.py @@ -1,10 +1,30 @@ from pyb import ADC from pyb import Pin +pin = Pin('X22', mode=Pin.IN, pull=Pin.PULL_DOWN) adc = ADC('X22') print(adc) -adc.read() +# read single sample +val = adc.read() +assert val < 500 -buf = bytearray(100) +# read into bytearray +buf = bytearray(50) adc.read_timed(buf, 500) +print(len(buf)) +for i in buf: + assert i < 500 + +# read into arrays with different element sizes +import array +ar = array.array('h', 25 * [0]) +adc.read_timed(ar, 500) +print(len(ar)) +for i in buf: + assert i < 500 +ar = array.array('i', 30 * [0]) +adc.read_timed(ar, 500) +print(len(ar)) +for i in buf: + assert i < 500 diff --git a/tests/pyb/adc.py.exp b/tests/pyb/adc.py.exp index bbc6af737..76f3914b0 100644 --- a/tests/pyb/adc.py.exp +++ b/tests/pyb/adc.py.exp @@ -1 +1,4 @@ <ADC on X22 channel=13> +50 +25 +30 |
