123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #include "twali_task.h"
- #include "twali_system.h"
- #include "twali_power.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/queue.h"
- #include "freertos/task.h"
- struct twali_task {
- struct twali_system * system;
- struct twali_task * parent;
- char * name;
- TaskHandle_t task;
- QueueHandle_t queue;
- void * data;
- int low_power_delay;
- int delay;
- void (*update)(struct twali_task *t);
- };
- void twali_task_task(void * object) {
- struct twali_task * t = object;
- struct twali_power * p = twali_system_power(t->system);
-
- for (;;) {
- /*
- bool update_display = false;
- unsigned int delay_time = 0;
- */
- if (twali_power_low(p) && (t->low_power_delay > 0)) {
- vTaskDelay(t->low_power_delay / portTICK_PERIOD_MS);
- continue;
- }
- /* twali_task_check_wake_time(t); */
- if (t->update) {
- t->update(t);
- }
- vTaskDelay(t->delay / portTICK_PERIOD_MS);
- }
- printf("deleting task %s\n", t->name);
- vTaskDelete(NULL);
- }
- int twali_task_start(struct twali_task * t, int priority) {
- BaseType_t res;
- res = xTaskCreate(twali_task_task, t->name, 10000, (void *) t, priority, &t->task);
- return res == pdPASS;
- }
- /*
- class Actor {
- public:
- static TTGOClass *watch;
- static TFT_eSPI *screen;
- static PowerManager * power;
- static TaskHandle_t display_task;
- // system accessors
- static void setPower(PowerManager * _power);
- static void setDisplayTask(TaskHandle_t _display_task);
- static void setWatch(TTGOClass * _watch);
- // setup and init
- bool needsInit();
- void setup();
- virtual void init() { }
- // run and display
- virtual void run() = 0;
- void execute(unsigned int & sleep_time, bool & display_update);
- virtual void display() = 0;
- virtual const uint32_t displayIdentifier() = 0;
- // low power considerations
- virtual const bool runDuringLowPower() { return false; }
- virtual const uint32_t delayDuringLowPower() { return 1000; }
- // sleep-wake
- static void systemWokeUp();
- void checkWakeTime();
- bool wakeUpRun();
- protected:
- unsigned int delay_time = 100;
- bool refresh_display = false;
- private:
- static unsigned int woke_up_at;
- unsigned int last_wake_up_tasked = 0;
- bool wake_up_run = true;
- bool inited = false;
- };
- void actorTask(void * object);
- void runActor(const char * name, Actor * object, int priority);
- */
|