Skip to content

Millibyte platforms and specific configuration - #29

Open
millibyte-products wants to merge 46 commits into
jcfain:Developmentfrom
millibyte-products:MillibytePlatforms
Open

millibyte-products wants to merge 46 commits into
jcfain:Developmentfrom
millibyte-products:MillibytePlatforms

Conversation

@millibyte-products

@millibyte-products millibyte-products commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

I did some rearchitecting in my fork.
These changes may be interesting, or they might be too much in which case, no worries.

The biggest change is collecting tasks into a task manager. This reduces the need for additional stack allocations and lets tasks share resources (heap) more efficiently.
I've also taken a whack at reducing/optimizing some of the HTTP server files, tried to add chunking and fix some memory alloc issues I ran into.
Added SSR1PCB and SR6PCB as first-class build targets, extending the existing common content and setting some different defaults.
Added pull-up config to the web interface, just for the lube button for now.
Added some helper provisioning scripts I found useful, and an #ip command to support them.
Switched tags to a binary format. Easier to send between threads and more memory efficient.

1) Consolidate tasks, no need to spawn a separate stack for each
2) Support pullup/down modes for lube button pin, default to pulldown
3) Add lube button pin mode setting to settings factory and UI
4) Remove old minified web assets that are no longer used
5) Update index.html and settings.js to reflect pin mode setting
6) Update platformio.ini to reflect new source files and dependencies
Cleans up codebase, adds task management
Adds explicit millibyte build targets
Switches from LEDC to MCPWM for servo control on ESP32
Cleans up serial handling code, adds more robust serial parsing
Cleans up some HTTP handling code, adds more robust error handling
…tforms

# Conflicts:
#	ESP32/data/www/bldc-motor-min.js.gz
#	ESP32/data/www/buttons-min.js.gz
#	ESP32/data/www/esp-timer-setup-min.js.gz
#	ESP32/data/www/index-min.html.gz
#	ESP32/data/www/modal-component-min.js.gz
#	ESP32/data/www/motion-generator-min.js.gz
#	ESP32/data/www/settings-min.js.gz
#	ESP32/data/www/style-min.css.gz
#	ESP32/data/www/utils-min.js.gz
#	ESP32/dataEdit/www/esp-timer-setup.js
#	ESP32/dataEdit/www/index.html
#	ESP32/dataEdit/www/settings.js
#	ESP32/lib/constants.h
#	ESP32/lib/enum.h
#	ESP32/lib/pinMap.h
#	ESP32/lib/settingConstants.h
#	ESP32/lib/settingsFactory.h
#	ESP32/platformio.ini
#	ESP32/sdkconfig.defaults
#	ESP32/src/BatteryHandler.h
#	ESP32/src/DisplayHandler.h
#	ESP32/src/HTTP/SecureWebSocketHandler.hpp
#	ESP32/src/HTTP/WebSocketBase.h
#	ESP32/src/MDNSHandler.hpp
#	ESP32/src/SettingsHandler.h
#	ESP32/src/SystemCommandHandler.h
#	ESP32/src/TCode/MotorHandler.h
#	ESP32/src/TCode/v0.3/BLDCHandler0_3.h
#	ESP32/src/TCode/v0.3/MotorHandler0_3.h
#	ESP32/src/TCode/v0.3/ServoHandler0_3.h
#	ESP32/src/TCode/v0.4/BLDCHandler0_4.h
#	ESP32/src/TCode/v0.4/MotorHandler0_4.h
#	ESP32/src/TCode/v0.4/OutputStream.h
#	ESP32/src/TCode/v0.4/ServoHandler0_4.h
#	ESP32/src/TagHandler.h
#	ESP32/src/TemperatureHandler.h
#	ESP32/src/UdpHandler.h
#	ESP32/src/VoiceHandler.hpp
#	ESP32/src/WebHandler.h
#	ESP32/src/WebSocketHandler.h
#	ESP32/src/WifiHandler.h
#	ESP32/src/bluetooth/BLE/BLEHandler.hpp
#	ESP32/src/bluetooth/BluetoothHandler.h
#	ESP32/src/logging/LogHandler.h
#	ESP32/src/main.cpp
#	ESP32/src/sensors/ButtonHandler.hpp
Lean toward MillibytePlatforms patterns (Tags namespace, callback.h typedefs, void setup() with m_initFailed, numeric MOTOR_TYPE). Servo build envs (sr6_pcb, esp32doit-devkit-v1) now compile. BLDC envs (ssr1_pcb, *-bldc) still have pre-existing issues in BLDCHandler0_3.h / 0_4.h (undeclared bootmode/xLin/xPosition/zeroAngle/motorB/_TAG) that need separate work.
…apSSR1PCB

