mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-05-23 21:47:46 +01:00
add display + some refactoring
This commit is contained in:
@@ -20,11 +20,57 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "config.h"
|
||||
|
||||
#define LINELEN 40
|
||||
#define TAG "display"
|
||||
#include "ssd1306.h"
|
||||
#include "ssd1306_draw.h"
|
||||
#include "ssd1306_font.h"
|
||||
#include "ssd1306_default_if.h"
|
||||
|
||||
#define LINELEN 40
|
||||
#define I2C_PORT 1
|
||||
#define I2C_ADDRESS 0x3C
|
||||
#define TAG "display"
|
||||
|
||||
static struct SSD1306_Device I2CDisplay;
|
||||
static bool init, display;
|
||||
|
||||
void display_init(void) {
|
||||
char *item = config_alloc_get(NVS_TYPE_STR, "display_config");
|
||||
|
||||
if (!item || !*item) {
|
||||
ESP_LOGI(TAG, "no display");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strstr(item, "I2C")) {
|
||||
int scl = -1, sda = -1;
|
||||
int width = -1, height = -1;
|
||||
char *p;
|
||||
|
||||
// done no matter what
|
||||
init = true;
|
||||
|
||||
// no time for smart parsing - this is for tinkerers
|
||||
if ((p = strcasestr(item, "scl")) != NULL) scl = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(item, "sda")) != NULL) sda = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(item, "width")) != NULL) width = atoi(strchr(p, '=') + 1);
|
||||
if ((p = strcasestr(item, "height")) != NULL) height = atoi(strchr(p, '=') + 1);
|
||||
|
||||
if (sda != -1 && scl != -1 && width != -1 && height != -1) {
|
||||
SSD1306_I2CMasterInitDefault( I2C_PORT, sda, scl );
|
||||
SSD1306_I2CMasterAttachDisplayDefault( &I2CDisplay, width, height, I2C_ADDRESS, -1);
|
||||
SSD1306_SetFont( &I2CDisplay, &Font_droid_sans_fallback_15x17 );
|
||||
ESP_LOGI(TAG, "initialized I2C display %dx%d (sda:%d, scl:%d)", width, height, sda, scl);
|
||||
display = true;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "cannot initialized I2C display %s [%dx%d sda:%d, scl:%d]", item, width, height, sda, scl);
|
||||
}
|
||||
} else {
|
||||
// other types
|
||||
}
|
||||
}
|
||||
|
||||
//Change special LCD chars to something more printable on screen
|
||||
unsigned char printable(unsigned char c) {
|
||||
@@ -69,6 +115,13 @@ void show_display_buffer(char *ddram) {
|
||||
makeprintable((unsigned char *)line2);
|
||||
|
||||
ESP_LOGI(TAG, "\n\t%.40s\n\t%.40s", line1, line2);
|
||||
|
||||
if (display) {
|
||||
SSD1306_Clear( &I2CDisplay, SSD_COLOR_BLACK );
|
||||
SSD1306_FontDrawAnchoredString( &I2CDisplay, TextAnchor_NorthWest, line1, SSD_COLOR_WHITE );
|
||||
SSD1306_FontDrawAnchoredString( &I2CDisplay, TextAnchor_SouthWest, line2, SSD_COLOR_WHITE );
|
||||
SSD1306_Update( &I2CDisplay );
|
||||
}
|
||||
}
|
||||
|
||||
// Check if char is printable, or a valid symbol
|
||||
@@ -93,6 +146,8 @@ void vfd_data( unsigned short *data, int bytes_read) {
|
||||
int n;
|
||||
int addr = 0; /* counter */
|
||||
|
||||
if (!init) display_init();
|
||||
|
||||
if (bytes_read % 2) bytes_read--; /* even number of bytes */
|
||||
// if we use Noritake VFD codes, display data starts at 12
|
||||
display_data = &(data[5]); /* display data starts at byte 10 */
|
||||
|
||||
Reference in New Issue
Block a user