v0.0.29 - Feather firmware: auto-approve sign_event and always return explicit JSON-RPC errors for unhandled/oversized requests
This commit is contained in:
@@ -41,6 +41,9 @@
|
||||
#define CHAR_SCALE 2
|
||||
#define CHAR_W (6 * CHAR_SCALE)
|
||||
#define CHAR_H (8 * CHAR_SCALE)
|
||||
#define CHAR_SCALE_SMALL 1
|
||||
#define CHAR_W_SMALL (6 * CHAR_SCALE_SMALL)
|
||||
#define CHAR_H_SMALL (8 * CHAR_SCALE_SMALL)
|
||||
|
||||
static spi_device_handle_t s_lcd = NULL;
|
||||
static bool s_initialized = false;
|
||||
@@ -238,12 +241,16 @@ esp_err_t display_clear(uint16_t color)
|
||||
return display_fill_rect(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, color);
|
||||
}
|
||||
|
||||
static esp_err_t draw_char(int x, int y, char c, uint16_t fg, uint16_t bg)
|
||||
static esp_err_t draw_char_scaled(int x, int y, char c, int scale, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
if (c < 0x20 || c > 0x7F) {
|
||||
c = '?';
|
||||
}
|
||||
|
||||
if (scale <= 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
const uint8_t *glyph = font5x7[(uint8_t)c - 0x20];
|
||||
|
||||
for (int col = 0; col < 5; ++col) {
|
||||
@@ -251,28 +258,30 @@ static esp_err_t draw_char(int x, int y, char c, uint16_t fg, uint16_t bg)
|
||||
for (int row = 0; row < 7; ++row) {
|
||||
bool on = (bits >> row) & 0x1;
|
||||
ESP_RETURN_ON_ERROR(
|
||||
display_fill_rect(x + (col * CHAR_SCALE), y + (row * CHAR_SCALE), CHAR_SCALE, CHAR_SCALE, on ? fg : bg),
|
||||
display_fill_rect(x + (col * scale), y + (row * scale), scale, scale, on ? fg : bg),
|
||||
TAG,
|
||||
"pixel draw failed");
|
||||
}
|
||||
}
|
||||
|
||||
// spacing column + bottom row
|
||||
ESP_RETURN_ON_ERROR(display_fill_rect(x + (5 * CHAR_SCALE), y, CHAR_SCALE, 7 * CHAR_SCALE, bg), TAG, "spacing failed");
|
||||
ESP_RETURN_ON_ERROR(display_fill_rect(x, y + (7 * CHAR_SCALE), 6 * CHAR_SCALE, CHAR_SCALE, bg), TAG, "baseline failed");
|
||||
/* spacing column + bottom row */
|
||||
ESP_RETURN_ON_ERROR(display_fill_rect(x + (5 * scale), y, scale, 7 * scale, bg), TAG, "spacing failed");
|
||||
ESP_RETURN_ON_ERROR(display_fill_rect(x, y + (7 * scale), 6 * scale, scale, bg), TAG, "baseline failed");
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t display_draw_text(int x, int y, const char *text, uint16_t fg, uint16_t bg)
|
||||
static esp_err_t draw_text_scaled(int x, int y, const char *text, int scale, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
if (!s_initialized) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (!text) {
|
||||
if (!text || scale <= 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
const int char_w = 6 * scale;
|
||||
const int char_h = 8 * scale;
|
||||
int cursor_x = x;
|
||||
int cursor_y = y;
|
||||
|
||||
@@ -280,25 +289,79 @@ esp_err_t display_draw_text(int x, int y, const char *text, uint16_t fg, uint16_
|
||||
char c = text[i];
|
||||
if (c == '\n') {
|
||||
cursor_x = x;
|
||||
cursor_y += CHAR_H;
|
||||
cursor_y += char_h;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cursor_x + CHAR_W > DISPLAY_WIDTH) {
|
||||
if (cursor_x + char_w > DISPLAY_WIDTH) {
|
||||
cursor_x = x;
|
||||
cursor_y += CHAR_H;
|
||||
cursor_y += char_h;
|
||||
}
|
||||
if (cursor_y + CHAR_H > DISPLAY_HEIGHT) {
|
||||
if (cursor_y + char_h > DISPLAY_HEIGHT) {
|
||||
break;
|
||||
}
|
||||
|
||||
ESP_RETURN_ON_ERROR(draw_char(cursor_x, cursor_y, c, fg, bg), TAG, "draw_char failed");
|
||||
cursor_x += CHAR_W;
|
||||
ESP_RETURN_ON_ERROR(draw_char_scaled(cursor_x, cursor_y, c, scale, fg, bg), TAG, "draw_char failed");
|
||||
cursor_x += char_w;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t display_draw_text(int x, int y, const char *text, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
return draw_text_scaled(x, y, text, CHAR_SCALE, fg, bg);
|
||||
}
|
||||
|
||||
esp_err_t display_draw_text_small(int x, int y, const char *text, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
return draw_text_scaled(x, y, text, CHAR_SCALE_SMALL, fg, bg);
|
||||
}
|
||||
|
||||
esp_err_t display_draw_text_centered(int y, const char *text, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (text == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
x = (DISPLAY_WIDTH - ((int)strlen(text) * CHAR_W)) / 2;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
return display_draw_text(x, y, text, fg, bg);
|
||||
}
|
||||
|
||||
esp_err_t display_draw_text_small_centered(int y, const char *text, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
int x;
|
||||
|
||||
if (text == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
x = (DISPLAY_WIDTH - ((int)strlen(text) * CHAR_W_SMALL)) / 2;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
return display_draw_text_small(x, y, text, fg, bg);
|
||||
}
|
||||
|
||||
esp_err_t display_draw_text_inverse(int x, int y, const char *text, uint16_t bg, uint16_t fg)
|
||||
{
|
||||
int w;
|
||||
int h = CHAR_H;
|
||||
|
||||
if (text == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
w = (int)strlen(text) * CHAR_W;
|
||||
ESP_RETURN_ON_ERROR(display_fill_rect(x, y, w, h, bg), TAG, "inverse bg fill failed");
|
||||
return display_draw_text(x, y, text, fg, bg);
|
||||
}
|
||||
|
||||
esp_err_t display_draw_button_status(int btn_id, bool pressed)
|
||||
{
|
||||
if (btn_id < 0 || btn_id > 2) {
|
||||
|
||||
Reference in New Issue
Block a user