diff --git a/idf/taskboard/main/hal/board/TaskBoardDriver_v1.hpp b/idf/taskboard/main/hal/board/TaskBoardDriver_v1.hpp index 770cf26..0c5aea4 100644 --- a/idf/taskboard/main/hal/board/TaskBoardDriver_v1.hpp +++ b/idf/taskboard/main/hal/board/TaskBoardDriver_v1.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -264,13 +265,18 @@ struct TaskBoardDriver_v1 : default_precondition_task_ = new SimultaneousConditionTask(*precondition_steps, "Precondition Task"); TaskStep* timed_fader_operation = - new TaskStepEqual(*get_sensor_by_name("FADER"), SensorMeasurement(0.8f), 0.05f); - timed_fader_operation->set_clue_timeout(*get_sensor_by_name("BLUE_BUTTON"), 3000); + new TaskStepEqual(*get_sensor_by_name("FADER"), SensorMeasurement(0.5f), 0.05f); + // timed_fader_operation->set_clue_timeout(*get_sensor_by_name("BLUE_BUTTON"), 3000); + + TaskStep* random_fader_step = + new TaskStepEqualToRandom(*get_sensor_by_name("FADER"), 0.05f); + // random_fader_step->set_clue_timeout(*get_sensor_by_name("BLUE_BUTTON"), 3000); std::vector* main_steps = new std::vector { new TaskStepEqual(*get_sensor_by_name("BLUE_BUTTON"), SensorMeasurement(true)), timed_fader_operation, + random_fader_step, new TaskStepEqual(*get_sensor_by_name("FADER_BLUE_BUTTON"), SensorMeasurement(0.2f), 0.05f), new TaskStepEqual(*get_sensor_by_name("DOOR_OPEN"), SensorMeasurement(true)), new TaskStepEqual(*get_sensor_by_name("PROBE_GOAL"), SensorMeasurement(true)), diff --git a/idf/taskboard/main/task/TaskExecutor.hpp b/idf/taskboard/main/task/TaskExecutor.hpp index 57d10e0..88d7d49 100644 --- a/idf/taskboard/main/task/TaskExecutor.hpp +++ b/idf/taskboard/main/task/TaskExecutor.hpp @@ -105,6 +105,8 @@ struct TaskExecutor current_task_->is_human_task() ? TFT_DARKGREY : TFT_BLACK); force_screen_update_ = false; + + blinkLED(); } // Print clue @@ -296,6 +298,16 @@ struct TaskExecutor return ret; } + void blinkLED() { + // Turn LED on + M5.Power.setLed(255); + + // Start the timer to turn LED off + if (timer_led_ != nullptr) { + xTimerStart(timer_led_, 0); + } + } + ScreenController& screen_controller_; ///< Reference to screen controller NonVolatileStorage& non_volatile_storage_; ///< Reference to non-volatile storage @@ -306,5 +318,16 @@ struct TaskExecutor SemaphoreHandle_t mutex_; ///< Mutex for thread safety + TimerHandle_t timer_led_ = xTimerCreate( ///< Timer to turn LED off + "LedOff", // Timer name + pdMS_TO_TICKS(500), // Delay in ms + pdFALSE, // Disabled auto-reload + nullptr, + [](TimerHandle_t xTimer) { // Callback + // Turn LED off + M5.Power.setLed(0); + } + ); + std::vector> task_callbacks_; ///< Vector of task update callbacks }; diff --git a/idf/taskboard/main/task/TaskStepEqualToRandom.hpp b/idf/taskboard/main/task/TaskStepEqualToRandom.hpp index c231001..c5560d1 100644 --- a/idf/taskboard/main/task/TaskStepEqualToRandom.hpp +++ b/idf/taskboard/main/task/TaskStepEqualToRandom.hpp @@ -51,5 +51,26 @@ struct TaskStepEqualToRandom : private: + /// Virtual method implementation + void show_clue_implementation( + ClueScreenController& screen_controller) const override + { + if (!success()) + { + screen_controller.print_task_clue(sensor_.name() + " != " + random_expected_value_.to_string()); + + const auto sensor_value = sensor_.read(); + + if (sensor_value.get_type() == SensorMeasurement::Type::ANALOG) + { + screen_controller.print_task_clue_analog(sensor_value.get_analog(), random_expected_value_.get_analog()); + } + } + else + { + reset_clue(); + } + } + mutable SensorMeasurement random_expected_value_; ///< Current random target value, updated when matched };