twali_task.c 2.6 KB

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