12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- /*
- * (c) 2004,2006 Richard Titmuss for SlimProtoLib
- * (c) Philippe G. 2019, philippe_44@outlook.com
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- #include <string.h>
- #include <ctype.h>
- #include <stdint.h>
- #include <arpa/inet.h>
- #include "esp_log.h"
- #include "config.h"
- #include "embedded.h"
- #include "display.h"
- #define TAG "display"
- static bool (*slimp_handler_chain)(u8_t *data, int len);
- static struct display_handle_s *handle;
- static void (*chained_notify)(in_addr_t ip, u16_t hport, u16_t cport);
- static void server_attach(in_addr_t ip, u16_t hport, u16_t cport);
- static bool display_handler(u8_t *data, int len);
- /****************************************************************************************
- *
- */
- void display_init(char *welcome) {
- char *item = config_alloc_get(NVS_TYPE_STR, "display_config");
- if (item && *item) {
- handle = &SSD1306_handle;
- if (handle->init(item, welcome)) {
- slimp_handler_chain = slimp_handler;
- slimp_handler = display_handler;
- ESP_LOGI(TAG, "Display initialization successful");
- } else {
- ESP_LOGI(TAG, "Display initialization failed");
- }
- } else {
- ESP_LOGI(TAG, "no display");
- }
-
- chained_notify = server_notify;
- server_notify = server_attach;
- if (item) free(item);
- }
- /****************************************************************************************
- *
- */
- static void server_attach(in_addr_t ip, u16_t hport, u16_t cport) {
- char msg[32];
- sprintf(msg, "%s:%hu", inet_ntoa(ip), hport);
- handle->print_message(msg);
- if (chained_notify) (*chained_notify)(ip, hport, cport);
- }
- /****************************************************************************************
- * Process graphic display data
- */
- static bool display_handler(u8_t *data, int len){
- bool res = true;
- if (!strncmp((char*) data, "vfdc", 4)) {
- handle->vfdc_handler(data, len);
- } else if (!strncmp((char*) data, "grfe", 4)) {
- handle->grfe_handler(data, len);
- } else {
- res = false;
- }
-
- // chain protocol handlers (bitwise or is fine)
- if (*slimp_handler_chain) res |= (*slimp_handler_chain)(data, len);
- return res;
- }
|