PocketPutr/Desktop_Test/program.cpp

50 lines
1.2 KiB
C++

#include "program.h"
#include "shell.h"
#include "tft_handler.h"
Program::Program()
: _window(nullptr), _shell(nullptr), _tft(nullptr),
_display_state(nullptr), _task_handle(nullptr),
_id(-1), _running(false) {
}
Program::~Program() {
close();
}
void Program::init(char id, const std::string& name, Window* window, Shell* shell, TFT_Handler* tft, DISPLAY_STATE* display_state, CALIBRATION_IDLE calibration_idle) {
_id = id;
_name = name;
_window = window;
_shell = shell;
_tft = tft;
_display_state = display_state;
_running = true;
_calibration_idle = calibration_idle;
// Create the task
xTaskCreatePinnedToCore(task_wrapper, _name.c_str(), 4096, this, 1, &_task_handle, 0);
}
void Program::task_wrapper(void* pvParameters) {
Program* program = static_cast<Program*>(pvParameters);
// Call the specific program's run method
program->run();
// If run() returns, the program has finished
program->_running = false;
vTaskDelete(NULL);
}
void Program::on_click_event(CLICK_EVENT event) {
// Default implementation, do nothing
}
void Program::close() {
_running = false;
if (_task_handle) {
vTaskDelete(_task_handle);
_task_handle = nullptr;
}
}