Skip to content

Commit d76b318

Browse files
committed
PiStorms support
1 parent c41d8e3 commit d76b318

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ python-ev3dev (1.2.0) stable; urgency=medium
44
* Return handle to aplay in Sound.espeak
55

66
[ David Lechner ]
7+
* PiStorms support
78
* Update BrickPi port names for 4.14 kernel
89
* Fix brickpi led names
910
* brickpi3 support

ev3dev/pistorms.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# ------------------------------------------------------------------------------
2+
# Copyright (c) 2018 David Lechner <david@lechnology.com>
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in
12+
# all copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
# THE SOFTWARE.
21+
# -----------------------------------------------------------------------------
22+
23+
"""
24+
An assortment of classes modeling specific features of the EV3 brick.
25+
"""
26+
27+
from .core import *
28+
29+
30+
OUTPUT_A = 'pistorms:BAM1'
31+
OUTPUT_B = 'pistorms:BAM2'
32+
OUTPUT_C = 'pistorms:BBM1'
33+
OUTPUT_D = 'pistorms:BBM2'
34+
35+
INPUT_1 = 'pistorms:BAS1'
36+
INPUT_2 = 'pistorms:BAS2'
37+
INPUT_3 = 'pistorms:BBS1'
38+
INPUT_4 = 'pistorms:BBS2'
39+
40+
41+
class Leds(object):
42+
"""
43+
The PiStorms LEDs.
44+
"""
45+
46+
red_left = Led(name_pattern='pistorms:BB:red:brick-status')
47+
red_right = Led(name_pattern='pistorms:BA:red:brick-status')
48+
green_left = Led(name_pattern='pistorms:BB:green:brick-status')
49+
green_right = Led(name_pattern='pistorms:BA:green:brick-status')
50+
blue_left = Led(name_pattern='pistorms:BB:blue:brick-status')
51+
blue_right = Led(name_pattern='pistorms:BA:blue:brick-status')
52+
53+
LEFT = (red_left, green_left, blue_left)
54+
RIGHT = (red_right, green_right, blue_right)
55+
56+
BLACK = (0, 0, 0)
57+
RED = (1, 0, 0)
58+
GREEN = (0, 1, 0)
59+
BLUE = (0, 0, 1)
60+
YELLOW = (1, 1, 0)
61+
CYAN = (0, 1, 1)
62+
MAGENTA = (1, 0, 1)
63+
64+
@staticmethod
65+
def set_color(group, color, pct=1):
66+
"""
67+
Sets brightness of leds in the given group to the values specified in
68+
color tuple. When percentage is specified, brightness of each led is
69+
reduced proportionally.
70+
71+
Example::
72+
73+
Leds.set_color(LEFT, MAGENTA)
74+
"""
75+
for l, v in zip(group, color):
76+
l.brightness_pct = v * pct
77+
78+
@staticmethod
79+
def set(group, **kwargs):
80+
"""
81+
Set attributes for each led in group.
82+
83+
Example::
84+
85+
Leds.set(LEFT, brightness_pct=0.5, trigger='timer')
86+
"""
87+
for led in group:
88+
for k in kwargs:
89+
setattr(led, k, kwargs[k])
90+
91+
@staticmethod
92+
def all_off():
93+
"""
94+
Turn all leds off
95+
"""
96+
Leds.red_left.brightness = 0
97+
Leds.red_right.brightness = 0
98+
Leds.green_left.brightness = 0
99+
Leds.green_right.brightness = 0
100+
Leds.blue_left.brightness = 0
101+
Leds.blue_right.brightness = 0
102+
103+
104+
class Button(ButtonEVIO):
105+
"""
106+
PiStorms Buttons
107+
"""
108+
109+
@staticmethod
110+
def on_go(state):
111+
"""
112+
This handler is called by `process()` whenever state of 'enter' button
113+
has changed since last `process()` call. `state` parameter is the new
114+
state of the button.
115+
"""
116+
pass
117+
118+
_buttons = {
119+
'go': {
120+
'name': '/dev/input/by-path/platform-3f804000.i2c-event',
121+
'value': 103,
122+
},
123+
}
124+
125+
@property
126+
def go(self):
127+
"""
128+
Check if 'go' button is pressed.
129+
"""
130+
return 'go' in self.buttons_pressed

0 commit comments

Comments
 (0)