Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions sysfs/gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -74,6 +76,13 @@
EDGES = (RISING, FALLING, BOTH)
ACTIVE_LOW_MODES = (ACTIVE_LOW_ON, ACTIVE_LOW_OFF)

def GetGpioDirFromPin(number):
Copy link
Owner

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).

ds = listdir(SYSFS_BASE_PATH)
nd = filter(lambda a: a.startswith("gpio" + str(number)),ds)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does ds and nd mean?

if len(nd) > 0:
return nd[0]
else:
return "DONOT"
Copy link
Owner

Choose a reason for hiding this comment

The 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):
"""
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a function _sysfs_gpio_pin_path that returns the absolute GPIO path, which would avoid repeating SYSFS_BASE_PATH everywhere.


def _sysfs_gpio_direction_path(self):
"""
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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):
'''
Expand Down Expand Up @@ -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):
Expand Down