Skip to content

Commit 3c0ca5d

Browse files
authored
Merge pull request #70 from openppg/v7-2
V7.2
2 parents c8dfb76 + d1ff89a commit 3c0ca5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5860
-1501
lines changed

.claude/settings.local.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(pio)",
5+
"Bash(pio run)",
6+
"Bash(cpplint:*)"
7+
],
8+
"deny": []
9+
}
10+
}

.devcontainer/devcontainer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "Ubuntu Development Environment",
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
4+
5+
"features": {
6+
"ghcr.io/devcontainers/features/python:1": {
7+
"version": "3.12"
8+
},
9+
"ghcr.io/devcontainers/features/git:1": {},
10+
"ghcr.io/devcontainers/features/node:1": {
11+
"version": "20"
12+
}
13+
},
14+
15+
"customizations": {
16+
"vscode": {
17+
"extensions": [
18+
"platformio.platformio-ide",
19+
"ms-vscode.cpptools-extension-pack",
20+
"ms-python.python"
21+
],
22+
"settings": {
23+
"C_Cpp.default.intelliSenseMode": "gcc-x64",
24+
"C_Cpp.default.compilerPath": "/usr/bin/gcc",
25+
"editor.tabSize": 2,
26+
"editor.insertSpaces": true,
27+
"files.associations": {
28+
"*.ino": "cpp",
29+
"*.h": "c",
30+
"*.hpp": "cpp"
31+
}
32+
}
33+
}
34+
},
35+
36+
"postCreateCommand": "bash .devcontainer/setup.sh",
37+
38+
"remoteUser": "vscode",
39+
40+
"mounts": [
41+
"source=/dev,target=/dev,type=bind,consistency=cached",
42+
"source=/Users/zach/.claude-code-router,target=/home/vscode/.claude-code-router,type=bind"
43+
],
44+
45+
"runArgs": [
46+
"--privileged"
47+
]
48+
}

.devcontainer/setup.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
# Setup script for Ubuntu development environment
4+
5+
set -e
6+
7+
echo "Setting up development environment..."
8+
9+
# Update package lists
10+
sudo apt-get update
11+
12+
# Install essential development tools
13+
sudo apt-get install -y \
14+
build-essential \
15+
git \
16+
curl \
17+
wget \
18+
unzip \
19+
software-properties-common \
20+
udev \
21+
python3-pip \
22+
python3-venv \
23+
pkg-config \
24+
libusb-1.0-0-dev \
25+
libudev-dev
26+
27+
# Install PlatformIO
28+
echo "Installing PlatformIO..."
29+
python3 -m pip install --upgrade pip
30+
python3 -m pip install --upgrade platformio
31+
32+
# Add PlatformIO to PATH
33+
echo 'export PATH=$PATH:~/.local/bin' >> ~/.bashrc
34+
35+
# Install PlatformIO udev rules for device access
36+
echo "Setting up udev rules for device access..."
37+
curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/platformio/assets/system/99-platformio-udev.rules | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
38+
sudo service udev restart
39+
sudo usermod -a -G dialout $USER
40+
sudo usermod -a -G plugdev $USER
41+
42+
# Create a symlink for common Arduino libraries location
43+
mkdir -p ~/Arduino/libraries
44+
45+
# Install additional Python packages that might be useful
46+
python3 -m pip install --upgrade \
47+
esptool \
48+
adafruit-ampy \
49+
pyserial
50+
51+
# Install Gemini CLI
52+
echo "Installing Gemini CLI..."
53+
curl -sS https://storage.googleapis.com/gemini-cli/install.sh | bash
54+
55+
# Install Claude Code CLI
56+
echo "Installing Claude Code CLI..."
57+
npm install -g @anthropic-ai/claude-code
58+
npm install -g @musistudio/claude-code-router
59+
60+
# Set up Git configuration (if not already configured)
61+
if [ -z "$(git config --global user.name)" ]; then
62+
echo "Git user name not configured. You may want to run:"
63+
echo "git config --global user.name 'Your Name'"
64+
echo "git config --global user.email '[email protected]'"
65+
fi
66+
67+
echo "✅ Development environment setup complete!"
68+
echo ""
69+
echo "🚀 You can now:"
70+
echo " - Use 'pio' commands for PlatformIO operations"
71+
echo " - Use 'node' and 'npm' for JavaScript/TypeScript development"
72+
echo " - Develop Arduino/ESP32 projects with IntelliSense"
73+
echo ""
74+
echo "📋 Next steps:"
75+
echo " 1. Run 'pio run' to build the project"
76+
echo " 2. Run 'pio device list' to see connected devices"
77+
echo " 3. Use 'pio run --target upload' to flash firmware"
78+
echo ""
79+
echo "🔧 Hardware debugging:"
80+
echo " - USB devices are mounted with --privileged access"
81+
echo " - Serial ports should be accessible in /dev/"

