-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_release.sh
More file actions
396 lines (338 loc) · 11.4 KB
/
build_release.sh
File metadata and controls
396 lines (338 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
#!/bin/bash
#
# SledLink Release Build Script
# Compiles firmware and packages everything for a GitHub release
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Version handling with validation
if [ -n "$1" ]; then
VERSION="$1"
# Validate semantic version format (v1.2.3) or date format (YYYY.MM.DD)
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]] && \
[[ ! "$VERSION" =~ ^[0-9]{4}\.[0-9]{2}\.[0-9]{2}$ ]]; then
echo "ERROR: Invalid version format: $VERSION"
echo "Expected: v1.2.3, v1.2.3-beta, or YYYY.MM.DD"
exit 1
fi
else
VERSION="$(date +%Y.%m.%d)"
fi
RELEASE_DIR="$SCRIPT_DIR/release"
RELEASE_NAME="SledLink-$VERSION"
OUTPUT_DIR="$RELEASE_DIR/$RELEASE_NAME"
echo ""
echo "========================================"
echo " SledLink Release Builder"
echo " Version: $VERSION"
echo "========================================"
echo ""
# Check for arduino-cli
if ! command -v arduino-cli &> /dev/null; then
echo "ERROR: arduino-cli is not installed."
echo ""
echo "Install it with:"
echo " Mac: brew install arduino-cli"
echo " Linux: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | sh"
echo ""
exit 1
fi
# Ensure ESP32 core is installed
echo "Checking ESP32 board support..."
if ! arduino-cli core list 2>/dev/null | grep -q "esp32:esp32"; then
echo "Installing ESP32 board support..."
arduino-cli config init 2>/dev/null || true
arduino-cli config add board_manager.additional_urls https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
arduino-cli core update-index
arduino-cli core install esp32:esp32
fi
# Ensure LiquidCrystal library is installed
if ! arduino-cli lib list 2>/dev/null | grep -q "LiquidCrystal"; then
echo "Installing LiquidCrystal library..."
arduino-cli lib install "LiquidCrystal"
fi
# Clean and create release directory
echo ""
echo "Creating release directory..."
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR/firmware"
mkdir -p "$OUTPUT_DIR/tools"
mkdir -p "$OUTPUT_DIR/source"
# Copy upload tools for compiling from source
echo "Copying upload tools..."
cp "$SCRIPT_DIR/upload_firmware.sh" "$OUTPUT_DIR/tools/"
cp "$SCRIPT_DIR/upload_firmware.ps1" "$OUTPUT_DIR/tools/"
cp "$SCRIPT_DIR/Upload Firmware (Windows).bat" "$OUTPUT_DIR/"
chmod +x "$OUTPUT_DIR/tools/upload_firmware.sh"
# Copy source code
echo "Copying source code..."
cp -r "$SCRIPT_DIR/arduino" "$OUTPUT_DIR/source/"
# Copy documentation
echo "Copying documentation..."
cp "$SCRIPT_DIR/UPLOAD_GUIDE.md" "$OUTPUT_DIR/"
cp "$SCRIPT_DIR/docs/README.md" "$OUTPUT_DIR/docs_README.md" 2>/dev/null || true
# Create release README
cat > "$OUTPUT_DIR/README.txt" << HEREDOC
================================================================================
SledLink Firmware Release $VERSION
Tractor Pull Distance Measurement System
================================================================================
RELEASE INFORMATION
-------------------
Version: $VERSION
Firmware: v1.0.0
Build Date: $(date +%Y-%m-%d)
Download: https://github.com/thompcd/SledLink/releases/tag/$VERSION
This release contains source code and tools to compile and upload firmware to the SledLink system.
CONTENTS
--------
source/ - Arduino source code
arduino/SledController/ - Sled controller source
arduino/JudgeController/ - Judge controller source
tools/ - Upload utilities
upload_firmware.sh - Mac/Linux upload script
upload_firmware.ps1 - Windows PowerShell upload script
Upload Firmware (Windows).bat - Double-click to upload firmware
QUICK START - UPLOAD FIRMWARE
-----------------------------
The firmware is compiled fresh from source code during upload.
Windows:
1. Connect the controller via USB
2. Double-click "Upload Firmware (Windows).bat"
3. Follow the prompts
Mac/Linux:
1. Connect the controller via USB
2. Open Terminal in this folder
3. Run: ./tools/upload_firmware.sh
4. Follow the prompts
WHICH CONTROLLER IS WHICH?
--------------------------
SLED Controller:
- Goes ON THE SLED
- Has the measuring wheel encoder attached
- SENDS distance to the judge wirelessly
JUDGE Controller:
- Stays at the JUDGE'S TABLE
- RECEIVES and displays distance
- No encoder attached
TROUBLESHOOTING
---------------
See UPLOAD_GUIDE.md for detailed troubleshooting steps.
Common issues:
- "No device found" - Try a different USB cable (some are charge-only)
- "Upload failed" - Hold BOOT button on ESP32 during upload
- Driver issues - Install CP210x or CH340 USB driver for your OS
SUPPORT
-------
For issues, visit: https://github.com/tulsasoftware/SledLink/issues
================================================================================
HEREDOC
# Create the flash script for pre-compiled binaries
cat > "$OUTPUT_DIR/flash_firmware.sh" << 'FLASHSCRIPT'
#!/bin/bash
#
# SledLink Firmware Flash Script
# Flashes pre-compiled firmware using esptool
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FIRMWARE_DIR="$SCRIPT_DIR/firmware"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
print_header() {
clear
echo ""
echo -e "${CYAN}╔══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║${NC}${BOLD} SledLink Firmware Flash Tool ${NC}${CYAN}║${NC}"
echo -e "${CYAN}║${NC} Flash Pre-Compiled Firmware ${CYAN}║${NC}"
echo -e "${CYAN}╚══════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
check_esptool() {
if command -v esptool.py &> /dev/null; then
ESPTOOL="esptool.py"
return 0
elif command -v esptool &> /dev/null; then
ESPTOOL="esptool"
return 0
elif python3 -m esptool version &> /dev/null 2>&1; then
ESPTOOL="python3 -m esptool"
return 0
elif python -m esptool version &> /dev/null 2>&1; then
ESPTOOL="python -m esptool"
return 0
fi
return 1
}
install_esptool() {
echo -e "${YELLOW}esptool is not installed.${NC}"
echo ""
echo "esptool is required to flash pre-compiled firmware."
echo ""
if command -v pip3 &> /dev/null; then
echo -e "${BOLD}Install esptool now?${NC} (yes/no): "
read -r response
if [[ "$response" =~ ^[Yy] ]]; then
echo ""
echo "Installing esptool..."
pip3 install esptool
return 0
fi
elif command -v pip &> /dev/null; then
echo -e "${BOLD}Install esptool now?${NC} (yes/no): "
read -r response
if [[ "$response" =~ ^[Yy] ]]; then
echo ""
echo "Installing esptool..."
pip install esptool
return 0
fi
else
echo "Python pip is required to install esptool."
echo ""
echo "Install Python from: https://www.python.org/downloads/"
echo "Then run: pip install esptool"
fi
return 1
}
get_serial_ports() {
case "$(uname -s)" in
Darwin*)
for port in /dev/cu.usbserial* /dev/cu.wchusbserial* /dev/cu.SLAB* /dev/cu.usbmodem*; do
[ -e "$port" ] && echo "$port"
done
;;
*)
for port in /dev/ttyUSB* /dev/ttyACM*; do
[ -e "$port" ] && echo "$port"
done
;;
esac
}
print_header
echo "This tool flashes pre-compiled firmware to your SledLink controller."
echo "No compilation needed - just select your controller type and port."
echo ""
echo -e "${YELLOW}Press ENTER to continue...${NC}"
read -r
# Check for esptool
if ! check_esptool; then
if ! install_esptool; then
echo -e "${RED}Cannot continue without esptool.${NC}"
exit 1
fi
check_esptool
fi
echo -e "${GREEN}✓ esptool found${NC}"
echo ""
# Select controller
echo -e "${BOLD}Which controller do you want to flash?${NC}"
echo ""
echo " 1) SLED Controller - goes on the sled, has encoder"
echo " 2) JUDGE Controller - judge's table display"
echo ""
while true; do
echo -n "Enter 1 or 2: "
read -r choice
case "$choice" in
1) CONTROLLER="SledController"; break ;;
2) CONTROLLER="JudgeController"; break ;;
*) echo "Please enter 1 or 2" ;;
esac
done
echo ""
echo -e "${GREEN}✓ Selected: $CONTROLLER${NC}"
echo ""
# Check firmware exists
if [ ! -f "$FIRMWARE_DIR/$CONTROLLER.bin" ]; then
echo -e "${RED}ERROR: Firmware file not found: $FIRMWARE_DIR/$CONTROLLER.bin${NC}"
exit 1
fi
# Select port
echo -e "${BOLD}Connect the controller via USB, then press ENTER${NC}"
read -r
echo "Scanning for devices..."
ports=($(get_serial_ports))
if [ ${#ports[@]} -eq 0 ]; then
echo -e "${RED}No serial devices found!${NC}"
echo ""
echo "Try:"
echo " - Different USB cable (some are charge-only)"
echo " - Different USB port"
echo " - Install USB driver (CP210x or CH340)"
exit 1
fi
if [ ${#ports[@]} -eq 1 ]; then
PORT="${ports[0]}"
echo -e "${GREEN}Found: $PORT${NC}"
else
echo "Multiple devices found:"
for i in "${!ports[@]}"; do
echo " $((i+1))) ${ports[$i]}"
done
while true; do
echo -n "Select device (1-${#ports[@]}): "
read -r choice
if [ "$choice" -ge 1 ] 2>/dev/null && [ "$choice" -le ${#ports[@]} ]; then
PORT="${ports[$((choice-1))]}"
break
fi
done
fi
echo ""
echo -e "${BOLD}Ready to flash:${NC}"
echo " Controller: $CONTROLLER"
echo " Port: $PORT"
echo " Firmware: $FIRMWARE_DIR/$CONTROLLER.bin"
echo ""
echo -e "${YELLOW}Do NOT disconnect during flash!${NC}"
echo ""
echo -n "Start flash? (yes/no): "
read -r confirm
if [[ ! "$confirm" =~ ^[Yy] ]]; then
echo "Cancelled."
exit 0
fi
echo ""
echo "Flashing firmware..."
echo ""
# Flash the firmware
$ESPTOOL --chip esp32 --port "$PORT" --baud 460800 \
--before default_reset --after hard_reset \
write_flash -z \
--flash_mode dio --flash_freq 40m --flash_size detect \
0x1000 "$FIRMWARE_DIR/$CONTROLLER.bootloader.bin" \
0x8000 "$FIRMWARE_DIR/$CONTROLLER.partitions.bin" \
0x10000 "$FIRMWARE_DIR/$CONTROLLER.bin"
echo ""
echo -e "${GREEN}════════════════════════════════════════════════════${NC}"
echo -e "${GREEN} FIRMWARE FLASH COMPLETE!${NC}"
echo -e "${GREEN}════════════════════════════════════════════════════${NC}"
echo ""
echo "The controller will restart automatically."
echo ""
FLASHSCRIPT
chmod +x "$OUTPUT_DIR/flash_firmware.sh"
# Create ZIP file
echo ""
echo "Creating release archive..."
cd "$RELEASE_DIR"
zip -r "$RELEASE_NAME.zip" "$RELEASE_NAME"
echo ""
echo "========================================"
echo " Release Build Complete!"
echo "========================================"
echo ""
echo "Release directory: $OUTPUT_DIR"
echo "Release archive: $RELEASE_DIR/$RELEASE_NAME.zip"
echo ""
echo "Contents:"
ls -la "$OUTPUT_DIR"
echo ""
echo "Firmware files:"
ls -la "$OUTPUT_DIR/firmware/"
echo ""