Skip to content

Commit

Permalink
Merge pull request #252 from doudar/december21Updates
Browse files Browse the repository at this point in the history
December21 updates
  • Loading branch information
doudar authored Nov 24, 2021
2 parents 9287a7c + 960d838 commit a20d101
Show file tree
Hide file tree
Showing 21 changed files with 638 additions and 132 deletions.
40 changes: 40 additions & 0 deletions .pre-commit-config.oldyaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
exclude: (\.pio|lib/NimBLE-Arduino|lib/ArduinoCompat)/.*
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.9
hooks:
- id: insert-license
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
args:
- --license-filepath
- license_header.txt
- --comment-style
- /*| *| */
- repo: local
hooks:
- id: docker-validate-changelog
name: validate-changelog
description: Validate the `CHANGELOG.md` file
files: CHANGELOG\.md$
pass_filenames: false
language: docker_image
entry: kadaan/parse_a_changelog:latest
- id: docker-clang-format
name: clang-format
description: Run `clang-format` against C/C++ header and source files in Docker container
language: docker_image
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
entry: daverona/pre-commit-cpp:0.8.0 clang-format -i -style=file
- id: docker-cpplint
name: cpplint
description: Run `cpplint` against C/C++ header and source files in Docker container
language: docker_image
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
entry: daverona/pre-commit-cpp:0.8.0 cpplint
- id: docker-pio
name: pio
description: Run platformio check, test, and build C/C++ source files in Docker container
language: docker_image
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
pass_filenames: false
entry: kadaan/platformio_esp32:latest --check --test=native
24 changes: 12 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
exclude: (\.pio|lib/NimBLE-Arduino|lib/ArduinoCompat)/.*
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.9
hooks:
- id: insert-license
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
args:
- --license-filepath
- license_header.txt
- --comment-style
- /*| *| */
exclude: (\.pio|lib/NimBLE-Arduino|lib/ArduinoCompat)/.*
repos:
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.9
hooks:
- id: insert-license
files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$
args:
- --license-filepath
- license_header.txt
- --comment-style
- /*| *| */
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Moved FTMS callback decoding outside of the callback.
- Revamped the way notify buffer works as it was causing a memory leak.
- BLE Custom Characteristic motor driver calls now apply settings received.
- Motor current now automatically scales if ESP32 temp starts getting too high.
- Added comments after compiler #endif Statements to make it easier to see what the partner #if statement is.
Expand Down
2 changes: 1 addition & 1 deletion data/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h2>
if (document.getElementById("ssid").value == "loading") {
requestConfigValues();
}
}, 1000);
}, 1500);
}

function requestConfigValues() {
Expand Down
2 changes: 1 addition & 1 deletion data/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ <h2>
if (updateTimer === undefined) {
updateTimer = setInterval(function () {
requestConfigValues();
}, 1000);
}, 1500);
}
}

Expand Down
31 changes: 17 additions & 14 deletions include/BLE_Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void BLECommunications(void *pvParameters);

extern int bleConnDesc;
extern bool updateConnParametersFlag;
extern std::string FTMSWrite;

