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

main.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "fat_disk.h"
  28. #include "debug_disk.h"
  29. #include "buttons.h"
  30. #include "ble.h"
  31. #include "lcd.h"
  32. #include "text.h"
  33. #include "image.h"
  34. #include "state.h"
  35. int main(void) {
  36. // required for debug console
  37. cnsl_init();
  38. usb_init();
  39. debug("lcd_init");
  40. lcd_init();
  41. draw_splash();
  42. lcd_set_backlight(0x1000);
  43. if (watchdog_caused_reboot()) {
  44. debug("reset by watchdog");
  45. }
  46. debug("buttons_init");
  47. buttons_init();
  48. // required for LiPo voltage reading
  49. debug("adc_init");
  50. adc_init();
  51. // required for BLE and LiPo voltage reading
  52. debug("cyw43_arch_init");
  53. if (cyw43_arch_init()) {
  54. debug("cyw43_arch_init failed");
  55. }
  56. debug("heartbeat_init");
  57. heartbeat_init();
  58. debug("ble_init");
  59. ble_init();
  60. debug("fat_disk_init");
  61. fat_disk_init();
  62. debug("debug_disk_init");
  63. debug_disk_init();
  64. // trigger after 1000ms
  65. watchdog_enable(1000, 1);
  66. debug("init done");
  67. lcd_set_backlight(0x8000);
  68. // wait for BLE stack to be ready before using it
  69. while (!ble_is_ready()) {
  70. sleep_ms(1);
  71. }
  72. debug("starting app");
  73. state_switch(STATE_SCAN);
  74. while (1) {
  75. watchdog_update();
  76. heartbeat_run();
  77. buttons_run();
  78. usb_run();
  79. cnsl_run();
  80. battery_run();
  81. state_run();
  82. }
  83. return 0;
  84. }