Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Format Checks

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0

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

- name: Install dprint
run: |
task install

- name: Fmt check
run: |
task fmt:check
20 changes: 14 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
uses: actions/checkout@v5
with:
fetch-depth: 0

- name: Show tag info
run: echo "Building release for tag ${{ github.ref_name }}"

- name: Install Go
uses: actions/setup-go@v5
with:
Expand All @@ -26,20 +26,28 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '18'
node-version: "18"

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

- name: Scratch init
- name: Install dprint
run: |
task install

- name: Fmt check
run: |
task fmt:check

- name: Scratch init
run: |
task scratch:init

- name: Create build
- name: Create build
run: |
task app:build

- name: Create zip
- name: Create zip
run: task app:zip
env:
APP_VERSION: ${{ github.ref_name }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
scratch-editor
build/
build/
.bin/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

- Connect to the board using `adb` following https://docs.arduino.cc/software/app-lab/tutorials/cli/ and open the `adb shell`
- From inside the board, Install the latest `scratch-arduino-app` into the board running the command:

```
curl -sSL https://raw.githubusercontent.com/dido18/scratch-arduino-app/main/install.sh | bash
```

- Open the `ArduinoAppLab` and start the app
- Visit the `<IP_OR_BOARD_NAME>:7000` to open the Scratch App.

### Local development

- `task scratch:init`
- `task scratch:local:start`
- `ŧask board:upload`
- change the `const wsServerURL = `ws://<YOUR_IP>:7000`;` in the `index.js`
- change the `const wsServerURL =`ws://<YOUR_IP>:7000`;` in the `index.js`
- Open local scratch on http://localhost:8601/
49 changes: 32 additions & 17 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
version: "3"
vars:
SCRATCH_EDITOR_VERSION: v12.0.1
DPRINT_VERSION: 0.48.0

tasks:
install:
cmds:
- curl -fsSL https://dprint.dev/install.sh | sh -s {{ .DPRINT_VERSION }}
- mkdir -p .bin && cp $HOME/.dprint/bin/dprint .bin/dprint # workaround for local install

fmt:
desc: Run format
cmds:
- ${PWD}/.bin/dprint fmt

fmt:check:
desc: Check format
cmds:
- ${PWD}/.bin/dprint check

scratch:init:
cmds:
- rm -rf scratch-editor
Expand Down Expand Up @@ -33,8 +49,8 @@ tasks:
- cp scratch-editor/packages/scratch-gui/build/gui.js build/scratch-arduino-app/assets/gui.js
- mkdir -p build/scratch-arduino-app/assets/static
- cp -r scratch-editor/packages/scratch-gui/build/static/blocks-media build/scratch-arduino-app/assets/static/blocks-media
scratch:build:

scratch:build:
desc: "Build Scratch GUI files"
dir: scratch-editor/packages/scratch-gui
cmds:
Expand All @@ -45,27 +61,26 @@ tasks:
cmds:
- task app:zip
- |
ZIP_FILE=$(ls -t build/scratch-arduino-app-*.zip 2>/dev/null | head -n1)
if [ -z "$ZIP_FILE" ]; then
echo "No zip file found. Run 'task app:zip' first."
exit 1
fi
adb push "$ZIP_FILE" /tmp/
ZIP_BASENAME=$(basename "$ZIP_FILE")
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"
echo "App deployed to /home/arduino/ArduinoApps/scratch-arduino-app"
ZIP_FILE=$(ls -t build/scratch-arduino-app-*.zip 2>/dev/null | head -n1)
if [ -z "$ZIP_FILE" ]; then
echo "No zip file found. Run 'task app:zip' first."
exit 1
fi
adb push "$ZIP_FILE" /tmp/
ZIP_BASENAME=$(basename "$ZIP_FILE")
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"
echo "App deployed to /home/arduino/ArduinoApps/scratch-arduino-app"

app:zip:
desc: "Create a zip file with version (defaults to git commit hash)"
vars:
APP_VERSION:
sh: echo "${APP_VERSION:-$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')}"
cmds:
- |
if [ ! -d "build/scratch-arduino-app" ]; then
echo "Build folder does not exist. Run 'task app:build' first."
exit 1
fi
if [ ! -d "build/scratch-arduino-app" ]; then
echo "Build folder does not exist. Run 'task app:build' first."
exit 1
fi
- echo "Creating zip with version {{.APP_VERSION}}"
- cd build && zip -r scratch-arduino-app-{{.APP_VERSION}}.zip scratch-arduino-app && cd ..

4 changes: 2 additions & 2 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: scratch-arduino-app
description: Control the Uno-Q board using Scratch blocks
ports:
- 7000
- 7000
bricks:
- arduino:web_ui
- arduino:web_ui
icon: 🐱
24 changes: 24 additions & 0 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"typescript": {},
"json": {},
"markdown": {},
"yaml": {},
"ruff": {
"indentStyle": "space",
"lineLength": 100,
"indentWidth": 4
},
"excludes": [
"**/.venv/**",
"**/assets/**",
"**/scratch-editor/**",
"**/build/**"
],
"plugins": [
"https://plugins.dprint.dev/json-0.19.4.wasm",
"https://plugins.dprint.dev/markdown-0.17.8.wasm",
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm",
"https://plugins.dprint.dev/ruff-0.3.9.wasm",
"https://plugins.dprint.dev/typescript-0.95.12.wasm"
]
}
35 changes: 19 additions & 16 deletions python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,31 @@
import time

ui = WebUI()
ui.on_connect(
lambda sid: (
print(f"Client connected: {sid} "),
)
)
ui.on_connect(lambda sid: (print(f"Client connected: {sid} "),))


def on_matrix_draw(_, data):
print(f"Received frame to draw on matrix: {data}")
# from 5x5 to 8x13 matrix
frame_5x5 = data.get('frame')
row0 = "0"*13
row1 = "0"*4 + frame_5x5[0:5] + "0"*4
row2 = "0"*4 + frame_5x5[5:10] + "0"*4
row3 = "0"*4 + frame_5x5[10:15] + "0"*4
row4 = "0"*4 + frame_5x5[15:20] + "0"*4
row5 = "0"*4 + frame_5x5[20:25] + "0"*4
row6 = "0"*13
row7 = "0"*13
frame_5x5 = data.get("frame")
row0 = "0" * 13
row1 = "0" * 4 + frame_5x5[0:5] + "0" * 4
row2 = "0" * 4 + frame_5x5[5:10] + "0" * 4
row3 = "0" * 4 + frame_5x5[10:15] + "0" * 4
row4 = "0" * 4 + frame_5x5[15:20] + "0" * 4
row5 = "0" * 4 + frame_5x5[20:25] + "0" * 4
row6 = "0" * 13
row7 = "0" * 13
frame_8x13 = row0 + row1 + row2 + row3 + row4 + row5 + row6 + row7
print(f"Transformed frame to draw on 8x13 matrix: {frame_8x13}")
Bridge.call("matrix_draw", frame_8x13)


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


def on_set_led_rgb(_, data):
led = data.get("led")
r = data.get("r")
Expand All @@ -41,14 +39,19 @@ def on_set_led_rgb(_, data):
g_digital = rgb_to_digital(g)
b_digital = rgb_to_digital(b)

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


ui.on_message("matrix_draw", on_matrix_draw)
ui.on_message("set_led_rgb", on_set_led_rgb)


def on_modulino_button_pressed(btn):
ui.send_message('modulino_buttons_pressed', {"btn": btn})
ui.send_message("modulino_buttons_pressed", {"btn": btn})


Bridge.provide("modulino_button_pressed", on_modulino_button_pressed)

Expand Down
Loading