S&B Volcano vaporizer remote control with Pi Pico W
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

main.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * main.c
  3. *
  4. * Copyright (c) 2022 - 2023 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include "pico/stdlib.h"
  19. #include "pico/cyw43_arch.h"
  20. #include "hardware/watchdog.h"
  21. #include "hardware/adc.h"
  22. #include "config.h"
  23. #include "util.h"
  24. #include "console.h"
  25. #include "log.h"
  26. #include "usb.h"
  27. #include "usb_msc.h"
  28. #include "fat_disk.h"
  29. #include "debug_disk.h"
  30. #include "buttons.h"
  31. #include "ble.h"
  32. #include "lcd.h"
  33. #include "text.h"
  34. #include "image.h"
  35. #include "mem.h"
  36. #include "state.h"
  37. #include "serial.h"
  38. #include "workflow.h"
  39. #include "wifi.h"
  40. void main_loop_hw(void) {
  41. watchdog_update();
  42. usb_run();
  43. serial_run();
  44. heartbeat_run();
  45. if (lcd_get_backlight() != mem_data()->backlight) {
  46. lcd_set_backlight(mem_data()->backlight);
  47. }
  48. wifi_run();
  49. }
  50. int main(void) {
  51. watchdog_enable(WATCHDOG_PERIOD_MS, 1);
  52. // required for debug console
  53. cnsl_init();
  54. #ifndef NDEBUG
  55. serial_init();
  56. #endif
  57. usb_init();
  58. debug("mem_load");
  59. mem_load();
  60. debug("lcd_init");
  61. lcd_init();
  62. watchdog_update();
  63. debug("draw_splash");
  64. draw_splash();
  65. lcd_set_backlight(mem_data()->backlight);
  66. if (watchdog_caused_reboot()) {
  67. debug("reset by watchdog");
  68. }
  69. debug("buttons_init");
  70. buttons_init();
  71. // required for LiPo voltage reading
  72. debug("adc_init");
  73. adc_init();
  74. // required for BLE and LiPo voltage reading
  75. debug("cyw43_arch_init");
  76. if (cyw43_arch_init()) {
  77. debug("cyw43_arch_init failed");
  78. lcd_set_backlight(0x00FF);
  79. while (1) {}
  80. }
  81. watchdog_update();
  82. debug("heartbeat_init");
  83. heartbeat_init();
  84. debug("ble_init");
  85. ble_init();
  86. debug("fat_disk_init");
  87. fat_disk_init();
  88. debug("debug_disk_init");
  89. debug_disk_init();
  90. #ifdef AUTO_MOUNT_MASS_STORAGE
  91. msc_set_medium_available(true);
  92. #endif // AUTO_MOUNT_MASS_STORAGE
  93. watchdog_update();
  94. debug("init done");
  95. battery_run();
  96. // wait for BLE stack to be ready before using it
  97. debug("wait for bt stack");
  98. while (!ble_is_ready()) {
  99. sleep_ms(1);
  100. }
  101. if (mem_data()->enable_wifi) {
  102. debug("wifi_init");
  103. wifi_init();
  104. } else {
  105. debug("wifi not enabled");
  106. }
  107. debug("starting app");
  108. state_switch(STATE_SCAN);
  109. while (1) {
  110. main_loop_hw();
  111. buttons_run();
  112. cnsl_run();
  113. battery_run();
  114. state_run();
  115. wf_run();
  116. }
  117. return 0;
  118. }