Skip to content

Commit 9778135

Browse files
authored
chore: add dprint formatter (#19)
* Refactor patch-gui.js for improved readability and maintainability; update README.md for Arduino Modulino library to enhance clarity and formatting * fix: change set_led_rgb parameters from uint8_t to bool for LED control (#20) * feat: add format check task to Taskfile and release workflow * fix: update format check task name to use correct syntax in Taskfile and release workflow * feat: add format checks workflow for automated code formatting * feat: add dprint installation to workflows and Taskfile for code formatting
1 parent 0522e4b commit 9778135

File tree

13 files changed

+217
-126
lines changed

13 files changed

+217
-126
lines changed

.github/workflows/check.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Format Checks
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v5
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Install Task
19+
uses: arduino/setup-task@v2
20+
21+
- name: Install dprint
22+
run: |
23+
task install
24+
25+
- name: Fmt check
26+
run: |
27+
task fmt:check

.github/workflows/release.yaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
uses: actions/checkout@v5
1515
with:
1616
fetch-depth: 0
17-
17+
1818
- name: Show tag info
1919
run: echo "Building release for tag ${{ github.ref_name }}"
20-
20+
2121
- name: Install Go
2222
uses: actions/setup-go@v5
2323
with:
@@ -26,20 +26,28 @@ jobs:
2626
- name: Set up Node.js
2727
uses: actions/setup-node@v6
2828
with:
29-
node-version: '18'
29+
node-version: "18"
3030

3131
- name: Install Task
3232
uses: arduino/setup-task@v2
3333

34-
- name: Scratch init
34+
- name: Install dprint
35+
run: |
36+
task install
37+
38+
- name: Fmt check
39+
run: |
40+
task fmt:check
41+
42+
- name: Scratch init
3543
run: |
3644
task scratch:init
3745
38-
- name: Create build
46+
- name: Create build
3947
run: |
4048
task app:build
4149
42-
- name: Create zip
50+
- name: Create zip
4351
run: task app:zip
4452
env:
4553
APP_VERSION: ${{ github.ref_name }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
scratch-editor
2-
build/
2+
build/
3+
.bin/

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
- Connect to the board using `adb` following https://docs.arduino.cc/software/app-lab/tutorials/cli/ and open the `adb shell`
66
- From inside the board, Install the latest `scratch-arduino-app` into the board running the command:
7+
78
```
89
curl -sSL https://raw.githubusercontent.com/dido18/scratch-arduino-app/main/install.sh | bash
910
```
11+
1012
- Open the `ArduinoAppLab` and start the app
1113
- Visit the `<IP_OR_BOARD_NAME>:7000` to open the Scratch App.
1214

1315
### Local development
16+
1417
- `task scratch:init`
1518
- `task scratch:local:start`
1619
- `ŧask board:upload`
17-
- change the `const wsServerURL = `ws://<YOUR_IP>:7000`;` in the `index.js`
20+
- change the `const wsServerURL =`ws://<YOUR_IP>:7000`;` in the `index.js`
1821
- Open local scratch on http://localhost:8601/

Taskfile.yaml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
version: "3"
22
vars:
33
SCRATCH_EDITOR_VERSION: v12.0.1
4+
DPRINT_VERSION: 0.48.0
45

56
tasks:
7+
install:
8+
cmds:
9+
- curl -fsSL https://dprint.dev/install.sh | sh -s {{ .DPRINT_VERSION }}
10+
- mkdir -p .bin && cp $HOME/.dprint/bin/dprint .bin/dprint # workaround for local install
11+
12+
fmt:
13+
desc: Run format
14+
cmds:
15+
- ${PWD}/.bin/dprint fmt
16+
17+
fmt:check:
18+
desc: Check format
19+
cmds:
20+
- ${PWD}/.bin/dprint check
21+
622
scratch:init:
723
cmds:
824
- rm -rf scratch-editor
@@ -33,8 +49,8 @@ tasks:
3349
- cp scratch-editor/packages/scratch-gui/build/gui.js build/scratch-arduino-app/assets/gui.js
3450
- mkdir -p build/scratch-arduino-app/assets/static
3551
- cp -r scratch-editor/packages/scratch-gui/build/static/blocks-media build/scratch-arduino-app/assets/static/blocks-media
36-
37-
scratch:build:
52+
53+
scratch:build:
3854
desc: "Build Scratch GUI files"
3955
dir: scratch-editor/packages/scratch-gui
4056
cmds:
@@ -45,27 +61,26 @@ tasks:
4561
cmds:
4662
- task app:zip
4763
- |
48-
ZIP_FILE=$(ls -t build/scratch-arduino-app-*.zip 2>/dev/null | head -n1)
49-
if [ -z "$ZIP_FILE" ]; then
50-
echo "No zip file found. Run 'task app:zip' first."
51-
exit 1
52-
fi
53-
adb push "$ZIP_FILE" /tmp/
54-
ZIP_BASENAME=$(basename "$ZIP_FILE")
55-
adb shell "cd /tmp && unzip -o $ZIP_BASENAME && mkdir -p /home/arduino/ArduinoApps && rm -rf /home/arduino/ArduinoApps/scratch-arduino-app && mv scratch-arduino-app /home/arduino/ArduinoApps/ && rm $ZIP_BASENAME"
56-
echo "App deployed to /home/arduino/ArduinoApps/scratch-arduino-app"
57-
64+
ZIP_FILE=$(ls -t build/scratch-arduino-app-*.zip 2>/dev/null | head -n1)
65+
if [ -z "$ZIP_FILE" ]; then
66+
echo "No zip file found. Run 'task app:zip' first."
67+
exit 1
68+
fi
69+
adb push "$ZIP_FILE" /tmp/
70+
ZIP_BASENAME=$(basename "$ZIP_FILE")
71+
adb shell "cd /tmp && unzip -o $ZIP_BASENAME && mkdir -p /home/arduino/ArduinoApps && rm -rf /home/arduino/ArduinoApps/scratch-arduino-app && mv scratch-arduino-app /home/arduino/ArduinoApps/ && rm $ZIP_BASENAME"
72+
echo "App deployed to /home/arduino/ArduinoApps/scratch-arduino-app"
73+
5874
app:zip:
5975
desc: "Create a zip file with version (defaults to git commit hash)"
6076
vars:
6177
APP_VERSION:
6278
sh: echo "${APP_VERSION:-$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')}"
6379
cmds:
6480
- |
65-
if [ ! -d "build/scratch-arduino-app" ]; then
66-
echo "Build folder does not exist. Run 'task app:build' first."
67-
exit 1
68-
fi
81+
if [ ! -d "build/scratch-arduino-app" ]; then
82+
echo "Build folder does not exist. Run 'task app:build' first."
83+
exit 1
84+
fi
6985
- echo "Creating zip with version {{.APP_VERSION}}"
7086
- cd build && zip -r scratch-arduino-app-{{.APP_VERSION}}.zip scratch-arduino-app && cd ..
71-

app.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: scratch-arduino-app
22
description: Control the Uno-Q board using Scratch blocks
33
ports:
4-
- 7000
4+
- 7000
55
bricks:
6-
- arduino:web_ui
6+
- arduino:web_ui
77
icon: 🐱

dprint.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"typescript": {},
3+
"json": {},
4+
"markdown": {},
5+
"yaml": {},
6+
"ruff": {
7+
"indentStyle": "space",
8+
"lineLength": 100,
9+
"indentWidth": 4
10+
},
11+
"excludes": [
12+
"**/.venv/**",
13+
"**/assets/**",
14+
"**/scratch-editor/**",
15+
"**/build/**"
16+
],
17+
"plugins": [
18+
"https://plugins.dprint.dev/json-0.19.4.wasm",
19+
"https://plugins.dprint.dev/markdown-0.17.8.wasm",
20+
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm",
21+
"https://plugins.dprint.dev/ruff-0.3.9.wasm",
22+
"https://plugins.dprint.dev/typescript-0.95.12.wasm"
23+
]
24+
}

python/main.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,31 @@
33
import time
44

55
ui = WebUI()
6-
ui.on_connect(
7-
lambda sid: (
8-
print(f"Client connected: {sid} "),
9-
)
10-
)
6+
ui.on_connect(lambda sid: (print(f"Client connected: {sid} "),))
117

128

139
def on_matrix_draw(_, data):
1410
print(f"Received frame to draw on matrix: {data}")
1511
# from 5x5 to 8x13 matrix
16-
frame_5x5 = data.get('frame')
17-
row0 = "0"*13
18-
row1 = "0"*4 + frame_5x5[0:5] + "0"*4
19-
row2 = "0"*4 + frame_5x5[5:10] + "0"*4
20-
row3 = "0"*4 + frame_5x5[10:15] + "0"*4
21-
row4 = "0"*4 + frame_5x5[15:20] + "0"*4
22-
row5 = "0"*4 + frame_5x5[20:25] + "0"*4
23-
row6 = "0"*13
24-
row7 = "0"*13
12+
frame_5x5 = data.get("frame")
13+
row0 = "0" * 13
14+
row1 = "0" * 4 + frame_5x5[0:5] + "0" * 4
15+
row2 = "0" * 4 + frame_5x5[5:10] + "0" * 4
16+
row3 = "0" * 4 + frame_5x5[10:15] + "0" * 4
17+
row4 = "0" * 4 + frame_5x5[15:20] + "0" * 4
18+
row5 = "0" * 4 + frame_5x5[20:25] + "0" * 4
19+
row6 = "0" * 13
20+
row7 = "0" * 13
2521
frame_8x13 = row0 + row1 + row2 + row3 + row4 + row5 + row6 + row7
2622
print(f"Transformed frame to draw on 8x13 matrix: {frame_8x13}")
2723
Bridge.call("matrix_draw", frame_8x13)
2824

25+
2926
def rgb_to_digital(value, threshold=128) -> bool:
3027
"""Convert RGB value (0-255) to digital HIGH(1) or LOW(0)"""
3128
return value >= threshold
3229

30+
3331
def on_set_led_rgb(_, data):
3432
led = data.get("led")
3533
r = data.get("r")
@@ -41,14 +39,19 @@ def on_set_led_rgb(_, data):
4139
g_digital = rgb_to_digital(g)
4240
b_digital = rgb_to_digital(b)
4341

44-
print(f"Setting LED {led} to color: RGB({r},{g},{b}) -> Digital({r_digital},{g_digital},{b_digital})")
42+
print(
43+
f"Setting LED {led} to color: RGB({r},{g},{b}) -> Digital({r_digital},{g_digital},{b_digital})"
44+
)
4545
Bridge.call("set_led_rgb", led, r_digital, g_digital, b_digital)
4646

47+
4748
ui.on_message("matrix_draw", on_matrix_draw)
4849
ui.on_message("set_led_rgb", on_set_led_rgb)
4950

51+
5052
def on_modulino_button_pressed(btn):
51-
ui.send_message('modulino_buttons_pressed', {"btn": btn})
53+
ui.send_message("modulino_buttons_pressed", {"btn": btn})
54+
5255

5356
Bridge.provide("modulino_button_pressed", on_modulino_button_pressed)
5457

0 commit comments

Comments
 (0)