Skip to content

Commit

Permalink
added homingSensitivy to the web settings
Browse files Browse the repository at this point in the history
  • Loading branch information
doudar committed Dec 16, 2024
1 parent a558196 commit d0cd20a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 48 deletions.
20 changes: 17 additions & 3 deletions data/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ <h2 id="simulation-header">Main Settings</h2>
</div>
</div>

<div class="setting-group">
<label for="homingSensitivity" class="setting-label tooltip">
Homing Force
<span class="tooltiptext">Decrease if the SmartSpin2k grinds during homing.</span>
</label>
<div class="slider-group">
<button type="button" onclick="clickStep(document.getElementById('homingSensitivity'), '-')" class="adjust-button"></button>
<div class="slider-container">
<output id="homingSensitivityValue">0</output>
<input type="range" id="homingSensitivity" name="homingSensitivity" min="10" max="100" value="0" step="1"
onchange="updateSliderAndSend(this, document.getElementById('homingSensitivityValue'))">
</div>
<button type="button" onclick="clickStep(document.getElementById('homingSensitivity'), '+')" class="adjust-button">+</button>
</div>
</div>

<div class="setting-group">
<label for="minWatts" class="setting-label tooltip">
Min Brake Watts
Expand Down Expand Up @@ -204,7 +220,7 @@ <h2 id="system-header">System Settings</h2>
<div class="setting-group">
<label class="setting-label tooltip">
UDP Logging
<span class="tooltiptext">Send log-messages via UDP Port 10.000</span>
<span class="tooltiptext">Send log-messages via UDP Port 10000</span>
</label>
<label class="switch">
<input type="checkbox" name="udpLogEnabled" id="udpLogEnabled" onchange="sendSetting(this)">
Expand Down Expand Up @@ -343,8 +359,6 @@ <h2>Reset to Defaults?</h2>
params.append(element.name, element.value);
}

params.append('shiftStep', document.getElementById('shiftStep').value);

['stealthChop', 'autoUpdate', 'stepperDir', 'shifterDir', 'udpLogEnabled'].forEach(id => {
if (document.getElementById(id).checked) {
params.append(id, 'true');
Expand Down
52 changes: 7 additions & 45 deletions src/SmartSpin_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,43 +125,12 @@ void userParameters::saveToLittleFS() {
return;
}

// Allocate a temporary JsonDocument
// Don't forget to change the capacity to match your requirements.
// Use arduinojson.org/assistant to compute the capacity.
DynamicJsonDocument doc(USERCONFIG_JSON_SIZE);

// Set the values in the document
// commented items are not needed in save file

doc["firmwareUpdateURL"] = firmwareUpdateURL;
doc["deviceName"] = deviceName;
doc["shiftStep"] = shiftStep;
doc["stepperPower"] = stepperPower;
doc["stepperSpeed"] = stepperSpeed;
doc["stealthChop"] = stealthChop;
doc["inclineMultiplier"] = inclineMultiplier;
doc["powerCorrectionFactor"] = powerCorrectionFactor;
doc["ERGSensitivity"] = ERGSensitivity;
doc["autoUpdate"] = autoUpdate;
doc["ssid"] = ssid;
doc["password"] = password;
doc["connectedPowerMeter"] = connectedPowerMeter;
doc["connectedHeartMonitor"] = connectedHeartMonitor;
doc["connectedRemote"] = connectedRemote;
// doc["foundDevices"] = foundDevices;
doc["maxWatts"] = maxWatts;
doc["minWatts"] = minWatts;
doc["shifterDir"] = shifterDir;
doc["stepperDir"] = stepperDir;
doc["udpLogEnabled"] = udpLogEnabled;
doc["hMin"] = hMin;
doc["hMax"] = hMax;
doc["homingSensitivity"] = homingSensitivity;

// Serialize JSON to file
if (serializeJson(doc, file) == 0) {
// Get JSON string from returnJSON() and write to file
String jsonStr = returnJSON();
if (file.print(jsonStr) == 0) {
SS2K_LOG(CONFIG_LOG_TAG, "Failed to write to file");
}

// Close the file
file.close();
}
Expand Down Expand Up @@ -300,16 +269,9 @@ void physicalWorkingCapacity::saveToLittleFS() {
return;
}

StaticJsonDocument<500> doc;

doc["session1HR"] = session1HR;
doc["session1Pwr"] = session1Pwr;
doc["session2HR"] = session2HR;
doc["session2Pwr"] = session2Pwr;
doc["hr2Pwr"] = hr2Pwr;

// Serialize JSON to file
if (serializeJson(doc, file) == 0) {
// Get JSON string from returnJSON() and write to file
String jsonStr = returnJSON();
if (file.print(jsonStr) == 0) {
SS2K_LOG(CONFIG_LOG_TAG, "Failed to write to file");
}
// Close the file
Expand Down
7 changes: 7 additions & 0 deletions src/http/HTTPSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ void HTTPSettings::processERGSettings(WebServer& server) {
}
}

if (!server.arg("homingSensitivity").isEmpty()) {
int homingSensitivity = server.arg("homingSensitivity").toInt();
if (homingSensitivity >= 10 && homingSensitivity <= 100) {
userConfig->setHomingSensitivity(homingSensitivity);
}
}

if (!server.arg("inclineMultiplier").isEmpty()) {
float inclineMultiplier = server.arg("inclineMultiplier").toFloat();
if (inclineMultiplier >= 0 && inclineMultiplier <= 10) {
Expand Down

0 comments on commit d0cd20a

Please sign in to comment.