|
| 1 | +#!/bin/bash |
| 2 | +######################################################################################### |
| 3 | +# |
| 4 | +# Build script for the ProtoCentral Pulse Express library — Arduino Uno R4 |
| 5 | +# |
| 6 | +# Compiles every sketch under examples/ against the Uno R4 Minima target by |
| 7 | +# default, or the Uno R4 WiFi target with --wifi. Installs the Renesas core |
| 8 | +# on first run if it is not already present. |
| 9 | +# |
| 10 | +# Copyright (c) 2025 ProtoCentral Electronics |
| 11 | +# |
| 12 | +# This software is licensed under the MIT License (http://opensource.org/licenses/MIT). |
| 13 | +# |
| 14 | +######################################################################################### |
| 15 | + |
| 16 | +set -euo pipefail |
| 17 | + |
| 18 | +LIBRARY_PATH="$(cd "$(dirname "$0")" && pwd)" |
| 19 | +EXAMPLES_DIR="$LIBRARY_PATH/examples" |
| 20 | +BOARD_FQBN="arduino:renesas_uno:minima" |
| 21 | +CORE_ID="arduino:renesas_uno" |
| 22 | + |
| 23 | +RED='\033[0;31m' |
| 24 | +GREEN='\033[0;32m' |
| 25 | +YELLOW='\033[1;33m' |
| 26 | +BLUE='\033[0;34m' |
| 27 | +NC='\033[0m' |
| 28 | + |
| 29 | +print_info() { echo -e "${BLUE}[INFO]${NC} $1"; } |
| 30 | +print_success() { echo -e "${GREEN}[OK]${NC} $1"; } |
| 31 | +print_warning() { echo -e "${YELLOW}[WARN]${NC} $1"; } |
| 32 | +print_error() { echo -e "${RED}[ERROR]${NC} $1"; } |
| 33 | + |
| 34 | +show_help() { |
| 35 | + cat <<EOF |
| 36 | +Pulse Express build script — Arduino Uno R4 |
| 37 | +
|
| 38 | +Usage: $0 [OPTIONS] |
| 39 | +
|
| 40 | +Options: |
| 41 | + --wifi Build for Uno R4 WiFi (arduino:renesas_uno:unor4wifi) |
| 42 | + instead of the default Minima target. |
| 43 | + --fqbn FQBN Override the board FQBN entirely. |
| 44 | + -h, --help Show this help. |
| 45 | +
|
| 46 | +The script compiles every directory found in examples/ that contains a .ino |
| 47 | +file with a matching name. Exit code is non-zero if any sketch fails to build. |
| 48 | +EOF |
| 49 | +} |
| 50 | + |
| 51 | +while [[ $# -gt 0 ]]; do |
| 52 | + case "$1" in |
| 53 | + --wifi) |
| 54 | + BOARD_FQBN="arduino:renesas_uno:unor4wifi" |
| 55 | + shift |
| 56 | + ;; |
| 57 | + --fqbn) |
| 58 | + BOARD_FQBN="$2" |
| 59 | + shift 2 |
| 60 | + ;; |
| 61 | + -h|--help) |
| 62 | + show_help |
| 63 | + exit 0 |
| 64 | + ;; |
| 65 | + *) |
| 66 | + print_error "Unknown option: $1" |
| 67 | + show_help |
| 68 | + exit 1 |
| 69 | + ;; |
| 70 | + esac |
| 71 | +done |
| 72 | + |
| 73 | +if ! command -v arduino-cli &> /dev/null; then |
| 74 | + print_error "arduino-cli not found" |
| 75 | + echo "Install from: https://arduino.github.io/arduino-cli/" |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +if ! arduino-cli core list 2>/dev/null | awk 'NR>1 {print $1}' | grep -qx "$CORE_ID"; then |
| 80 | + print_info "Installing $CORE_ID core..." |
| 81 | + arduino-cli core update-index |
| 82 | + arduino-cli core install "$CORE_ID" |
| 83 | +fi |
| 84 | + |
| 85 | +if [[ ! -d "$EXAMPLES_DIR" ]]; then |
| 86 | + print_error "examples/ directory not found at $EXAMPLES_DIR" |
| 87 | + exit 1 |
| 88 | +fi |
| 89 | + |
| 90 | +print_info "Target FQBN: $BOARD_FQBN" |
| 91 | +print_info "Library: $LIBRARY_PATH" |
| 92 | +echo |
| 93 | + |
| 94 | +declare -a SKETCHES=() |
| 95 | +while IFS= read -r dir; do |
| 96 | + name=$(basename "$dir") |
| 97 | + if [[ -f "$dir/$name.ino" ]]; then |
| 98 | + SKETCHES+=("$dir") |
| 99 | + else |
| 100 | + print_warning "Skipping $name (no $name.ino inside)" |
| 101 | + fi |
| 102 | +done < <(find "$EXAMPLES_DIR" -mindepth 1 -maxdepth 1 -type d | sort) |
| 103 | + |
| 104 | +if [[ ${#SKETCHES[@]} -eq 0 ]]; then |
| 105 | + print_error "No example sketches found under $EXAMPLES_DIR" |
| 106 | + exit 1 |
| 107 | +fi |
| 108 | + |
| 109 | +PASS=0 |
| 110 | +FAIL=0 |
| 111 | +FAILED_NAMES=() |
| 112 | + |
| 113 | +for sketch in "${SKETCHES[@]}"; do |
| 114 | + name=$(basename "$sketch") |
| 115 | + print_info "Compiling $name ..." |
| 116 | + if arduino-cli compile \ |
| 117 | + --fqbn "$BOARD_FQBN" \ |
| 118 | + --library "$LIBRARY_PATH" \ |
| 119 | + --warnings default \ |
| 120 | + "$sketch" > /tmp/pulse-express-build.log 2>&1; then |
| 121 | + SIZE_LINE=$(grep -E "^Sketch uses" /tmp/pulse-express-build.log || true) |
| 122 | + print_success "$name ${SIZE_LINE#Sketch uses }" |
| 123 | + PASS=$((PASS + 1)) |
| 124 | + else |
| 125 | + print_error "$name failed:" |
| 126 | + sed 's/^/ /' /tmp/pulse-express-build.log |
| 127 | + FAIL=$((FAIL + 1)) |
| 128 | + FAILED_NAMES+=("$name") |
| 129 | + fi |
| 130 | +done |
| 131 | + |
| 132 | +echo |
| 133 | +echo "================================================================" |
| 134 | +print_info "$PASS passed, $FAIL failed (out of ${#SKETCHES[@]} sketches)" |
| 135 | +if [[ $FAIL -gt 0 ]]; then |
| 136 | + for n in "${FAILED_NAMES[@]}"; do |
| 137 | + echo " - $n" |
| 138 | + done |
| 139 | + exit 1 |
| 140 | +fi |
| 141 | +echo "================================================================" |
0 commit comments