display.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. char * drivername=strstr(item,"driver");
  38. if( !drivername || (drivername && (strstr(drivername,"SSD1306") || strstr(drivername,"ssd1306")))){
  39. handle = &SSD1306_handle;
  40. if (handle->init(item)) {
  41. slimp_handler_chain = slimp_handler;
  42. slimp_handler = display_handler;
  43. ESP_LOGI(TAG, "Display initialization successful");
  44. } else {
  45. ESP_LOGE(TAG, "Display initialization failed");
  46. }
  47. }else {
  48. ESP_LOGE(TAG,"Unknown display driver name in display config: %s",item);
  49. }
  50. } else {
  51. ESP_LOGW(TAG, "no display");
  52. }
  53. if (item) free(item);
  54. }
  55. /****************************************************************************************
  56. * Process graphic display data
  57. */
  58. static bool display_handler(u8_t *data, int len){
  59. bool res = true;
  60. if (!strncmp((char*) data, "vfdc", 4)) {
  61. handle->vfdc_handler(data, len);
  62. } else if (!strncmp((char*) data, "grfe", 4)) {
  63. handle->grfe_handler(data, len);
  64. } else {
  65. res = false;
  66. }
  67. // chain protocol handlers (bitwise or is fine)
  68. if (*slimp_handler_chain) res |= (*slimp_handler_chain)(data, len);
  69. return res;
  70. }