diff --git a/CHANGELOG.md b/CHANGELOG.md index 087ab411..12898e34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/include/settings.h b/include/settings.h index b8420fc7..f2e4ca3d 100644 --- a/include/settings.h +++ b/include/settings.h @@ -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 @@ -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 @@ -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. diff --git a/src/BLE_Client.cpp b/src/BLE_Client.cpp index 5f4d2950..f09977b0 100644 --- a/src/BLE_Client.cpp +++ b/src/BLE_Client.cpp @@ -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"); } } diff --git a/src/Main.cpp b/src/Main.cpp index fbba254b..55500ea4 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -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 @@ -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. @@ -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(); @@ -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; @@ -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 diff --git a/src/SmartSpin_parameters.cpp b/src/SmartSpin_parameters.cpp index 51b10fef..e113a0aa 100644 --- a/src/SmartSpin_parameters.cpp +++ b/src/SmartSpin_parameters.cpp @@ -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;