mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-06 19:47:02 +03:00
display improvements, reset player_id when switching server
This commit is contained in:
@@ -30,18 +30,20 @@
|
||||
|
||||
static bool (*slimp_handler_chain)(u8_t *data, int len);
|
||||
static struct display_handle_s *handle;
|
||||
static void (*chained_notify)(in_addr_t ip, u16_t hport, u16_t cport);
|
||||
|
||||
static void server_attach(in_addr_t ip, u16_t hport, u16_t cport);
|
||||
static bool display_handler(u8_t *data, int len);
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void display_init(void) {
|
||||
void display_init(char *welcome) {
|
||||
char *item = config_alloc_get(NVS_TYPE_STR, "display_config");
|
||||
|
||||
if (item && *item) {
|
||||
handle = &SSD1306_handle;
|
||||
if (handle->init(item)) {
|
||||
if (handle->init(item, welcome)) {
|
||||
slimp_handler_chain = slimp_handler;
|
||||
slimp_handler = display_handler;
|
||||
ESP_LOGI(TAG, "Display initialization successful");
|
||||
@@ -51,10 +53,23 @@ void display_init(void) {
|
||||
} else {
|
||||
ESP_LOGI(TAG, "no display");
|
||||
}
|
||||
|
||||
chained_notify = server_notify;
|
||||
server_notify = server_attach;
|
||||
|
||||
if (item) free(item);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void server_attach(in_addr_t ip, u16_t hport, u16_t cport) {
|
||||
char msg[32];
|
||||
sprintf(msg, "%s:%hu", inet_ntoa(ip), hport);
|
||||
handle->print_message(msg);
|
||||
if (chained_notify) (*chained_notify)(ip, hport, cport);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Process graphic display data
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
#pragma once
|
||||
|
||||
struct display_handle_s {
|
||||
bool (*init)(char *config);
|
||||
bool (*init)(char *config, char* welcome);
|
||||
void (*print_message)(char *msg);
|
||||
void (*vfdc_handler)(u8_t *data, int len);
|
||||
void (*grfe_handler)(u8_t *data, int len);
|
||||
void (*grfb_handler)(u8_t *data, int len);
|
||||
|
||||
@@ -35,11 +35,13 @@
|
||||
#define TAG "display"
|
||||
|
||||
static void vfdc_handler( u8_t *_data, int bytes_read);
|
||||
void grfe_handler( u8_t *data, int len);
|
||||
static bool display_init(char *config);
|
||||
static void grfe_handler( u8_t *data, int len);
|
||||
static bool display_init(char *config, char *welcome);
|
||||
static void print_message(char *msg);
|
||||
|
||||
struct display_handle_s SSD1306_handle = {
|
||||
display_init,
|
||||
print_message,
|
||||
vfdc_handler,
|
||||
grfe_handler,
|
||||
NULL, NULL,
|
||||
@@ -71,7 +73,7 @@ static const unsigned char BitReverseTable256[] =
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static bool display_init(char *config) {
|
||||
static bool display_init(char *config, char *welcome) {
|
||||
bool res = false;
|
||||
|
||||
if (strstr(config, "I2C")) {
|
||||
@@ -89,6 +91,7 @@ static bool display_init(char *config) {
|
||||
SSD1306_I2CMasterInitDefault( I2C_PORT, sda, scl );
|
||||
SSD1306_I2CMasterAttachDisplayDefault( &I2CDisplay, width, height, I2C_ADDRESS, -1);
|
||||
SSD1306_SetFont( &I2CDisplay, &Font_droid_sans_fallback_15x17 );
|
||||
print_message(welcome);
|
||||
ESP_LOGI(TAG, "Initialized I2C display %dx%d (sda:%d, scl:%d)", width, height, sda, scl);
|
||||
res = true;
|
||||
} else {
|
||||
@@ -101,6 +104,17 @@ static bool display_init(char *config) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void print_message(char *msg) {
|
||||
if (!msg) return;
|
||||
SSD1306_Clear( &I2CDisplay, SSD_COLOR_BLACK );
|
||||
SSD1306_SetDisplayAddressMode( &I2CDisplay, AddressMode_Horizontal );
|
||||
SSD1306_FontDrawAnchoredString( &I2CDisplay, TextAnchor_Center, msg, SSD_COLOR_WHITE );
|
||||
SSD1306_Update( &I2CDisplay );
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Change special LCD chars to something more printable on screen
|
||||
*/
|
||||
|
||||
@@ -134,6 +134,8 @@ static void sendHELO(bool reconnect, const char *fixed_cap, const char *var_cap,
|
||||
base_cap = BASE_CAP;
|
||||
#endif
|
||||
|
||||
if (!reconnect) player_id = PLAYER_ID;
|
||||
|
||||
memset(&pkt, 0, sizeof(pkt));
|
||||
memcpy(&pkt.opcode, "HELO", 4);
|
||||
pkt.length = htonl(sizeof(struct HELO_packet) - 8 + strlen(base_cap) + strlen(fixed_cap) + strlen(var_cap));
|
||||
|
||||
@@ -71,7 +71,7 @@ extern const uint8_t server_cert_pem_start[] asm("_binary_github_pem_start");
|
||||
extern const uint8_t server_cert_pem_end[] asm("_binary_github_pem_end");
|
||||
|
||||
extern void services_init(void);
|
||||
extern void display_init(void);
|
||||
extern void display_init(char *welcome);
|
||||
|
||||
/* brief this is an exemple of a callback that you can setup in your own app to get notified of wifi manager event */
|
||||
void cb_connection_got_ip(void *pvParameter){
|
||||
@@ -337,7 +337,7 @@ void app_main()
|
||||
services_init();
|
||||
|
||||
ESP_LOGD(TAG,"Initializing display");
|
||||
display_init();
|
||||
display_init("SqueezeESP32");
|
||||
|
||||
#if !RECOVERY_APPLICATION
|
||||
ESP_LOGI(TAG,"Checking if certificates need to be updated");
|
||||
|
||||
@@ -20,7 +20,7 @@ sub initPlugin {
|
||||
my $class = shift;
|
||||
|
||||
$class->SUPER::initPlugin(@_);
|
||||
Slim::Networking::Slimproto::addPlayerClass($class, 100, 'squeeze2esp32', { client => 'Plugins::SqueezeESP32::Player', display => 'Plugins::SqueezeESP32::Graphics' });
|
||||
Slim::Networking::Slimproto::addPlayerClass($class, 100, 'squeezeesp32', { client => 'Plugins::SqueezeESP32::Player', display => 'Plugins::SqueezeESP32::Graphics' });
|
||||
$log->info("Added class 100 for SqueezeESP32");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user