Skip to content

Commit d8a46e7

Browse files
authored
Add watchers for sketch and python (#40)
1 parent a128f55 commit d8a46e7

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
scratch-editor
22
build/
33
.bin/
4+
.cache/

Taskfile.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,87 @@ tasks:
8686
fi
8787
- echo "Creating zip with version {{.APP_VERSION}}"
8888
- cd build && zip -r scratch-arduino-app-{{.APP_VERSION}}.zip scratch-arduino-app && cd ..
89+
90+
python:watch:
91+
desc: "Watch Python folder for changes and auto-upload/restart"
92+
cmds:
93+
- echo "Press Ctrl+C to stop watching"
94+
- |
95+
while true; do
96+
echo "Waiting for changes in python/ folder..."
97+
inotifywait -r -e modify,create,delete,move python/ 2>/dev/null || {
98+
echo "inotifywait failed, retrying..."
99+
sleep 2
100+
continue
101+
}
102+
103+
sleep 1 #W aiting 1 second for file writes to complete..."
104+
105+
task python:upload-and-restart || {
106+
echo "Upload/restart failed, continuing to watch..."
107+
continue
108+
}
109+
110+
echo "[ok] Upload and restart completed!"
111+
done
112+
113+
python:upload-and-restart:
114+
desc: "Upload Python files and restart container"
115+
cmds:
116+
- |
117+
adb push ./python/ /home/arduino/ArduinoApps/scratch-arduino-app/
118+
echo "Python files uploaded successfully"
119+
120+
CONTAINER_ID=$(adb shell "docker ps -q --filter 'ancestor=ghcr.io/arduino/app-bricks/python-apps-base:0.5.0'")
121+
if [ -n "$CONTAINER_ID" ]; then
122+
adb shell "docker restart $CONTAINER_ID"
123+
echo "[ok] Container restarted successfully"
124+
else
125+
echo "[warning] No running container found with image ghcr.io/arduino/app-bricks/python-apps-base"
126+
fi
127+
128+
sketch:watch:
129+
desc: "Watch sketch folder for changes and auto-compile/upload"
130+
cmds:
131+
- |
132+
echo "Press Ctrl+C to stop watching"
133+
while true; do
134+
echo "Waiting for changes in sketch folder..."
135+
inotifywait -r -e modify,create,delete sketch/ --include '\.(ino|cpp|h|c)$' 2>/dev/null || {
136+
echo "inotifywait failed, retrying..."
137+
sleep 2
138+
continue
139+
}
140+
141+
sleep 1 # Waiting 1 second for file writes to complete
142+
143+
task sketch:compile-and-upload|| {
144+
echo "Compile/upload failed, continuing to watch..."
145+
continue
146+
}
147+
done
148+
149+
sketch:compile-and-upload:
150+
desc: "Compile and upload Arduino sketch"
151+
cmds:
152+
- arduino-cli compile --build-path .cache -b arduino:zephyr:unoq sketch/
153+
- arduino-cli upload -p /dev/ttyACM0 -b arduino:zephyr:unoq:flash_mode=ram --input-dir .cache sketch/
154+
155+
sketch:monitor:
156+
desc: "Open serial monitor for Arduino debugging"
157+
cmds:
158+
- echo "Opening serial monitor (Press Ctrl+C to exit)..."
159+
- arduino-cli monitor -p /dev/ttyACM0
160+
161+
python:monitor:
162+
desc: "Watch sketch folder for changes and auto-compile/upload"
163+
cmds:
164+
- |
165+
while true; do
166+
CONTAINER_ID=$(adb shell "docker ps -q --filter 'ancestor=ghcr.io/arduino/app-bricks/python-apps-base:0.5.0'")
167+
if [ -n "$CONTAINER_ID" ]; then
168+
adb shell "docker logs -f $CONTAINER_ID"
169+
else
170+
echo "[warning] No running container found with image ghcr.io/arduino/app-bricks/python-apps-base"
171+
fi
172+
done

sketch/sketch.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void matrix_draw(String frame){
5454
}
5555
for (int i = 0; i < 104; i++) {
5656
if (frame.charAt(i) == '1') {
57-
shades[i] = 7;
57+
shades[i] = 7;
5858
} else{
5959
shades[i] = 0;
6060
}

0 commit comments

Comments
 (0)