The merge introduced a half-finished SSR2 dual-motor refactor in BLDCHandler0_3.h/0_4.h with duplicate motorA/driverA declarations and undeclared bootmode/xLin/xPosition/zeroAngle/motorVoltage/motorB/sensorB/driverB/m_deviceType/_TAG/BLDCBootMode usages. Reverted to the pre-merge (v1.0.0) versions and re-applied the only intended change (TCODE_FUNCTION_PTR_T -> TCodeCommandCallback) plus the rename of PinMapSSR1 to PinMapSSR1PCB. Also fix DEFAULT_DEVICE=DeviceType::SR1 typo (should be SSR1) in esp32doit-devkit-v1-bldc env.
Drop 21 stale upstream-style flat headers in src/ plus src/HTTP/ that duplicate the refactored versions in src/network/, src/messages/, src/settings/, src/sensors/, src/serial/, src/tasks/. None were reachable from main.cpp; they only included each other (InitHandler.hpp, InstanceHandler.h, TaskHandler.hpp, etc.). All 4 active build envs (sr6_pcb, ssr1_pcb, esp32doit-devkit-v1, esp32doit-devkit-v1-bldc) still build successfully.
High-frequency vibe attaches (e.g. 8 kHz x 15-bit = 262 MHz) caused IDF mcpwm_new_timer to compute prescale = src_clk / resolution_hz = 0, then later divide by prescale -> IntegerDivideByZero panic during boot. Reject configurations where resolution_hz exceeds the MCPWM source clock so callers get a clean failure instead of a hardware panic.
The per-chip config headers were unconditionally redefining BOARD_TYPE_DEFAULT,
clobbering the BoardType passed via -D DEFAULT_BOARD in platformio.ini. As a
result ssr1_pcb (and other PCB envs) booted with DEVKIT pins instead of their
actual board pinout. Guard each cfg with #ifndef DEFAULT_BOARD so the build
flag wins.
lib/settingConstants.h had a duplicate #define block that re-declared
BLDC_MOTORA_VOLTAGE/SUPPLY/CURRENT/ZEROELECANGLE etc. with the truncated
string keys 'BLDC_Motor_VoltageLimit'... overriding the earlier canonical
'BLDC_MotorA_VoltageLimit' names. Saved JSON written via SettingsFactory
then used the wrong keys and the BLDC handler always read defaults
(ZeroElecAngle = -12345 sentinel), which broke FOC initialization.
millibyte-products and others added 18 commits May 7, 2026 15:35
The AsyncWebServer-based WebHandler (the one main.cpp actually instantiates)
was missing /debugInfo, so the settings UI got a 404 and the polling chain
faulted. GET streams /debugInfo.json (or returns an empty doc when absent),
POST clears the file.
pingDevice() declared 'let polling = false' as a function-local variable,
so every other function (getSystemInfo/getDebugInfo/...) referencing bare
'polling' threw ReferenceError on the first call from onDocumentLoad.
Move the declaration to module scope. Also stop treating a missing /debugInfo
endpoint as a fatal error so older firmware keeps loading.
Makes it possible to tell from the boot log whether BLDCDriver3PWM->init()
succeeded and whether the EN pin was actually asserted before initFOC()
attempts sensor alignment. Calls driverA->enable() right after init so the
gate-driver chip is unambiguously enabled when the alignment voltage is
applied.
The class-based rewrite was incomplete: it generated DOM elements with
IDs like BLDC_Motor_VoltageLimit (no 'A') that don't match the static
HTML form (BLDC_MotorA_VoltageLimit), it expected motorA/motorB instances
that were never constructed, and it left BLDCMotor.setup() calls hanging
on a class with no static method. Restoring the prior object-literal
singleton fixes the 'BLDCMotor.setup is not a function' TypeError thrown
from setUserSettings during settings load.
The BLDC branch in setPinoutSettings was a no-op with a comment claiming
pins were populated from user settings, but they weren't populated anywhere
else either - the BLDC pin inputs in the web UI were always blank. Call
BLDCMotor.setupPins() to populate them from /pins like the pre-merge build.
…sed PWM resolution UI

- settingsFactory: register BLDC_PIDProportionalConstant and BLDC_LowPassFilter so they appear in /settings JSON and persist.

- BLDCHandler0_3: load PID P-const and low-pass filter from settings (m_pConst/m_lowPass) replacing compile-time P_CONST/LOW_PASS macros; force encoder type to MT6701 SSI (SSR1PCB always ships with MT6701, ignore stale BLDC_Encoder=0/NONE in saved settings).

- bldc-motor.js: populate and persist BLDC_PIDProportionalConstant and BLDC_LowPassFilter; for SSR1PCB lock the BLDC_Encoder dropdown to MT6701 (=1) and force-save corrected value.

