twali_system.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #define LILYGO_TWATCH_2020_V1
  2. #include <TTGO.h>
  3. #define TWALI_INTERNAL
  4. #include "twali_system_internal.h"
  5. #include "twali_power.h"
  6. #include "twali_screen.h"
  7. extern "C" {
  8. static struct twali_system twali_system_singleton;
  9. static struct twali_system * twali_system_singleton_pointer = NULL;
  10. struct twali_power * twali_system_power(struct twali_system * s) {
  11. return s->power;
  12. }
  13. void twali_system_power_interrupt(void) {
  14. if (twali_system_singleton_pointer) {
  15. twali_power_interrupt(twali_system_singleton_pointer->power);
  16. }
  17. }
  18. struct twali_system * twali_system_make(void) {
  19. if (twali_system_singleton_pointer) {
  20. return twali_system_singleton_pointer;
  21. }
  22. twali_system_singleton.handle = TTGOClass::getWatch();
  23. twali_system_singleton.handle->begin();
  24. twali_system_singleton.handle->rtc->check();
  25. twali_system_singleton.handle->bl->adjust(150);
  26. twali_system_singleton.tft = twali_system_singleton.handle->eTFT;
  27. twali_system_singleton.tft->fillScreen(TFT_BLUE);
  28. twali_system_singleton.tft->setTextColor(TFT_WHITE, TFT_BLACK);
  29. twali_system_singleton.tft->setTextFont(8);
  30. twali_system_singleton.handle->openBL();
  31. twali_system_singleton.power = twali_power_make(&twali_system_singleton);
  32. twali_system_singleton.bus = { 0 };
  33. pinMode(AXP202_INT, INPUT);
  34. attachInterrupt(AXP202_INT, twali_system_power_interrupt, FALLING);
  35. twali_system_singleton_pointer = &twali_system_singleton;
  36. return twali_system_singleton_pointer;
  37. }
  38. void twali_system_start(struct twali_system * s) {
  39. twali_power_start_task(s->power);
  40. }
  41. void twali_system_update(struct twali_system * s) {
  42. vTaskDelay(10000);
  43. }
  44. void twali_system_wake_up(struct twali_system *s) {
  45. twali_system_publish_str(s, "POWER", (char *)"ON");
  46. }
  47. int twali_system_publish_data(struct twali_system *s, const char * topic, void * mesg, size_t size) {
  48. return upubsub_publish_data(s->bus, topic, mesg, size);
  49. }
  50. int twali_system_publish_str(struct twali_system *s, const char * topic, char * str) {
  51. return upubsub_publish_str(s->bus, topic, str);
  52. }
  53. }