twali_task.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "twali_task.h"
  2. #include "twali_system.h"
  3. #include "twali_power.h"
  4. #include "freertos/FreeRTOS.h"
  5. #include "freertos/queue.h"
  6. #include "freertos/task.h"
  7. struct twali_task {
  8. struct twali_system * system;
  9. struct twali_task * parent;
  10. char * name;
  11. TaskHandle_t task;
  12. QueueHandle_t queue;
  13. void * data;
  14. int low_power_delay;
  15. int delay;
  16. void (*update)(struct twali_task *t);
  17. };
  18. void twali_task_task(void * object) {
  19. struct twali_task * t = object;
  20. struct twali_power * p = twali_system_power(t->system);
  21. for (;;) {
  22. /*
  23. bool update_display = false;
  24. unsigned int delay_time = 0;
  25. */
  26. if (twali_power_low(p) && (t->low_power_delay > 0)) {
  27. vTaskDelay(t->low_power_delay / portTICK_PERIOD_MS);
  28. continue;
  29. }
  30. /* twali_task_check_wake_time(t); */
  31. if (t->update) {
  32. t->update(t);
  33. }
  34. vTaskDelay(t->delay / portTICK_PERIOD_MS);
  35. }
  36. printf("deleting task %s\n", t->name);
  37. vTaskDelete(NULL);
  38. }
  39. int twali_task_start(struct twali_task * t, int priority) {
  40. BaseType_t res;
  41. res = xTaskCreate(twali_task_task, t->name, 10000, (void *) t, priority, &t->task);
  42. return res == pdPASS;
  43. }
  44. /*
  45. class Actor {
  46. public:
  47. static TTGOClass *watch;
  48. static TFT_eSPI *screen;
  49. static PowerManager * power;
  50. static TaskHandle_t display_task;
  51. // system accessors
  52. static void setPower(PowerManager * _power);
  53. static void setDisplayTask(TaskHandle_t _display_task);
  54. static void setWatch(TTGOClass * _watch);
  55. // setup and init
  56. bool needsInit();
  57. void setup();
  58. virtual void init() { }
  59. // run and display
  60. virtual void run() = 0;
  61. void execute(unsigned int & sleep_time, bool & display_update);
  62. virtual void display() = 0;
  63. virtual const uint32_t displayIdentifier() = 0;
  64. // low power considerations
  65. virtual const bool runDuringLowPower() { return false; }
  66. virtual const uint32_t delayDuringLowPower() { return 1000; }
  67. // sleep-wake
  68. static void systemWokeUp();
  69. void checkWakeTime();
  70. bool wakeUpRun();
  71. protected:
  72. unsigned int delay_time = 100;
  73. bool refresh_display = false;
  74. private:
  75. static unsigned int woke_up_at;
  76. unsigned int last_wake_up_tasked = 0;
  77. bool wake_up_run = true;
  78. bool inited = false;
  79. };
  80. void actorTask(void * object);
  81. void runActor(const char * name, Actor * object, int priority);
  82. */