Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] (Multiple user-support HR->PWR) #333

Open
Nico1320 opened this issue Mar 4, 2022 · 1 comment
Open

[FR] (Multiple user-support HR->PWR) #333

Nico1320 opened this issue Mar 4, 2022 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Nico1320
Copy link

Nico1320 commented Mar 4, 2022

Is your feature request related to a problem? Please describe.
I have not yet built SS2K, but since I had an esp32 lying around, I would give it shot for testing. I've noticed that there isn't support for multiple users (When using HR for power calculation)

Describe the solution you'd like
Add the ability to save and select hr->pwr settings for different users

Describe alternatives you've considered
Re-enter hr->pwr settings each time before use

@doudar
Copy link
Owner

doudar commented Mar 4, 2022

I like the idea! I'll put it on the list but it could be quite a while before I get around to it. In the meantime if you'd like to check into it, I'd recommend just creating an interface to select user profiles in:

https://github.com/doudar/SmartSpin2k/blob/1f8d20299e34dc9c27d6b98c2bcb9d22a16e3918/data/hrtowatts.html

Adding a vector parameter to the physicalWorkingCapacity Class to hold the list of user names or numbers and the index of the selected one.
Adding a Class to the physicalWorkingCapacity Class that would then hold all of the session1 and session 2 parameters for all users.

class physicalWorkingCapacity {
public:
int session1HR;
int session1Pwr;
int session2HR;
int session2Pwr;
bool hr2Pwr;

Then refactoring the physicalWorkingCapacity::loadFromSPIFFS() function in SmartSpin_parameters.cpp to save this info.

// Loads the JSON configuration from a file
void physicalWorkingCapacity::loadFromSPIFFS() {
// Open file for reading
SS2K_LOG(CONFIG_LOG_TAG, "Reading File: %s", userPWCFILENAME);
File file = SPIFFS.open(userPWCFILENAME);
// load defaults if filename doesn't exist
if (!file) {
SS2K_LOG(CONFIG_LOG_TAG, "Couldn't find configuration file. Loading Defaults");
setDefaults();
return;
}
StaticJsonDocument<500> doc;
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, file);
if (error) {
SS2K_LOG(CONFIG_LOG_TAG, "Failed to read file, using default configuration");
setDefaults();
return;
}
// Copy values from the JsonDocument to the Config
session1HR = doc["session1HR"];
session1Pwr = doc["session1Pwr"];
session2HR = doc["session2HR"];
session2Pwr = doc["session2Pwr"];
hr2Pwr = doc["hr2Pwr"];
SS2K_LOG(CONFIG_LOG_TAG, "Config File Loaded: %s", userPWCFILENAME);
file.close();
}

Then refactoring the calculateInstPwrFromHR() function to use the new data formats above.

void calculateInstPwrFromHR() {
static int oldHR = rtConfig.getSimulatedHr();
static int newHR = rtConfig.getSimulatedHr();
static double delta = 0;
oldHR = newHR; // Copying HR from Last loop
newHR = rtConfig.getSimulatedHr();
delta = (newHR - oldHR) / (BLE_CLIENT_DELAY / 1000);
// userConfig.setSimulatedWatts((s1Pwr*s2HR)-(s2Pwr*S1HR))/(S2HR-s1HR)+(userConfig.getSimulatedHr(*((s1Pwr-s2Pwr)/(s1HR-s2HR)));
int avgP = ((userPWC.session1Pwr * userPWC.session2HR) - (userPWC.session2Pwr * userPWC.session1HR)) / (userPWC.session2HR - userPWC.session1HR) +
(newHR * ((userPWC.session1Pwr - userPWC.session2Pwr) / (userPWC.session1HR - userPWC.session2HR)));
if (avgP < 50) {
avgP = 50;
}
if (delta < 0) {
// magic math here for inst power
}
if (delta > 0) {
// magic math here for inst power
}
#ifndef DEBUG_HR_TO_PWR
rtConfig.setSimulatedWatts(avgP);
rtConfig.setSimulatedCad(90);
#endif // DEBUG_HR_TO_PWR
SS2K_LOG(BLE_SERVER_LOG_TAG, "Power From HR: %d", avgP);
}

@doudar doudar added enhancement New feature or request help wanted Extra attention is needed labels Jan 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants