Rewrite combining full stop and line break handling for character displays by using an intermediate buffer
This commit is contained in:
parent
29f9a71107
commit
23f5df8c3c
|
@ -25,26 +25,14 @@ class Display:
|
|||
count = len(s)
|
||||
return count
|
||||
|
||||
def make_framebuf(self, text):
|
||||
framebuf = [0] * self.display_info["charbuf_size"]
|
||||
val = ""
|
||||
for e in text.split("\n"):
|
||||
actual_len = self.get_actual_char_count(e)
|
||||
excess = actual_len - self.display_info["width"]
|
||||
if excess < 0:
|
||||
# Need to pad
|
||||
val += e.ljust(len(e) - excess, " ")
|
||||
else:
|
||||
# Need to cut off
|
||||
cutoff_pos = len(e) - excess
|
||||
val += e[:cutoff_pos]
|
||||
val_len = len(val)
|
||||
for i in range(self.display_info["charbuf_size"]):
|
||||
if i >= val_len:
|
||||
framebuf[i] = 0
|
||||
else:
|
||||
code = ord(val[i])
|
||||
framebuf[i] = code if code <= 255 else 0
|
||||
def make_textbuf(self, text):
|
||||
textbuf = [0] * self.display_info["textbuf_size"]
|
||||
val_len = len(text)
|
||||
i = 0
|
||||
while i < val_len and i < self.display_info["textbuf_size"]:
|
||||
code = ord(val[i])
|
||||
textbuf[i] = code if code <= 255 else 0
|
||||
i += 1
|
||||
return framebuf
|
||||
|
||||
def load_display_info(self):
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "macros.h"
|
||||
#include "char_16seg_led_spi.h"
|
||||
#include "util_buffer.h"
|
||||
#include "util_generic.h"
|
||||
#include "util_gpio.h"
|
||||
#include "char_16seg_font.h"
|
||||
|
@ -188,35 +189,16 @@ void display_setCharDataAt(uint8_t* frameBuf, uint16_t charPos, uint16_t charDat
|
|||
}
|
||||
}
|
||||
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize) {
|
||||
uint8_t prevWasLetter = 0;
|
||||
uint16_t decPointMergeCnt = 0;
|
||||
uint16_t cb_i_display = 0;
|
||||
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize) {
|
||||
memset(frameBuf, 0x00, frameBufSize);
|
||||
|
||||
for (uint16_t cb_i_source = 0; cb_i_source < charBufSize; cb_i_source++) {
|
||||
if (charBuf[cb_i_source] == '.') {
|
||||
if (!prevWasLetter) {
|
||||
// Current char is . and previous was . too
|
||||
display_setDecimalPointAt(frameBuf, cb_i_display, 1);
|
||||
} else {
|
||||
// Current char is . but previous was a letter
|
||||
// Add the point to the previous letter and update the respective counter
|
||||
cb_i_display--;
|
||||
display_setDecimalPointAt(frameBuf, cb_i_display, 1);
|
||||
decPointMergeCnt++;
|
||||
prevWasLetter = 0;
|
||||
}
|
||||
} else {
|
||||
// Current char is a letter
|
||||
if (charBuf[cb_i_source] >= char_seg_font_min && charBuf[cb_i_source] <= char_seg_font_max) {
|
||||
display_setCharDataAt(frameBuf, cb_i_display, char_16seg_font[charBuf[cb_i_source] - char_seg_font_min]);
|
||||
}
|
||||
prevWasLetter = 1;
|
||||
for (uint16_t charBufIndex = 0; charBufIndex < charBufSize; charBufIndex++) {
|
||||
if (charBuf[charBufIndex] >= char_seg_font_min && charBuf[charBufIndex] <= char_seg_font_max) {
|
||||
display_setCharDataAt(frameBuf, charBufIndex, char_16seg_font[charBuf[charBufIndex] - char_seg_font_min]);
|
||||
}
|
||||
if (quirkFlagBuf[charBufIndex] & QUIRK_FLAG_COMBINING_FULL_STOP) {
|
||||
display_setDecimalPointAt(frameBuf, charBufIndex, 1);
|
||||
}
|
||||
|
||||
cb_i_display++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,6 @@ void display_enable();
|
|||
void display_disable();
|
||||
void display_latch();
|
||||
esp_err_t display_set_brightness(uint8_t brightness);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_render_frame(uint8_t* frame, uint8_t* prevFrame, uint16_t frameBufSize);
|
||||
uint8_t display_get_fan_speed(uint8_t* frameBuf, uint16_t frameBufSize);
|
|
@ -5,6 +5,6 @@
|
|||
|
||||
esp_err_t display_init(nvs_handle_t* nvsHandle);
|
||||
esp_err_t display_set_brightness(uint8_t brightness);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_render_frame(uint8_t* frame, uint8_t* prevFrame, uint16_t frameBufSize);
|
||||
uint8_t display_get_fan_speed(uint8_t* frameBuf, uint16_t frameBufSize);
|
|
@ -235,7 +235,7 @@ void display_setCharDataAt(uint8_t* frameBuf, uint16_t charPos, uint16_t charDat
|
|||
}
|
||||
}
|
||||
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize) {
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize) {
|
||||
uint8_t prevWasLetter = 0;
|
||||
uint16_t decPointMergeCnt = 0;
|
||||
uint16_t cb_i_display = 0;
|
||||
|
|
|
@ -20,5 +20,5 @@ uint32_t display_calculateFrameBufferCharacterIndex(uint16_t charPos);
|
|||
void display_setLEDColor(uint8_t* frameBuf, uint16_t ledPos, color_t color);
|
||||
void display_setDecimalPointAt(uint8_t* frameBuf, uint16_t charPos, uint8_t state, color_t color);
|
||||
void display_setCharDataAt(uint8_t* frameBuf, uint16_t charPos, uint16_t charData, color_t color);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_render_frame(uint8_t* frame, uint8_t* prevFrame, uint16_t frameBufSize);
|
|
@ -6,6 +6,6 @@
|
|||
esp_err_t display_init(nvs_handle_t* nvsHandle);
|
||||
esp_err_t display_set_brightness(uint8_t brightness);
|
||||
esp_err_t display_set_shader(void* shaderData);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_render_frame(uint8_t* frame, uint8_t* prevFrame, uint16_t frameBufSize);
|
||||
uint8_t display_get_fan_speed(uint8_t* frameBuf, uint16_t frameBufSize);
|
|
@ -58,7 +58,7 @@ void getCommandBytes_SetCode(uint8_t address, uint8_t code, uint8_t* outBuf) {
|
|||
outBuf[2] = code & 0x7F;
|
||||
}
|
||||
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize) {
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize) {
|
||||
// No conversion needed, display takes straight text data
|
||||
memcpy(frameBuf, charBuf, frameBufSize < charBufSize ? frameBufSize : charBufSize);
|
||||
}
|
||||
|
|
|
@ -14,5 +14,5 @@
|
|||
|
||||
esp_err_t display_init(nvs_handle_t* nvsHandle);
|
||||
void getCommandBytes_SetCode(uint8_t address, uint8_t code, uint8_t* outBuf);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_render_frame(uint8_t* frame, uint8_t* prevFrame, uint16_t frameBufSize);
|
|
@ -4,5 +4,5 @@
|
|||
#include "nvs.h"
|
||||
|
||||
esp_err_t display_init(nvs_handle_t* nvsHandle);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_render_frame(uint8_t* frame, uint8_t* prevFrame, uint16_t frameBufSize);
|
|
@ -124,7 +124,7 @@ void display_latch() {
|
|||
gpio_pulse_inv(CONFIG_CSEG_LCD_LATCH_IO, 1, CONFIG_CSEG_LCD_LATCH_PULSE_LENGTH, CONFIG_CSEG_LCD_LATCH_PULSE_LENGTH, CONFIG_CSEG_LCD_LATCH_INV);
|
||||
}
|
||||
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize) {
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize) {
|
||||
uint16_t fb_i = 0;
|
||||
const uint8_t* charData;
|
||||
memset(frameBuf, 0x00, frameBufSize);
|
||||
|
|
|
@ -4,5 +4,5 @@
|
|||
#include "nvs.h"
|
||||
|
||||
esp_err_t display_init(nvs_handle_t* nvsHandle);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_charbuf_to_framebuf(uint8_t* charBuf, uint16_t* quirkFlagBuf, uint8_t* frameBuf, uint16_t charBufSize, uint16_t frameBufSize);
|
||||
void display_render_frame(uint8_t* frame, uint8_t* prevFrame, uint16_t frameBufSize);
|
|
@ -56,6 +56,7 @@
|
|||
"viewport_offset_y": null,
|
||||
"framebuf_size": 256,
|
||||
"frame_type": "unit",
|
||||
"textbuf_size": null,
|
||||
"charbuf_size": null,
|
||||
"brightness_control": false,
|
||||
"config": {
|
||||
|
@ -669,30 +670,14 @@
|
|||
}
|
||||
}
|
||||
} else if (display_info["type"] == "character") {
|
||||
let framebuf = new Array(display_info["charbuf_size"]);
|
||||
let val = "";
|
||||
$("#text-input").val().split("\n").forEach(function(e) {
|
||||
var actualLen = getActualCharCount(e);
|
||||
var excess = actualLen - display_info["width"];
|
||||
if (excess < 0) {
|
||||
// Need to pad
|
||||
val += e.padEnd(e.length - excess, " ");
|
||||
} else {
|
||||
// Need to cut off
|
||||
var cutoffPos = e.length - excess;
|
||||
val += e.substring(0, cutoffPos);
|
||||
}
|
||||
});
|
||||
let textbuf = new Array(display_info["textbuf_size"]);
|
||||
let val = $("#text-input").val();
|
||||
let valLen = val.length;
|
||||
for (let i = 0; i < display_info["charbuf_size"]; i++) {
|
||||
if (i >= valLen) {
|
||||
framebuf[i] = 0;
|
||||
} else {
|
||||
let code = val.charCodeAt(i);
|
||||
framebuf[i] = code > 255 ? 0 : code;
|
||||
}
|
||||
for (let i = 0; i < valLen && i < display_info["textbuf_size"]; i++) {
|
||||
let code = val.charCodeAt(i);
|
||||
textbuf[i] = code > 255 ? 0 : code;
|
||||
}
|
||||
return framebuf;
|
||||
return textbuf;
|
||||
} else if (display_info["type"] == "selection") {
|
||||
let framebuf = new Array(display_info["framebuf_size"]);
|
||||
let inputs = $("[data-is-unit=true]");
|
||||
|
|
|
@ -379,31 +379,12 @@ esp_err_t telegram_bot_process_response(telegram_api_endpoint_t endpoint, cJSON*
|
|||
|
||||
ESP_LOGD(LOG_TAG, "Converting message for display");
|
||||
memset(output_buffer, 0x00, output_buffer_size);
|
||||
str_convertLineBreaks((char*)output_buffer, filteredText_iso88591, DISPLAY_FRAME_HEIGHT, DISPLAY_FRAME_WIDTH);
|
||||
strncpy((char*)output_buffer, filteredText_iso88591, output_buffer_size);
|
||||
free(filteredText_utf8);
|
||||
free(filteredText_iso88591);
|
||||
|
||||
ESP_LOGD(LOG_TAG, "Converting output buffer for Telegram reply");
|
||||
ESP_LOGD(LOG_TAG, "Free Heap: %u", esp_get_free_heap_size());
|
||||
char* formattedOutput = malloc(output_buffer_size + DISPLAY_FRAME_HEIGHT); // + DISPLAY_FRAME_HEIGHT to get one newline character per line
|
||||
ESP_LOGV(LOG_TAG, "formattedOutput = %p", formattedOutput);
|
||||
memset(formattedOutput, 0x00, output_buffer_size + DISPLAY_FRAME_HEIGHT);
|
||||
ESP_LOGV(LOG_TAG, "str_insertLineBreaks");
|
||||
str_insertLineBreaks(formattedOutput, (char*)output_buffer, DISPLAY_FRAME_WIDTH, output_buffer_size);
|
||||
|
||||
ESP_LOGD(LOG_TAG, "Sending reply");
|
||||
char* tgText;
|
||||
asprintf(&tgText, "Current display text:\n\n`%s`", formattedOutput);
|
||||
|
||||
char* tgText_utf8 = malloc(strlen(tgText) * 2 + 1); // Text can be at most twice as long in UTF-8
|
||||
memset(tgText_utf8, 0x00, strlen(tgText) * 2 + 1);
|
||||
ESP_LOGD(LOG_TAG, "Converting reply text from ISO-8859-1 to UTF-8");
|
||||
buffer_iso88591_to_utf8(tgText_utf8, tgText);
|
||||
ESP_LOGD(LOG_TAG, "Result: %s", tgText_utf8);
|
||||
telegram_bot_send_request(TG_SEND_MESSAGE, chat_id, tgText_utf8);
|
||||
free(tgText_utf8);
|
||||
free(formattedOutput);
|
||||
free(tgText);
|
||||
telegram_bot_send_request(TG_SEND_MESSAGE, chat_id, "Message is being displayed");
|
||||
ESP_LOGD(LOG_TAG, "Message processing finished");
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -8,7 +8,12 @@ typedef enum {
|
|||
MT_KEEP_0
|
||||
} buf_merge_t;
|
||||
|
||||
typedef enum {
|
||||
QUIRK_FLAG_COMBINING_FULL_STOP = (1 << 0),
|
||||
} quirk_flag_t;
|
||||
|
||||
|
||||
void buffer_8to1(uint8_t* buf8, uint8_t* buf1, uint16_t width, uint16_t height, buf_merge_t mergeType);
|
||||
void buffer_utf8_to_iso88591(char* dst, char* src);
|
||||
void buffer_iso88591_to_utf8(char* dst, char* src);
|
||||
void buffer_iso88591_to_utf8(char* dst, char* src);
|
||||
void buffer_textbuf_to_charbuf(uint8_t* display_text_buffer, uint8_t* display_char_buffer, uint16_t* display_quirk_flags_buffer, uint16_t textBufSize, uint16_t charBufSize);
|
|
@ -1,5 +1,6 @@
|
|||
#include "util_buffer.h"
|
||||
#include "util_generic.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void buffer_8to1(uint8_t* buf8, uint8_t* buf1, uint16_t width, uint16_t height, buf_merge_t mergeType) {
|
||||
|
@ -57,4 +58,81 @@ void buffer_iso88591_to_utf8(char* dst, char* src) {
|
|||
*dst++ = (*src++ & 0x3f) + 0x80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void buffer_textbuf_to_charbuf(uint8_t* display_text_buffer, uint8_t* display_char_buffer, uint16_t* display_quirk_flags_buffer, uint16_t textBufSize, uint16_t charBufSize) {
|
||||
/*
|
||||
Convert a text buffer to a character buffer and a quirk flag buffer.
|
||||
The character buffer will contain the base characters for the display,
|
||||
the quirk flags buffer will contain quirk flags per character,
|
||||
such as a combining full stop.
|
||||
This function also handles line breaks.
|
||||
*/
|
||||
|
||||
uint16_t charBufIndex = 0;
|
||||
uint16_t charBufCol = 0;
|
||||
uint16_t charBufRow = 0;
|
||||
uint8_t incrementCharBufIndex = 0; // Temporary flag to store whether a character was added to the char buffer
|
||||
uint8_t characterHandlingCompleted = 0; // Temporary flag to tellwhether a character needs to be handles further
|
||||
|
||||
// Reset the char buffer to spaces and the quirk flags buffer to 0x00
|
||||
memset(display_char_buffer, ' ', charBufSize);
|
||||
memset(display_quirk_flags_buffer, 0x00, charBufSize * 2);
|
||||
|
||||
for (uint16_t textBufIndex = 0; textBufIndex < textBufSize; textBufIndex++) {
|
||||
incrementCharBufIndex = 0;
|
||||
characterHandlingCompleted = 0;
|
||||
|
||||
#if defined(CONFIG_DISPLAY_QUIRKS_COMBINING_FULL_STOP)
|
||||
if (display_text_buffer[textBufIndex] == '.') {
|
||||
/*
|
||||
If a full stop is found:
|
||||
|
||||
- If this is the first character in the text buffer, set this index's full stop flag and increment charBufIndex
|
||||
- If this is not the first character, but the previous character was already a full stop, set this index's full stop flag and increment charBufIndex
|
||||
- If this is not the first character and the previous character was not a full stop, set the previous index's full stop flag and do not increase charBufIndex
|
||||
*/
|
||||
|
||||
if (charBufIndex == 0) {
|
||||
display_quirk_flags_buffer[charBufIndex] |= QUIRK_FLAG_COMBINING_FULL_STOP;
|
||||
incrementCharBufIndex = 1;
|
||||
} else if (display_text_buffer[textBufIndex - 1] == '.') {
|
||||
display_quirk_flags_buffer[charBufIndex] |= QUIRK_FLAG_COMBINING_FULL_STOP;
|
||||
incrementCharBufIndex = 1;
|
||||
} else {
|
||||
display_quirk_flags_buffer[charBufIndex - 1] |= QUIRK_FLAG_COMBINING_FULL_STOP;
|
||||
}
|
||||
characterHandlingCompleted = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (display_text_buffer[textBufIndex] == '\n') {
|
||||
// If a line break is encountered, skip to the beginning of the next line
|
||||
while (charBufCol < CONFIG_DISPLAY_FRAME_WIDTH) {
|
||||
charBufCol++;
|
||||
charBufIndex++;
|
||||
if (charBufIndex >= charBufSize) return;
|
||||
}
|
||||
charBufCol = 0;
|
||||
charBufRow++;
|
||||
characterHandlingCompleted = 1;
|
||||
}
|
||||
|
||||
if (!characterHandlingCompleted) {
|
||||
// If none of the above cases were true, treat the character as a normal character
|
||||
display_char_buffer[charBufIndex] = display_text_buffer[textBufIndex];
|
||||
incrementCharBufIndex = 1;
|
||||
}
|
||||
|
||||
if (incrementCharBufIndex) {
|
||||
// Increase the char buffer index and positions if a character was added
|
||||
charBufIndex++;
|
||||
if (charBufIndex >= charBufSize) return;
|
||||
charBufCol++;
|
||||
if (charBufCol >= CONFIG_DISPLAY_FRAME_WIDTH) {
|
||||
charBufCol = 0;
|
||||
charBufRow++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
/*
|
||||
Explanation of the different buffer sizes
|
||||
|
||||
DISPLAY_BUF_SIZE[_*BPP]: Number of pixels / characters on the display
|
||||
|
||||
DISPLAY_FRAMEBUF_SIZE[_*BPP]: Number of pixels / characters in the internal framebuffer[s].
|
||||
This is the display data as sent to the display.
|
||||
|
||||
DISPLAY_CHARBUF_SIZE: Number of characters in the internal character buffer.
|
||||
This is the buffer that holds the display data before it is being converted
|
||||
into the display-specific bytestream format.
|
||||
If applicable, the quirk flag buffer is the same size and holds the quirk flags
|
||||
for each character.
|
||||
|
||||
DISPLAY_TEXTBUF_SIZE: Number of characters in the user-facing text buffer.
|
||||
This is the buffer that holds the display data as entered by the user,
|
||||
before handling things like line breaks.
|
||||
*/
|
||||
|
||||
#define DIV_CEIL(x, y) ((x % y) ? x / y + 1 : x / y)
|
||||
|
||||
#define SET_MASK(buf, pos) (buf)[(pos)/8] |= (1 << ((pos)%8))
|
||||
|
@ -7,9 +26,9 @@
|
|||
#define GET_MASK(buf, pos) (!!((buf)[(pos)/8] & (1 << ((pos)%8))))
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
#define STRCPY_CHARBUF(dst, txt, len) strncpy(dst, txt, len);
|
||||
#define STRCPY_TEXTBUF(dst, txt, len) strncpy(dst, txt, len);
|
||||
#else
|
||||
#define STRCPY_CHARBUF(dst, txt, len)
|
||||
#define STRCPY_TEXTBUF(dst, txt, len)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_PIXEL) || defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
|
@ -60,11 +79,19 @@
|
|||
#define DISPLAY_BUF_SIZE (CONFIG_DISPLAY_WIDTH * CONFIG_DISPLAY_HEIGHT)
|
||||
#define DISPLAY_CHARBUF_SIZE (CONFIG_DISPLAY_FRAME_WIDTH * CONFIG_DISPLAY_FRAME_HEIGHT)
|
||||
|
||||
#if defined(CONFIG_DISPLAY_QUIRKS_COMBINING_FULL_STOP)
|
||||
// If the display has combining full stops, the text buffer needs to be
|
||||
// twice as large as the frame buffer, since every character could be succeeded by a full stop
|
||||
#define DISPLAY_TEXTBUF_SIZE (DISPLAY_CHARBUF_SIZE * 2)
|
||||
#else
|
||||
#define DISPLAY_TEXTBUF_SIZE DISPLAY_CHARBUF_SIZE
|
||||
#endif
|
||||
|
||||
// TODO: Review this. Why is this different?
|
||||
#if defined(CONFIG_DISPLAY_DRIVER_CHAR_16SEG_LED_WS281X)
|
||||
#define DISPLAY_FRAMEBUF_SIZE (DISPLAY_CHARBUF_SIZE * DIV_CEIL(CONFIG_DISPLAY_FRAMEBUF_BITS_PER_CHAR, 8))
|
||||
#define DISPLAY_FRAMEBUF_SIZE (DISPLAY_CHARBUF_SIZE * DIV_CEIL(CONFIG_DISPLAY_FRAMEBUF_BITS_PER_CHAR, 8))
|
||||
#else
|
||||
#define DISPLAY_FRAMEBUF_SIZE (DIV_CEIL(DISPLAY_CHARBUF_SIZE * CONFIG_DISPLAY_FRAMEBUF_BITS_PER_CHAR, 8))
|
||||
#define DISPLAY_FRAMEBUF_SIZE (DIV_CEIL(DISPLAY_CHARBUF_SIZE * CONFIG_DISPLAY_FRAMEBUF_BITS_PER_CHAR, 8))
|
||||
#endif
|
||||
#elif defined(CONFIG_DISPLAY_TYPE_SELECTION)
|
||||
#define DISPLAY_TYPE "selection"
|
||||
|
|
|
@ -640,13 +640,13 @@ CONFIG_HEAP_TRACING_OFF=y
|
|||
#
|
||||
# Log output
|
||||
#
|
||||
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_NONE is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_ERROR is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_WARN is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_INFO is not set
|
||||
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
|
||||
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
|
||||
CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
CONFIG_LOG_DEFAULT_LEVEL=3
|
||||
# CONFIG_LOG_COLORS is not set
|
||||
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
|
||||
# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set
|
||||
|
|
|
@ -119,8 +119,10 @@ static esp_err_t display_info_get_handler(httpd_req_t *req) {
|
|||
cJSON_AddNumberToObject(json, "framebuf_size", DISPLAY_FRAMEBUF_SIZE);
|
||||
cJSON_AddStringToObject(json, "frame_type", DISPLAY_FRAME_TYPE);
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
cJSON_AddNumberToObject(json, "textbuf_size", DISPLAY_TEXTBUF_SIZE);
|
||||
cJSON_AddNumberToObject(json, "charbuf_size", DISPLAY_CHARBUF_SIZE);
|
||||
#else
|
||||
cJSON_AddNullToObject(json, "textbuf_size");
|
||||
cJSON_AddNullToObject(json, "charbuf_size");
|
||||
#endif
|
||||
cJSON_AddBoolToObject(json, "brightness_control", DISPLAY_HAS_BRIGHTNESS_CONTROL);
|
||||
|
|
23
src/main.c
23
src/main.c
|
@ -23,6 +23,7 @@
|
|||
#include "tpm2net.h"
|
||||
#include "ethernet.h"
|
||||
#include "wifi.h"
|
||||
#include "util_buffer.h"
|
||||
#include "util_fan.h"
|
||||
#include "util_gpio.h"
|
||||
#include "wg.h"
|
||||
|
@ -75,6 +76,8 @@ uint8_t artnet_output_buffer[ARTNET_FRAMEBUF_SIZE] = {0};
|
|||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
uint8_t display_char_buffer[DISPLAY_CHARBUF_SIZE] = {0};
|
||||
uint16_t display_quirk_flags_buffer[DISPLAY_CHARBUF_SIZE] = {0};
|
||||
uint8_t display_text_buffer[DISPLAY_TEXTBUF_SIZE] = {0};
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_SELECTION)
|
||||
|
@ -125,7 +128,8 @@ static void display_refresh_task(void* arg) {
|
|||
display_render_frame_24bpp(temp_output_buffer, prev_display_output_buffer, DISPLAY_FRAMEBUF_SIZE);
|
||||
#endif
|
||||
#elif defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
display_charbuf_to_framebuf(display_char_buffer, display_output_buffer, DISPLAY_CHARBUF_SIZE, DISPLAY_FRAMEBUF_SIZE);
|
||||
buffer_textbuf_to_charbuf(display_text_buffer, display_char_buffer, display_quirk_flags_buffer, DISPLAY_TEXTBUF_SIZE, DISPLAY_CHARBUF_SIZE);
|
||||
display_charbuf_to_framebuf(display_char_buffer, display_quirk_flags_buffer, display_output_buffer, DISPLAY_CHARBUF_SIZE, DISPLAY_FRAMEBUF_SIZE);
|
||||
display_render_frame(display_output_buffer, prev_display_output_buffer, DISPLAY_FRAMEBUF_SIZE);
|
||||
#elif defined(CONFIG_DISPLAY_TYPE_SELECTION)
|
||||
display_render_frame(display_output_buffer, prev_display_output_buffer, DISPLAY_FRAMEBUF_SIZE, display_framebuf_mask, display_num_units);
|
||||
|
@ -219,6 +223,12 @@ void app_main(void) {
|
|||
ESP_ERROR_CHECK(fan_init());
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_SELECTION)
|
||||
ret = display_init(&nvs_handle, display_framebuf_mask, &display_num_units);
|
||||
#else
|
||||
ret = display_init(&nvs_handle);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
|
@ -242,11 +252,6 @@ void app_main(void) {
|
|||
browser_config_init(&server, &nvs_handle);
|
||||
browser_spiffs_init(&server);
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_SELECTION)
|
||||
ret = display_init(&nvs_handle, display_framebuf_mask, &display_num_units);
|
||||
#else
|
||||
ret = display_init(&nvs_handle);
|
||||
#endif
|
||||
if (ret == ESP_OK) {
|
||||
#if defined(CONFIG_DISPLAY_TYPE_PIXEL)
|
||||
tpm2net_init(display_output_buffer, tpm2net_output_buffer, DISPLAY_FRAMEBUF_SIZE, TPM2NET_FRAMEBUF_SIZE);
|
||||
|
@ -255,8 +260,8 @@ void app_main(void) {
|
|||
#endif
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
browser_canvas_init(&server, display_char_buffer, DISPLAY_CHARBUF_SIZE);
|
||||
telegram_bot_init(&nvs_handle, display_char_buffer, DISPLAY_CHARBUF_SIZE);
|
||||
browser_canvas_init(&server, display_text_buffer, DISPLAY_TEXTBUF_SIZE);
|
||||
telegram_bot_init(&nvs_handle, display_text_buffer, DISPLAY_TEXTBUF_SIZE);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_SELECTION)
|
||||
|
@ -273,7 +278,7 @@ void app_main(void) {
|
|||
#endif
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
display_char_buffer[0] = '-';
|
||||
display_text_buffer[0] = '-';
|
||||
#endif
|
||||
|
||||
xTaskCreatePinnedToCore(display_refresh_task, "display_refresh", 4096, NULL, 24, NULL, 1);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
extern uint8_t display_char_buffer[DISPLAY_CHARBUF_SIZE];
|
||||
extern uint8_t display_text_buffer[DISPLAY_TEXTBUF_SIZE];
|
||||
#endif
|
||||
|
||||
bool ntp_initialized = false;
|
||||
|
@ -19,7 +19,7 @@ bool ntp_started = false;
|
|||
void ntp_sync_cb(struct timeval *tv) {
|
||||
ESP_LOGI(LOG_TAG, "NTP time synced");
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
//display_char_buffer[0] = 'N';
|
||||
//display_text_buffer[0] = 'N';
|
||||
#endif
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
wg_start();
|
||||
|
|
6
src/wg.c
6
src/wg.c
|
@ -8,7 +8,7 @@
|
|||
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
extern uint8_t display_char_buffer[DISPLAY_CHARBUF_SIZE];
|
||||
extern uint8_t display_text_buffer[DISPLAY_TEXTBUF_SIZE];
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -91,7 +91,7 @@ esp_err_t wg_start() {
|
|||
ESP_LOGI(LOG_TAG, "Connecting");
|
||||
if (wg_started) {
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
//display_char_buffer[0] = 'W';
|
||||
//display_text_buffer[0] = 'W';
|
||||
#endif
|
||||
ESP_LOGI(LOG_TAG, "Already connected!");
|
||||
return ESP_OK;
|
||||
|
@ -99,7 +99,7 @@ esp_err_t wg_start() {
|
|||
esp_err_t ret = esp_wireguard_connect(&wg_ctx);
|
||||
if (ret == ESP_OK) {
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
//display_char_buffer[0] = 'W';
|
||||
//display_text_buffer[0] = 'W';
|
||||
#endif
|
||||
ESP_LOGI(LOG_TAG, "Connected");
|
||||
wg_started = true;
|
||||
|
|
|
@ -26,7 +26,7 @@ uint8_t wifi_gotIP = 0;
|
|||
extern char hostname[63];
|
||||
|
||||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
extern uint8_t display_char_buffer[DISPLAY_CHARBUF_SIZE];
|
||||
extern uint8_t display_text_buffer[DISPLAY_TEXTBUF_SIZE];
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -83,7 +83,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
|
|||
#if defined(CONFIG_DISPLAY_TYPE_CHARACTER)
|
||||
char temp[19];
|
||||
sprintf(temp, IPSTR, IP2STR(&event->ip_info.ip));
|
||||
STRCPY_CHARBUF((char*)&display_char_buffer[1], temp, DISPLAY_CHARBUF_SIZE-1);
|
||||
STRCPY_TEXTBUF((char*)&display_text_buffer[1], temp, DISPLAY_TEXTBUF_SIZE-1);
|
||||
#endif
|
||||
s_retry_num = 0;
|
||||
ntp_sync_time();
|
||||
|
@ -123,7 +123,7 @@ void wifi_init_ap(void) {
|
|||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(LOG_TAG, "AP started. SSID: %s, password: %s", ap_ssid, ap_pass);
|
||||
STRCPY_CHARBUF((char*)&display_char_buffer[1], "AP MODE", DISPLAY_CHARBUF_SIZE-1);
|
||||
STRCPY_TEXTBUF((char*)&display_text_buffer[1], "AP MODE", DISPLAY_TEXTBUF_SIZE-1);
|
||||
}
|
||||
|
||||
void wifi_init(nvs_handle_t* nvsHandle) {
|
||||
|
@ -229,5 +229,5 @@ void wifi_init(nvs_handle_t* nvsHandle) {
|
|||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
ESP_ERROR_CHECK(tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, hostname));
|
||||
|
||||
STRCPY_CHARBUF((char*)&display_char_buffer[1], "CONNECTING", DISPLAY_CHARBUF_SIZE-1);
|
||||
STRCPY_TEXTBUF((char*)&display_text_buffer[1], "CONNECTING", DISPLAY_TEXTBUF_SIZE-1);
|
||||
}
|
Loading…
Reference in New Issue