浏览代码

tweak airplay artwork

Philippe G 3 年之前
父节点
当前提交
a4d2017a07
共有 4 个文件被更改,包括 23 次插入6 次删除
  1. 1 0
      components/display/CMakeLists.txt
  2. 3 3
      components/display/core/gds_image.c
  3. 19 3
      components/display/display.c
  4. 二进制
      components/display/note.jpg

+ 1 - 0
components/display/CMakeLists.txt

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

+ 3 - 3
components/display/core/gds_image.c

@@ -142,7 +142,7 @@ static unsigned OutHandlerDirect(JDEC *Decoder, void *Bitmap, JRECT *Frame) {
 	JpegCtx *Context = (JpegCtx*) Decoder->device;
     uint8_t *Pixels = (uint8_t*) Bitmap;
 	int Shift = 8 - Context->Depth;
-	
+
 	// decoded image is RGB888, shift only make sense for grayscale
 	if (Context->Mode == GDS_RGB888) {
 		OUTHANDLERDIRECT(Scaler888, 0);
@@ -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) {
     JDEC Decoder;
     JpegCtx Context;
-	char *Scratch = calloc(SCRATCH_SIZE, 1);
+	char *Scratch = malloc(SCRATCH_SIZE);
 	
     if (!Scratch) {
         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;
     JpegCtx Context;
 	bool Ret = false;
-	char *Scratch = calloc(SCRATCH_SIZE, 1);
+	char *Scratch = malloc(SCRATCH_SIZE);
 	
     if (!Scratch) {
         ESP_LOGE(TAG, "Cannot allocate workspace");

+ 19 - 3
components/display/display.c

@@ -33,6 +33,8 @@ static const char *TAG = "display";
 #define	DEFAULT_SLEEP			3600
 #define ARTWORK_BORDER			1
 
+extern const uint8_t default_artwork[]   asm("_binary_note_jpg_start");
+
 static EXT_RAM_ATTR struct {
 	TaskHandle_t task;
 	SemaphoreHandle_t mutex;
@@ -51,6 +53,8 @@ static EXT_RAM_ATTR struct {
 	} duration;
 	struct {
 		bool enable, fit;
+		bool updated;
+		int tick;
 		int offset;
 	}  artwork;
 	TickType_t tick;
@@ -239,7 +243,12 @@ static void displayer_task(void *args) {
 				// just re-write the whole line it's easier
 				GDS_TextLine(display, 1, GDS_TEXT_LEFT, GDS_TEXT_CLEAR, displayer.header);	
 				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;
 			} else timer_sleep = max(1000 - elapsed, 0);	
 		} 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 y = x ? 0 : 32;
 	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:
 		// let the task self-suspend (we might be doing i2c_write)
 		GDS_SetTextWidth(display, 0);
+		GDS_Clear(display, GDS_COLOR_BLACK); 
 		displayer.state = DISPLAYER_DOWN;
 		display_bus(&displayer, DISPLAY_BUS_GIVE);
 		break;

二进制
components/display/note.jpg