Skip to content

Commit 8dd4f2d

Browse files
authored
Merge pull request #602 from doudar/Homing_Sensitivity
Added Homing Sensitivity
2 parents 1dc4a1b + c6ca432 commit 8dd4f2d

File tree

8 files changed

+57
-11
lines changed

8 files changed

+57
-11
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
### Changed
13+
- Added "Homing Sensitivity" so that the homing force value can be adjusted.
14+
### Hardware
15+
16+
17+
## [24.11.25]
18+
19+
### Added
20+
1221
### Changed
1322

1423
### Hardware
Binary file not shown.

include/BLE_Custom_Characteristic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const uint8_t BLE_simulatedTargetWatts = 0x28; // current target watts
6060
const uint8_t BLE_simulateTargetWatts = 0x29; // are we sending target watts
6161
const uint8_t BLE_hMin = 0x2A; // Minimum homing value
6262
const uint8_t BLE_hMax = 0x2B; // Maximum homing value
63+
const uint8_t BLE_homingSensitivity = 0x2C; // Homing sensitivity value
6364

6465
class BLE_ss2kCustomCharacteristic {
6566
public:

include/SmartSpin_parameters.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ class userParameters {
123123
int stepperSpeed;
124124
bool stepperDir;
125125
bool shifterDir;
126-
bool udpLogEnabled = false;
127-
int32_t hMin = INT32_MIN;
128-
int32_t hMax = INT32_MIN;
129-
126+
bool udpLogEnabled = false;
127+
int32_t hMin = INT32_MIN;
128+
int32_t hMax = INT32_MIN;
130129
bool FTMSControlPointWrite = false;
130+
int homingSensitivity = DEFAULT_HOMING_SENSITIVITY; // Use default from settings.h
131131
String ssid;
132132
String password;
133133
String connectedPowerMeter = CONNECTED_POWER_METER;
@@ -208,6 +208,9 @@ class userParameters {
208208
void setHMax(int32_t max) { hMax = max; }
209209
int32_t getHMax() { return hMax; }
210210

211+
void setHomingSensitivity(int sensitivity) { homingSensitivity = sensitivity; }
212+
int getHomingSensitivity() { return homingSensitivity; }
213+
211214
void setDefaults();
212215
String returnJSON();
213216
void saveToLittleFS();

include/settings.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ const char* const DEFAULT_PASSWORD = "password";
249249
#endif
250250

251251
// Max size of userconfig
252-
#define USERCONFIG_JSON_SIZE 1524 + DEBUG_LOG_BUFFER_SIZE
252+
#define USERCONFIG_JSON_SIZE 2000 + DEBUG_LOG_BUFFER_SIZE
253253

254-
#define RUNTIMECONFIG_JSON_SIZE 512 + DEBUG_LOG_BUFFER_SIZE
254+
#define RUNTIMECONFIG_JSON_SIZE 1000 + DEBUG_LOG_BUFFER_SIZE
255255

256256
// PowerTable Version
257257
#define TABLE_VERSION 5
@@ -308,11 +308,14 @@ const char* const DEFAULT_PASSWORD = "password";
308308
// Initial and web scan duration.
309309
#define DEFAULT_SCAN_DURATION 5
310310

311+
// Default homing sensitivity value
312+
#define DEFAULT_HOMING_SENSITIVITY 50
313+
311314
// BLE automatic reconnect duration. Set this low to avoid interruption.
312315
#define BLE_RECONNECT_SCAN_DURATION 5
313316

314317
// Task Stack Sizes
315-
#define MAIN_STACK 6500
318+
#define MAIN_STACK 6500
316319
#define BLE_CLIENT_STACK 6000
317320

318321
// Uncomment to enable stack size debugging info

src/BLE_Custom_Characteristic.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ void BLE_ss2kCustomCharacteristic::process(std::string rxValue) {
229229
} break;
230230

231231
case BLE_deviceName: // 0x07
232-
logBufLength = snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-deviceName");
232+
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-deviceName");
233233
if (rxValue[0] == cc_read) {
234234
returnValue[0] = cc_success;
235235
returnString = userConfig->getDeviceName();
@@ -740,6 +740,26 @@ void BLE_ss2kCustomCharacteristic::process(std::string rxValue) {
740740
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, " (%f)", userConfig->getHMax());
741741
}
742742
break;
743+
744+
case BLE_homingSensitivity: // 0x2C
745+
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-homingSensitivity");
746+
if (rxValue[0] == cc_read) {
747+
returnValue[0] = cc_success;
748+
returnValue[2] = (uint8_t)(userConfig->getHomingSensitivity() & 0xff);
749+
returnValue[3] = (uint8_t)(userConfig->getHomingSensitivity() >> 8);
750+
returnLength += 2;
751+
}
752+
if (rxValue[0] == cc_write) {
753+
returnValue[0] = cc_success;
754+
userConfig->setHomingSensitivity(bytes_to_u16(rxValue[3], rxValue[2]));
755+
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "(%d)", userConfig->getHomingSensitivity());
756+
}
757+
break;
758+
759+
default:
760+
logBufLength += snprintf(logBuf + logBufLength, kLogBufCapacity - logBufLength, "<-Unknown Characteristic");
761+
returnValue[0] = cc_error;
762+
break;
743763
}
744764

745765
SS2K_LOG(CUSTOM_CHAR_LOG_TAG, "%s", logBuf);
@@ -895,10 +915,14 @@ void BLE_ss2kCustomCharacteristic::parseNemit() {
895915
BLE_ss2kCustomCharacteristic::notify(BLE_hMin);
896916
return;
897917
}
898-
899918
if (userConfig->getHMax() != _oldParams.getHMax()) {
900919
_oldParams.setHMax(userConfig->getHMax());
901920
BLE_ss2kCustomCharacteristic::notify(BLE_hMax);
902921
return;
903922
}
923+
if (userConfig->getHomingSensitivity() != _oldParams.getHomingSensitivity()) {
924+
_oldParams.setHomingSensitivity(userConfig->getHomingSensitivity());
925+
BLE_ss2kCustomCharacteristic::notify(BLE_homingSensitivity);
926+
return;
927+
}
904928
}

