Skip to content

Commit

Permalink
Merge pull request #456 from doudar/3-23-FIxes
Browse files Browse the repository at this point in the history
  • Loading branch information
doudar authored Feb 26, 2023
2 parents fd582f6 + 9020d85 commit ac7bdd7
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added battery monitoring of BLE devices by @Flo100. Implemented BLE HID shifting.
### Changed
-Disregard Peloton serial power and cadence if user has a BLE power Meter selected.
- Disregard Peloton serial power and cadence if user has a BLE power Meter selected.
- Filesystem no longer updates when auto-update is unchecked.
- Holding shifter buttons on boot now erases LittleFS as well as resetting settings.
- Fixed bug where "none" hr still scanned. Credit to @xpectnil for discovering.
- Simplified Platform Packages to work better with newest version of PlatformIO.
- Fixed broken images in wiki
- Fixed broken images in wiki.
- Valid files displayed on OTA page.
### Hardware
- Revised an old shifter cover for more options.
- Updated arm folder to procedurally generated arms ov various lengths.
Expand Down
3 changes: 0 additions & 3 deletions data/bluetoothscanner.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,8 @@ <h2>
anyOptionPM.text = 'any';
let anyOptionHR = document.createElement('option');
anyOptionHR.text = 'any';
let anyOptionRemote = document.createElement('option');
anyOptionRemote.text = 'any';
PMDropdown.add(anyOptionPM);
HRDropdown.add(anyOptionHR);
remoteDropdown.add(anyOptionRemote);
let noneOptionPM = document.createElement('option');
noneOptionPM.text = 'none';
let noneOptionHR = document.createElement('option');
Expand Down
1 change: 1 addition & 0 deletions include/Builtin_Pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ String OTAServerIndex = "<body style='font-family: Verdana,sans-serif; font-size
"<div style='width:100%;background-color:#e0e0e0;border-radius:8px;'>"
"<div id='prg' style='width:0%;background-color:#2196F3;padding:2px;border-radius:8px;color:white;text-align:center;'>0%</div>"
"</div>"
"<div>Valid files are firmware.bin or littlefs.bin</div>"
"</div>"
"</body>"
"<script>"
Expand Down
6 changes: 3 additions & 3 deletions include/SmartSpin_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ class userParameters {
bool logComm = false;
String ssid;
String password;
String connectedPowerMeter = "any";
String connectedHeartMonitor = "any";
String connectedRemote = "any";
String connectedPowerMeter = CONNECTED_POWER_METER;
String connectedHeartMonitor = CONNECTED_HEART_MONITOR;
String connectedRemote = CONNECTED_REMOTE;
String foundDevices = " ";

public:
Expand Down
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
#define BATTERY_UPDATE_INTERVAL_MILLIS 300000

// Initial and web scan duration.
#define DEFAULT_SCAN_DURATION 1
#define DEFAULT_SCAN_DURATION 10

// BLE automatic reconnect duration. Set this low to avoid interruption.
#define BLE_RECONNECT_SCAN_DURATION 1
Expand Down
19 changes: 11 additions & 8 deletions src/BLE_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ bool SpinBLEClient::connectToServer() {
SS2K_LOG(BLE_CLIENT_LOG_TAG, "%d left.", reconnectTries);
if (reconnectTries < 1) {
spinBLEClient.myBLEDevices[device_number].reset();
spinBLEClient.resetDevices(pClient);
spinBLEClient.resetDevices(pClient);
pClient->deleteServices();
pClient->disconnect();
NimBLEDevice::getScan()->erase(pClient->getPeerAddress());
Expand Down Expand Up @@ -310,14 +310,14 @@ bool SpinBLEClient::connectToServer() {
** Remove as you see fit for your needs */

void MyClientCallback::onConnect(NimBLEClient *pClient) {
// additional characteristic subscriptions.
spinBLEClient.handleBattInfo(pClient, true);
// additional characteristic subscriptions.
spinBLEClient.handleBattInfo(pClient, true);
}

void MyClientCallback::onDisconnect(NimBLEClient *pClient) {
NimBLEDevice::getScan()->stop();
//NimBLEDevice::getScan()->clearResults();
//NimBLEDevice::getScan()->clearDuplicateCache();
// NimBLEDevice::getScan()->clearResults();
// NimBLEDevice::getScan()->clearDuplicateCache();
SS2K_LOG(BLE_CLIENT_LOG_TAG, "Disconnect Called");
if (spinBLEClient.intentionalDisconnect) {
SS2K_LOG(BLE_CLIENT_LOG_TAG, "Intentional Disconnect");
Expand Down Expand Up @@ -474,7 +474,9 @@ void SpinBLEClient::scanProcess(int duration) {

String output;
serializeJson(devices, output);
SS2K_LOGW(BLE_CLIENT_LOG_TAG, "Bluetooth Client Found Devices: %s", output.c_str());
if (duration > BLE_RECONNECT_SCAN_DURATION) {
SS2K_LOG(BLE_CLIENT_LOG_TAG, "Bluetooth Client Found Devices: %s", output.c_str());
}
#ifdef USE_TELEGRAM
SEND_TO_TELEGRAM("Bluetooth Client Found Devices: " + output);
#endif
Expand Down Expand Up @@ -784,7 +786,7 @@ void SpinBLEAdvertisedDevice::reset() {
}
}
// Poll BLE devices for battCharacteristic if available and read value.
void SpinBLEClient::handleBattInfo(NimBLEClient *pClient, bool updateNow=false) {
void SpinBLEClient::handleBattInfo(NimBLEClient *pClient, bool updateNow = false) {
static unsigned long last_battery_update = 0;
if ((millis() - last_battery_update >= BATTERY_UPDATE_INTERVAL_MILLIS) || (last_battery_update == 0) || updateNow) {
last_battery_update = millis();
Expand All @@ -797,7 +799,8 @@ void SpinBLEClient::handleBattInfo(NimBLEClient *pClient, bool updateNow=false)
} else {
rtConfig.hr_batt.setValue(0);
}
} else if ((pClient->getService(CYCLINGPOWERMEASUREMENT_UUID) || pClient->getService(CYCLINGPOWERSERVICE_UUID)) && pClient->getService(BATTERYSERVICE_UUID)) { // get batterylevel at first connect
} else if ((pClient->getService(CYCLINGPOWERMEASUREMENT_UUID) || pClient->getService(CYCLINGPOWERSERVICE_UUID)) &&
pClient->getService(BATTERYSERVICE_UUID)) { // get batterylevel at first connect
BLERemoteCharacteristic *battCharacteristic = pClient->getService(BATTERYSERVICE_UUID)->getCharacteristic(BATTERYCHARACTERISTIC_UUID);
if (battCharacteristic != nullptr) {
std::string value = battCharacteristic->readValue();
Expand Down
11 changes: 5 additions & 6 deletions src/HTTP_Server_Basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ void HTTP_Server::start() {
"15 seconds.</body><script> setTimeout(\"location.href = 'http://" +
myIP.toString() + "/bluetoothscanner.html';\",15000);</script></html>";
// spinBLEClient.resetDevices();
// spinBLEClient.serverScan(true);
spinBLEClient.dontBlockScan = true;
spinBLEClient.scanProcess(DEFAULT_SCAN_DURATION);
server.send(200, "text/html", response);
});

Expand Down Expand Up @@ -333,7 +334,7 @@ void HTTP_Server::start() {
if (upload.status == UPLOAD_FILE_START) {
SS2K_LOG(HTTP_SERVER_LOG_TAG, "Update: %s", upload.filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS)) { // start with max
// available size
// available size
Update.printError(Serial);
}
} else if (upload.status == UPLOAD_FILE_WRITE) {
Expand All @@ -344,7 +345,7 @@ void HTTP_Server::start() {
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) { // true to set the size to the
// current progress
server.send(200, "text/plain", "Spiffs Uploaded Successfully. Rebooting...");
server.send(200, "text/plain", "Littlefs Uploaded Successfully. Rebooting...");
userConfig.saveToLittleFS();
userPWC.saveToLittleFS();
vTaskDelay(100);
Expand Down Expand Up @@ -615,8 +616,6 @@ void HTTP_Server::settingsProcessor() {
"Selections Saved!</h2></body><script> setTimeout(\"location.href "
"= 'http://" +
myIP.toString() + "/bluetoothscanner.html';\",1000);</script></html>";
// spinBLEClient.resetDevices();
// spinBLEClient.serverScan(true);
} else if (wasSettingsUpdate) { // Special Settings Page update response
response +=
"Network settings will be applied at next reboot. <br> Everything "
Expand Down Expand Up @@ -688,7 +687,7 @@ void HTTP_Server::FirmwareUpdate() {
Version availableVer(payload.c_str());
Version currentVer(FIRMWARE_VERSION);

if (((availableVer > currentVer) && (userConfig.getAutoUpdate())) || (updateAnyway)) {
if (((availableVer > currentVer) && (userConfig.getAutoUpdate())) || (updateAnyway)) {
SS2K_LOG(HTTP_SERVER_LOG_TAG, "New firmware detected!");
SS2K_LOG(HTTP_SERVER_LOG_TAG, "Upgrading from %s to %s", FIRMWARE_VERSION, payload.c_str());

Expand Down
1 change: 1 addition & 0 deletions src/SmartSpin_parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void userParameters::setDefaults() {
connectedPowerMeter = CONNECTED_POWER_METER;
connectedHeartMonitor = CONNECTED_HEART_MONITOR;
connectedRemote = CONNECTED_REMOTE;
foundDevices = " ";
maxWatts = DEFAULT_MAX_WATTS;
minWatts = DEFAULT_MIN_WATTS;
stepperDir = true;
Expand Down

0 comments on commit ac7bdd7

Please sign in to comment.