Skip to content

Commit 2f5a479

Browse files
committed
updated
1 parent 399118f commit 2f5a479

6 files changed

Lines changed: 55 additions & 7 deletions

File tree

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Enjoy
2525
- [IO Mechanism](#io-mechanism)
2626
- [Layers](#layers)
2727
- [Auto-Pinning of Layers](#auto-pinning-of-layers)
28-
- [Feedback](#feedback)
28+
- [Feedbacks of Layers](#feedbacks-of-layers)
2929
- [Poll for Feedback](#poll-for-feedback)
3030
- [Callback for Feedback](#callback-for-feedback)
3131
- [Selected Demos](#selected-demos)
@@ -180,6 +180,30 @@ Other then the `DumbDisplay`, you will need to create one or more layer objects
180180
|:--:|
181181
|<img style="width: 300px; height: 300px;" src="screenshots/layer_plotter.png"></img>|
182182
183+
- `LayerJoystick` -- a joystick; also can be a horizontal or vertical slider
184+
```
185+
from dumbdisplay.core import *
186+
from dumbdisplay.layer_joystick import *
187+
dd = DumbDisplay()
188+
l = LayerJoystick(dd)
189+
```
190+
|[`demo_LayerJoystick()` in `dd_demo.py`](dd_demo.py)|
191+
|:--:|
192+
|<img style="width: 300px; height: 300px;" src="screenshots/layer_joystick.png"></img>|
193+
194+
As shown in the example
195+
* you can configure the joystick to be a horizontal or vertical slider by changing the `directions` parameter to `LayerJoystick`
196+
- param `maxStickValue`: the max value of the stick; e.g. 255 or 1023 (the default); min is 15
197+
- param `directions`: "lr" or "hori": left-to-right; "tb" or "vert": top-to-bottom; "rl": right-to-left; "bt": bottom-to-top;
198+
use "+" combines the above like "lr+tb" to mean both directions; "" the same as "lr+tb"
199+
* feedback -- to be talked about later -- is enabled by default, and you can poll for feedback like
200+
```
201+
while True:
202+
fb = l.getFeedback()
203+
if fb:
204+
print(f"* Feedback: {fb.type} at ({fb.x}, {fb.y})")
205+
```
206+
183207
## Auto-Pinning of Layers
184208
185209
In case of multiple layers, you can "auto pin" them together; otherwise, multiple layers will be stacked on top of each other
@@ -192,7 +216,7 @@ AutoPin('V', AutoPin('H', l_ledgrid, l_lcd), AutoPin('H', l_selection, l_7segmen
192216
|:--:|
193217
|<img style="width: 400px; height: 400px;" src="screenshots/autopin_layers.png"></img>|
194218
195-
## Feedback
219+
## Feedbacks of Layers
196220
197221
Certain user interaction, like pressing, with the layers (the UI) can trigger feedback to the corresponding layer objects
198222
@@ -205,7 +229,7 @@ or to enable feedback with auto flashing (UI feedback) of the layer by provide o
205229
l.enable_feedback("fl")
206230
```
207231
208-
There are two ways feedback of the layer can be received -- polling or callback
232+
There are two ways feedback of a layer can be received -- polling or callback
209233
210234
### Poll for Feedback
211235
@@ -237,6 +261,12 @@ The parameters passed to the callback `lambda`:
237261
- `type`: the type of feedback (as mentioned above)
238262
- `x`, `y`: the "coordinates" of the feedback (as mentioned above)
239263
264+
***Important*** note: Since DumbDisplay is "cooperative", you should give "time-slices" for DumbDisplay to process feedback signals from the Android app, like:
265+
```
266+
while True:
267+
dd.timeslice()
268+
```
269+
240270
Please take [`demo_Feedback_callback()` in `dd_demo.py`](dd_demo.py) as an example.
241271
242272

dd_demo.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ def demo_LayerPlotter():
155155
dd.timeslice()
156156

157157

158+
def demo_LayerJoystick(maxStickValue: int = 1023, directions: str = ""):
159+
from dumbdisplay.layer_joystick import LayerJoystick
160+
161+
# Create a DumbDisplay instance
162+
dd = _create_demo_dd()
163+
164+
# Create a LayerJoystick layer with the specified maxStickValue and directions, and set it up, like border and colors
165+
l = LayerJoystick(dd, maxStickValue=maxStickValue, directions=directions)
166+
l.border(5, "blue")
167+
l.colors(stick_color="green", stick_outline_color="darkgreen")
168+
169+
while True:
170+
fb = l.getFeedback()
171+
if fb:
172+
print(f"* Feedback: {fb.type} at ({fb.x}, {fb.y})")
173+
174+
158175
def demo_AutoPin():
159176
from dumbdisplay.full import LayerLedGrid, LayerLcd, LayerGraphical, Layer7SegmentRow, LayerSelection, AutoPin
160177

@@ -280,10 +297,11 @@ def run_mnist_app():
280297
# demo_Layer7SegmentRow()
281298
# demo_LayerSelection()
282299
# demo_LayerPlotter()
300+
demo_LayerJoystick(directions="") # directions can be "", "lr" or "tb"
283301

284-
#demo_AutoPin()
285-
#demo_Feedback()
286-
demo_Feedback_callback()
302+
# demo_AutoPin()
303+
# demo_Feedback()
304+
# demo_Feedback_callback()
287305

288306
# run_passive_blink_app()
289307
# run_sliding_puzzle_app()

dumbdisplay/ddlayer_joystick.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, dd, maxStickValue: int = 1023, directions: str = "", stickLoo
1515
super().__init__(dd, layer_id)
1616
def autoRecenter(self, auto_recenter: bool = True):
1717
self.dd._sendCommand(self.layer_id, "autorecenter", _DD_BOOL_ARG(auto_recenter))
18-
def colors(self, stick_color: str, stick_outline_color: str, socket_color: str, socket_outline_color):
18+
def colors(self, stick_color: str = "", stick_outline_color: str = "", socket_color: str = "", socket_outline_color = ""):
1919
self.dd._sendCommand(self.layer_id, "colors", _DD_COLOR_ARG(stick_color), _DD_COLOR_ARG(stick_outline_color), _DD_COLOR_ARG(socket_color), _DD_COLOR_ARG(socket_outline_color))
2020
def moveToPos(self, x: int, y: int, send_feedback: bool = False):
2121
'''

screenshots/layer_joystick.png

26.8 KB
Loading

screenshots/layer_joystick_tb.png

13.1 KB
Loading

screenshots/layer_joystock_lr.png

12.6 KB
Loading

0 commit comments

Comments
 (0)