.gemini/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"telemetry": {
3+
"enabled": false
4+
},
5+
"usageStatisticsEnabled": false
6+
}

.github/workflows/config.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@ jobs:
1818
python-version: 3.x
1919
- run: pip install cpplint
2020
- run: cpplint --linelength 140 --filter=-legal/copyright,-runtime/int,-build/include_subdir,-readability/casting,-readability/todo,-build/include_order,-build/include_what_you_use --recursive ./inc/ ./lib/ ./src/
21+
22+
pio-test:
23+
name: PlatformIO Tests
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
with:
28+
token: ${{ secrets.GH_TOKEN }}
29+
persist-credentials: true
30+
show-progress: false
31+
- name: Setup Git Credentials
32+
run: |
33+
git config --global credential.helper store
34+
echo "https://oauth2:${{ secrets.GH_TOKEN }}@github.com" > ~/.git-credentials
35+
- name: Setup Python
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: 3.x
39+
- name: Install Platform IO
40+
run: |
41+
python -m pip install --upgrade pip
42+
pip install -U platformio
43+
- name: Run Unit Tests
44+
run: platformio test -e native-test
45+
2146
pio-build:
2247
name: PlatformIO Build
2348
runs-on: ubuntu-latest

CLAUDE.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Build and Development Commands
6+
7+
This is an Arduino/ESP32 project using PlatformIO for build management.
8+
9+
**Build Commands:**
10+
- `pio run` - Build the project (compiles firmware)
11+
- `pio run --target upload` - Flash firmware to connected device
12+
- `pio run --target clean` - Clean build artifacts
13+
- `pio device list` - List connected devices/serial ports
14+
- `pio device monitor` - Serial monitor for debugging
15+
16+
**Environment:**
17+
- Default target: `OpenPPG-CESP32S3-CAN-SP140` (ESP32-S3 based)
18+
- Build type: debug (configurable in platformio.ini)
19+
- Monitor speed: 115200 baud
20+
21+
**Binary Generation:**
22+
For creating update files, use esptool to merge binaries:
23+
```bash
24+
esptool.py --chip esp32s3 merge_bin \
25+
-o .pio/build/OpenPPG-CESP32S3-CAN-SP140/merged-firmware.bin \
26+
--flash_mode dio --flash_freq 80m --flash_size 8MB \
27+
0x0 .pio/build/OpenPPG-CESP32S3-CAN-SP140/bootloader.bin \
28+
0x8000 .pio/build/OpenPPG-CESP32S3-CAN-SP140/partitions.bin \
29+
0xe000 ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin \
30+
0x10000 .pio/build/OpenPPG-CESP32S3-CAN-SP140/firmware.bin
31+
```
32+
33+
**Testing:**
34+
- Basic test files exist in `/test/` directory
35+
- No automated test framework configured - testing is primarily hardware-in-the-loop
36+
37+
## Code Architecture
38+
39+
**Project Structure:**
40+
- `/src/sp140/` - Main application source code
41+
- `/inc/sp140/` - Header files and configuration
42+
- `/src/assets/` - Fonts, images, and UI resources
43+
- `/lib/` - Custom libraries
44+
- `platformio.ini` - Build configuration
45+
46+
**Core Components:**
47+
48+
**Main Controller (`sp140.ino`):**
49+
The entry point that coordinates all subsystems. Handles:
50+
- Hardware initialization and SPI bus management
51+
- Main control loop and state management
52+
- Button input processing with debouncing
53+
- Safety interlocks and watchdog management
54+
55+
**Key Subsystems:**
56+
- **ESC Control** (`esc.h/cpp`) - Motor speed control and CAN communication
57+
- **BMS Interface** (`bms.h/cpp`) - Battery management system communication
58+
- **Throttle Processing** (`throttle.h/cpp`) - Input filtering and response curves
59+
- **Display/LVGL** (`lvgl/`) - LCD graphics and user interface
60+
- **Altimeter** (`altimeter.h/cpp`) - Barometric altitude sensing
61+
- **Device State** (`device_state.h/cpp`) - System state machine management
62+
- **Mode Control** (`mode.h/cpp`) - Flight modes (manual, cruise, etc.)
63+
64+
**Hardware Platform:**
65+
- ESP32-S3 microcontroller (M5Stack STAMPS3 board)
66+
- CAN bus communication for ESC and BMS
67+
- Shared SPI bus for display and peripherals
68+
- NeoPixel RGB LEDs for status indication
69+
- Analog throttle input with ResponsiveAnalogRead filtering
70+
71+
**Configuration:**
72+
- Hardware pin definitions in `esp32s3-config.h`
73+
- Device settings and globals in `globals.h`
74+
- Build flags and library versions in `platformio.ini`
75+
76+
**Data Structures:**
77+
- Telemetry data structures defined in `structs.h`
78+
- Temperature monitoring with multiple sensor states
79+
- BMS pack data with cell-level monitoring
80+
- ESC telemetry with real-time performance data
81+
82+
This codebase implements a safety-critical paramotor throttle controller with real-time requirements and hardware integration.

