SDSPI fix for ESP32-C5: correct API v5.5, CMake dependencies, pin mapping
This commit is contained in:
@@ -1,115 +1,108 @@
|
||||
/**
|
||||
* Frame-Scroller — rollende Liste der letzten Frames
|
||||
*
|
||||
* Zeigt bis zu 7 Frames an, jeder Frame = 1 Zeile (12px hoch):
|
||||
* [RSSI-Balk] X #####-#####-##### CH:161 RSSI:-45
|
||||
*
|
||||
* Der Scroller aktualisiert sich nur wenn sich ein Frame ändert.
|
||||
* Frame-Scroller - rollende Liste der letzten Frames
|
||||
* Verwendet st7735_draw_pixel statt esp_lcd_panel_draw_bitmap
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "v2x_display.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "st7735.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
extern esp_lcd_panel_handle_t s_panel;
|
||||
extern bool s_initialized;
|
||||
extern void *s_dev;
|
||||
|
||||
static const char *TAG = "v2x-scroller";
|
||||
// static const char *TAG = "v2x-scroller";
|
||||
|
||||
/* Scroller-Konfiguration */
|
||||
#define SCROLLER_FRAMES_VISIBLE 7 /* Frames sichtbar */
|
||||
#define SCROLLER_LINE_HEIGHT 13 /* Pixel pro Zeile */
|
||||
#define SCROLLER_START_Y 28 /* Erste Zeile beginnt bei Y=28 */
|
||||
#define SCROLLER_MAX_ENTRIES 64 /* Frames im Buffer */
|
||||
#define SCROLLER_FRAMES_VISIBLE 7
|
||||
#define SCROLLER_LINE_HEIGHT 13
|
||||
#define SCROLLER_START_Y 28
|
||||
#define SCROLLER_MAX_ENTRIES 64
|
||||
|
||||
/* Frame-Daten für den Scroller */
|
||||
typedef struct {
|
||||
char msg_char; /* 'B', 'C', 'D', '?' */
|
||||
int8_t rssi; /* RSSI dBm */
|
||||
uint8_t ch; /* Kanal */
|
||||
char bssid_hex[9]; /* #####-#####-##### */
|
||||
char msg_char;
|
||||
int8_t rssi;
|
||||
uint8_t ch;
|
||||
char bssid_hex[9];
|
||||
} scroller_entry_t;
|
||||
|
||||
static scroller_entry_t s_entries[SCROLLER_MAX_ENTRIES];
|
||||
static uint32_t s_entry_count = 0;
|
||||
|
||||
/* RSSI-Balk als ASCII (20 Zeichen breit) */
|
||||
static void rssi_to_bar(int8_t rssi, char *bar, int len)
|
||||
{
|
||||
if (rssi <= -100) rssi = -100;
|
||||
if (rssi >= -20) rssi = -20;
|
||||
|
||||
float pct = (float)(rssi + 100) / 80.0f;
|
||||
int filled = (int)(pct * 20);
|
||||
|
||||
for (int i = 0; i < len - 1; i++) {
|
||||
bar[i] = (i < filled) ? '\x5C' : '\xC1'; /* ▌ und ░ (block chars) */
|
||||
}
|
||||
bar[len - 1] = '\0';
|
||||
}
|
||||
|
||||
/* BSSID als #####-#####-##### hex */
|
||||
static void bssid_to_str(const uint8_t *bssid, char *str)
|
||||
{
|
||||
snprintf(str, 14, "%02X-%02X-%02X-%02X-%02X-%02X",
|
||||
bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
|
||||
}
|
||||
|
||||
/* Scroller-Eintrag hinzufügen */
|
||||
void scroller_add_entry(uint8_t msg_type, int8_t rssi, uint8_t ch, const uint8_t *bssid)
|
||||
{
|
||||
scroller_entry_t *e = &s_entries[s_entry_count % SCROLLER_MAX_ENTRIES];
|
||||
|
||||
/* Msg-Type Character */
|
||||
switch (msg_type) {
|
||||
case 1: e->msg_char = 'B'; break; /* BSM */
|
||||
case 2: e->msg_char = 'C'; break; /* CAM */
|
||||
case 3: e->msg_char = 'D'; break; /* DENM */
|
||||
case 1: e->msg_char = 'B'; break;
|
||||
case 2: e->msg_char = 'C'; break;
|
||||
case 3: e->msg_char = 'D'; break;
|
||||
default: e->msg_char = '?'; break;
|
||||
}
|
||||
|
||||
e->rssi = rssi;
|
||||
e->ch = ch;
|
||||
if (bssid) {
|
||||
bssid_to_str(bssid, e->bssid_hex);
|
||||
snprintf(e->bssid_hex, 9, "%02X-%02X-%02X", bssid[0], bssid[1], bssid[2]);
|
||||
} else {
|
||||
snprintf(e->bssid_hex, 14, "----------");
|
||||
snprintf(e->bssid_hex, 9, "-----");
|
||||
}
|
||||
|
||||
s_entry_count++;
|
||||
}
|
||||
|
||||
/* Scroller neu zeichnen (vollständig) */
|
||||
/* Zeile pixel-weise löschen */
|
||||
static void scroller_clear_line(int16_t y)
|
||||
{
|
||||
for (int16_t py = 0; py < SCROLLER_LINE_HEIGHT; py++) {
|
||||
for (int16_t px = 0; px < DISP_W; px++) {
|
||||
st7735_draw_pixel((void *)s_dev, px, y + py, DISP_COLOR_BLACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* RSSI-Balk pixel-weise zeichnen */
|
||||
static void scroller_draw_rssi_bar(int16_t x, int16_t y, int16_t w, int16_t h, int8_t rssi)
|
||||
{
|
||||
if (rssi < -100) rssi = -100;
|
||||
if (rssi > -20) rssi = -20;
|
||||
float pct = (float)(rssi + 100) / 80.0f;
|
||||
|
||||
uint16_t bar_color = DISP_COLOR_RED;
|
||||
if (pct > 0.6f) bar_color = DISP_COLOR_GREEN;
|
||||
else if (pct > 0.3f) bar_color = DISP_COLOR_YELLOW;
|
||||
|
||||
int filled_w = (int16_t)(w * pct);
|
||||
|
||||
for (int16_t py = 0; py < h; py++) {
|
||||
for (int16_t px = 0; px < w; px++) {
|
||||
uint16_t color = (px < filled_w) ? bar_color : DISP_COLOR_BLACK;
|
||||
st7735_draw_pixel((void *)s_dev, x + px, y + py, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void scroller_redraw(void)
|
||||
{
|
||||
if (!s_initialized) return;
|
||||
|
||||
int32_t total = s_entry_count;
|
||||
int start = (total > SCROLLER_FRAMES_VISIBLE) ?
|
||||
int start = (total > SCROLLER_FRAMES_VISIBLE) ?
|
||||
(total - SCROLLER_FRAMES_VISIBLE) : 0;
|
||||
|
||||
/* Hintergrund zeichnen */
|
||||
int total_h = SCROLLER_FRAMES_VISIBLE * SCROLLER_LINE_HEIGHT;
|
||||
v2x_display_rect(0, SCROLLER_START_Y, DISP_W, total_h, DISP_COLOR_BLACK, true);
|
||||
/* Ganzes Display schwarz */
|
||||
st7735_fill_screen((void *)s_dev, DISP_COLOR_BLACK);
|
||||
|
||||
/* Zeilenweise rendern (von oben nach unten = neueste Frames zuerst) */
|
||||
for (int i = SCROLLER_FRAMES_VISIBLE - 1; i >= 0; i--) {
|
||||
int idx = (start + i) % SCROLLER_MAX_ENTRIES;
|
||||
scroller_entry_t *e = &s_entries[idx];
|
||||
int y = SCROLLER_START_Y + (SCROLLER_FRAMES_VISIBLE - 1 - i) * SCROLLER_LINE_HEIGHT;
|
||||
|
||||
/* RSSI-Farbbalk links (5px breit, 11px hoch) */
|
||||
uint16_t bar_color = DISP_COLOR_RED;
|
||||
float pct = (float)(e->rssi + 100) / 80.0f;
|
||||
if (pct > 0.6f) bar_color = DISP_COLOR_GREEN;
|
||||
else if (pct > 0.3f) bar_color = DISP_COLOR_YELLOW;
|
||||
scroller_draw_rssi_bar(2, y + 1, 5, 11, e->rssi);
|
||||
|
||||
v2x_display_rect(2, y + 1, 5, 11, bar_color, true);
|
||||
|
||||
/* Msg-Type Zeichen (grün/cyan/rot/gray) */
|
||||
/* Msg-Type Zeichen */
|
||||
uint16_t msg_color = DISP_COLOR_GRAY;
|
||||
if (e->msg_char == 'B') msg_color = DISP_COLOR_GREEN;
|
||||
else if (e->msg_char == 'C') msg_color = DISP_COLOR_CYAN;
|
||||
@@ -118,29 +111,28 @@ void scroller_redraw(void)
|
||||
char msg_line[2] = { e->msg_char, '\0' };
|
||||
v2x_display_text(9, y + 1, msg_line, msg_color, FONT_6x8);
|
||||
|
||||
/* BSSID als Hex (blau) */
|
||||
/* BSSID als Hex */
|
||||
v2x_display_text(16, y + 1, e->bssid_hex, DISP_COLOR_BLUE, FONT_6x8);
|
||||
|
||||
/* Kanal + RSSI (weiß) */
|
||||
/* Kanal + RSSI */
|
||||
char ch_buf[20];
|
||||
snprintf(ch_buf, sizeof(ch_buf), "CH:%d %3d", e->ch, e->rssi);
|
||||
v2x_display_text(60, y + 1, ch_buf, DISP_COLOR_WHITE, FONT_6x8);
|
||||
}
|
||||
}
|
||||
|
||||
/* Geänderte Zeile neu zeichnen (nur die betroffene Zeile — schnell) */
|
||||
void scroller_redraw_line(uint32_t entry_idx)
|
||||
{
|
||||
if (!s_initialized) return;
|
||||
|
||||
int32_t total = s_entry_count;
|
||||
if (entry_idx < (total > SCROLLER_FRAMES_VISIBLE ? total - SCROLLER_FRAMES_VISIBLE : 0)) {
|
||||
return; /* Zu alt, nicht sichtbar */
|
||||
return;
|
||||
}
|
||||
|
||||
int start = (total > SCROLLER_FRAMES_VISIBLE) ?
|
||||
int start = (total > SCROLLER_FRAMES_VISIBLE) ?
|
||||
(total - SCROLLER_FRAMES_VISIBLE) : 0;
|
||||
|
||||
|
||||
int line_idx = (int)(entry_idx - start);
|
||||
if (line_idx < 0 || line_idx >= SCROLLER_FRAMES_VISIBLE) return;
|
||||
|
||||
@@ -149,15 +141,10 @@ void scroller_redraw_line(uint32_t entry_idx)
|
||||
int y = SCROLLER_START_Y + (SCROLLER_FRAMES_VISIBLE - 1 - line_idx) * SCROLLER_LINE_HEIGHT;
|
||||
|
||||
/* Zeile löschen */
|
||||
v2x_display_rect(0, y, DISP_W, SCROLLER_LINE_HEIGHT, DISP_COLOR_BLACK, true);
|
||||
scroller_clear_line(y);
|
||||
|
||||
/* Neu zeichnen */
|
||||
uint16_t bar_color = DISP_COLOR_RED;
|
||||
float pct = (float)(e->rssi + 100) / 80.0f;
|
||||
if (pct > 0.6f) bar_color = DISP_COLOR_GREEN;
|
||||
else if (pct > 0.3f) bar_color = DISP_COLOR_YELLOW;
|
||||
|
||||
v2x_display_rect(2, y + 1, 5, 11, bar_color, true);
|
||||
scroller_draw_rssi_bar(2, y + 1, 5, 11, e->rssi);
|
||||
|
||||
uint16_t msg_color = DISP_COLOR_GRAY;
|
||||
if (e->msg_char == 'B') msg_color = DISP_COLOR_GREEN;
|
||||
|
||||
Reference in New Issue
Block a user