-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add cubieboard support #14
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ | |
|
||
import errno | ||
import os | ||
from os import listdir | ||
from os.path import isdir,join | ||
import select | ||
|
||
from twisted.internet import reactor | ||
|
@@ -48,10 +50,10 @@ | |
SYSFS_UNEXPORT_PATH = SYSFS_BASE_PATH + '/unexport' | ||
|
||
SYSFS_GPIO_PATH = SYSFS_BASE_PATH + '/gpio%d' | ||
SYSFS_GPIO_DIRECTION_PATH = SYSFS_GPIO_PATH + '/direction' | ||
SYSFS_GPIO_EDGE_PATH = SYSFS_GPIO_PATH + '/edge' | ||
SYSFS_GPIO_VALUE_PATH = SYSFS_GPIO_PATH + '/value' | ||
SYSFS_GPIO_ACTIVE_LOW_PATH = SYSFS_GPIO_PATH + '/active_low' | ||
SYSFS_GPIO_DIRECTION_PATH = '/direction' | ||
SYSFS_GPIO_EDGE_PATH = '/edge' | ||
SYSFS_GPIO_VALUE_PATH = '/value' | ||
SYSFS_GPIO_ACTIVE_LOW_PATH ='/active_low' | ||
|
||
SYSFS_GPIO_VALUE_LOW = '0' | ||
SYSFS_GPIO_VALUE_HIGH = '1' | ||
|
@@ -74,6 +76,13 @@ | |
EDGES = (RISING, FALLING, BOTH) | ||
ACTIVE_LOW_MODES = (ACTIVE_LOW_ON, ACTIVE_LOW_OFF) | ||
|
||
def GetGpioDirFromPin(number): | ||
ds = listdir(SYSFS_BASE_PATH) | ||
nd = filter(lambda a: a.startswith("gpio" + str(number)),ds) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does |
||
if len(nd) > 0: | ||
return nd[0] | ||
else: | ||
return "DONOT" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd not return a bogus string. Raising an exception would work much better. |
||
|
||
class Pin(object): | ||
""" | ||
|
@@ -198,7 +207,7 @@ def _sysfs_gpio_value_path(self): | |
@rtype: str | ||
@return: the path to sysfs value file | ||
""" | ||
return SYSFS_GPIO_VALUE_PATH % self.number | ||
return SYSFS_BASE_PATH + "/" + GetGpioDirFromPin(self.number) + SYSFS_GPIO_VALUE_PATH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer a function |
||
|
||
def _sysfs_gpio_direction_path(self): | ||
""" | ||
|
@@ -207,7 +216,7 @@ def _sysfs_gpio_direction_path(self): | |
@rtype: str | ||
@return: the path to sysfs direction file | ||
""" | ||
return SYSFS_GPIO_DIRECTION_PATH % self.number | ||
return SYSFS_BASE_PATH + "/" + GetGpioDirFromPin(self.number) + SYSFS_GPIO_DIRECTION_PATH | ||
|
||
def _sysfs_gpio_edge_path(self): | ||
""" | ||
|
@@ -216,7 +225,7 @@ def _sysfs_gpio_edge_path(self): | |
@rtype: str | ||
@return: the path to sysfs edge file | ||
""" | ||
return SYSFS_GPIO_EDGE_PATH % self.number | ||
return SYSFS_BASE_PATH + "/" + GetGpioDirFromPin(self.number) + SYSFS_GPIO_EDGE_PATH | ||
|
||
def _sysfs_gpio_active_low_path(self): | ||
""" | ||
|
@@ -225,8 +234,7 @@ def _sysfs_gpio_active_low_path(self): | |
@rtype: str | ||
@return: the path to sysfs active_low file | ||
""" | ||
return SYSFS_GPIO_ACTIVE_LOW_PATH % self.number | ||
|
||
return SYSFS_BASE_PATH + "/" + GetGpioDirFromPin(self.number) + SYSFS_GPIO_ACTIVE_LOW_PATH | ||
|
||
class Controller(object): | ||
''' | ||
|
@@ -402,7 +410,7 @@ def _check_pin_already_exported(self, number): | |
@rtype: bool | ||
@return: C{True} when it's already exported, otherwise C{False} | ||
""" | ||
gpio_path = SYSFS_GPIO_PATH % number | ||
gpio_path = SYSFS_BASE_PATH + "/" + GetGpioDirFromPin(number) | ||
return os.path.isdir(gpio_path) | ||
|
||
def _check_pin_validity(self, number): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Project is following snake case. Rename the function to
_sysfs_gpio_pin_path
(see more below).