src/Main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ void SS2K::goHome(bool bothDirections) {
598598
userConfig->setHMax(INT32_MIN);
599599
return;
600600
}
601-
stalled = (driver.SG_RESULT() < threshold - 50);
601+
stalled = (driver.SG_RESULT() < threshold - userConfig->getHomingSensitivity());
602602
}
603603
stepper->forceStop();
604604
vTaskDelay(100 / portTICK_PERIOD_MS);
@@ -627,7 +627,7 @@ void SS2K::goHome(bool bothDirections) {
627627
userConfig->setHMax(INT32_MIN);
628628
return;
629629
}
630-
stalled = (driver.SG_RESULT() < threshold - 100);
630+
stalled = (driver.SG_RESULT() < threshold - userConfig->getHomingSensitivity());
631631
}
632632
stepper->forceStop();
633633
fitnessMachineService.spinDown(0x02);

src/SmartSpin_parameters.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void userParameters::setDefaults() {
6969
udpLogEnabled = false;
7070
hMin = INT32_MIN;
7171
hMax = INT32_MIN;
72+
homingSensitivity = DEFAULT_HOMING_SENSITIVITY;
7273
}
7374

7475
//---------------------------------------------------------------------------------
@@ -104,6 +105,7 @@ String userParameters::returnJSON() {
104105
doc["udpLogEnabled"] = udpLogEnabled;
105106
doc["hMin"] = hMin;
106107
doc["hMax"] = hMax;
108+
doc["homingSensitivity"] = homingSensitivity;
107109

108110
String output;
109111
serializeJson(doc, output);
@@ -154,6 +156,7 @@ void userParameters::saveToLittleFS() {
154156
doc["udpLogEnabled"] = udpLogEnabled;
155157
doc["hMin"] = hMin;
156158
doc["hMax"] = hMax;
159+
doc["homingSensitivity"] = homingSensitivity;
157160

158161
// Serialize JSON to file
159162
if (serializeJson(doc, file) == 0) {
@@ -238,6 +241,9 @@ void userParameters::loadFromLittleFS() {
238241
if (!doc["hMax"].isNull()) {
239242
setHMax(doc["hMax"]);
240243
}
244+
if (!doc["homingSensitivity"].isNull()) {
245+
setHomingSensitivity(doc["homingSensitivity"]);
246+
}
241247

242248
SS2K_LOG(CONFIG_LOG_TAG, "Config File Loaded: %s", configFILENAME);
243249
file.close();

0 commit comments

Comments
 (0)