CPPLINT.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
linelength=140
2+
filter=-legal/copyright,-runtime/int,-build/include_subdir,-readability/casting,-readability/todo,-build/include_order,-build/include_what_you_use

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Arduino based logic for OpenPPG SP140 Throttle Controller
66

7-
#### This master branch is only for testing the latest firmware for the and SP140 controllers running the ESP32-S3 processor.
7+
#### This master branch is only for testing the latest firmware for the SP140 controllers running the ESP32-S3 processor.
88

99
X4 code has been migrated to a separate repo - https://github.com/openppg/x4-controller
1010

SIMPLE_MONITOR_README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Sensor Monitoring System
2+
3+
## Overview
4+
Real-time health monitoring for ESP32 electric ultralight sensors. Monitors ESC, BMS, altimeter, and system health with threshold-based alerting.
5+
6+
## Features
7+
- **Comprehensive**: 50+ sensors monitored across all flight systems
8+
- **Smart Alerting**: Hysteresis protection prevents false alerts
9+
- **Multiple Outputs**: Serial, display, and extensible logging
10+
- **Efficient**: Minimal overhead, change-only notifications
11+
12+
## What's Monitored
13+
14+
### ESC
15+
- Temperatures (MOS, MCU, CAP, Motor)
16+
- Error states (over-current, over-temp, voltage issues)
17+
- Hardware faults and diagnostics
18+
19+
### BMS
20+
- Cell voltages and temperature sensors
21+
- State of charge and charge/discharge status
22+
- Voltage differential monitoring
23+
24+
### System
25+
- CPU temperature and altimeter readings
26+
- System health and diagnostics
27+
28+
## How It Works
29+
30+
System automatically monitors all sensors and alerts on threshold violations. Hysteresis prevents false alerts from sensor noise.
31+
32+
### Alert Levels
33+
- **OK**: Normal operation
34+
- **WARN**: Advisory thresholds exceeded
35+
- **CRIT**: Critical thresholds requiring attention
36+
37+
### Example Output
38+
```
39+
[15234] [WARN_HIGH] ESC_MOS_Temp = 92.50
40+
[15467] [CRIT_HIGH] Motor_Temp = 112.30
41+
[15890] [OK] ESC_MOS_Temp = 88.20
42+
```
43+
44+
### Integration
45+
- Runs every 40ms in FreeRTOS task
46+
- Displays alerts on screen with haptic feedback
47+
- Serial logging for diagnostics
48+
- Thread-safe with minimal CPU overhead
49+
50+
The system provides comprehensive flight safety monitoring while maintaining performance for electric ultralight operation.

extra_script.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1+
import subprocess
2+
13
Import("env")
24
folder = env.GetProjectOption("src_folder")
35

46
# Generic
57
env.Replace(
68
PROJECT_SRC_DIR="$PROJECT_DIR/src/" + folder
79
)
10+
11+
def get_git_revision_short_hash():
12+
try:
13+
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode('utf-8').strip()
14+
except Exception:
15+
return "unknown"
16+
17+
git_revision = get_git_revision_short_hash()
18+
19+
env.Append(CPPDEFINES=[
20+
("GIT_REV", f'\\"{git_revision}\\"')
21+
])
22+
23+
print(f"Current git revision: {git_revision}")

0 commit comments

Comments
 (0)