Skip to content

Commit

Permalink
Merge pull request #583 from doudar/Zwift_Gear_UI
Browse files Browse the repository at this point in the history
Zwift gear UI
  • Loading branch information
doudar authored Nov 5, 2024
2 parents dfd1449 + e5ab1d6 commit a358091
Show file tree
Hide file tree
Showing 20 changed files with 594 additions and 187 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Update Changelog

on:
pull_request:
branches:
- develop
types: [opened, synchronize, reopened]

jobs:
update-changelog:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Update Changelog
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")
echo "Latest tag: $LATEST_TAG"
if ! grep -q "## \[Unreleased\]" CHANGELOG.md; then
echo "No [Unreleased] section found"
exit 0
fi
FIRST_VERSION=$(grep -oP "## \[\K[0-9]+\.[0-9]+\.[0-9]+" CHANGELOG.md | head -1 || echo "0.0.0")
if [ "$LATEST_TAG" = "$FIRST_VERSION" ]; then
echo "Latest tag matches first version in changelog"
exit 0
fi
# Create temporary files
echo -e "# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [Unreleased]\n\n### Added\n\n### Changed\n\n### Hardware\n" > header.tmp
# Update the old unreleased section
sed "0,/## \[Unreleased\]/s/## \[Unreleased\]/## [$LATEST_TAG]/" CHANGELOG.md | tail -n +7 > content.tmp
# Combine files
cat header.tmp content.tmp > CHANGELOG.md
rm header.tmp content.tmp
if git diff --quiet CHANGELOG.md; then
echo "No changes to commit"
exit 0
fi
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -m "Update changelog for version $LATEST_TAG"
git push
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Knob homing if calibrate trainer is selected in an app.

### Changed

### Hardware

## [24.10.30]

### Added

- Added pass through shifting in both ERG and SIM mode.
- Refined and added BLE custom characteristics for upcoming configuration app.
- Added CSC Service to BLE server.
- Added Yosuda-007C.
- Updated wiki banner.
- Added automatic update of Changelog sections on pull request to develop.
- Added support for the Zwift gear display.

### Changed

Expand Down Expand Up @@ -55,7 +66,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a final test to check if ERG mode has commanded a move in the proper direction.
- Aligned the values between the config app and web interface.
- Added ability to send target watts through the custom characteristic.
- Added a final test to check if ERG mode has commanded a move in the proper direction.
- Added a final test to check if ERG mode has commanded a move in the proper direction.
- Cleaned up targetPosition to make it easier to understand.

### Hardware

Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# You can now visit us at [Facebook](https://www.facebook.com/groups/716297469953492/)
# There's now a companion App!

