Skip to content

Commit 9504f44

Browse files
authored
Firmware builder: sensorless homing, case light, advanced pin panel (#47)
* Add Ender 5 Pro preset and endstop state config * Add sensorless homing output to firmware config generator * Add preview and default-value tests for sensorless config * Pass sensorless homing fields through firmware build worker * Add sensorless XY homing option to firmware builder wizard * Restore driver choice when leaving sensorless mode * Apply sensorless XY homing in firmware build workflow * Add case light output to firmware config generator * Pass case light fields through firmware build worker * Add case light LED option to firmware builder wizard * Apply case light LED in firmware build workflow * Add board pin map module for firmware builder * Add advanced pin panel container to firmware builder * Render advanced pin panel from board map in firmware builder * Escape raw pin value in advanced panel rendering * Resolve advanced pin overrides into firmware build request * Pass advanced pin overrides through firmware build worker * Apply advanced endstop and fan pin overrides in build workflow * Apply advanced pin overrides to firmware config download path * Fix case light pin and power-up default parity * Relabel case light as build volume light * Show pin names in advanced pin panel and fix download icon * Move motor socket assignment into advanced panel * Add dual Z stepper option with independent endstop switch * Rename light section and add LED pin selector * Make motor sockets functional with default no-op behavior * Remove 500mm cap on bed-size inputs for larger printers
1 parent 16b5673 commit 9504f44

8 files changed

Lines changed: 985 additions & 102 deletions

File tree

.github/workflows/firmware-build.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,126 @@ jobs:
192192
echo "Set B endstop hit state to $ENDSTOP_B"
193193
fi
194194
195+
# === SENSORLESS XY HOMING ===
196+
XY_HOMING_MODE=$(echo "$CUSTOMIZATIONS" | jq -r '.xyHomingMode // empty')
197+
if [ "$XY_HOMING_MODE" = "sensorless" ]; then
198+
STALL_X=$(echo "$CUSTOMIZATIONS" | jq -r '.stallSensitivityX // 8')
199+
STALL_Y=$(echo "$CUSTOMIZATIONS" | jq -r '.stallSensitivityY // 8')
200+
201+
# Enable SENSORLESS_HOMING (commented + indented inside the TMC block)
202+
sed -i 's|^[[:space:]]*//#define SENSORLESS_HOMING.*| #define SENSORLESS_HOMING|' marlin/Marlin/Configuration_adv.h
203+
204+
# Set X/Y stall sensitivities (the X2_/Y2_ lines reference these, leave them)
205+
sed -i "s|^[[:space:]]*#define X_STALL_SENSITIVITY .*| #define X_STALL_SENSITIVITY $STALL_X|" marlin/Marlin/Configuration_adv.h
206+
sed -i "s|^[[:space:]]*#define Y_STALL_SENSITIVITY .*| #define Y_STALL_SENSITIVITY $STALL_Y|" marlin/Marlin/Configuration_adv.h
207+
208+
# Marlin recommends zero homing bump for sensorless axes
209+
sed -i 's|^#define HOMING_BUMP_MM .*|#define HOMING_BUMP_MM { 0, 0, 3, 5, 2 }|' marlin/Marlin/Configuration_adv.h
210+
211+
echo "Enabled sensorless XY homing (X sensitivity=$STALL_X, Y sensitivity=$STALL_Y)"
212+
else
213+
echo "XY homing uses physical endstops"
214+
fi
215+
216+
# === CASE LIGHT LED ===
217+
CASE_LIGHT_ENABLED=$(echo "$CUSTOMIZATIONS" | jq -r '.caseLightEnabled // empty')
218+
if [ "$CASE_LIGHT_ENABLED" = "true" ]; then
219+
CASE_LIGHT_BRIGHTNESS=$(echo "$CUSTOMIZATIONS" | jq -r '.caseLightBrightness // 105')
220+
LED_PIN=$(echo "$CUSTOMIZATIONS" | jq -r '.caseLightPin // "PD13"')
221+
222+
# Enable the feature (commented at column 0 in the base config)
223+
sed -i 's|^//#define CASE_LIGHT_ENABLE|#define CASE_LIGHT_ENABLE|' marlin/Marlin/Configuration_adv.h
224+
225+
# Set the LED pin (commented + indented inside the CASE_LIGHT block)
226+
sed -i "s|^[[:space:]]*//#define CASE_LIGHT_PIN .*| #define CASE_LIGHT_PIN $LED_PIN|" marlin/Marlin/Configuration_adv.h
227+
228+
# Set default brightness (already uncommented + indented)
229+
sed -i "s|^[[:space:]]*#define CASE_LIGHT_DEFAULT_BRIGHTNESS .*| #define CASE_LIGHT_DEFAULT_BRIGHTNESS $CASE_LIGHT_BRIGHTNESS|" marlin/Marlin/Configuration_adv.h
230+
231+
# Keep the light off at power-up (base config defaults it on)
232+
sed -i 's|^[[:space:]]*#define CASE_LIGHT_DEFAULT_ON .*| #define CASE_LIGHT_DEFAULT_ON false|' marlin/Marlin/Configuration_adv.h
233+
234+
echo "Enabled case light LED on pin $LED_PIN (brightness $CASE_LIGHT_BRIGHTNESS)"
235+
else
236+
echo "Case light disabled"
237+
fi
238+
239+
# === ADVANCED PIN OVERRIDES (endstops + fans) ===
240+
PIN_ENDSTOP_X=$(echo "$CUSTOMIZATIONS" | jq -r '.pinOverrides.endstopX // empty')
241+
PIN_ENDSTOP_Y=$(echo "$CUSTOMIZATIONS" | jq -r '.pinOverrides.endstopY // empty')
242+
PIN_ENDSTOP_Z=$(echo "$CUSTOMIZATIONS" | jq -r '.pinOverrides.endstopZ // empty')
243+
PIN_ENDSTOP_C=$(echo "$CUSTOMIZATIONS" | jq -r '.pinOverrides.endstopC // empty')
244+
PIN_ENDSTOP_B=$(echo "$CUSTOMIZATIONS" | jq -r '.pinOverrides.endstopB // empty')
245+
246+
# C and B endstops already have #define lines in the base config
247+
if [ -n "$PIN_ENDSTOP_C" ]; then
248+
sed -i "s|^#define I_MIN_PIN .*|#define I_MIN_PIN $PIN_ENDSTOP_C // C-axis endstop (Rep5x Firmware Builder)|" marlin/Marlin/Configuration.h
249+
echo "Set I_MIN_PIN (C endstop) to $PIN_ENDSTOP_C"
250+
fi
251+
if [ -n "$PIN_ENDSTOP_B" ]; then
252+
sed -i "s|^#define J_MIN_PIN .*|#define J_MIN_PIN $PIN_ENDSTOP_B // B-axis endstop (Rep5x Firmware Builder)|" marlin/Marlin/Configuration.h
253+
echo "Set J_MIN_PIN (B endstop) to $PIN_ENDSTOP_B"
254+
fi
255+
256+
# X/Y/Z endstops: append guarded overrides after the J_MIN_PIN line
257+
for AXIS_PIN in "X_MIN_PIN:$PIN_ENDSTOP_X" "Y_MIN_PIN:$PIN_ENDSTOP_Y" "Z_MIN_PIN:$PIN_ENDSTOP_Z"; do
258+
DEF_NAME="${AXIS_PIN%%:*}"
259+
DEF_VAL="${AXIS_PIN##*:}"
260+
if [ -n "$DEF_VAL" ]; then
261+
sed -i "/^#define J_MIN_PIN /a #ifndef $DEF_NAME\\n #define $DEF_NAME $DEF_VAL // Rep5x Firmware Builder\\n#endif" marlin/Marlin/Configuration.h
262+
echo "Set $DEF_NAME to $DEF_VAL"
263+
fi
264+
done
265+
266+
# Hotend / auto fan -> E0_AUTO_FAN_PIN (settable define in Configuration_adv.h)
267+
PIN_FAN_HOTEND=$(echo "$CUSTOMIZATIONS" | jq -r '.pinOverrides.fanHotend // empty')
268+
if [ -n "$PIN_FAN_HOTEND" ]; then
269+
sed -i "s|^#define E0_AUTO_FAN_PIN .*|#define E0_AUTO_FAN_PIN $PIN_FAN_HOTEND // Rep5x Firmware Builder|" marlin/Marlin/Configuration_adv.h
270+
echo "Set E0_AUTO_FAN_PIN to $PIN_FAN_HOTEND"
271+
fi
272+
273+
# Controller fan -> enable USE_CONTROLLER_FAN + set its pin
274+
PIN_FAN_CONTROLLER=$(echo "$CUSTOMIZATIONS" | jq -r '.pinOverrides.fanController // empty')
275+
if [ -n "$PIN_FAN_CONTROLLER" ]; then
276+
sed -i 's|^//#define USE_CONTROLLER_FAN|#define USE_CONTROLLER_FAN|' marlin/Marlin/Configuration_adv.h
277+
sed -i "s|^[[:space:]]*//#define CONTROLLER_FAN_PIN .*| #define CONTROLLER_FAN_PIN $PIN_FAN_CONTROLLER // Rep5x Firmware Builder|" marlin/Marlin/Configuration_adv.h
278+
echo "Set CONTROLLER_FAN_PIN to $PIN_FAN_CONTROLLER"
279+
fi
280+
281+
# === DUAL Z STEPPERS ===
282+
DUAL_Z=$(echo "$CUSTOMIZATIONS" | jq -r '.dualZ // empty')
283+
if [ "$DUAL_Z" = "true" ]; then
284+
# Z2 runs in sync with Z and uses the same driver type
285+
Z2_DRIVER=$(echo "$CUSTOMIZATIONS" | jq -r '.driverZ // "TMC2208"')
286+
sed -i "s|^//#define Z2_DRIVER_TYPE.*|#define Z2_DRIVER_TYPE $Z2_DRIVER|" marlin/Marlin/Configuration.h
287+
echo "Enabled dual Z steppers (Z2 driver $Z2_DRIVER)"
288+
289+
Z_MULTI=$(echo "$CUSTOMIZATIONS" | jq -r '.zMultiEndstops // empty')
290+
if [ "$Z_MULTI" = "true" ]; then
291+
# Independent Z endstops: enable Z_MULTI_ENDSTOPS + the Z2-STOP header
292+
sed -i 's|^[[:space:]]*//#define Z_MULTI_ENDSTOPS| #define Z_MULTI_ENDSTOPS|' marlin/Marlin/Configuration_adv.h
293+
sed -i 's|^[[:space:]]*//#define Z2_STOP_PIN .*| #define Z2_STOP_PIN PG11|' marlin/Marlin/Configuration_adv.h
294+
echo "Enabled independent Z endstops (Z2_STOP_PIN PG11)"
295+
else
296+
echo "Z2 shares the single Z endstop"
297+
fi
298+
else
299+
echo "Single Z stepper"
300+
fi
301+
302+
# === MOTOR SOCKET OVERRIDES ===
303+
# Re-map motor driver pins in the cloned board pin file. Only axes
304+
# the user changed from the Rep5x default appear in motorOverrides.
305+
BOARD_PINS=marlin/Marlin/src/pins/stm32f4/pins_BTT_OCTOPUS_V1_common.h
306+
echo "$CUSTOMIZATIONS" | jq -r '(.motorOverrides // {}) | to_entries[] | "\(.key) \(.value.step) \(.value.dir) \(.value.enable) \(.value.uart)"' | while read -r LOGICAL STEP DIR ENABLE UART; do
307+
[ -z "$LOGICAL" ] && continue
308+
sed -i "s|^#define ${LOGICAL}_STEP_PIN .*|#define ${LOGICAL}_STEP_PIN ${STEP} // Rep5x Firmware Builder|" "$BOARD_PINS"
309+
sed -i "s|^#define ${LOGICAL}_DIR_PIN .*|#define ${LOGICAL}_DIR_PIN ${DIR} // Rep5x Firmware Builder|" "$BOARD_PINS"
310+
sed -i "s|^#define ${LOGICAL}_ENABLE_PIN .*|#define ${LOGICAL}_ENABLE_PIN ${ENABLE} // Rep5x Firmware Builder|" "$BOARD_PINS"
311+
sed -i "s|^[[:space:]]*#define ${LOGICAL}_SERIAL_TX_PIN .*| #define ${LOGICAL}_SERIAL_TX_PIN ${UART} // Rep5x Firmware Builder|" "$BOARD_PINS"
312+
echo "Remapped motor ${LOGICAL} -> STEP ${STEP} DIR ${DIR} ENABLE ${ENABLE} UART ${UART}"
313+
done
314+
195315
# === IK PARAMETERS ===
196316
IK_LC=$(echo "$CUSTOMIZATIONS" | jq -r '.ikLC // empty')
197317
IK_LB=$(echo "$CUSTOMIZATIONS" | jq -r '.ikLB // empty')

0 commit comments

Comments
 (0)