Skip to content

Commit 2d80664

Browse files
committed
wip
1 parent ebe031a commit 2d80664

4 files changed

Lines changed: 30 additions & 21 deletions

File tree

‎pcduino/adc.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from exceptions import InvalidChannelException
2+
import os.path
3+
4+
_ADC_PREFIX = '/proc'
5+
_N_PINS= 6
6+
_ADC_PINS = set(('adc%s' % i for i in xrange(_N_PINS)))
7+
8+
9+
def _get_path(id_):
10+
if id_ in _ADC_PINS:
11+
return os.path.join(_ADC_PREFIX, id_)
12+
raise InvalidChannelException
13+
14+
def analogRead(channel):
15+
with open(_ADC_PREFIX % channel, 'r') as f:
16+
return "%s" % f.read(32)

‎pcduino/exceptions.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class InvalidChannelException(KeyError):
2+
"""The channel sent was invalid."""
3+
pass

‎pcduino/gpio.py‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#
33
# io test code for pcDuino ( http://www.pcduino.com )
44
#
5+
from exceptions import InvalidChannelException
56
__all__ = ['HIGH', 'LOW', 'INPUT', 'OUTPUT','digitalWrite', 'digitalRead', "pinMode"]
67

7-
_GPIO_PINS = ('gpio0','gpio1','gpio2','gpio3','gpio4','gpio5','gpio6','gpio7',
8-
'gpio8', 'gpio9', 'gpio10', 'gpio11', 'gpio12', 'gpio13',
9-
'gpio14', 'gpio15', 'gpio16', 'gpio17', 'gpio18', 'gpio19')
8+
_GPIO_PINS = set(('gpio%s' % i for i in xrange(20)))
109

1110
_PIN_FD_PATH = '/sys/devices/virtual/misc/gpio/pin/%s'
1211
_MODE_FD_PATH = '/sys/devices/virtual/misc/gpio/mode/%s'
@@ -15,30 +14,26 @@
1514
INPUT = 0
1615
OUTPUT = 1
1716

18-
class InvalidChannelException(Exception):
19-
"""The channel sent is invalid on pcDuino board """
20-
pass
21-
22-
def _GetValidId(channel):
17+
def _get_valid_id(channel):
2318
if channel in _GPIO_PINS:
2419
return channel
2520
else:
2621
raise InvalidChannelException
2722

28-
def digitalWrite(channel, value):
23+
def digital_write(channel, value):
2924
"""Write to a GPIO channel"""
30-
id = _GetValidId(channel)
25+
id = _get_valid_id(channel)
3126
with open(_PIN_FD_PATH % id, 'w') as f:
3227
f.write('1' if value == HIGH else '0')
3328

34-
def digitalRead(channel):
29+
def digital_read(channel):
3530
"""Read from a GPIO channel"""
36-
id = _GetValidId(channel)
31+
id = _get_valid_id(channel)
3732
with open(_PIN_FD_PATH % id, 'r') as f:
3833
return f.read(1) == '1'
3934

40-
def pinMode(channel, mode):
35+
def pin_mode(channel, mode):
4136
""" Set Mode of a GPIO channel """
42-
id = _GetValidId(channel)
37+
id = _get_valid_id(channel)
4338
with open(_MODE_FD_PATH % id, 'w') as f:
4439
f.write('0' if mode == INPUT else '1')

‎pcduino/pwm.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
_ADC_PREFIX = '/proc/adc'
2-
_N_PINS= 6
3-
4-
5-
def analogRead(channel):
6-
with open(_ADC_PREFIX % id, 'r') as f:
7-
return f.read(1)
1+
def digitalWrite(channel, value):
2+
pass

0 commit comments

Comments
 (0)