-
Notifications
You must be signed in to change notification settings - Fork 48
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
Enum #109
base: master
Are you sure you want to change the base?
Enum #109
Changes from all commits
bf2e4e2
21e9a82
5f9eb2f
757f904
2b37237
f68298b
0857ac0
d5aad1a
4721c35
ab1f2a5
5ea737f
7addd83
56464b8
c6bb567
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 |
---|---|---|
@@ -1,32 +1,32 @@ | ||
from __future__ import absolute_import | ||
|
||
# api | ||
from board import ANALOG # noqa | ||
from board import IN # noqa | ||
from board import OUT # noqa | ||
from board import PWM # noqa | ||
from board import HIGH # noqa | ||
from board import LOW # noqa | ||
from board import ModeNotSuported # noqa | ||
from board import WrongPinMode # noqa | ||
from board import PwmOutputCapable # noqa | ||
from board import AnalogInputCapable # noqa | ||
from board import Board # noqa | ||
from board import PwmPin # noqa | ||
from board import AnalogPin # noqa | ||
from board import DigitalPin # noqa | ||
from board import GroundPin # noqa | ||
from board import Pin # noqa | ||
from board import VccPin # noqa | ||
import parts # noqa | ||
from .board import State # noqa | ||
from .board import Mode # noqa | ||
from .board import ModeNotSuported # noqa | ||
from .board import WrongPinMode # noqa | ||
from .board import PwmOutputCapable # noqa | ||
from .board import AnalogInputCapable # noqa | ||
from .board import Board # noqa | ||
from .board import PwmPin # noqa | ||
from .board import AnalogPin # noqa | ||
from .board import DigitalPin # noqa | ||
from .board import GroundPin # noqa | ||
from .board import Pin # noqa | ||
from .board import VccPin # noqa | ||
import pingo.parts # import * # noqa | ||
|
||
|
||
# boards | ||
import rpi # noqa | ||
import ghost # noqa | ||
import intel # noqa | ||
import udoo # noqa | ||
import pcduino # noqa | ||
import arduino # noqa | ||
import bbb # noqa | ||
import pingo.rpi # noqa | ||
import pingo.ghost # noqa | ||
import pingo.intel # noqa | ||
import pingo.udoo # noqa | ||
import pingo.pcduino # noqa | ||
import pingo.arduino # noqa | ||
import pingo.bbb # noqa | ||
|
||
|
||
# resources | ||
import detect # noqa | ||
import test # noqa | ||
import pingo.detect # noqa | ||
import pingo.test # noqa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from firmata import ArduinoFirmata # noqa | ||
from firmata import get_arduino # noqa | ||
from pyun import YunBridge # noqa | ||
from pyun import ArduinoYun # noqa | ||
from .firmata import ArduinoFirmata # noqa | ||
from .firmata import get_arduino # noqa | ||
from .pyun import YunBridge # noqa | ||
from .pyun import ArduinoYun # noqa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import unittest | ||
|
||
from util_firmata import pin_list_to_board_dict | ||
from .util_firmata import pin_list_to_board_dict | ||
|
||
|
||
class FirmataCapabilityDetect(unittest.TestCase): | ||
|
@@ -43,12 +43,8 @@ def test_capability_response(self): | |
0x7F, # END_SYSEX (Pin delimiter) | ||
] | ||
|
||
data_arduino = list( | ||
# [0x6C] # CAPABILITY_RESPONSE | ||
unavailible_pin | ||
+ digital_pin | ||
+ analog_pin | ||
) | ||
data_arduino = list(unavailible_pin + digital_pin + analog_pin) | ||
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. Why did you change this line? 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. because of flake8 errors |
||
# [0x6C] # CAPABILITY_RESPONSE | ||
|
||
pinmap = pin_list_to_board_dict(data_arduino) | ||
for key in test_layout.keys(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from bbb import BeagleBoneBlack # noqa | ||
from .bbb import BeagleBoneBlack # noqa |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,11 @@ | |
from abc import ABCMeta, abstractmethod | ||
|
||
from .util import StrKeyDict | ||
from enum import Enum | ||
|
||
HIGH = 'HIGH' | ||
LOW = 'LOW' | ||
State = Enum('State', 'LOW HIGH') | ||
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. Great! 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. ;-) |
||
|
||
# TODO: 4 states implementation: IN, OUT, ANALOG, PWM | ||
IN = 'IN' | ||
OUT = 'OUT' | ||
ANALOG = 'ANALOG' | ||
PWM = 'PWM' | ||
Mode = Enum('Mode', 'IN OUT ANALOG PWM') | ||
|
||
|
||
class WrongPinMode(Exception): | ||
|
@@ -249,24 +245,28 @@ def __repr__(self): | |
|
||
@property | ||
def mode(self): | ||
"""[property] Get/set pin mode to ``pingo.IN``, ``pingo.OUT`` | ||
``pingo.ANALOG`` or ``pingo.PWM``""" | ||
"""[property] Get/set pin mode to ``Mode.IN``, ``Mode.OUT`` | ||
``Mode.ANALOG`` or ``Mode.PWM``""" | ||
return self._mode | ||
|
||
@mode.setter | ||
def mode(self, value): | ||
if value not in self.suported_modes: | ||
raise ModeNotSuported() | ||
|
||
if value in [IN, OUT]: | ||
if value in [Mode.IN, Mode.OUT]: | ||
self.board._set_digital_mode(self, value) | ||
elif value == ANALOG: | ||
elif value == Mode.ANALOG: | ||
self.board._set_analog_mode(self, value) | ||
elif value == PWM: | ||
elif value == Mode.PWM: | ||
self.board._set_pwm_mode(self, value) | ||
|
||
self._mode = value | ||
|
||
@property | ||
def is_analog(self): | ||
return issubclass(type(self), AnalogPin) | ||
|
||
|
||
class DigitalPin(Pin): | ||
"""Defines common interface for all digital pins. | ||
|
@@ -279,60 +279,60 @@ class DigitalPin(Pin): | |
because pins delegate all board-dependent behavior to the board. | ||
""" | ||
|
||
suported_modes = [IN, OUT] | ||
suported_modes = [Mode.IN, Mode.OUT] | ||
|
||
def __init__(self, board, location, gpio_id=None): | ||
Pin.__init__(self, board, location, gpio_id) | ||
self._state = None | ||
|
||
@property | ||
def state(self): | ||
"""[property] Get/set pin state to ``pingo.HIGH`` or ``pingo.LOW``""" | ||
if self.mode not in [IN, OUT]: | ||
"""[property] Get/set pin state to ``State.HIGH`` or ``State.LOW``""" | ||
if self.mode not in [Mode.IN, Mode.OUT]: | ||
raise WrongPinMode() | ||
|
||
if self.mode == IN: | ||
if self.mode == Mode.IN: | ||
self._state = self.board._get_pin_state(self) | ||
|
||
return self._state | ||
|
||
@state.setter | ||
def state(self, value): | ||
if self.mode != OUT: | ||
if self.mode != Mode.OUT: | ||
raise WrongPinMode() | ||
|
||
self.board._set_pin_state(self, value) | ||
self._state = value | ||
|
||
def low(self): | ||
"""Set voltage of pin to ``pingo.LOW`` (GND).""" | ||
self.state = LOW | ||
"""Set voltage of pin to ``State.LOW`` (GND).""" | ||
self.state = State.LOW | ||
|
||
lo = low # shortcut for interactive use | ||
|
||
def high(self): | ||
"""Set state of the pin to ``pingo.HIGH`` (Vcc).""" | ||
self.state = HIGH | ||
self.state = State.HIGH | ||
|
||
hi = high # shortcut for interactive use | ||
|
||
def toggle(self): | ||
"""Change state of the pin.""" | ||
self.state = HIGH if self.state == LOW else LOW | ||
self.state = State.HIGH if self.state == State.LOW else State.LOW | ||
|
||
def pulse(self): | ||
"""Generate a pulse in state of the pin.""" | ||
if self.state == LOW: | ||
self.state = HIGH | ||
self.state = LOW | ||
if self.state == State.LOW: | ||
self.state = State.HIGH | ||
self.state = State.LOW | ||
else: | ||
self.state = LOW | ||
self.state = HIGH | ||
self.state = State.LOW | ||
self.state = State.HIGH | ||
|
||
|
||
class PwmPin(DigitalPin): | ||
|
||
suported_modes = [IN, OUT, PWM] | ||
suported_modes = [Mode.IN, Mode.OUT, Mode.PWM] | ||
|
||
def __init__(self, board, location, gpio_id=None, frequency=None): | ||
DigitalPin.__init__(self, board, location, gpio_id) | ||
|
@@ -344,13 +344,13 @@ def __init__(self, board, location, gpio_id=None, frequency=None): | |
|
||
@property | ||
def value(self): | ||
if self.mode != PWM: | ||
if self.mode != Mode.PWM: | ||
raise WrongPinMode() | ||
return self.board._get_pwm_duty_cycle(self) | ||
|
||
@value.setter | ||
def value(self, value): | ||
if self.mode != PWM: | ||
if self.mode != Mode.PWM: | ||
raise WrongPinMode() | ||
if not 0.0 <= value <= 100.0: | ||
raise ArgumentOutOfRange() | ||
|
@@ -359,13 +359,13 @@ def value(self, value): | |
|
||
@property | ||
def frequency(self): | ||
if self.mode != PWM: | ||
if self.mode != Mode.PWM: | ||
raise WrongPinMode() | ||
return self.board._get_pwm_frequency(self) | ||
|
||
@frequency.setter | ||
def frequency(self, new_frequency): | ||
if self.mode != PWM: | ||
if self.mode != Mode.PWM: | ||
raise WrongPinMode() | ||
if new_frequency <= 0.0: | ||
raise ArgumentOutOfRange() | ||
|
@@ -382,7 +382,7 @@ class AnalogPin(Pin): | |
This pin type supports read operations only. | ||
""" | ||
|
||
suported_modes = [IN, ANALOG] | ||
suported_modes = [Mode.IN, Mode.ANALOG] | ||
|
||
def __init__(self, board, location, resolution, gpio_id=None): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import sys | ||
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. Why this name I don't know if you followed the early discussion. There was a consensus on supporting Python3 only if Python2 compatibility is assured. Read more on Py3k support #45 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.
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. Ok, That was a new one for me. Thanks. |
||
|
||
PY2 = sys.version_info[0] == 2 | ||
PY3 = (sys.version_info[0] >= 3) | ||
|
||
|
||
def iteritems(obj, **kwargs): | ||
"""replacement for six's iteritems for Python2/3 compat | ||
uses 'iteritems' if available and otherwise uses 'items'. | ||
Passes kwargs to method. | ||
""" | ||
func = getattr(obj, "iteritems", None) | ||
if not func: | ||
func = obj.items | ||
return func(**kwargs) | ||
|
||
|
||
def iterkeys(obj, **kwargs): | ||
func = getattr(obj, "iterkeys", None) | ||
if not func: | ||
func = obj.keys | ||
return func(**kwargs) | ||
|
||
|
||
if PY2: | ||
from UserDict import UserDict # noqa | ||
else: | ||
from collections import UserDict # noqa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from detect import get_board | ||
from .detect import get_board | ||
|
||
|
||
def has_module(module_name): | ||
|
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.
Why this is necessary?
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.
Because it's necessary to install dependencies (enum34). So as
enum34
is in dependencies of this package, installing package will install dependenciesThere 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.
ok, because you added
enum34
to setup.py and to requirements.txtThere 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.
Moreover it's a way to ensure that this package installs correctly