From c8c7ced3edf1c4ff1a53f2bdad7dfe71c9aac885 Mon Sep 17 00:00:00 2001 From: Austen Bartels Date: Thu, 27 Feb 2025 14:25:32 -0500 Subject: [PATCH 1/4] SR6PCB alpha test --- ESP32/dataEdit/www/settings.js | 32 ++++++++++++++++++++++++++++++++ ESP32/lib/pinDefaultsWROOM32.h | 34 +++++++++++++++++----------------- ESP32/src/main.cpp | 10 ++++++++++ 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/ESP32/dataEdit/www/settings.js b/ESP32/dataEdit/www/settings.js index 2774354..f5bb6b7 100644 --- a/ESP32/dataEdit/www/settings.js +++ b/ESP32/dataEdit/www/settings.js @@ -854,6 +854,12 @@ function setPinoutSettings() { document.getElementById('Internal_Temp_PIN').value = pinoutSettings["Internal_Temp_PIN"]; document.getElementById('i2cSda_PIN').value = pinoutSettings["i2cSda_PIN"]; document.getElementById('i2cScl_PIN').value = pinoutSettings["i2cScl_PIN"]; + document.getElementById("Servo_Power_Enable_PIN").value = pinoutSettings["Servo_Power_Enable_PIN"]; + document.getElementById('Bus_Voltage_Feedback_PIN').value = pinoutSettings["Bus_Voltage_Feedback_PIN"]; + document.getElementById('Servo_Voltage_Feedback_PIN').value = pinoutSettings["Servo_Voltage_Feedback_PIN"]; + document.getElementById('PDCFG1_PIN').value = pinoutSettings["PDCFG1_PIN"]; + document.getElementById('PDCFG2_PIN').value = pinoutSettings["PDCFG2_PIN"]; + document.getElementById('PDCFG3_PIN').value = pinoutSettings["PDCFG3_PIN"]; setPinChannel("Vibe0_CHANNEL", pinoutSettings["Vibe0_CHANNEL"]); @@ -1816,6 +1822,12 @@ function updateCommonPins(pinValues) { pinoutSettings["Internal_Temp_PIN"] = pinValues.internalTemp; pinoutSettings["i2cSda_PIN"] = pinValues.i2cSda; pinoutSettings["i2cScl_PIN"] = pinValues.i2cScl; + pinoutSettings["Servo_Power_Enable_PIN"] = pinValues.servoPowerEnable; + pinoutSettings["Servo_Voltage_Feedback_PIN"] = pinValues.servoVoltageFeedback; + pinoutSettings["Bus_Voltage_Feedback_PIN"] = pinValues.busVoltageFeedback; + pinoutSettings["PDCFG1_PIN"] = pinValues.pdCFG1; + pinoutSettings["PDCFG2_PIN"] = pinValues.pdCFG2; + pinoutSettings["PDCFG3_PIN"] = pinValues.pdCFG3; // pinoutSettings["Battery_Voltage_PIN"] = pinValues.Battery_Voltage_PIN; // } @@ -2074,6 +2086,14 @@ function validateNonPWMPins(assignedPins, duplicatePins, invalidPins, pinValues) validatePin(pinValues.i2cScl, "I2C SCL", assignedPins, duplicatePins); } + validatePin(pinValues.servoPowerEnable, assignedPins, duplicatePins); + validatePin(pinValues.servoVoltageFeedback, assignedPins, duplicatePins); + + validatePin(pinValues.busVoltageFeedback, assignedPins, duplicatePins); + validatePin(pinValues.pdCFG1, assignedPins, duplicatePins); + validatePin(pinValues.pdCFG2, assignedPins, duplicatePins); + validatePin(pinValues.pdCFG3, assignedPins, duplicatePins); + validatePin(pinValues.lubeButton, "Lube button", assignedPins, duplicatePins, true, invalidPins); if(userSettings.tempSleeveEnabled) { @@ -2138,6 +2158,18 @@ function getCommonPinValues(pinValues) { pinValues.i2cSda = parseInt(document.getElementById('i2cSda_PIN').value); pinValues.i2cScl = parseInt(document.getElementById('i2cScl_PIN').value); + var pdCFGPins = document.getElementsByName('pdCFGPins'); + pinValues.pdCFG = []; + pdCFGPins.forEach((node, index) => { + pinValues.pdCFG[index] = parseInt(document.getElementById('pdCFGPins'+index).value); + }); + pinValues.servoPowerEnable = parseInt(document.getElementById('Servo_Power_Enable_PIN').value); + pinValues.servoVoltageFeedback = parseInt(document.getElementById('Servo_Voltage_Feedback_PIN').value); + pinValues.busVoltageFeedback = parseInt(document.getElementById('Bus_Voltage_Feedback_PIN').value); + pinValues.pdCFG1 = parseInt(document.getElementById('PDCFG1_PIN').value); + pinValues.pdCFG2 = parseInt(document.getElementById('PDCFG2_PIN').value); + pinValues.pdCFG3 = parseInt(document.getElementById('PDCFG3_PIN').value); + pinValues.lubeButton = parseInt(document.getElementById('LubeButton_PIN').value); pinValues.temp = parseInt(document.getElementById('Temp_PIN').value); pinValues.internalTemp = parseInt(document.getElementById('Internal_Temp_PIN').value); diff --git a/ESP32/lib/pinDefaultsWROOM32.h b/ESP32/lib/pinDefaultsWROOM32.h index 8d53dc0..7799030 100644 --- a/ESP32/lib/pinDefaultsWROOM32.h +++ b/ESP32/lib/pinDefaultsWROOM32.h @@ -5,33 +5,33 @@ // Common PWM #define VALVE_SERVO_PIN_DEFAULT 25 #define VALVE_SERVO_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH3_CH6 -#define TWIST_SERVO_PIN_DEFAULT 27 +#define TWIST_SERVO_PIN_DEFAULT -1 #define TWIST_SERVO_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH2_CH4 -#define SQUEEZE_PIN_DEFAULT 17 +#define SQUEEZE_PIN_DEFAULT -1 #define SQUEEZE_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH2_CH5 -#define VIBE0_PIN_DEFAULT 18 +#define VIBE0_PIN_DEFAULT -1 #define VIBE0_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::LOW0_CH0 -#define VIBE1_PIN_DEFAULT 19 +#define VIBE1_PIN_DEFAULT -1 #define VIBE1_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::LOW0_CH1 #define VIBE2_PIN_DEFAULT 23 #define VIBE2_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::LOW1_CH2 -#define VIBE3_PIN_DEFAULT 32 +#define VIBE3_PIN_DEFAULT -1 #define VIBE3_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::LOW2_CH4 -#define CASE_FAN_PIN_DEFAULT 16 +#define CASE_FAN_PIN_DEFAULT -1 #define CASE_FAN_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::LOW3_CH6 -#define HEATER_PIN_DEFAULT 33 +#define HEATER_PIN_DEFAULT -1 #define HEATER_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::LOW2_CH4 // Common Analog -#define TWIST_FEEDBACK_PIN_DEFAULT 26 +#define TWIST_FEEDBACK_PIN_DEFAULT -1 #define LUBE_BUTTON_PIN_DEFAULT 35 -#define INTERNAL_TEMP_PIN_DEFAULT 34 +#define INTERNAL_TEMP_PIN_DEFAULT -1 #define DISPLAY_RST_PIN_DEFAULT -1 #define TEMP_PIN_DEFAULT 5 #define I2C_SDA_PIN_DEFAULT 21 #define I2C_SCL_PIN_DEFAULT 22 #define BUTTON_SET_PINS_DEFAULT {}// Arrays dont work like this. See Settingsfactory::loadDefaultVector for defaults workaround -#define BUTTON_SET_PINS_1 39 +#define BUTTON_SET_PINS_1 34 #define BUTTON_SET_PINS_2 -1 #define BUTTON_SET_PINS_3 -1 #define BUTTON_SET_PINS_4 -1 @@ -74,19 +74,19 @@ #endif // OSR -#define RIGHT_SERVO_PIN_DEFAULT 13 +#define RIGHT_SERVO_PIN_DEFAULT 23 #define RIGHT_SERVO_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH0_CH0 -#define LEFT_SERVO_PIN_DEFAULT 15 +#define LEFT_SERVO_PIN_DEFAULT 19 #define LEFT_SERVO_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH0_CH1 -#define PITCH_LEFT_SERVO_PIN_DEFAULT 4 +#define PITCH_LEFT_SERVO_PIN_DEFAULT 16 #define PITCH_LEFT_SERVO_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH1_CH2 // SR6 -#define RIGHT_UPPER_SERVO_PIN_DEFAULT 12 +#define RIGHT_UPPER_SERVO_PIN_DEFAULT 18 #define RIGHT_UPPER_SERVO_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH2_CH4 -#define LEFT_UPPER_SERVO_PIN_DEFAULT 2 +#define LEFT_UPPER_SERVO_PIN_DEFAULT 5 #define LEFT_UPPER_SERVO_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH2_CH5 -#define PITCH_RIGHTSERVO_PIN_DEFAULT 14 +#define PITCH_RIGHTSERVO_PIN_DEFAULT 17 #define PITCH_RIGHTSERVO_CHANNEL_DEFAULT (int8_t)ESPTimerChannelNum::HIGH1_CH3 // BLDC (SSR1) @@ -96,4 +96,4 @@ #define BLDC_HALLEFFECT_PIN_DEFAULT 35 #define BLDC_PWMCHANNEL1_PIN_DEFAULT 27 #define BLDC_PWMCHANNEL2_PIN_DEFAULT 26 -#define BLDC_PWMCHANNEL3_PIN_DEFAULT 25 \ No newline at end of file +#define BLDC_PWMCHANNEL3_PIN_DEFAULT 25 diff --git a/ESP32/src/main.cpp b/ESP32/src/main.cpp index 2a20035..b2d29e7 100644 --- a/ESP32/src/main.cpp +++ b/ESP32/src/main.cpp @@ -698,6 +698,16 @@ void setup() LogHandler::info(TagHandler::Main, "Chip ID: %u", chipId); Serial.println(); + // Pinhacks for SR6PCB, remove + pinMode(13, OUTPUT); // PSU EN + pinMode(12, OUTPUT); // PDCFG1 + pinMode(14, OUTPUT); // PDCFG2 + pinMode(27, OUTPUT); // PDCFG3 + digitalWrite(13, HIGH); // Enable regualtor + digitalWrite(12, LOW); // Request 20V + digitalWrite(14, HIGH); // Request 20V + digitalWrite(27, LOW); // Request 20V + // esp_log_level_set("*", ESP_LOG_VERBOSE); // LogHandler::debug("main", "this is verbose"); // LogHandler::debug("main", "this is debug"); From 636aae08ccd0ff40d27c0fe2cc1b6162522d10d8 Mon Sep 17 00:00:00 2001 From: Austen Bartels Date: Wed, 9 Apr 2025 16:31:22 -0400 Subject: [PATCH 2/4] Power Subsystem Support for SR6PCB --- ESP32/dataEdit/www/battery.js | 4 +- ESP32/dataEdit/www/bldc-motor.js | 16 +- ESP32/dataEdit/www/buttons.js | 24 +- ESP32/dataEdit/www/esp-timer-setup.js | 2 +- ESP32/dataEdit/www/index.html | 334 +++++++++------ .../www/modal-component/modal-component.js | 10 +- ESP32/dataEdit/www/motion-generator.js | 58 +-- ESP32/dataEdit/www/power.js | 85 ++++ ESP32/dataEdit/www/range-slider.css | 14 +- ESP32/dataEdit/www/range-slider.js | 12 +- ESP32/dataEdit/www/settings.js | 381 +++++++++--------- ESP32/dataEdit/www/style.css | 28 +- ESP32/lib/constants.h | 5 +- ESP32/lib/enum.h | 6 +- ESP32/lib/pinDefaultsS3.h | 8 +- ESP32/lib/pinDefaultsS3Zero.h | 9 +- ESP32/lib/pinDefaultsWROOM32.h | 7 + ESP32/lib/pinMap.h | 73 +++- ESP32/lib/settingConstants.h | 8 + ESP32/lib/settingsFactory.h | 61 ++- ESP32/lib/struct/setting.h | 3 +- ESP32/minify.js | 4 + ESP32/platformio.ini | 258 ++++-------- ESP32/src/HTTP/WebSocketBase.h | 30 +- ESP32/src/PowerHandler.h | 316 +++++++++++++++ ESP32/src/SettingsHandler.h | 10 +- ESP32/src/TagHandler.h | 7 +- ESP32/src/WebHandler.h | 2 +- ESP32/src/main.cpp | 99 ++++- 29 files changed, 1273 insertions(+), 601 deletions(-) create mode 100644 ESP32/dataEdit/www/power.js create mode 100644 ESP32/src/PowerHandler.h diff --git a/ESP32/dataEdit/www/battery.js b/ESP32/dataEdit/www/battery.js index ee18f6e..d777401 100644 --- a/ESP32/dataEdit/www/battery.js +++ b/ESP32/dataEdit/www/battery.js @@ -35,7 +35,7 @@ function wsBatteryStatus(data) { var batteryCapacityRemainingPercentage = status["batteryCapacityRemainingPercentage"]; var batteryCapacityRemaining = status["batteryCapacityRemaining"]; var batteryTemperature = status["batteryTemperature"]; - + document.getElementById("batteryVoltage").value = batteryVoltage; document.getElementById("batteryCapacityRemaining").value = batteryCapacityRemaining; document.getElementById("batteryCapacityRemainingPercentage").value = batteryCapacityRemainingPercentage; @@ -55,7 +55,7 @@ function setBatterySettings() { userSettings["batteryCapacityMax"] = parseFloat(document.getElementById('batteryCapacityMax').value); setRestartRequired(); updateUserSettings(); -} +} function setBatteryFull() { sendWebsocketCommand("setBatteryFull"); } \ No newline at end of file diff --git a/ESP32/dataEdit/www/bldc-motor.js b/ESP32/dataEdit/www/bldc-motor.js index 00903bb..a1d5445 100644 --- a/ESP32/dataEdit/www/bldc-motor.js +++ b/ESP32/dataEdit/www/bldc-motor.js @@ -65,11 +65,11 @@ function updateBLDCSettings() { } function updateBLDCPins() { - if(upDateTimeout !== null) + if(upDateTimeout !== null) { clearTimeout(upDateTimeout); } - upDateTimeout = setTimeout(() => + upDateTimeout = setTimeout(() => { var pinValues = validateBLDCPins(); if(pinValues) { @@ -101,7 +101,7 @@ function getBLDCPinValues() { } function validateBLDCPins() { - clearErrors("pinValidation"); + clearErrors("pinValidation"); var assignedPins = []; var duplicatePins = []; var pwmErrors = []; @@ -125,7 +125,7 @@ function validateBLDCPins() { } } } - else + else { //assignedPins.push({name:"SPI1", pin:5}); assignedPins.push({name:"SPI CLK", pin:18}); @@ -143,7 +143,7 @@ function validateBLDCPins() { // } validatePin(pinValues.BLDC_Encoder_PIN, "Encoder", assignedPins, duplicatePins); - + // if(pinValues.BLDC_ChipSelect_PIN > -1) { // pinDupeIndex = assignedPins.findIndex(x => x.pin === pinValues.BLDC_ChipSelect_PIN); // if(pinDupeIndex > -1) @@ -199,7 +199,7 @@ function validateBLDCPins() { // } validatePin(pinValues.BLDC_HallEffect_PIN, "HallEffect", assignedPins, duplicatePins); } - + validateCommonPWMPins(assignedPins, duplicatePins, pinValues, pwmErrors); var invalidPins = []; @@ -217,10 +217,10 @@ function validateBLDCPins() { if (pwmErrors.length) { if(duplicatePins.length || invalidPins.length) { errorString += "
"; - } + } errorString += "
The following pins are invalid PWM pins:
"+pwmErrors.join("
")+"
"; } - + errorString += ""; showError(errorString); return undefined; diff --git a/ESP32/dataEdit/www/buttons.js b/ESP32/dataEdit/www/buttons.js index b7d72c9..ff70c3d 100644 --- a/ESP32/dataEdit/www/buttons.js +++ b/ESP32/dataEdit/www/buttons.js @@ -31,12 +31,12 @@ Buttons = { document.getElementById("buttonAnalogDebounce").value = buttonSettings["buttonAnalogDebounce"]; removeByClass("buttonSetRow"); buttonSettings["buttonSets"].forEach((buttonSet, setIndex) => { - + const buttons = buttonSet["buttons"]; //Main UI template const buttonSetsDiv = document.getElementById("buttonControls"); - + let buttonSetNameRow = Utils.createTextFormRow(0, "Name", 'buttonSetName'+setIndex, buttonSet.name, 25, function(setIndex) {this.update(setIndex)}.bind(this, setIndex)); buttonSetNameRow.input.setAttribute("readonly", true); let buttonSetPinRow = Utils.createNumericFormRow(0, "Pin", 'buttonSetPin'+setIndex, buttonSet.pin, -1, 255, function(setIndex) {this.update(setIndex)}.bind(this, setIndex)); @@ -72,7 +72,7 @@ Buttons = { buttonSetsDiv.appendChild(buttonSetPinRow.row); buttonSetsDiv.appendChild(buttonSetEditButton); - + //Modal Template var modalRootdiv = document.createElement("div"); modalRootdiv.classList.add("formTable"); @@ -100,7 +100,7 @@ Buttons = { }.bind(this, setIndex)); buttonSetPinRowEdit.input.required = true; buttonSetPinRowEdit.title = `The pin this button set is on` - + buttonTableDiv.appendChild(buttonSetNameRowEdit.row); buttonTableDiv.appendChild(buttonSetPinRowEdit.row); @@ -141,7 +141,7 @@ Buttons = { For example: '#motion-disable #resume #device-home #ok' NOTE: There is currently no way to delay between the command execution. ` - + modalParent.appendChild(buttonTable); buttonTable.appendChild(buttonTableDiv); modalParent.appendChild(span); @@ -166,7 +166,7 @@ Buttons = { buttonSettings["buttonSetsEnabled"] = setsEnabled; showRestartRequired(); } - + buttonSettings["bootButtonCommand"] = document.getElementById('bootButtonCommand').value.replace("\n", " "); if(validateIntControl("buttonAnalogDebounce", buttonSettings, "buttonAnalogDebounce")) { buttonSettings["buttonAnalogDebounce"] = parseInt(document.getElementById("buttonAnalogDebounce").value); @@ -211,7 +211,7 @@ Buttons = { modal.appendChild(this.templates[index]); this.setbuttonSet(index); const header = document.createElement("span"); - header.innerText = "Edit button set" + header.innerText = "Edit button set" header.setAttribute("slot", "title"); modal.appendChild(header); modal.show(); @@ -222,13 +222,13 @@ Buttons = { const buttonIndex = i; const button = buttons[i]; document.getElementById('buttonName'+setIndex+buttonIndex).value = button.name; - document.getElementById('buttonCommand'+setIndex+buttonIndex).value = button.command; + document.getElementById('buttonCommand'+setIndex+buttonIndex).value = button.command; // document.getElementById('buttonIndex'+setIndex+buttonIndex).value = button[i].index; }; }, updatebuttonSet(setIndex) { buttonSettings["buttonSets"][setIndex]["name"] = document.getElementById('buttonSetNameEdit'+setIndex).value; - buttonSettings["buttonSets"][setIndex]["pin"] = parseInt(document.getElementById('buttonSetPinEdit'+setIndex).value); + buttonSettings["buttonSets"][setIndex]["pin"] = parseInt(document.getElementById('buttonSetPinEdit'+setIndex).value); const buttons = buttonSettings["buttonSets"][setIndex]["buttons"]; for(var i = 0; i < buttons.length; i++) { const buttonIndex = i; @@ -236,17 +236,17 @@ Buttons = { const nameNode = document.getElementById('buttonName'+setIndex+buttonIndex); if(nameNode) { buttonSettings["buttonSets"][setIndex]["buttons"][i]["name"] = document.getElementById('buttonName'+setIndex+buttonIndex).value; - buttonSettings["buttonSets"][setIndex]["buttons"][i]["command"] = document.getElementById('buttonCommand'+setIndex+buttonIndex).value.replace("\n", " "); + buttonSettings["buttonSets"][setIndex]["buttons"][i]["command"] = document.getElementById('buttonCommand'+setIndex+buttonIndex).value.replace("\n", " "); } // document.getElementById('buttonIndex'+setIndex+buttonIndex).value = button[i].index; }; }, - + setButtonSetName(profileIndex) { if(this.setNameDebounce) { clearTimeout(this.setNameDebounce); } - + this.setNameDebounce = setTimeout(function(profileIndex) { if(validateStringControl("buttonSetName"+profileIndex, buttonSettings['buttonSets'][profileIndex], "name")) { //updateMotionProfileName(profileIndex); diff --git a/ESP32/dataEdit/www/esp-timer-setup.js b/ESP32/dataEdit/www/esp-timer-setup.js index 1d5f8c4..f52facf 100644 --- a/ESP32/dataEdit/www/esp-timer-setup.js +++ b/ESP32/dataEdit/www/esp-timer-setup.js @@ -49,7 +49,7 @@ ESPTimer = { } }, defaultDebounce); }.bind(this, timerObj, timerFrequencyRow); - + table.body.appendChild(timerFrequencyRow.row); } } diff --git a/ESP32/dataEdit/www/index.html b/ESP32/dataEdit/www/index.html index ad153da..774448d 100644 --- a/ESP32/dataEdit/www/index.html +++ b/ESP32/dataEdit/www/index.html @@ -9,7 +9,7 @@ - + @@ -19,6 +19,7 @@ +