123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #include <string.h>
- #include <ctype.h>
- #include <arpa/inet.h>
- #include "esp_log.h"
- #define LINELEN 40
- #define TAG "display"
- unsigned char printable(unsigned char c) {
- switch (c) {
- case 11:
- return '#';
- break;;
- case 16:
- return '>';
- break;;
- case 22:
- return '@';
- break;;
- case 145:
- return ' ';
- break;;
- case 152:
- return 'o';
- break;
- default:
- return c;
- }
- }
- void makeprintable(unsigned char * line) {
- for (int n = 0; n < LINELEN; n++) line[n] = printable(line[n]);
- }
- void show_display_buffer(char *ddram) {
- char line1[LINELEN+1];
- char *line2;
- memset(line1, 0, LINELEN+1);
- strncpy(line1, ddram, LINELEN);
- line2 = &(ddram[LINELEN]);
- line2[LINELEN] = '\0';
-
- makeprintable((unsigned char *)line1);
- makeprintable((unsigned char *)line2);
- ESP_LOGI(TAG, "\n\t%.40s\n\t%.40s", line1, line2);
- }
- bool charisok(unsigned char c) {
- switch (c) {
- case 11:
- case 16:
- case 22:
- case 145:
- case 152:
- return true;
- break;;
- default:
- return isprint(c);
- }
- }
- void vfd_data( unsigned short *data, int bytes_read) {
- unsigned short *display_data;
- char ddram[LINELEN * 2];
- int n;
- int addr = 0;
- if (bytes_read % 2) bytes_read--;
-
- display_data = &(data[5]);
- memset(ddram, ' ', LINELEN * 2);
- for (n = 0; n < (bytes_read/2); n++) {
- unsigned short d;
- unsigned char t, c;
- d = ntohs(display_data[n]);
- t = (d & 0x00ff00) >> 8;
- c = (d & 0x0000ff);
- switch (t) {
- case 0x03:
- if (!charisok(c)) c = ' ';
- if (addr <= LINELEN * 2) {
- ddram[addr++] = c;
- }
- break;
- case 0x02:
- switch (c) {
- case 0x06:
- memset(ddram, ' ', LINELEN * 2);
- break;
- case 0x02:
- addr = 0;
- break;
- case 0xc0:
- addr = LINELEN;
- break;
- }
- }
- }
- show_display_buffer(ddram);
- }
|