- settings.js: declare module-level upDateTimeout to fix ReferenceError in updateBLDCPins/updatePins; remove servo/vibe/lube/heater/case-fan resolution setters that were assigning undefined into the inputs.

- index.html: hide servo/vibe/lube/heater/case-fan resolution rows (PwmManager auto-derives resolution per timer).

- scripts/tcode-stroke-test.ps1: helper script that drives the L0 axis Max/Min/Center over T-Code on a serial port.
- MotorHandler0_3/0_4: default servoResolution/vibeResolution/lubeResolution
  to SERVO_PWM_RES before getValue() and clamp to 1..16. Previously the
  uninitialized local could produce m_servoPWMMaxDuty = UINT32_MAX, which
  saturated every map() call and made all servos appear idle.
- battery.js: hold-off window so server-broadcast powerStatus does not
  overwrite the user's VMOTOR toggle for 2.5s.
- settings.js: declare upDatePinsTimeout; suppress 'Error loading <name>'
  toasts during the polling/restart wait loop.
- index-min.html.gz: regenerate minified bundles.
- scripts/: add capture-boot-log, ws-listen, ws-stroke-test, test-vser-* helpers.
- TaskHandler: collapse the unused two-list (core0/core1) split into a
  single cooperatively-polled list. The old critical/priority/auxiliary/
  realtime/lazy aliases are kept as no-op wrappers around add() so call
  sites compile without churn.
- main.cpp: header doc block enumerates every task/thread (motor pinned
  to PRO_CPU, servoWiggle, Arduino loop poll on APP_CPU, WiFi/AsyncTCP
  SDK tasks, AsyncWebServer task) and the motorCmdQueue bridge.
- main.cpp + NetworkHandler.h + OperatingModeHandler.h: switch all task
  registrations from priority() to add() now that there's only one list.
- UdpHandler: drop dead TaskHandle_t m_task field (never assigned).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Keeps our architecture (flat settings files, enum-tag LogHandler, task
manager + motor task, websocket log streaming, singleton BLDC UI) and ports
upstream fixes/features into it. Upstream's /systemSettings.json split,
websocket settings protocol and new terminal UI were not adopted.

Ported from upstream:
- Vendored TCode library (lib/TCode) replaces TCode-Library#a5ec926; v0.4
  handlers rewritten against it with our PwmManager/BLDC hold/identify
  changes re-applied. Restores the setupCommon() call for OSR/SR6 in
  ServoHandler0_4 that the previous WIP commit dropped.
- D0/D1 device info + startup "Ready!", TCODE_CHANNEL_* macros, surge/sway
  naming, v0.4 channel map support.
- BLDC motor status: SimpleFOC init messages stored in /debugInfo.json
  (motorState) and shown in the BLDC section of the web UI.
- Web terminal command input: $/# system commands and TCode sent over the
  websocket; command output and TCode replies routed via LogHandler::raw
  into the UI log.
- JSON escaping of websocket messages (log lines with quotes/newlines no
  longer break the client).
- Reset ALL also clears /channels.json; display shows the current IP;
  S3 Zero pin defaults (I2C 8/9); UI null guards and label fixes.

Also fixes SystemCommandHandler::process() leaking its mutex on invalid
value commands (would hang all later commands once reachable from the web).

Kept ours: TCODE_VERSION_DEFAULT stays v0.3, platform 55.03.30-2 and
ESPAsyncWebServer 3.8.0 (chunk patch targets it).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Brings in jcfain/Development: NimBLE-Arduino 2.5.1 with the NIMBLE_V2
callback signatures and heap-integrity checks, utils split into
header/cpp with a bounded substr(), tcode queue sizing, UDP packet
length validation, firmware version 0.581b, and the PrintX /
PrintMotorStatus helpers.

Conflict resolution notes:
- main.cpp, BLDCHandler0_3/0_4 and settingsFactory.h keep the fork's
  task-manager architecture and BLDC hold-controller code; upstream's
  single-buffer main loop and PrintMotorStatus refactor do not apply.
  The debug-level guard around settings file dumps was ported.
- InitHandler/InstanceHandler/SerialHandler/SystemCommandHandler/
  UdpHandler/WebSocketHandler were already replaced by the fork's
  tasks/, serial/, messages/ and network/ equivalents. Upstream's UDP
  length check and the bounded #command:value parser were ported into
  those files; the fork's queue depths are unchanged.
- BLE handlers take upstream's NimBLE 2.x changes with the fork's
  binary Tags:: identifiers. The static ServerCallbacks instance is
  kept so isConnected() still observes the registered callbacks.
- logging/printX.h is removed in favour of upstream's PrintX.h to
  avoid a case-only filename collision.
- platformio.ini keeps the fork's pioarduino 55.03.30-2 pin and takes
  upstream's NimBLE 2.5.1 / NIMBLE_V2 flags.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant