tweak airplay artwork

This commit is contained in:
Philippe G
2022-01-09 16:47:28 -08:00
parent a16a1678e5
commit a4d2017a07
4 changed files with 23 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ idf_component_register(SRC_DIRS . core core/ifaces fonts
INCLUDE_DIRS . fonts core INCLUDE_DIRS . fonts core
REQUIRES platform_config tools esp_common REQUIRES platform_config tools esp_common
PRIV_REQUIRES services freertos driver PRIV_REQUIRES services freertos driver
EMBED_FILES note.jpg
) )
set_source_files_properties(display.c set_source_files_properties(display.c

View File

@@ -167,7 +167,7 @@ static unsigned OutHandlerDirect(JDEC *Decoder, void *Bitmap, JRECT *Frame) {
static void* DecodeJPEG(uint8_t *Source, int *Width, int *Height, float Scale, bool SizeOnly, int RGB_Mode) { static void* DecodeJPEG(uint8_t *Source, int *Width, int *Height, float Scale, bool SizeOnly, int RGB_Mode) {
JDEC Decoder; JDEC Decoder;
JpegCtx Context; JpegCtx Context;
char *Scratch = calloc(SCRATCH_SIZE, 1); char *Scratch = malloc(SCRATCH_SIZE);
if (!Scratch) { if (!Scratch) {
ESP_LOGE(TAG, "Cannot allocate workspace"); ESP_LOGE(TAG, "Cannot allocate workspace");
@@ -372,7 +372,7 @@ bool GDS_DrawJPEG(struct GDS_Device* Device, uint8_t *Source, int x, int y, int
JDEC Decoder; JDEC Decoder;
JpegCtx Context; JpegCtx Context;
bool Ret = false; bool Ret = false;
char *Scratch = calloc(SCRATCH_SIZE, 1); char *Scratch = malloc(SCRATCH_SIZE);
if (!Scratch) { if (!Scratch) {
ESP_LOGE(TAG, "Cannot allocate workspace"); ESP_LOGE(TAG, "Cannot allocate workspace");

View File

@@ -33,6 +33,8 @@ static const char *TAG = "display";
#define DEFAULT_SLEEP 3600 #define DEFAULT_SLEEP 3600
#define ARTWORK_BORDER 1 #define ARTWORK_BORDER 1
extern const uint8_t default_artwork[] asm("_binary_note_jpg_start");
static EXT_RAM_ATTR struct { static EXT_RAM_ATTR struct {
TaskHandle_t task; TaskHandle_t task;
SemaphoreHandle_t mutex; SemaphoreHandle_t mutex;
@@ -51,6 +53,8 @@ static EXT_RAM_ATTR struct {
} duration; } duration;
struct { struct {
bool enable, fit; bool enable, fit;
bool updated;
int tick;
int offset; int offset;
} artwork; } artwork;
TickType_t tick; TickType_t tick;
@@ -240,6 +244,11 @@ static void displayer_task(void *args) {
GDS_TextLine(display, 1, GDS_TEXT_LEFT, GDS_TEXT_CLEAR, displayer.header); GDS_TextLine(display, 1, GDS_TEXT_LEFT, GDS_TEXT_CLEAR, displayer.header);
GDS_TextLine(display, 1, GDS_TEXT_RIGHT, GDS_TEXT_UPDATE, _line); GDS_TextLine(display, 1, GDS_TEXT_RIGHT, GDS_TEXT_UPDATE, _line);
// if we have not received artwork after 5s, display a default icon
if (displayer.artwork.enable && !displayer.artwork.updated && tick - displayer.artwork.tick > pdMS_TO_TICKS(5000)) {
ESP_LOGI(TAG, "no artwork received, setting default");
displayer_artwork((uint8_t*) default_artwork);
}
timer_sleep = 1000; timer_sleep = 1000;
} else timer_sleep = max(1000 - elapsed, 0); } else timer_sleep = max(1000 - elapsed, 0);
} else timer_sleep = DEFAULT_SLEEP; } else timer_sleep = DEFAULT_SLEEP;
@@ -252,7 +261,6 @@ static void displayer_task(void *args) {
} }
} }
/**************************************************************************************** /****************************************************************************************
* *
*/ */
@@ -262,7 +270,14 @@ void displayer_artwork(uint8_t *data) {
int x = displayer.artwork.offset ? displayer.artwork.offset + ARTWORK_BORDER : 0; int x = displayer.artwork.offset ? displayer.artwork.offset + ARTWORK_BORDER : 0;
int y = x ? 0 : 32; int y = x ? 0 : 32;
GDS_ClearWindow(display, x, y, -1, -1, GDS_COLOR_BLACK); GDS_ClearWindow(display, x, y, -1, -1, GDS_COLOR_BLACK);
if (data) GDS_DrawJPEG(display, data, x, y, GDS_IMAGE_CENTER | (displayer.artwork.fit ? GDS_IMAGE_FIT : 0)); if (data) {
displayer.artwork.updated = true;
GDS_DrawJPEG(display, data, x, y, GDS_IMAGE_CENTER | (displayer.artwork.fit ? GDS_IMAGE_FIT : 0));
} else {
displayer.artwork.updated = false;
displayer.artwork.tick = xTaskGetTickCount();
}
} }
/**************************************************************************************** /****************************************************************************************
@@ -428,6 +443,7 @@ void displayer_control(enum displayer_cmd_e cmd, ...) {
case DISPLAYER_SHUTDOWN: case DISPLAYER_SHUTDOWN:
// let the task self-suspend (we might be doing i2c_write) // let the task self-suspend (we might be doing i2c_write)
GDS_SetTextWidth(display, 0); GDS_SetTextWidth(display, 0);
GDS_Clear(display, GDS_COLOR_BLACK);
displayer.state = DISPLAYER_DOWN; displayer.state = DISPLAYER_DOWN;
display_bus(&displayer, DISPLAY_BUS_GIVE); display_bus(&displayer, DISPLAY_BUS_GIVE);
break; break;

BIN
components/display/note.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB