S&B Volcano vaporizer remote control with Pi Pico W
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

state_volcano_run.c 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * state_volcano_run.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 <stdio.h>
  19. #include <string.h>
  20. #include "config.h"
  21. #include "workflow.h"
  22. #include "state.h"
  23. #include "state_volcano_run.h"
  24. #include "menu.h"
  25. static uint16_t wf_index;
  26. static bd_addr_t ble_addr;
  27. static bd_addr_type_t ble_type;
  28. static bool wait_for_connect = false;
  29. void state_volcano_run_index(uint16_t index) {
  30. wf_index = index;
  31. }
  32. void state_volcano_run_target(bd_addr_t addr, bd_addr_type_t type) {
  33. memcpy(ble_addr, addr, sizeof(bd_addr_t));
  34. ble_type = type;
  35. }
  36. void state_volcano_run_enter(void) {
  37. ble_connect(ble_addr, ble_type);
  38. wait_for_connect = true;
  39. }
  40. void state_volcano_run_exit(void) {
  41. wf_reset();
  42. ble_disconnect();
  43. }
  44. static void draw(struct menu_state *menu) {
  45. struct wf_state state = wf_status();
  46. snprintf(menu->buff, MENU_MAX_LEN, "%d / %d", state.step, state.count);
  47. }
  48. void state_volcano_run_run(void) {
  49. if (wait_for_connect && ble_is_connected()) {
  50. wait_for_connect = false;
  51. wf_start(wf_index);
  52. }
  53. menu_run(draw);
  54. struct wf_state state = wf_status();
  55. if (state.status == WF_IDLE) {
  56. state_switch(STATE_SCAN);
  57. }
  58. }