Start Here¶
This page is written for open-source contributors: anyone from a hobbyist who has run the Arduino Blink example up through experienced developers.
What the software stack is¶
- Firmware: Arduino C++ running on an ESP32-S3 microcontroller. It reads the sensors, runs the charging control loop, enforces the safety protections, and acts as a small web server.
- Embedded web dashboard: plain HTML, JavaScript, and CSS (no framework) stored in the device's flash and served over WiFi to any browser on the same network. The same web bundle is also wrapped as the iOS and Android phone apps (using Capacitor), so keep phones in mind when touching the interface.
- Optional cloud features: the device can upload history and statistics to the owner's cloud account on the project's servers, for long-term trend plots and fleet leaderboards. Everything safety-critical runs entirely on the device; the XREG-010 operates fully without internet.
Where the code is published¶
The public source repository is github.com/XEngineeringLLC/XREG-010.
It contains the firmware (.ino files), the web dashboard source (web_src/: index.html, script.js, styles.css, plus the uPlot charting library files), and the Victron GX app with its offline tests (gx_app/).
A tour of the repository¶
The starting point is Xregulator.ino. It holds all the global variables, setup(), and loop(). All primary program flow and state are in this file, the same layout as a basic Arduino sketch.
The remaining numbered files hold supporting functions. The numeric prefixes (2_, 3_, ...) exist only because the Arduino IDE presents files as alphabetized tabs; the numbers fix the display order, nothing more.
| File | Broad role |
|---|---|
Xregulator.ino |
All globals, setup(), loop(): the main program file |
2_functions.ino |
Storage and persistence layer (the key-value settings helpers settingExists() / settingRead() / settingWrite() and their NK_* key names, plus flash-filesystem helpers), the background tasks defined here (TempTask, httpsTask, faDetTask), and the sensor-history ring buffers and cloud upload payload builders |
3_functions.ino |
Networking and the web server: WiFi mode selection (setupWiFi()), the first-time-setup captive portal, the HTTP endpoint handlers (setupServer()), and assembly of the five live-telemetry payloads (SendWifiData()) |
4_functions.ino |
Hardware bring-up (initializeHardware()), boot-time settings loading (InitSystemSettings()), motion metrics from the inertial sensor (IMU), the solar-forecast mode (Defer to Solar), and the over-the-air firmware update machinery |
5_functions.ino |
External data sources (NMEA2000 message handlers, Victron VE.Direct via ReadVEData()), sensor acquisition (ReadAnalogInputs()), alarms (CheckAlarms()), battery state-of-charge and engine/travel statistics, the battery wear record (batteryWearTick()), and the persistence of runtime counters (saveNVSDataFull() / loadNVSData()) |
6_functions.ino |
The core control code: the field control loop (AdjustFieldLearnMode()), mode and safety-reason selection (selectFieldControlMode()), the ramp-rate governor and shutdown paths, charging stages, RPM tables, and tuning logs/scoring |
7_functions.ino |
Analytics layers: alternator health tracking, sailing and motoring performance, high-rate current statistics, and serving of the pre-compressed web files (cacheWebAssets()) |
8_functions.ino |
Fast alternator-current failure detector (the high-rate diode/winding-fault detector), the config-sharing manifest (CONFIG_MANIFEST[]) that drives both config export/import and the daily fleet config snapshot, equipment records export and import, the handling of record files across an update boot (OTA_REC_FMT), the commissioning stress test (cvStress_tick()) and CV plant fit, and the battery-health monitor (internal resistance and capacity tracking) |
9_demo.ino |
Demo mode (Hardware Present set to No): the simulated boat that feeds every sensor input, the in-RAM settings overlay that keeps demo writes out of flash, the demo allow-list for settings writes (demoParamDenied()), and entry and exit |
The web_src/ folder is the dashboard: index.html for structure, script.js for behavior, styles.css for styling. Workflow there is much the same as the firmware, and you'll often edit all three together.
Design philosophy¶
The codebase is an intentional monolith, and the large majority of variables are global. The layout is flat and predictable: state in one file, functions grouped loosely by purpose in the rest.
This goes against conventional software engineering practice, and that trade is deliberate:
- Beginner navigation. There are no class hierarchies or dependency injection, and the Arduino IDE is the only build tool you need. If you can read one function, you can read them all.
- AI-assisted development. A flat global-state layout means an AI assistant (or a new human) can reason about any function from
Xregulator.inoplus one supporting file, without following abstractions across many modules. This keeps token spend, and human reading time, low.
The original goal was fast solo iteration; the goal now is clarity, as the open community starts to help.
How to find your way in a codebase this large¶
The codebase is far too large to read end-to-end, and you never need to.
Search-driven. Use your editor's project-wide search (or grep on the command line) for the function or variable name you care about. Names are long and descriptive on purpose: searching BulkVoltage or AdjustFieldLearnMode finds the relevant code directly. The file table above tells you which file to expect a hit in.
AI-assisted.
- Paste
Xregulator.inointo your AI assistant along with your question or change request. - Ask it what other files or functions it needs to see.
- Paste those in as requested.
Because the code is organized in a predictable, mostly flat way, this converges quickly; the assistant rarely needs more than one or two supporting files.
Suggested reading order¶
- Architecture first. Boot and the main loop: how the program starts and what runs every tick. Then memory and persistence: where state is stored and survives reboots. Then the telemetry pipeline: how live data reaches the dashboard.
- Then the subsystem you care about: charging control, safeties and protections, sensors, external interfaces, networking and the web server, alternator health, sailing performance, or over-the-air updates.
- The client side, if you're touching the dashboard: dashboard architecture and styling.
- When you're ready to modify: the Extending the System recipes (adding telemetry, adding a setting, and adding a dashboard control) and the contributing guide.
To put the current release on a regulator over USB, see Install Firmware First. To build and flash the firmware yourself, see Building the Firmware. For the optional cloud account side, see account management.
Questions, bugs, ideas: email joe@xengineering.net or open an issue on the public repo.