display.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * (c) 2004,2006 Richard Titmuss for SlimProtoLib
  3. * (c) Philippe G. 2019, philippe_44@outlook.com
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #include <string.h>
  20. #include <ctype.h>
  21. #include <stdint.h>
  22. #include <arpa/inet.h>
  23. #include "esp_log.h"
  24. #include "config.h"
  25. #include "embedded.h"
  26. #include "display.h"
  27. #define TAG "display"
  28. static bool (*slimp_handler_chain)(u8_t *data, int len);
  29. static struct display_handle_s *handle;
  30. static bool display_handler(u8_t *data, int len);
  31. /****************************************************************************************
  32. *
  33. */
  34. void display_init(void) {
  35. char *item = config_alloc_get(NVS_TYPE_STR, "display_config");
  36. if (item && *item) {
  37. handle = &SSD1306_handle;
  38. if (handle->init(item)) {
  39. slimp_handler_chain = slimp_handler;
  40. slimp_handler = display_handler;
  41. ESP_LOGI(TAG, "Display initialization successful");
  42. } else {
  43. ESP_LOGI(TAG, "Display initialization failed");
  44. }
  45. } else {
  46. ESP_LOGI(TAG, "no display");
  47. }
  48. if (item) free(item);
  49. }
  50. /****************************************************************************************
  51. * Process graphic display data
  52. */
  53. static bool display_handler(u8_t *data, int len){
  54. bool res = true;
  55. if (!strncmp((char*) data, "vfdc", 4)) {
  56. handle->vfdc_handler(data, len);
  57. } else if (!strncmp((char*) data, "grfe", 4)) {
  58. handle->grfe_handler(data, len);
  59. } else {
  60. res = false;
  61. }
  62. // chain protocol handlers (bitwise or is fine)
  63. if (*slimp_handler_chain) res |= (*slimp_handler_chain)(data, len);
  64. return res;
  65. }