diff --git a/Software/src/ossm/OSSM.SimplePenetration.cpp b/Software/src/ossm/OSSM.SimplePenetration.cpp index f362378d..ff2bb6ff 100644 --- a/Software/src/ossm/OSSM.SimplePenetration.cpp +++ b/Software/src/ossm/OSSM.SimplePenetration.cpp @@ -98,9 +98,40 @@ void OSSM::startSimplePenetrationTask(void *pvParameters) { void OSSM::startSimplePenetration() { int stackSize = 30 * configMINIMAL_STACK_SIZE; - xTaskCreatePinnedToCore(startSimplePenetrationTask, - "startSimplePenetrationTask", stackSize, this, - configMAX_PRIORITIES - 1, - &Tasks::runSimplePenetrationTaskH, + xTaskCreatePinnedToCore( + startSimplePenetrationTask, "startSimplePenetrationTask", stackSize, + this, configMAX_PRIORITIES - 1, &Tasks::runSimplePenetrationTaskH, + Tasks::operationTaskCore); +} + +void startStreamingTask(void *pvParameters) { + OSSM *ossm = (OSSM *)pvParameters; + + auto isInCorrectState = [](OSSM *ossm) { + // Add any states that you want to support here. + // return ossm->sm->is("streaming"_s) || + // ossm->sm->is("streaming.preflight"_s) || + // ossm->sm->is("streaming.idle"_s); + return true; + }; + + // create a function that, given a time, returns a value between 0 and 100 + // from a sine wave with period of 1000ms + auto sineWave = [](int time) { return sin(time * 2 * M_PI / 1000) * 100; }; + + while (isInCorrectState(ossm)) { + ossm->stepper->moveTo(sineWave(millis()), false); + vTaskDelay(1); + } + + vTaskDelete(nullptr); +} + +void OSSM::startStreaming() { + int stackSize = 10 * configMINIMAL_STACK_SIZE; + + xTaskCreatePinnedToCore(startStreamingTask, "startStreamingTask", + stackSize, + this, configMAX_PRIORITIES - 1, nullptr, Tasks::operationTaskCore); } \ No newline at end of file diff --git a/Software/src/ossm/OSSM.Streaming.cpp b/Software/src/ossm/OSSM.Streaming.cpp deleted file mode 100644 index fbf80091..00000000 --- a/Software/src/ossm/OSSM.Streaming.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "OSSM.h" - -#include "services/stepper.h" - -void startStreamingTask(void *pvParameters) { - // OSSM *ossm = (OSSM *)pvParameters; - - // auto isInCorrectState = [](OSSM *ossm) { - // // Add any states that you want to support here. - // // return ossm->sm->is("streaming"_s) || - // // ossm->sm->is("streaming.preflight"_s) || - // // ossm->sm->is("streaming.idle"_s); - // return true; - // }; - - // // create a function that, given a time, returns a value between 0 and - // 100 - // // from a sine wave with period of 1000ms - // auto sineWave = [](int time) { return sin(time * 2 * M_PI / 1000) * 100; - // }; - - // while (isInCorrectState(ossm)) { - // stepper->moveTo(sineWave(millis()), false); - // vTaskDelay(1); - // } - - // vTaskDelete(nullptr); -} - -void OSSM::startStreaming() { - // int stackSize = 10 * configMINIMAL_STACK_SIZE; - - // xTaskCreatePinnedToCore(startStreamingTask, "startStreamingTask", - // stackSize, - // this, configMAX_PRIORITIES - 1, nullptr, - // Tasks::operationTaskCore); -} \ No newline at end of file diff --git a/Software/src/ossm/OSSM.h b/Software/src/ossm/OSSM.h index 600bf82f..9ec87a97 100644 --- a/Software/src/ossm/OSSM.h +++ b/Software/src/ossm/OSSM.h @@ -109,7 +109,7 @@ class OSSM : public OSSMInterface { o.startSimplePenetration(); }; - // auto startStreaming = [](OSSM &o) { o.startStreaming(); }; + auto startStreaming = [](OSSM &o) { o.startStreaming(); }; auto startStrokeEngine = [](OSSM &o) { o.startStrokeEngine(); }; auto emergencyStop = [](OSSM &o) { @@ -185,11 +185,12 @@ class OSSM : public OSSMInterface { "homing.backward"_s + done[isFirstHomed] / setHomed = "menu"_s, "homing.backward"_s + done[(isOption(Menu::SimplePenetration))] / setHomed = "simplePenetration"_s, "homing.backward"_s + done[(isOption(Menu::StrokeEngine))] / setHomed = "strokeEngine"_s, - // "homing.backward"_s + done[(isOption(Menu::Streaming))] / setHomed = "streaming"_s, + "homing.backward"_s + done[(isOption(Menu::Streaming))] / setHomed = "streaming"_s, "menu"_s / (drawMenu, startWifi) = "menu.idle"_s, "menu.idle"_s + buttonPress[(isOption(Menu::SimplePenetration))] = "simplePenetration"_s, "menu.idle"_s + buttonPress[(isOption(Menu::StrokeEngine))] = "strokeEngine"_s, + "menu.idle"_s + buttonPress[(isOption(Menu::Streaming))] = "streaming"_s, "menu.idle"_s + buttonPress[(isOption(Menu::UpdateOSSM))] = "update"_s, "menu.idle"_s + buttonPress[(isOption(Menu::WiFiSetup))] = "wifi"_s, "menu.idle"_s + buttonPress[isOption(Menu::Help)] = "help"_s, @@ -201,11 +202,11 @@ class OSSM : public OSSMInterface { "simplePenetration.preflight"_s + done / (resetSettings, drawPlayControls, startSimplePenetration) = "simplePenetration.idle"_s, "simplePenetration.idle"_s + longPress / (emergencyStop, setNotHomed) = "menu"_s, - // "streaming"_s [isNotHomed] = "homing"_s, - // "streaming"_s [isPreflightSafe] / (resetSettings, drawPlayControls, startStreaming) = "streaming.idle"_s, - // "streaming"_s / drawPreflight = "streaming.preflight"_s, - // "streaming.preflight"_s + done / (resetSettings, drawPlayControls, startStreaming) = "streaming.idle"_s, - // "streaming.idle"_s + longPress / (emergencyStop, setNotHomed) = "menu"_s, + "streaming"_s [isNotHomed] = "homing"_s, + "streaming"_s [isPreflightSafe] / (resetSettings, drawPlayControls, startStreaming) = "streaming.idle"_s, + "streaming"_s / drawPreflight = "streaming.preflight"_s, + "streaming.preflight"_s + done / (resetSettings, drawPlayControls, startStreaming) = "streaming.idle"_s, + "streaming.idle"_s + longPress / (emergencyStop, setNotHomed) = "menu"_s, "strokeEngine"_s [isNotHomed] = "homing"_s, @@ -243,18 +244,6 @@ class OSSM : public OSSMInterface { } }; - /** - * /////////////////////////////////////////// - * //// - * //// Private Objects and Services - * //// - * /////////////////////////////////////////// - */ - FastAccelStepper *stepper; - U8G2_SSD1306_128X64_NONAME_F_HW_I2C &display; - StateLogger logger; - AiEsp32RotaryEncoder &encoder; - /** * /////////////////////////////////////////// * //// @@ -354,6 +343,17 @@ class OSSM : public OSSMInterface { sml::logger>> sm = nullptr; // The state machine + /** + * /////////////////////////////////////////// + * //// + * //// Objects and Services + * //// + * /////////////////////////////////////////// + */ + FastAccelStepper *stepper; + U8G2_SSD1306_128X64_NONAME_F_HW_I2C &display; + StateLogger logger; + AiEsp32RotaryEncoder &encoder; WiFiManager wm; // Implement the interface methods