Skip to content

Commit ceefb34

Browse files
authored
Merge pull request #293 from doudar/ERG-Respin
Erg respin
2 parents d559c7e + 950d964 commit ceefb34

File tree

3 files changed

+167
-108
lines changed

3 files changed

+167
-108
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Added
10+
-
11+
12+
### Changed
13+
- Refactored ERG
14+
15+
### Hardware
16+
-
17+
18+
#### IC4 Mod
19+
-
20+
21+
## [1.12.30]
22+
923
### Added
1024
- Added userConfig shifterDir to change direction of shifters in software to compensate for wiring
1125
- Added userConfig StepperDir to change direction of stepper in software to compensate for wiring

include/ERG_Mode.h

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,11 @@
1414
#define ERG_MODE_LOG_CSV_TAG "ERG_Mode_CSV"
1515
#define POWERTABLE_LOG_TAG "PowTab"
1616
#define ERG_MODE_DELAY 700
17-
#define RETURN_ERROR -99
17+
#define RETURN_ERROR -99
1818

1919
extern TaskHandle_t ErgTask;
2020
void setupERG();
21-
void ergTaskLoop(void *pvParameters);
22-
23-
class ErgMode {
24-
public:
25-
void computErg(int newSetpoint);
26-
void _writeLogHeader();
27-
void _writeLog(int cycles, float currentIncline, float newIncline, int currentSetPoint, int newSetPoint, int currentWatts, int newWatts, int currentCadence, int newCadence);
28-
29-
private:
30-
bool engineStopped = false;
31-
bool initialized = false;
32-
int setPoint = 0;
33-
int cycles = 0;
34-
int offsetMultiplier = 0;
35-
Measurement watts = Measurement(0);
36-
int cadence = 0;
37-
38-
bool _userIsSpinning(int cadence, float incline);
39-
};
21+
void ergTaskLoop(void* pvParameters);
4022

4123
class PowerEntry {
4224
public:
@@ -46,15 +28,15 @@ class PowerEntry {
4628
int readings;
4729

4830
PowerEntry() {
49-
this->watts = 0;
31+
this->watts = 0;
5032
this->targetPosition = 0;
51-
this->cad = 0;
52-
this->readings = 0;
33+
this->cad = 0;
34+
this->readings = 0;
5335
}
5436
};
5537

5638
class PowerBuffer {
57-
public:
39+
public:
5840
PowerEntry powerEntry[POWER_SAMPLES];
5941
void set(int);
6042
void reset();
@@ -63,19 +45,55 @@ class PowerBuffer {
6345
class PowerTable {
6446
public:
6547
PowerEntry powerEntry[POWERTABLE_SIZE];
66-
48+
49+
// Pick up new power value and put them into the power table
50+
void processPowerValue(PowerBuffer& powerBuffer, int cadence, Measurement watts);
51+
52+
// Sets stepper min/max value from power table
53+
void setStepperMinMax();
54+
6755
// Catalogs a new entry into the power table.
68-
void newEntry(PowerBuffer powerBuffer);
69-
56+
void newEntry(PowerBuffer& powerBuffer);
57+
7058
// returns incline for wattTarget. Null if not found.
7159
int32_t lookup(int watts, int cad);
72-
60+
7361
// load power table from spiffs
7462
bool load();
75-
63+
7664
// save powertable from spiffs
7765
bool save();
78-
66+
7967
// Display power table in log
8068
void toLog();
8169
};
70+
71+
class ErgMode {
72+
public:
73+
ErgMode(PowerTable* powerTable) { this->powerTable = powerTable; }
74+
void computErg();
75+
void _writeLogHeader();
76+
void _writeLog(int cycles, float currentIncline, float newIncline, int currentSetPoint, int newSetPoint, int currentWatts, int newWatts, int currentCadence, int newCadence);
77+
78+
private:
79+
bool engineStopped = false;
80+
bool initialized = false;
81+
int setPoint = 0;
82+
int cycle = 0;
83+
int offsetMultiplier = 0;
84+
Measurement watts = Measurement(0);
85+
int cadence = 0;
86+
PowerTable* powerTable;
87+
88+
// check if user is spinning, reset incline if user stops spinning
89+
bool _userIsSpinning(int cadence, float incline);
90+
91+
// calculate incline if setpoint (from Zwift) changes
92+
void _setPointChangeState(int newSetPoint, int newCadence, Measurement& newWatts, float currentIncline);
93+
94+
// calculate incline if setpoint is unchanged
95+
void _inSetpointState(int newSetPoint, int newCadence, Measurement& newWatts, float currentIncline);
96+
97+
// update localvalues + incline, creates a log
98+
void _updateValues(int newSetPoint, int newCadence, Measurement& newWatts, float currentIncline, float newIncline);
99+
};

0 commit comments

Comments
 (0)