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.

state_string.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * state_string.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 "config.h"
  20. #include "buttons.h"
  21. #include "lcd.h"
  22. #include "menu.h"
  23. #include "text.h"
  24. #include "textbox.h"
  25. #include "state_string.h"
  26. static char *str_p = NULL;
  27. static size_t str_len = 0;
  28. static const char *str_name = NULL;
  29. static enum system_state str_ret_state = STATE_SCAN;
  30. void state_string_set(char *value, size_t length,
  31. const char *name) {
  32. str_p = value;
  33. str_len = length;
  34. str_name = name;
  35. }
  36. void state_string_return(enum system_state state) {
  37. str_ret_state = state;
  38. }
  39. static void draw(void) {
  40. static char buff[42];
  41. if ((str_p == NULL) || (str_len <= 0) || (str_name == NULL)) {
  42. snprintf(buff, sizeof(buff), "error");
  43. } else {
  44. snprintf(buff, sizeof(buff), "%s:\n\n%s", str_name, str_p);
  45. }
  46. text_box(buff, true,
  47. "fixed_10x20",
  48. 0, LCD_WIDTH,
  49. 50, MENU_BOX_HEIGHT(MENU_MAX_LINES, 20, 2),
  50. 0);
  51. }
  52. static void string_buttons(enum buttons btn, bool state) {
  53. if (state && (btn == BTN_Y)) {
  54. state_switch(str_ret_state);
  55. } else if (state && (btn == BTN_LEFT)) {
  56. // TODO
  57. } else if (state && (btn == BTN_RIGHT)) {
  58. // TODO
  59. } else if (state && (btn == BTN_UP)) {
  60. // TODO
  61. } else if (state && (btn == BTN_DOWN)) {
  62. // TODO
  63. }
  64. }
  65. void state_string_enter(void) {
  66. buttons_callback(string_buttons);
  67. draw();
  68. }
  69. void state_string_exit(void) {
  70. buttons_callback(NULL);
  71. }
  72. void state_string_run(void) { }