Skip to content

Commit f7a3b7a

Browse files
committed
rework cover state machine, scroll artist - song
1 parent 33d3859 commit f7a3b7a

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

effect/cover_art.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "effect.hpp"
22
#include "3rd-party/JPEGDEC/JPEGDEC.h"
3+
#include "btstack_util.h"
34

45
// cover art thumbnails are 200x200, main options:
56
#if 0
@@ -43,15 +44,20 @@ static int JPEGDraw(JPEGDRAW *pDraw) {
4344

4445
void CoverArt::update(int16_t *buffer16, size_t sample_count) {
4546
if (this->render){
46-
this->render = false;
4747
display.clear();
4848
if (this->cover_data != NULL){
49+
this->render = false;
4950
decoder.openRAM((uint8_t *) this->cover_data, this->cover_len, JPEGDraw);
5051
decoder.setUserPointer(&display);
5152
decoder.decode(0, 0, SCALING);
5253
decoder.close();
5354
} else {
54-
display.draw_string(0, 12, "Info");
55+
uint16_t scroll_offset = this->cover_art_scroller_offset / 2;
56+
display.draw_string(Display::WIDTH - scroll_offset, 12, this->cover_art_info);
57+
this->cover_art_scroller_offset++;
58+
if (scroll_offset >= ((MAX_TEXT_LEN * 8 * 2) + Display::WIDTH)){
59+
this->render = false;
60+
}
5561
}
5662
}
5763
}
@@ -65,12 +71,10 @@ void CoverArt::set_cover(const uint8_t * data, uint32_t len){
6571
this->render = true;
6672
};
6773

68-
void CoverArt::set_artist(const char * artist){
69-
70-
}
71-
void CoverArt::set_album(const char * album){
72-
73-
}
74-
void CoverArt::set_title(const char * title){
75-
74+
void CoverArt::set_info(const char *info) {
75+
btstack_strcpy(this->cover_art_info, sizeof(this->cover_art_info), info);
76+
printf("Scroller: %s\n", this->cover_art_info);
77+
this->cover_data = NULL;
78+
this->cover_art_scroller_offset = 0;
79+
this->render = true;
7680
}

effect/effect.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ class ClassicFFT : public Effect {
7676
void init(uint32_t sample_frequency) override;
7777
};
7878

79+
#define MAX_TEXT_LEN 32
7980
class CoverArt : public Effect {
8081
private:
8182
const uint8_t * cover_data;
8283
uint32_t cover_len;
8384
bool render;
85+
char cover_art_info[2 * MAX_TEXT_LEN];
86+
uint16_t cover_art_scroller_offset = 0;
87+
8488
public:
8589
CoverArt(Display& display, FIX_FFT &fft) : Effect(display, fft) {}
8690
void update(int16_t *buffer16, size_t sample_count) override;
8791
void init(uint32_t sample_frequency) override;
8892
void set_cover(const uint8_t * data, uint32_t len);
89-
void set_artist(const char * artist);
90-
void set_album(const char * album);
91-
void set_title(const char * title);
93+
void set_info(const char * info);
9294
};

src/a2dp_sink.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,15 @@ static FILE * a2dp_sink_cover_art_file;
178178
#ifdef COVER_ART_DEMO
179179
static uint8_t cover_art_jpeg[40000];
180180
void cover_art_set_cover(const uint8_t * cover_data, uint32_t cover_len);
181+
void cover_art_set_info(const char * info);
181182
#endif
182183
#endif
183184

184185
#define MAX_NAME_LEN 32
185186
static char avrcp_artist[MAX_NAME_LEN];
186187
static char avrcp_album[MAX_NAME_LEN];
187188
static char avrcp_title[MAX_NAME_LEN];
189+
static char avrcp_info[2 * MAX_NAME_LEN];
188190

189191
typedef struct {
190192
uint8_t reconfigure;
@@ -981,7 +983,11 @@ static void avrcp_controller_packet_handler(uint8_t packet_type, uint16_t channe
981983
printf("AVRCP Controller: Cover Art %s\n", a2dp_sink_demo_image_handle);
982984
#ifdef COVER_ART_DEMO
983985
#ifndef HAVE_POSIX_FILE_IO
984-
cover_art_set_cover(NULL, 0);
986+
// artist - album
987+
btstack_strcpy(avrcp_info, sizeof(avrcp_info), avrcp_artist);
988+
btstack_strcat( avrcp_info, sizeof(avrcp_info), " - ");
989+
btstack_strcat( avrcp_info, sizeof(avrcp_info), avrcp_title);
990+
cover_art_set_info(avrcp_info);
985991
#endif
986992
if (a2dp_sink_cover_art_download_active == false){
987993
#ifdef HAVE_POSIX_FILE_IO

src/btstack_audio_pico.cpp

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "btstack_debug.h"
5050
#include "btstack_audio.h"
5151
#include "btstack_run_loop.h"
52+
#include "btstack_util.h"
5253

5354
#include <stddef.h>
5455
#include <hardware/dma.h>
@@ -66,7 +67,7 @@
6667
#include "3rd-party/JPEGDEC/JPEGDEC.h"
6768

6869
#define DRIVER_POLL_INTERVAL_MS 5
69-
#define INFO_TIME_MS 3000
70+
#define INFO_TIME_MS 5000
7071
#define COVER_TIME_MS 3000
7172

7273
Display display;
@@ -343,26 +344,21 @@ const btstack_audio_sink_t * btstack_audio_pico_sink_get_instance(void){
343344
return &btstack_audio_pico_sink;
344345
}
345346

346-
void cover_art_set_cover(const uint8_t * data, uint32_t len){
347+
void cover_art_cache_effect(void){
348+
// cache active effect
349+
if (current_effect != 2){
350+
previous_effect = current_effect;
351+
current_effect = 2;
352+
}
353+
}
347354

355+
void cover_art_set_cover(const uint8_t * data, uint32_t len){
348356
cover_data = data;
349357
cover_len = len;
350-
351358
switch (display_mode){
352359
case DISPLAY_IDLE:
353360
case DISPLAY_COVER:
354361
case DISPLAY_FFT:
355-
// cache active effect
356-
btstack_assert(data != NULL);
357-
// new song started, show info
358-
if (display_mode != DISPLAY_COVER){
359-
previous_effect = current_effect;
360-
current_effect = 2;
361-
}
362-
printf("COVER: new song, show info\n");
363-
display_mode = DISPLAY_INFO;
364-
cover_time_counter = INFO_TIME_MS / DRIVER_POLL_INTERVAL_MS;
365-
cover_art.set_cover(NULL, 0);
366362
break;
367363
case DISPLAY_INFO:
368364
// info still shown, cache cover for later
@@ -381,14 +377,10 @@ void cover_art_set_cover(const uint8_t * data, uint32_t len){
381377
}
382378
}
383379

384-
void cover_art_set_title(const char * title){
385-
cover_art.set_title(title);
386-
};
387-
388-
void cover_art_set_artist(const char * artist){
389-
cover_art.set_artist(artist);
390-
};
391-
392-
void cover_art_set_album(const char * album){
393-
cover_art.set_album(album);
394-
};
380+
void cover_art_set_info(const char * info){
381+
cover_art_cache_effect();
382+
printf("COVER: new song, show info\n");
383+
cover_art.set_info(info);
384+
display_mode = DISPLAY_INFO;
385+
cover_time_counter = INFO_TIME_MS / DRIVER_POLL_INTERVAL_MS;
386+
}

0 commit comments

Comments
 (0)