diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..61d6355 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,28 @@ +# Repository Guidelines + +## Project Structure & Module Organization +`firmware/master` contains the access-point, web server, calibration, and ESP-NOW receiver firmware. `firmware/slave` contains the sensor/transmitter firmware for remote nodes. Source files live under each `src/` directory, and the Master web UI is served from `firmware/master/data/index.html`. Hardware documentation lives in `hardware/schematics` and `hardware/cad`. Top-level docs such as `README.md` and `IMPLEMENTATION_STATUS.md` describe project scope and phase status. + +## Build, Test, and Development Commands +Use PlatformIO from each firmware directory: + +```bash +cd firmware/master && pio run +cd firmware/master && pio run -t upload +cd firmware/master && pio device monitor -b 115200 +cd firmware/slave && pio run -e slave2 +``` + +`pio run` builds the current environment, `-t upload` flashes hardware, and `pio device monitor` opens the serial console. Use named slave environments such as `slave2` to build alternate `NODE_ID` values for multi-node setups. + +## Coding Style & Naming Conventions +The codebase is C++ for Arduino/ESP32 with 4-space indentation and opening braces on the same line. Keep header and implementation pairs aligned (`imu_driver.h` / `imu_driver.cpp`). Use `PascalCase` for classes (`CalibrationManager`), `camelCase` for functions and variables (`readBatteryPercent`), and `UPPER_SNAKE_CASE` for macros and config constants. Preserve the existing comment style: short section banners and targeted inline comments, not redundant narration. + +## Testing Guidelines +There is no automated unit-test suite yet. Treat a clean `pio run` for both Master and Slave as the baseline verification step. For behavior changes, validate on hardware through serial logs at 115200 baud and confirm the Master API/UI flow at `http://192.168.4.1`. Document any manual test coverage in the PR when changing IMU logic, ESP-NOW messaging, calibration, or battery reporting. + +## Commit & Pull Request Guidelines +Recent history uses concise, imperative commit subjects, for example: `Implement Phase 1-4: MVP with differential measurement and median filtering`. Follow that pattern and keep subjects focused on one change set. Pull requests should include a short summary, affected area (`master`, `slave`, `hardware`, or docs), manual validation steps, and screenshots or serial output when UI or device behavior changes. Link the relevant spec, issue, or phase task when applicable. + +## Configuration & Hardware Notes +Do not commit device-specific secrets or ad hoc MAC addresses without explanation. If slave pairing changes, update `firmware/slave/src/config.h` deliberately and mention it in review notes so others can reflash hardware correctly. diff --git a/firmware/diag_s3/platformio.ini b/firmware/diag_s3/platformio.ini new file mode 100644 index 0000000..083686a --- /dev/null +++ b/firmware/diag_s3/platformio.ini @@ -0,0 +1,10 @@ +[env:esp32-s3] +platform = espressif32 +board = esp32-s3-devkitc-1 +framework = arduino +monitor_speed = 115200 +upload_speed = 921600 +build_flags = + -D ARDUINO_USB_CDC_ON_BOOT=0 +lib_deps = + adafruit/Adafruit MPU6050@^2.2.4 diff --git a/firmware/diag_s3/src/main.cpp b/firmware/diag_s3/src/main.cpp new file mode 100644 index 0000000..48d3e34 --- /dev/null +++ b/firmware/diag_s3/src/main.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include + +static constexpr uint8_t SDA_PIN = 4; +static constexpr uint8_t SCL_PIN = 5; +Adafruit_MPU6050 mpu; + +void scanI2C() { + Serial.println("[I2C] scan start"); + uint8_t found = 0; + + for (uint8_t addr = 1; addr < 127; addr++) { + Wire.beginTransmission(addr); + uint8_t err = Wire.endTransmission(); + if (err == 0) { + Serial.printf("[I2C] found device at 0x%02X\n", addr); + found++; + } + } + + if (!found) { + Serial.println("[I2C] no devices found"); + } + Serial.println("[I2C] scan done"); +} + +void setup() { + Serial.begin(115200); + delay(500); + Serial.println(); + Serial.println("ESP32-S3 I2C diagnostic"); + Serial.printf("Pins: SDA=%u SCL=%u\n", SDA_PIN, SCL_PIN); + Wire.begin(SDA_PIN, SCL_PIN, 100000); + delay(100); + scanI2C(); + + if (!mpu.begin(0x68, &Wire)) { + Serial.println("[MPU] begin failed"); + return; + } + + mpu.setAccelerometerRange(MPU6050_RANGE_2_G); + mpu.setGyroRange(MPU6050_RANGE_250_DEG); + mpu.setFilterBandwidth(MPU6050_BAND_21_HZ); + Serial.println("[MPU] begin ok"); + + sensors_event_t accel, gyro, temp; + mpu.getEvent(&accel, &gyro, &temp); + Serial.printf("[MPU] accel=(%.2f, %.2f, %.2f) temp=%.2f\n", + accel.acceleration.x, accel.acceleration.y, accel.acceleration.z, temp.temperature); +} + +void loop() { + static uint32_t last = 0; + if (millis() - last > 3000) { + last = millis(); + scanI2C(); + } +}