Skip to content

Commit

Permalink
Merge pull request #539 from doudar/ConfigApp
Browse files Browse the repository at this point in the history
Config app
  • Loading branch information
doudar authored Mar 17, 2024
2 parents 5bcaf4d + 51ac459 commit 571febd
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated WiFi connection setup.
- Firmware no longer updates if only the html files need to be loaded.
- BLE scans blocked during firmware upgrade.
- Increased the default incline multiplier to 5.
- Added more robust activity monitoring and reboot every 30 minutes if there is no activity.

### Hardware
- added Yesoul S3.
Expand Down
6 changes: 3 additions & 3 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// into actual stepper steps that move the stepper motor. It takes 2,181.76 steps to rotate the knob 1 full revolution. with hardware version 1.
// Incline_Multiplier may be able to be removed in the future by dividing ShiftSteps by ~200 to get this value but we're not quite ready
// to make that commitment yet.
#define INCLINE_MULTIPLIER 6.0
#define INCLINE_MULTIPLIER 5.0

// Minumum value for power correction factor user setting
#define MIN_PCF .5
Expand All @@ -61,7 +61,7 @@
#define DEFAULT_STEPPER_POWER 900

// Default Shift Step. The amount to move the stepper motor for a shift press.
#define DEFAULT_SHIFT_STEP 1000
#define DEFAULT_SHIFT_STEP 1200

// Stepper Acceleration in steps/s^2
#define STEPPER_ACCELERATION 3000
Expand Down Expand Up @@ -97,7 +97,7 @@

// Default Max Watts that the brake on the spin bike can absorb from the user.
// This is used to set the upper travel limit for the motor.
#define DEFAULT_MAX_WATTS 800
#define DEFAULT_MAX_WATTS 1400

// Minimum resistance on a Peloton Bike.
// This is used to set the lower travel limit for the motor.
Expand Down
3 changes: 3 additions & 0 deletions src/BLE_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,15 @@ void SpinBLEClient::keepAliveBLE_HID(NimBLEClient *pClient) {
void SpinBLEClient::checkBLEReconnect() {
if ((String(userConfig->getConnectedHeartMonitor()) != "none") && !(spinBLEClient.connectedHRM)) {
this->doScan = true;
SS2K_LOG(BLE_CLIENT_LOG_TAG,"No HRM Connected");
}
if ((String(userConfig->getConnectedPowerMeter()) != "none") && !(spinBLEClient.connectedPM)) {
this->doScan = true;
SS2K_LOG(BLE_CLIENT_LOG_TAG,"No PM Connected");
}
if ((String(userConfig->getConnectedRemote()) != "none") && !(spinBLEClient.connectedRemote)) {
this->doScan = true;
SS2K_LOG(BLE_CLIENT_LOG_TAG,"No Rem Connected");
}
}

Expand Down
54 changes: 38 additions & 16 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,19 @@ void SS2K::maintenanceLoop(void *pvParameters) {

while (true) {
vTaskDelay(73 / portTICK_RATE_MS);

// send BLE notification for any userConfig values that changed.
ss2kCustomCharacteristic::parseNemit();

// If we're in ERG mode, modify shift commands to inc/dec the target watts instead.
ss2k->FTMSModeShiftModifier();

// if this hardware version has serial pins, check and process their data.
if (currentBoard.auxSerialTxPin) {
ss2k->txSerial();
}

// Handle flag set for rebooting
if (ss2k->rebootFlag) {
static bool _loopOnce = false;
// Let the main task loop complete once before rebooting
Expand All @@ -216,25 +221,13 @@ void SS2K::maintenanceLoop(void *pvParameters) {
_loopOnce = true;
}

// Handle a flag set to reset SmartSpin2k to defaults
if (ss2k->resetDefaultsFlag) {
LittleFS.format();
userConfig->setDefaults();
userConfig->saveToLittleFS();
ss2k->resetDefaultsFlag = false;
ss2k->rebootFlag = true;
}

// reboot every half hour if not in use.
if ((millis() - rebootTimer) > 1800000) {
if (NimBLEDevice::getServer()) {
if (!(NimBLEDevice::getServer()->getConnectedCount())) {
SS2K_LOGW(MAIN_LOG_TAG, "Rebooting due to inactivity");
logHandler.writeLogs();
ss2k->rebootFlag = true;
} else {
rebootTimer = millis();
}
}
ss2k->rebootFlag = true;
}

// required to set a flag instead of directly calling the function for saving from BLE_Custom Characteristic.
Expand All @@ -244,6 +237,7 @@ void SS2K::maintenanceLoop(void *pvParameters) {
userPWC->saveToLittleFS();
}

// Things to do every two seconds
if ((millis() - intervalTimer) > 2003) { // add check here for when to restart WiFi
// maybe if in STA mode and 8.8.8.8 no ping return?
// ss2k->restartWifi();
Expand All @@ -252,8 +246,35 @@ void SS2K::maintenanceLoop(void *pvParameters) {
intervalTimer = millis();
}

// Things to do every 6 seconds
if ((millis() - intervalTimer2) > 6007) {
if (NimBLEDevice::getScan()->isScanning()) { // workaround to prevent occasional runaway scans
// reboot every half hour if not in use.
static int _oldHR = 0;
static int _oldWatts = 0;
static double _oldTargetIncline = 0;
static int _oldClientCount = 0;
if (_oldHR == rtConfig->hr.getValue() && _oldWatts == rtConfig->watts.getValue() && _oldTargetIncline == rtConfig->getTargetIncline() &&
_oldClientCount == NimBLEDevice::getServer()->getConnectedCount()) {
// Inactivity detected
if (((millis() - rebootTimer) > 1800000)) {
// Timer expired
SS2K_LOGW(MAIN_LOG_TAG, "Rebooting due to inactivity.");
ss2k->rebootFlag = true;
logHandler.writeLogs();
webSocketAppender.Loop();
}

} else {
// We have activity, update monitored values
_oldHR = rtConfig->hr.getValue();
_oldWatts = rtConfig->watts.getValue();
_oldTargetIncline = rtConfig->getTargetIncline();
_oldClientCount = NimBLEDevice::getServer()->getConnectedCount();
rebootTimer = millis();
}

// Prevent occasional runaway scans
if (NimBLEDevice::getScan()->isScanning()) {
if (isScanning == true) {
SS2K_LOGW(MAIN_LOG_TAG, "Forcing Scan to stop.");
spinBLEClient.doScan = false;
Expand All @@ -266,7 +287,8 @@ void SS2K::maintenanceLoop(void *pvParameters) {
intervalTimer2 = millis();
}

if (loopCounter > 10) {
// Things to do every 20 loops
if (loopCounter > 20) {
ss2k->checkDriverTemperature();

#ifdef DEBUG_STACK
Expand Down
2 changes: 1 addition & 1 deletion src/SmartSpin_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void userParameters::setDefaults() {
stealthChop = STEALTHCHOP;
stepperPower = DEFAULT_STEPPER_POWER;
stepperSpeed = DEFAULT_STEPPER_SPEED;
inclineMultiplier = 3.0;
inclineMultiplier = INCLINE_MULTIPLIER;
powerCorrectionFactor = 1.0;
ERGSensitivity = ERG_SENSITIVITY;
autoUpdate = AUTO_FIRMWARE_UPDATE;
Expand Down

0 comments on commit 571febd

Please sign in to comment.