Skip to content

Commit

Permalink
change development to hit remote
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ-Koenig committed May 31, 2024
1 parent d73cc7b commit d6367fb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 36 deletions.
2 changes: 2 additions & 0 deletions Software/src/constants/copy/en-us.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const char en_Stroke[] PROGMEM = "Stroke";
const char en_StrokeEngine[] PROGMEM = "Stroke Engine";
const char en_StrokeTooShort[] PROGMEM = "Stroke too short. Please check your drive belt.";
const char en_Pair[] PROGMEM = "Pair Device";
const char en_PairingFailed[] PROGMEM = "Pairing failed. Please try again.";
const char en_PairingInstructions[] PROGMEM = "Enter the following code on the dashboard";
const char en_Update[] PROGMEM = "Update";
const char en_UpdateMessage[] PROGMEM = "Update is in progress. This may take up to 60s.";
Expand Down Expand Up @@ -79,6 +80,7 @@ static const LanguageStruct enUs = {
.StrokeEngine = en_StrokeEngine,
.StrokeTooShort = en_StrokeTooShort,
.Pair = en_Pair,
.PairingFailed = en_PairingFailed,
.PairingInstructions = en_PairingInstructions,
.Update = en_Update,
.UpdateMessage = en_UpdateMessage,
Expand Down
2 changes: 2 additions & 0 deletions Software/src/constants/copy/fr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const char fr_Stroke[] PROGMEM = "Coup";
const char fr_StrokeEngine[] PROGMEM = "Stroke Engine";
const char fr_StrokeTooShort[] PROGMEM = "Course trop courte. Veuillez vérifier votre courroie d'entraînement.";
const char fr_Pair[] PROGMEM = "Jumeler l'appareil";
const char fr_PairingFailed[] PROGMEM = "L'appairage a échoué. Veuillez réessayer.";
const char fr_PairingInstructions[] PROGMEM = "Entrez le code suivant sur le tableau de bord";
const char fr_Update[] PROGMEM = "Mettre à jour";
const char fr_UpdateMessage[] PROGMEM = "La mise à jour est en cours. Ça peut prendre jusqu'à 60 secondes.";
Expand Down Expand Up @@ -81,6 +82,7 @@ static const LanguageStruct fr = {
.StrokeEngine = fr_StrokeEngine,
.StrokeTooShort = fr_StrokeTooShort,
.Pair = fr_Pair,
.PairingFailed = fr_PairingFailed,
.PairingInstructions = fr_PairingInstructions,
.Update = fr_Update,
.UpdateMessage = fr_UpdateMessage,
Expand Down
17 changes: 9 additions & 8 deletions Software/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ void setup() {
button.attachLongPressStart([]() { ossm->sm->process_event(LongPress{}); });

xTaskCreate(
[](void* pvParameters) {
while (true) {
button.tick();
ossm->wm.process();
vTaskDelay(10);
}
},
"buttonTask", 4 * configMINIMAL_STACK_SIZE, nullptr, 1, nullptr);
[](void *pvParameters) {
while (true) {
button.tick();
vTaskDelay(10);
ossm->wm.process();
vTaskDelay(10);
}
},
"buttonTask", 5 * configMINIMAL_STACK_SIZE, nullptr, 1, nullptr);
};

void loop() { vTaskDelete(nullptr); };
58 changes: 31 additions & 27 deletions Software/src/ossm/OSSM.WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ void OSSM::drawWiFi() {
wm.startConfigPortal("OSSM Setup");
}

auto pairingTask = [](void *pvParameters) {
OSSM *ossm = (OSSM *) pvParameters;
int taskStart = millis();
auto isInCorrectState = [](OSSM *ossm) {
// Add any states that you want to support here.
return ossm->sm->is("pair"_s) || ossm->sm->is("pair.idle"_s);
};

while (isInCorrectState(ossm)) {
vTaskDelay(10);
int timeElapsed = millis() - taskStart;
if (timeElapsed > 300000) {
// 5 minutes have passed
ossm->errorMessage = UserConfig::language.PairingTookTooLong;
ossm->sm->process_event(Error{});
break;
}

}

vTaskDelete(nullptr);

};

void OSSM::drawPairing() {

String id = getId();
Expand All @@ -52,6 +76,10 @@ void OSSM::drawPairing() {
display.sendBuffer();
displayMutex.unlock();

// start a task to wait 5 minutes then throw an error:
xTaskCreate(pairingTask,
"pairingTask", 3 * configMINIMAL_STACK_SIZE, this, 1, nullptr);


// prepare the payload.
DynamicJsonDocument doc(1024);
Expand All @@ -78,39 +106,15 @@ void OSSM::drawPairing() {
http.addHeader("Authorization", "Bearer cchzYsEaUEy7zoqfYZO2loHg4pKIcIQAvCo3LW9aKYg=");
int httpCode = http.POST(payload);

if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
ESP_LOGD("PAIRING", "Response: %s", payload.c_str());
} else {
ESP_LOGE("PAIRING", "Error: %s", http.errorToString(httpCode).c_str());
errorMessage = String(UserConfig::language.PairingFailed) + " Code: " + httpCode;
sm->process_event(Error{});
}

http.end();

// start a task to wait 5 minutes then throw an error:
xTaskCreate(
[](void *pvParameters) {
OSSM *ossm = (OSSM *) pvParameters;
int taskStart = millis();
auto isInCorrectState = [](OSSM *ossm) {
// Add any states that you want to support here.
return ossm->sm->is("pair"_s) || ossm->sm->is("pair.idle"_s);
};

while (isInCorrectState(ossm)) {
vTaskDelay(10);
int timeElapsed = millis() - taskStart;
if (timeElapsed > 300000) {
// 5 minutes have passed
ossm->errorMessage = UserConfig::language.PairingTookTooLong;
ossm->sm->process_event(Error{});
break;
}

}

vTaskDelete(nullptr);

},
"buttonTask", 3 * configMINIMAL_STACK_SIZE, this, 1, nullptr);

}
2 changes: 1 addition & 1 deletion Software/src/ossm/OSSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ class OSSM {
bool isForward = true;

Menu menuOption;
String errorMessage = "";

SettingPercents setting = {.speed = 0,
.stroke = 0,
Expand Down Expand Up @@ -347,6 +346,7 @@ class OSSM {
sm = nullptr; // The state machine

WiFiManager wm;
String errorMessage = "";
};

#endif // OSSM_SOFTWARE_OSSM_H
1 change: 1 addition & 0 deletions Software/src/structs/LanguageStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct LanguageStruct {
const char* StrokeEngine;
const char* StrokeTooShort;
const char* Pair;
const char* PairingFailed;
const char* PairingInstructions;
const char* PairingTookTooLong;
const char* Update;
Expand Down

0 comments on commit d6367fb

Please sign in to comment.