// TODO add the rest of the server to this class
class SpinBLEServer {
Expand All @@ -86,6 +87,7 @@ void calculateInstPwrFromHR();
void updateHeartRateMeasurementChar();
int connectedClientCount();
void controlPointIndicate();
void processFTMSWrite();

class MyServerCallbacks : public BLEServerCallbacks {
void onConnect(BLEServer *, ble_gap_conn_desc *desc);
Expand Down Expand Up @@ -114,12 +116,16 @@ void bleClientTask(void *pvParameters);
// CYCLINGPOWERMEASUREMENT_UUID, HEARTCHARACTERISTIC_UUID,
// FLYWHEEL_UART_TX_UUID};

typedef struct DataHandle {
uint8_t *data;
typedef struct NotifyData {
uint8_t data[25];
size_t length;
} DataHandle_t;
} NotifyData;

class SpinBLEAdvertisedDevice {
private:
QueueHandle_t dataBufferQueue = nullptr;


public: // eventually these should be made private
// // TODO: Do we dispose of this object? Is so, we need to de-allocate the queue.
// // This distructor was called too early and the queue was deleted out from
Expand All @@ -133,6 +139,9 @@ class SpinBLEAdvertisedDevice {

NimBLEAdvertisedDevice *advertisedDevice = nullptr;
NimBLEAddress peerAddress;



int connectedClientID = BLE_HS_CONN_HANDLE_NONE;
BLEUUID serviceUUID = (uint16_t)0x0000;
BLEUUID charUUID = (uint16_t)0x0000;
Expand All @@ -148,8 +157,7 @@ class SpinBLEAdvertisedDevice {
connectedClientID = id;
serviceUUID = BLEUUID(inserviceUUID);
charUUID = BLEUUID(incharUUID);
// dataBuffer = xQueueCreate((4), // length
// sizeof(uint8_t *)); // size
dataBufferQueue = xQueueCreate(6, sizeof(NotifyData));
}

void reset() {
Expand All @@ -163,20 +171,15 @@ class SpinBLEAdvertisedDevice {
userSelectedCSC = false; // Cycling Speed/Cadence
userSelectedCT = false; // Controllable Trainer
doConnect = false; // Initiate connection flag
if (dataBuffer != nullptr) {
if (dataBufferQueue != nullptr) {
Serial.println("Resetting queue");
xQueueReset(dataBuffer);
xQueueReset(dataBufferQueue);
}
}

void print();

bool enqueueData(uint8_t *data, size_t length);
std::shared_ptr<DataHandle_t> dequeueData();
static void deletePayload(DataHandle_t *data);

private:
QueueHandle_t dataBuffer = nullptr;
bool enqueueData(uint8_t data[25], size_t length);
NotifyData dequeueData();
};

class SpinBLEClient {
Expand Down
8 changes: 1 addition & 7 deletions include/SS2KLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define DEBUG_INFO_LOG_TAG "DebugInfo"

#ifndef DEBUG_LOG_BUFFER_SIZE
#define DEBUG_LOG_BUFFER_SIZE 1000
#define DEBUG_LOG_BUFFER_SIZE 1500
#endif

#ifndef DEBUG_FILE_CHARS_PER_LINE
Expand Down Expand Up @@ -99,13 +99,7 @@ void ss2k_remove_newlines(std::string *str);

int ss2k_log_hex_to_buffer(const byte *data, const size_t data_length, char *buffer, const int buffer_offset, const size_t buffer_length);

void ss2k_log_file(const char *tag, File file);

void ss2k_log_write(esp_log_level_t level, const char *format, ...);

void ss2k_log_writev(esp_log_level_t level, const char *format, va_list args);

#define SS2K_LOG_FILE(tag, file) \
do { \
ss2k_log_file(tag, file); \
} while (0)
12 changes: 6 additions & 6 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

// Multiple to apply in ERG mode when within the watts range of 1 shift. It may be desirable to make this value less than 1 to prevent oscillating around the
// target watt point.
#define SUB_SHIFT_SCALE 1
#define SUB_SHIFT_SCALE .5

// Hardware pin for rocker Switch
#define RADIO_PIN 27
Expand Down Expand Up @@ -116,7 +116,7 @@
#define MAX_SCAN_RETRIES 1

// loop speed for the SmartSpin2k BLE communications
#define BLE_NOTIFY_DELAY 999
#define BLE_NOTIFY_DELAY 701

// loop speed for the SmartSpin2k BLE Client reconnect
#define BLE_CLIENT_DELAY 1000
Expand All @@ -125,7 +125,7 @@
#define NUM_BLE_DEVICES 4

// loop speed for the Webserver
#define WEBSERVER_DELAY 30
#define WEBSERVER_DELAY 60

// Name of default Power Meter. any connects to anything, none connects to
// nothing.
Expand All @@ -150,18 +150,18 @@

// Uncomment to enable sending Telegram debug messages back to the chat
// specified in telegram_token.h
#define USE_TELEGRAM
// #define USE_TELEGRAM

// Uncomment to enable stack size debugging info
// #define DEBUG_STACK
//#define DEBUG_STACK

// Uncomment to enable HR->PWR debugging info. Always displays HR->PWR
// Calculation. Never sets userConfig.setSimulatedPower(); #define
// DEBUG_HR_TO_PWR

#ifdef USE_TELEGRAM
// Max number of telegram messages to send per session
#define MAX_TELEGRAM_MESSAGES 5
#define MAX_TELEGRAM_MESSAGES 1
// Filler definitions for if telegram_token.h is not included (because it has
// sensitive information). Do not change these as this file is tracked and
// therefore public. Enter your own Telegram info into telegram_token.h
Expand Down
4 changes: 2 additions & 2 deletions lib/SS2K/src/sensors/CyclePowerData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "Data.h"
#include <os/endian.h>
#include "endian.h"
#include "sensors/CyclePowerData.h"

bool CyclePowerData::hasHeartRate() { return false; }
Expand All @@ -27,7 +27,7 @@ float CyclePowerData::getSpeed() { return nanf(""); }

void CyclePowerData::decode(uint8_t *data, size_t length) {
uint8_t flags = data[0];
int cPos = 2; // lowest position cadence could ever be
int cPos = 2; // lowest position power could ever be
// Instantaneous power is always present. Do that first.
// first calculate which fields are present. Power is always 2 & 3, cadence
// can move depending on the flags.
Expand Down
2 changes: 1 addition & 1 deletion lib/SS2K/src/sensors/FitnessMachineIndoorBikeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "Data.h"
#include "os/endian.h"
#include "endian.h"
#include "sensors/FitnessMachineIndoorBikeData.h"

// See:
Expand Down
2 changes: 1 addition & 1 deletion lib/SS2K/src/sensors/FlywheelData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* SPDX-License-Identifier: GPL-2.0-only
*/

#include "os/endian.h"
#include "endian.h"
#include "sensors/FlywheelData.h"

bool FlywheelData::hasHeartRate() { return false; }
Expand Down
Loading

0 comments on commit a20d101

Please sign in to comment.