S&B Volcano vaporizer remote control with Pi Pico W
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ota_shim.c 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * ota_shim.c
  3. *
  4. * Copyright (c) 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/cyw43_arch.h"
  19. #include "config.h"
  20. #include "lcd.h"
  21. #include "log.h"
  22. #include "mem.h"
  23. #include "wifi.h"
  24. int picowota_network_init(void) {
  25. debug("mem_load");
  26. mem_load();
  27. debug("lcd_init");
  28. lcd_init();
  29. lcd_set_backlight(mem_data()->backlight);
  30. log_dump_to_lcd();
  31. debug("cyw43_arch_init");
  32. log_dump_to_lcd();
  33. if (cyw43_arch_init_with_country(COUNTRY_CODE)) {
  34. debug("failed to init cyw43");
  35. log_dump_to_lcd();
  36. return 1;
  37. }
  38. debug("wifi_init");
  39. log_dump_to_lcd();
  40. wifi_init();
  41. const char *prev = NULL;
  42. while (!wifi_ready()) {
  43. cyw43_arch_poll();
  44. wifi_run();
  45. const char *state = wifi_state();
  46. if (state != prev) {
  47. prev = state;
  48. debug("new state: %s", state);
  49. }
  50. log_dump_to_lcd();
  51. // TODO open AP when timed out?
  52. }
  53. debug("wifi ready");
  54. log_dump_to_lcd();
  55. return 0;
  56. }
  57. void picowota_network_deinit(void) {
  58. debug("wifi_deinit");
  59. wifi_deinit();
  60. }