Skip to content

Commit 5587637

Browse files
committed
List view simplified pt1
1 parent 4f562d5 commit 5587637

File tree

2 files changed

+124
-89
lines changed

2 files changed

+124
-89
lines changed

src/common.h

Lines changed: 121 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// created: 10.Feb.2022
2-
// updated: 18.Dec 2024
2+
// updated: 22.Dec 2024
33

44
#pragma once
55
#pragma GCC optimize("Os") // optimize for code size
@@ -178,9 +178,29 @@
178178
#define ANSI_ESC_STRIKE "\033[9m"
179179

180180
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
181+
enum status {
182+
NONE = 0,
183+
RADIO = 1,
184+
PLAYER = 2,
185+
DLNA = 3,
186+
CLOCK = 4,
187+
BRIGHTNESS = 5,
188+
ALARM = 6,
189+
SLEEPTIMER = 7,
190+
STATIONSLIST = 8,
191+
AUDIOFILESLIST = 9,
192+
DLNAITEMSLIST = 10,
193+
BLUETOOTH = 11,
194+
EQUALIZER = 12,
195+
SETTINGS = 13,
196+
IR_SETTINGS = 14,
197+
UNDEFINED = 255
198+
};
199+
181200
static bool _newLine = false;
182201
extern SemaphoreHandle_t mutex_rtc;
183202
extern RTIME rtc;
203+
184204
#define SerialPrintfln(...) {xSemaphoreTake(mutex_rtc, portMAX_DELAY); \
185205
/* line feed */ if(_newLine){_newLine = false; Serial.println("");} \
186206
rtc.hasValidTime()? Serial.printf("%s ", rtc.gettime_s()) : Serial.printf("00:00:00 "); \
@@ -2607,6 +2627,82 @@ class alarmClock : public RegisterTable { // draw a clock in 12 or 24h format
26072627
}
26082628
};
26092629
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
2630+
class uniList {
2631+
2632+
private:
2633+
int16_t m_x = 0;
2634+
int16_t m_y = 0;
2635+
int16_t m_w = 0;
2636+
int16_t m_h = 0;
2637+
int16_t m_nr[10] = {0};
2638+
uint8_t m_fontSize = 0;
2639+
uint8_t m_lineHight = 0;
2640+
uint8_t m_mode = 0;
2641+
uint8_t m_insert = 0;
2642+
uint32_t m_bgColor = 0;
2643+
char* m_name = NULL;
2644+
char* m_buff = NULL;
2645+
char* m_txt[10] = {0};
2646+
char* m_ext[10] = {0};
2647+
bool m_enabled = false;
2648+
2649+
public:
2650+
uniList(const char* name){
2651+
if(name) m_name = x_ps_strdup(name);
2652+
else m_name = x_ps_strdup("dlnaList");
2653+
m_bgColor = TFT_BLACK;
2654+
}
2655+
~uniList(){
2656+
if(m_name){free(m_name); m_name = NULL;}
2657+
if(m_buff){free(m_buff); m_buff = NULL;}
2658+
for(int i = 0; i < 10; i++){if(m_txt[i]) free(m_txt[i]); if(m_ext[i]) free(m_ext[i]);}
2659+
}
2660+
void begin(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t fontSize){
2661+
m_x = x; // x pos
2662+
m_y = y; // y pos
2663+
m_w = w; // width
2664+
m_h = h; // high
2665+
m_fontSize = fontSize;
2666+
m_enabled = false;
2667+
m_lineHight = m_h / 10;
2668+
m_buff = x_ps_malloc(1024);
2669+
}
2670+
void setMode(uint8_t mode){
2671+
if(mode == RADIO) {m_mode = RADIO; m_insert = 10;}
2672+
if(mode == PLAYER) m_mode = PLAYER;
2673+
if(mode == DLNA) m_mode = DLNA;
2674+
}
2675+
void clearList(){
2676+
tft.fillRect(m_x, m_y, m_w, m_h, m_bgColor);
2677+
}
2678+
void drawLine(uint8_t pos, const char* txt, const char* ext, const char* color = ANSI_ESC_WHITE, int16_t nr = -1){
2679+
if(pos > 9) return;
2680+
tft.setFont(m_fontSize);
2681+
if(m_mode == RADIO){
2682+
sprintf(m_buff, ANSI_ESC_YELLOW "%03d %s%s" , nr, color, txt);
2683+
if(txt){free(m_txt[pos]); m_txt[pos] = NULL; m_txt[pos] = strdup(txt);}
2684+
if(ext){free(m_ext[pos]); m_ext[pos] = NULL; m_ext[pos] = strdup(ext);}
2685+
m_nr[pos] = nr;
2686+
}
2687+
tft.writeText(m_buff, m_insert, m_y + pos *m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
2688+
}
2689+
void colourLine(uint8_t pos, const char* color = ANSI_ESC_WHITE) {
2690+
if(pos > 9) return;
2691+
tft.setFont(m_fontSize);
2692+
if(m_mode == RADIO){
2693+
sprintf(m_buff, ANSI_ESC_YELLOW "%03d %s%s" , m_nr[pos], color, m_txt[pos]);
2694+
}
2695+
tft.writeText(m_buff, m_insert, m_y + pos *m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
2696+
}
2697+
const char* getTxtByPos(uint8_t pos){
2698+
return m_txt[pos];
2699+
}
2700+
int16_t getNumberByPos(uint8_t pos){
2701+
return m_nr[pos];
2702+
}
2703+
};
2704+
extern uniList myList;
2705+
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
26102706
/*
26112707
———————————————————————————————————————————————————————
26122708
| DLNA List Vol3 01:10:32 | m_itemsListPos
@@ -2739,7 +2835,7 @@ class dlnaList : public RegisterTable {
27392835
if(m_browseOnRelease == 0){;} // file
27402836
if(m_browseOnRelease == 1){(*m_dlnaLevel) ++; m_dlna->browseServer(m_currDLNAsrvNr, "0", 0 , 9);} // get serverlist
27412837
if(m_browseOnRelease == 2){(*m_dlnaLevel) --; m_dlna->browseServer(m_currDLNAsrvNr, m_dlnaHistory[*m_dlnaLevel].objId, 0 , 9);} // previous level
2742-
if(m_browseOnRelease == 3){(*m_dlnaLevel) ++; m_dlna->browseServer(m_currDLNAsrvNr, m_dlnaHistory[*m_dlnaLevel].objId, 0 , 9);} // folder
2838+
if(m_browseOnRelease == 3){(*m_dlnaLevel) ++; m_dlna->browseServer(m_currDLNAsrvNr, m_dlnaHistory[*m_dlnaLevel].objId, 0 , 9);} // folder, next level
27432839
if(m_browseOnRelease == 4){ m_dlna->browseServer(m_currDLNAsrvNr, m_dlnaHistory[*m_dlnaLevel].objId, m_viewPoint, 9);} // scroll up / down
27442840

27452841
m_browseOnRelease = 0;
@@ -2805,8 +2901,6 @@ class dlnaList : public RegisterTable {
28052901
tft.writeText(m_buff, posX, posY, width, height, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
28062902
}
28072903

2808-
2809-
28102904
void hasReleased(uint16_t x, uint16_t y){
28112905

28122906
bool guard1 = false; if(m_dlnaServer.friendlyName.size() > (m_itemListPos -1)) guard1 = true;
@@ -2950,7 +3044,7 @@ class dlnaList : public RegisterTable {
29503044
m_chptr = NULL;
29513045
m_dlna->browseServer(m_currDLNAsrvNr, m_dlnaHistory[*m_dlnaLevel].objId, m_viewPoint, 9);
29523046
m_dlna->loop();
2953-
while(m_dlna->getState() != m_dlna->IDLE) {m_dlna->loop(); vTaskDelay(10);} // wait of browse rady
3047+
while(m_dlna->getState() != m_dlna->IDLE) {m_dlna->loop(); vTaskDelay(10);} // wait of browse ready
29543048
m_srvContent = m_dlna->getBrowseResult();
29553049
dlnaItemsList();
29563050
return;
@@ -3017,7 +3111,7 @@ class dlnaList : public RegisterTable {
30173111
dlnaItemsList();
30183112
return NULL;
30193113
}
3020-
if(strcmp(m_srvContent.itemURL[m_currItemNr[*m_dlnaLevel] - m_viewPoint], "?") == 0){ // ----------------------------------------------------- choose folder
3114+
if(strcmp(m_srvContent.itemURL[m_currItemNr[*m_dlnaLevel] - m_viewPoint], "?") == 0){ // --------------------------------------- choose folder
30213115
drawItem(m_currItemNr[*m_dlnaLevel] - m_viewPoint + 1, true); // make cyan
30223116
vTaskDelay(300);
30233117
(*m_dlnaLevel) ++;
@@ -3460,6 +3554,10 @@ class stationsList : public RegisterTable {
34603554
char* m_pathBuff = NULL;
34613555
char* m_buff = NULL;
34623556
releasedArg m_ra;
3557+
const char* m_colorToDraw = NULL;
3558+
const char* m_staNameToDraw = NULL;
3559+
uint16_t m_staNrToDraw = 0;
3560+
34633561
public:
34643562
stationsList(const char* name){
34653563
register_object(this);
@@ -3527,9 +3625,10 @@ class stationsList : public RegisterTable {
35273625
}
35283626
if(m_browseOnRelease == 2) { stationslist(false); // wipe down
35293627
}
3530-
if(m_browseOnRelease == 3) { tft.writeText(m_buff, 10, m_y + (m_stationListPos)*m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
3628+
if(m_browseOnRelease == 3) { myList.getTxtByPos(m_stationListPos); // click
3629+
myList.colourLine(m_stationListPos, ANSI_ESC_CYAN);
35313630
vTaskDelay(300 / portTICK_PERIOD_MS);
3532-
m_ra.val1 = m_firstStationsLineNr + m_stationListPos + 1; // station number
3631+
m_ra.val1 = myList.getNumberByPos(m_stationListPos);
35333632
}
35343633
m_browseOnRelease = 0;
35353634
m_oldX = 0; m_oldY = 0;
@@ -3550,30 +3649,18 @@ class stationsList : public RegisterTable {
35503649
m_curStaNrCpy = *m_curSstationNr;
35513650
if(m_curStaNrCpy == 0) m_curStaNrCpy = 1;
35523651
}
3553-
else{
3554-
tft.fillRect(m_x, m_y, m_w, m_h, m_bgColor);
3555-
}
3556-
char* stationStr = x_ps_malloc(1024);
3557-
tft.setFont(m_fontSize);
3558-
for(uint8_t pos = 0; pos < 10; pos++) {
3652+
myList.clearList();
3653+
myList.setMode(RADIO);
35593654

3655+
for(uint8_t pos = 0; pos < 10; pos++) {
35603656
if(pos + m_firstStationsLineNr + 1 > staMgnt.getSumStations()) break;
3657+
if(staMgnt.getStationFav(pos + m_firstStationsLineNr + 1) == '*') m_colorToDraw = ANSI_ESC_WHITE; // is fav station
3658+
else m_colorToDraw = ANSI_ESC_GREY; // is not a fav station
3659+
if((pos + m_firstStationsLineNr + 1) == m_curStaNrCpy) m_colorToDraw = ANSI_ESC_MAGENTA; // is the current station
35613660

3562-
if((pos + m_firstStationsLineNr + 1) == m_curStaNrCpy){
3563-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_MAGENTA, ( pos + m_firstStationsLineNr + 1)); // is currStationNr
3564-
}
3565-
else{
3566-
if(staMgnt.getStationFav(pos + m_firstStationsLineNr + 1) == '*'){
3567-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_WHITE, (pos + m_firstStationsLineNr + 1));
3568-
}
3569-
else{
3570-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_GREY, (pos + m_firstStationsLineNr + 1));
3571-
}
3572-
}
3573-
strcpy(stationStr + strlen(stationStr), staMgnt.getStationName(pos + m_firstStationsLineNr + 1));
3574-
3575-
for(int i = 0; i < strlen(stationStr); i++) {if(stationStr[i] == '#') stationStr[i] = '\0';}
3576-
tft.writeText(stationStr, 10, m_y + (pos)*m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
3661+
m_staNameToDraw = staMgnt.getStationName(pos + m_firstStationsLineNr + 1); // the station name
3662+
m_staNrToDraw = pos + m_firstStationsLineNr + 1; // the station number
3663+
myList.drawLine(pos, m_staNameToDraw, "", m_colorToDraw, m_staNrToDraw);
35773664
}
35783665
xSemaphoreGive(mutex_display);
35793666
}
@@ -3598,16 +3685,9 @@ class stationsList : public RegisterTable {
35983685
return;
35993686
}
36003687

3601-
if(!m_buff) m_buff = x_ps_malloc(1024);
3602-
tft.setFont(m_fontSize);
3603-
sprintf(m_buff, ANSI_ESC_YELLOW "%03d " ANSI_ESC_CYAN, (m_firstStationsLineNr + m_stationListPos + 1));
3604-
strcpy(m_buff + strlen(m_buff), staMgnt.getStationName(m_firstStationsLineNr + m_stationListPos + 1));
3605-
3606-
for(int i = 0; i < strlen(m_buff); i++) {if(m_buff[i] == '#') m_buff[i] = '\0';}
3607-
// tft.writeText(m_buff, 10, m_y + (m_stationListPos)*m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
36083688
if(m_oldX || m_oldY) return;
36093689
m_oldX = x; m_oldY = y;
3610-
m_browseOnRelease = 3;
3690+
m_browseOnRelease = 3; // pos has clicked
36113691
return;
36123692
}
36133693
public:
@@ -3633,23 +3713,9 @@ class stationsList : public RegisterTable {
36333713
stationslist(false);
36343714
return;
36353715
}
3636-
char* stationStr = x_ps_malloc(1024);
3637-
if(!stationStr){log_e("oom"); return;}
3638-
if(!stationStr) return;
3639-
tft.setFont(m_fontSize);
3640-
if(staMgnt.getStationFav(m_curStaNrCpy) == '*'){
3641-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_WHITE, (m_curStaNrCpy));
3642-
}
3643-
else{
3644-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_GREY, (m_curStaNrCpy));
3645-
}
3646-
strcpy(stationStr + strlen(stationStr), staMgnt.getStationName(m_curStaNrCpy));
3647-
tft.writeText(stationStr, 10, m_y + (pos)*m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
3716+
myList.colourLine(pos,staMgnt.getStationFav(m_curStaNrCpy) == '*'? ANSI_ESC_WHITE : ANSI_ESC_GREY);
3717+
myList.colourLine(pos - 1, ANSI_ESC_MAGENTA);
36483718
m_curStaNrCpy--;
3649-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_MAGENTA, (m_curStaNrCpy));
3650-
strcpy(stationStr + strlen(stationStr), staMgnt.getStationName(m_curStaNrCpy));
3651-
tft.writeText(stationStr, 10, m_y + (pos - 1)*m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
3652-
free(stationStr);
36533719
}
36543720
void nextStation(){ // from IR control
36553721
if(m_curStaNrCpy >= staMgnt.getSumStations()) return;
@@ -3661,27 +3727,13 @@ class stationsList : public RegisterTable {
36613727
stationslist(false);
36623728
return;
36633729
}
3664-
char* stationStr = x_ps_malloc(1024);
3665-
if(!stationStr) return;
3666-
tft.setFont(m_fontSize);
3667-
if(staMgnt.getStationFav(m_curStaNrCpy) == '*'){
3668-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_WHITE, (m_curStaNrCpy));
3669-
}
3670-
else{
3671-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_GREY, (m_curStaNrCpy));
3672-
}
3673-
strcpy(stationStr + strlen(stationStr), staMgnt.getStationName(m_curStaNrCpy));
3674-
tft.writeText(stationStr, 10, m_y + (pos)*m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
3730+
myList.colourLine(pos,staMgnt.getStationFav(m_curStaNrCpy) == '*'? ANSI_ESC_WHITE : ANSI_ESC_GREY);
3731+
myList.colourLine(pos + 1, ANSI_ESC_MAGENTA);
36753732
m_curStaNrCpy++;
3676-
sprintf(stationStr, ANSI_ESC_YELLOW "%03d " ANSI_ESC_MAGENTA, (m_curStaNrCpy));
3677-
strcpy(stationStr + strlen(stationStr), staMgnt.getStationName(m_curStaNrCpy));
3678-
tft.writeText(stationStr, 10, m_y + (pos + 1)*m_lineHight, m_w - 10, m_lineHight, TFT_ALIGN_LEFT, TFT_ALIGN_CENTER, true, true);
3679-
free(stationStr);
36803733
}
36813734
uint16_t getSelectedStation(){ // from IR control
36823735
return m_curStaNrCpy;
36833736
}
3684-
36853737
};
36863738
//——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
36873739
class vuMeter : public RegisterTable {

src/main.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
MiniWebRadio -- Webradio receiver for ESP32
55
66
first release on 03/2017 */String Version ="\
7-
Version 3.6.0d - Dec 21/2024 ";
7+
Version 3.6.0e - Dec 22/2024 ";
88

99
/* 2.8" color display (320x240px) with controller ILI9341 or HX8347D (SPI) or
1010
3.5" color display (480x320px) with controller ILI9486 or ILI9488 (SPI)
@@ -27,25 +27,6 @@ SET_LOOP_TASK_STACK_SIZE(10 * 1024);
2727

2828
// global variables
2929

30-
enum status {
31-
NONE = 0,
32-
RADIO = 1,
33-
PLAYER = 2,
34-
DLNA = 3,
35-
CLOCK = 4,
36-
BRIGHTNESS = 5,
37-
ALARM = 6,
38-
SLEEPTIMER = 7,
39-
STATIONSLIST = 8,
40-
AUDIOFILESLIST = 9,
41-
DLNAITEMSLIST = 10,
42-
BLUETOOTH = 11,
43-
EQUALIZER = 12,
44-
SETTINGS = 13,
45-
IR_SETTINGS = 14,
46-
UNDEFINED = 255
47-
};
48-
4930
char _hl_item[16][40]{ "", // none
5031
"Internet Radio", // "* интернет-радио *" "ραδιόφωνο Internet"
5132
"Audio player", // "** цифрово́й плеер **
@@ -371,6 +352,7 @@ TFT tft(TFT_CONTROLLER, DISPLAY_INVERSION);
371352
displayHeader dispHeader("dispHeader", _fonts[1]);
372353
displayFooter dispFooter("dispFooter", _fonts[1]);
373354
numbersBox volBox("volBox");
355+
uniList myList("myList");
374356
// RADIO
375357
button2state btn_RA_Mute("btn_RA_Mute");
376358
button1state btn_RA_prevSta("btn_RA_prevSta"), btn_RA_nextSta("btn_RA_nextSta");
@@ -2056,6 +2038,7 @@ void placingGraphicObjects() { // and initialize them
20562038
dispHeader.begin( _winHeader.x, _winHeader.y, _winHeader.w, _winHeader.h);
20572039
dispFooter.begin( _winFooter.x, _winFooter.y, _winFooter.w, _winFooter.h);
20582040
volBox.begin( _winVolBox.x, _winVolBox.y, _winVolBox.w, _winVolBox.h);
2041+
myList.begin( _winWoHF.x, _winWoHF.y, _winWoHF.w, _winWoHF.h, _fonts[0]);
20592042
// RADIO -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
20602043
sdr_RA_volume.begin( _sdrOvBtns.x, _sdrOvBtns.y, _sdrOvBtns.w, _sdrOvBtns.h, 0, _volumeSteps); sdr_RA_volume.setValue(_cur_volume);
20612044
btn_RA_Mute.begin( 0 * _winButton.w, _winButton.y, _winButton.w, _winButton.h); btn_RA_Mute.setOffPicturePath("/btn/Button_Mute_Green.jpg");

0 commit comments

Comments
 (0)