A brand new shiny Companion app for SmartSpin2k is availiable! [SS2kConfigApp](https://github.com/doudar/SS2kConfigApp/tree/develop) (Google Play Store Coming Soon).
A brand new shiny Companion app for SmartSpin2k is availiable! [SS2kConfigApp](https://github.com/doudar/SS2kConfigApp/tree/develop)

You can get it from the Apple App Store here:

Expand All @@ -21,8 +21,6 @@ You can get it from the Apple App Store here:

</div>

If you have Android, it will be on the Play Store soon, but in the meantime, you can side load it using the .apk (located in the .zip) in the releases section of the repository: [SS2kConfigApp](https://github.com/doudar/SS2kConfigApp/releases)

# About
SmartSpin2k is a DIY project that allows you to turn any spin bike into a smart trainer. With SmartSpin2k, you can connect your spin bike to Zwift, TrainerRoad, or other popular training apps. This allows you to control your bike's resistance automatically, track your performance, and compete with other riders online.

Expand Down
21 changes: 11 additions & 10 deletions include/BLE_Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

#pragma once

// #define CONFIG_SW_COEXIST_ENABLE 1

#include <memory>
#include <NimBLEDevice.h>
#include <memory>
#include <Arduino.h>
#include <queue>
#include <deque>
#include "Main.h"
#include "BLE_Definitions.h"
#include "BLE_Wattbike_Service.h"

#define BLE_CLIENT_LOG_TAG "BLE_Client"
#define BLE_COMMON_LOG_TAG "BLE_Common"
Expand Down Expand Up @@ -44,12 +43,6 @@ class MyServerCallbacks : public NimBLEServerCallbacks {
bool onConnParamsUpdateRequest(NimBLEClient *pClient, const ble_gap_upd_params *params);
};

class MyCallbacks : public NimBLECharacteristicCallbacks {
public:
void onWrite(BLECharacteristic *);
void onSubscribe(NimBLECharacteristic *pCharacteristic, ble_gap_conn_desc *desc, uint16_t subValue);
};

// TODO add the rest of the server to this class
class SpinBLEServer {
private:
Expand All @@ -62,6 +55,7 @@ class SpinBLEServer {
bool IndoorBikeData : 1;
bool CyclingSpeedCadence : 1;
} clientSubscribed;
int spinDownFlag = 0;
NimBLEServer *pServer = nullptr;
void setClientSubscribed(NimBLEUUID pUUID, bool subscribe);
void notifyShift();
Expand All @@ -72,7 +66,14 @@ class SpinBLEServer {
SpinBLEServer() { memset(&clientSubscribed, 0, sizeof(clientSubscribed)); }
};

class MyCallbacks : public NimBLECharacteristicCallbacks {
public:
void onWrite(BLECharacteristic *);
void onSubscribe(NimBLECharacteristic *pCharacteristic, ble_gap_conn_desc *desc, uint16_t subValue);
};

extern SpinBLEServer spinBLEServer;
extern BLE_Wattbike_Service wattbikeService;

void startBLEServer();
void logCharacteristic(char *buffer, const size_t bufferCapacity, const byte *data, const size_t dataLength, const NimBLEUUID serviceUUID, const NimBLEUUID charUUID,
Expand Down Expand Up @@ -199,4 +200,4 @@ class MyClientCallback : public NimBLEClientCallbacks {
void onAuthenticationComplete(ble_gap_conn_desc);
};

extern SpinBLEClient spinBLEClient;
extern SpinBLEClient spinBLEClient;
4 changes: 3 additions & 1 deletion include/BLE_Custom_Characteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const uint8_t BLE_resetPowerTable = 0x26; // Delete all power table infor
const uint8_t BLE_powerTableData = 0x27; // sets or requests power table data
const uint8_t BLE_simulatedTargetWatts = 0x28; // current target watts
const uint8_t BLE_simulateTargetWatts = 0x29; // are we sending target watts
const uint8_t BLE_hMin = 0x2A; // Minimum homing value
const uint8_t BLE_hMax = 0x2B; // Maximum homing value

class BLE_ss2kCustomCharacteristic {
public:
Expand All @@ -79,4 +81,4 @@ class BLE_ss2kCustomCharacteristic {
class ss2kCustomCharacteristicCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *);
void onSubscribe(NimBLECharacteristic *pCharacteristic, ble_gap_conn_desc *desc, uint16_t subValue);
};
};
6 changes: 4 additions & 2 deletions include/BLE_Fitness_Machine_Service.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BLE_Fitness_Machine_Service {
BLE_Fitness_Machine_Service();
void setupService(NimBLEServer *pServer, MyCallbacks *chrCallbacks);
void update();
bool spinDown();

private:
BLEService *pFitnessMachineService;
Expand All @@ -27,6 +28,7 @@ class BLE_Fitness_Machine_Service {
BLECharacteristic *fitnessMachineInclinationRange;
BLECharacteristic *fitnessMachineTrainingStatus;
uint8_t ftmsIndoorBikeData[11] = {0};
bool spinDown();
void processFTMSWrite();
};
};

extern BLE_Fitness_Machine_Service fitnessMachineService;
23 changes: 23 additions & 0 deletions include/BLE_Wattbike_Service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#pragma once

#include <NimBLEDevice.h>

class BLE_Wattbike_Service {
public:
BLE_Wattbike_Service();
void setupService(NimBLEServer *pServer);
void update();
void parseNemit();

private:
NimBLEService *pWattbikeService;
NimBLECharacteristic *wattbikeReadCharacteristic;
NimBLECharacteristic *wattbikeWriteCharacteristic;
};
18 changes: 14 additions & 4 deletions include/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class SS2K {
int shiftersHoldForScan;
uint64_t scanDelayTime;
uint64_t scanDelayStart;

public:
int32_t targetPosition;
int32_t currentPosition;

public:
bool stepperIsRunning;
bool externalControl;
bool syncMode;
Expand All @@ -47,12 +47,21 @@ class SS2K {
static void IRAM_ATTR shiftUp();
static void IRAM_ATTR shiftDown();
static void moveStepper();

// the position the stepper motor will move to
int32_t getTargetPosition() { return targetPosition; }
void setTargetPosition(int32_t tp) { targetPosition = tp; }

// the position the stepper motor is currently at
int32_t getCurrentPosition() { return currentPosition; }
void setCurrentPosition(int32_t cp) { currentPosition = cp; }

void resetIfShiftersHeld();
void startTasks();
void stopTasks();
void restartWifi();
void setupTMCStepperDriver();
void updateStepperPower();
void setupTMCStepperDriver(bool reset = false);
void updateStepperPower(int pwr = 0);
void updateStealthChop();
void updateStepperSpeed(int speed = 0);
void checkDriverTemperature();
Expand All @@ -61,6 +70,7 @@ class SS2K {
static void rxSerial(void);
void txSerial();
void pelotonConnected();
void goHome(bool bothDirections = false);

SS2K() {
targetPosition = 0;
Expand Down
24 changes: 16 additions & 8 deletions include/SmartSpin_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class Measurement {

class RuntimeParameters {
private:
double targetIncline = 0.0;
double currentIncline = 0.0;
double targetIncline = 0.0;
float simulatedSpeed = 0.0;
uint8_t FTMSMode = 0x00;
int shifterPosition = 0;
int32_t minStep = -DEFAULT_STEPPER_TRAVEL;
int32_t maxStep = DEFAULT_STEPPER_TRAVEL;
bool homed = false;
int32_t minStep = -DEFAULT_STEPPER_TRAVEL;
int32_t maxStep = DEFAULT_STEPPER_TRAVEL;
int minResistance = -DEFAULT_RESISTANCE_RANGE;
int maxResistance = DEFAULT_RESISTANCE_RANGE;
bool simTargetWatts = false;
Expand All @@ -77,9 +77,6 @@ class RuntimeParameters {
void setTargetIncline(float inc) { targetIncline = inc; }
float getTargetIncline() { return targetIncline; }

void setCurrentIncline(float inc) { currentIncline = inc; }
float getCurrentIncline() { return currentIncline; }

void setSimulatedSpeed(float spd) { simulatedSpeed = spd; }
float getSimulatedSpeed() { return simulatedSpeed; }

Expand All @@ -89,6 +86,9 @@ class RuntimeParameters {
void setShifterPosition(int sp) { shifterPosition = sp; }
int getShifterPosition() { return shifterPosition; }

void setHomed(bool hmd) { homed = hmd; }
int getHomed() { return homed; }

void setMinStep(int ms) { minStep = ms; }
int getMinStep() { return minStep; }

Expand Down Expand Up @@ -124,7 +124,9 @@ class userParameters {
bool stepperDir;
bool shifterDir;
bool udpLogEnabled = false;

int32_t hMin = INT32_MIN;
int32_t hMax = INT32_MIN;

bool FTMSControlPointWrite = false;
String ssid;
String password;
Expand Down Expand Up @@ -200,6 +202,12 @@ class userParameters {
void setFoundDevices(String fdv) { foundDevices = fdv; }
const char* getFoundDevices() { return foundDevices.c_str(); }

void setHMin(int32_t min) { hMin = min; }
int32_t getHMin() { return hMin; }

void setHMax(int32_t max) { hMax = max; }
int32_t getHMax() { return hMax; }

void setDefaults();
String returnJSON();
void saveToLittleFS();
Expand Down
2 changes: 1 addition & 1 deletion include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ const char* const DEFAULT_PASSWORD = "password";
#define RUNTIMECONFIG_JSON_SIZE 512 + DEBUG_LOG_BUFFER_SIZE

// PowerTable Version
#define TABLE_VERSION 4
#define TABLE_VERSION 5

/* Number of entries in the ERG Power Lookup Table
This is currently maintained as to keep memory usage lower and reduce the print output of the table.
Expand Down
5 changes: 5 additions & 0 deletions lib/SS2K/include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
#define FITNESSMACHINEPOWERRANGE_UUID NimBLEUUID((uint16_t)0x2AD8)
#define FITNESSMACHINEINCLINATIONRANGE_UUID NimBLEUUID((uint16_t)0x2AD5)

// Wattbike Service
#define WATTBIKE_SERVICE_UUID NimBLEUUID("b4cc1223-bc02-4cae-adb9-1217ad2860d1")
#define WATTBIKE_READ_UUID NimBLEUUID("b4cc1224-bc02-4cae-adb9-1217ad2860d1")
#define WATTBIKE_WRITE_UUID NimBLEUUID("b4cc1225-bc02-4cae-adb9-1217ad2860d1")

// GATT service/characteristic UUIDs for Flywheel Bike from ptx2/gymnasticon/
#define FLYWHEEL_UART_SERVICE_UUID NimBLEUUID("6e400001-b5a3-f393-e0a9-e50e24dcca9e")
#define FLYWHEEL_UART_RX_UUID NimBLEUUID("6e400002-b5a3-f393-e0a9-e50e24dcca9e")
Expand Down
Loading

0 comments on commit a358091

Please sign in to comment.