diff --git a/CHANGELOG.md b/CHANGELOG.md index c2d7261d..15272d08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +### Changed +- Added "Homing Sensitivity" so that the homing force value can be adjusted. +### Hardware + + +## [24.11.25] + +### Added + ### Changed ### Hardware diff --git a/Hardware/Common Assets/Bike Mount/CAD/IC4 Mount.AD_PRT b/Hardware/Common Assets/Bike Mount/CAD/IC4 Mount.AD_PRT new file mode 100644 index 00000000..1bde92dd Binary files /dev/null and b/Hardware/Common Assets/Bike Mount/CAD/IC4 Mount.AD_PRT differ diff --git a/include/BLE_Custom_Characteristic.h b/include/BLE_Custom_Characteristic.h index ce91a0be..21a5eb3a 100644 --- a/include/BLE_Custom_Characteristic.h +++ b/include/BLE_Custom_Characteristic.h @@ -60,6 +60,7 @@ const uint8_t BLE_simulatedTargetWatts = 0x28; // current target watts const uint8_t BLE_simulateTargetWatts = 0x29; // are we sending target watts const uint8_t BLE_hMin = 0x2A; // Minimum homing value const uint8_t BLE_hMax = 0x2B; // Maximum homing value +const uint8_t BLE_homingSensitivity = 0x2C; // Homing sensitivity value class BLE_ss2kCustomCharacteristic { public: diff --git a/include/SmartSpin_parameters.h b/include/SmartSpin_parameters.h index 7174ede9..befe8d77 100644 --- a/include/SmartSpin_parameters.h +++ b/include/SmartSpin_parameters.h @@ -123,11 +123,11 @@ class userParameters { int stepperSpeed; bool stepperDir; bool shifterDir; - bool udpLogEnabled = false; - int32_t hMin = INT32_MIN; - int32_t hMax = INT32_MIN; - + bool udpLogEnabled = false; + int32_t hMin = INT32_MIN; + int32_t hMax = INT32_MIN; bool FTMSControlPointWrite = false; + int homingSensitivity = DEFAULT_HOMING_SENSITIVITY; // Use default from settings.h String ssid; String password; String connectedPowerMeter = CONNECTED_POWER_METER; @@ -208,6 +208,9 @@ class userParameters { void setHMax(int32_t max) { hMax = max; } int32_t getHMax() { return hMax; } + void setHomingSensitivity(int sensitivity) { homingSensitivity = sensitivity; } + int getHomingSensitivity() { return homingSensitivity; } + void setDefaults(); String returnJSON(); void saveToLittleFS(); diff --git a/include/settings.h b/include/settings.h index 2a66d45a..51314d62 100644 --- a/include/settings.h +++ b/include/settings.h @@ -249,9 +249,9 @@ const char* const DEFAULT_PASSWORD = "password"; #endif // Max size of userconfig -#define USERCONFIG_JSON_SIZE 1524 + DEBUG_LOG_BUFFER_SIZE +#define USERCONFIG_JSON_SIZE 2000 + DEBUG_LOG_BUFFER_SIZE -#define RUNTIMECONFIG_JSON_SIZE 512 + DEBUG_LOG_BUFFER_SIZE +#define RUNTIMECONFIG_JSON_SIZE 1000 + DEBUG_LOG_BUFFER_SIZE // PowerTable Version #define TABLE_VERSION 5 @@ -308,11 +308,14 @@ const char* const DEFAULT_PASSWORD = "password"; // Initial and web scan duration. #define DEFAULT_SCAN_DURATION 5 +// Default homing sensitivity value +#define DEFAULT_HOMING_SENSITIVITY 50 + // BLE automatic reconnect duration. Set this low to avoid interruption. #define BLE_RECONNECT_SCAN_DURATION 5 // Task Stack Sizes -#define MAIN_STACK 6500 +#define MAIN_STACK 6500 #define BLE_CLIENT_STACK 6000 // Uncomment to enable stack size debugging info diff --git a/src/BLE_Custom_Characteristic.cpp b/src/BLE_Custom_Characteristic.cpp index 5a0f7204..69f2a89f 100644 --- a/src/BLE_Custom_Characteristic.cpp +++ b/src/BLE_Custom_Characteristic.cpp @@ -229,7 +229,7 @@ void BLE_ss2kCustomCharacteristic::process(std::string rxValue) { } break; case BLE_deviceName: // 0x07 - logBufLength = snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-deviceName"); + logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-deviceName"); if (rxValue[0] == cc_read) { returnValue[0] = cc_success; returnString = userConfig->getDeviceName(); @@ -740,6 +740,26 @@ void BLE_ss2kCustomCharacteristic::process(std::string rxValue) { logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", userConfig->getHMax()); } break; + + case BLE_homingSensitivity: // 0x2C + logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-homingSensitivity"); + if (rxValue[0] == cc_read) { + returnValue[0] = cc_success; + returnValue[2] = (uint8_t)(userConfig->getHomingSensitivity() & 0xff); + returnValue[3] = (uint8_t)(userConfig->getHomingSensitivity() >> 8); + returnLength += 2; + } + if (rxValue[0] == cc_write) { + returnValue[0] = cc_success; + userConfig->setHomingSensitivity(bytes_to_u16(rxValue[3], rxValue[2])); + logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "(%d)", userConfig->getHomingSensitivity()); + } + break; + + default: + logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-Unknown Characteristic"); + returnValue[0] = cc_error; + break; } SS2K_LOG(CUSTOM_CHAR_LOG_TAG, "%s", logBuf); @@ -895,10 +915,14 @@ void BLE_ss2kCustomCharacteristic::parseNemit() { BLE_ss2kCustomCharacteristic::notify(BLE_hMin); return; } - if (userConfig->getHMax() != _oldParams.getHMax()) { _oldParams.setHMax(userConfig->getHMax()); BLE_ss2kCustomCharacteristic::notify(BLE_hMax); return; } + if (userConfig->getHomingSensitivity() != _oldParams.getHomingSensitivity()) { + _oldParams.setHomingSensitivity(userConfig->getHomingSensitivity()); + BLE_ss2kCustomCharacteristic::notify(BLE_homingSensitivity); + return; + } } \ No newline at end of file diff --git a/src/Main.cpp b/src/Main.cpp index 49f80c72..197837b5 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -598,7 +598,7 @@ void SS2K::goHome(bool bothDirections) { userConfig->setHMax(INT32_MIN); return; } - stalled = (driver.SG_RESULT() < threshold - 50); + stalled = (driver.SG_RESULT() < threshold - userConfig->getHomingSensitivity()); } stepper->forceStop(); vTaskDelay(100 / portTICK_PERIOD_MS); @@ -627,7 +627,7 @@ void SS2K::goHome(bool bothDirections) { userConfig->setHMax(INT32_MIN); return; } - stalled = (driver.SG_RESULT() < threshold - 100); + stalled = (driver.SG_RESULT() < threshold - userConfig->getHomingSensitivity()); } stepper->forceStop(); fitnessMachineService.spinDown(0x02); diff --git a/src/SmartSpin_parameters.cpp b/src/SmartSpin_parameters.cpp index 913e0563..d44ed0f5 100644 --- a/src/SmartSpin_parameters.cpp +++ b/src/SmartSpin_parameters.cpp @@ -69,6 +69,7 @@ void userParameters::setDefaults() { udpLogEnabled = false; hMin = INT32_MIN; hMax = INT32_MIN; + homingSensitivity = DEFAULT_HOMING_SENSITIVITY; } //--------------------------------------------------------------------------------- @@ -104,6 +105,7 @@ String userParameters::returnJSON() { doc["udpLogEnabled"] = udpLogEnabled; doc["hMin"] = hMin; doc["hMax"] = hMax; + doc["homingSensitivity"] = homingSensitivity; String output; serializeJson(doc, output); @@ -154,6 +156,7 @@ void userParameters::saveToLittleFS() { doc["udpLogEnabled"] = udpLogEnabled; doc["hMin"] = hMin; doc["hMax"] = hMax; + doc["homingSensitivity"] = homingSensitivity; // Serialize JSON to file if (serializeJson(doc, file) == 0) { @@ -238,6 +241,9 @@ void userParameters::loadFromLittleFS() { if (!doc["hMax"].isNull()) { setHMax(doc["hMax"]); } + if (!doc["homingSensitivity"].isNull()) { + setHomingSensitivity(doc["homingSensitivity"]); + } SS2K_LOG(CONFIG_LOG_TAG, "Config File Loaded: %s", configFILENAME); file.close();