|
| 1 | +#if ENABLE_VU_METER |
| 2 | +#ifndef display_vu_h |
| 3 | +#define display_vu_h |
| 4 | +#include "player.h" |
| 5 | + |
| 6 | +#ifdef VU_PARAMS |
| 7 | +enum : uint16_t VU_PARAMS; |
| 8 | +#else |
| 9 | +/*****************************************************************************************************************************************************************************/ |
| 10 | +/* vu left | vu top | band width | band height | band space |num of bands |max samples | horisontal | Max Bands Color | Min Bands Color */ |
| 11 | +/*****************************************************************************************************************************************************************************/ |
| 12 | +#if DSP_MODEL==DSP_ST7735 && DTYPE==INITR_BLACKTAB /* ST7735 160x128 */ |
| 13 | +enum : uint16_t { VU_X = 4, VU_Y = 50, VU_BW = 10, VU_BH = 44, VU_BS = 2, VU_NB = 8, VU_BMS = 2, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = SILVER }; |
| 14 | +#elif DSP_MODEL==DSP_ST7735 && DTYPE==INITR_144GREENTAB /* ST7735 128x128 */ |
| 15 | +enum : uint16_t { VU_X = 4, VU_Y = 45, VU_BW = 60, VU_BH = 8, VU_BS = 0, VU_NB = 10, VU_BMS = 3, VU_HOR = 1, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY }; |
| 16 | +#elif DSP_MODEL==DSP_ILI9341 /* ILI9341 320x240 */ |
| 17 | +enum : uint16_t { VU_X = 4, VU_Y = 100, VU_BW = 20, VU_BH = 86, VU_BS = 4, VU_NB = 10, VU_BMS = 2, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY }; |
| 18 | +#elif DSP_MODEL==DSP_ST7789 /* ST7789 320x240 */ |
| 19 | +enum : uint16_t { VU_X = 4, VU_Y = 100, VU_BW = 20, VU_BH = 86, VU_BS = 4, VU_NB = 10, VU_BMS = 3, VU_HOR = 0, VU_COLOR_MAX = TFT_LOGO, VU_COLOR_MIN = GRAY }; |
| 20 | +#else |
| 21 | +#error YOUR DISPLAY DOES NOT SUPPORT ENABLE_VU_METER FEATURE YET |
| 22 | +#endif |
| 23 | +#endif //VU_PARAMS |
| 24 | + |
| 25 | +/*****************************************************************************************************************************************************************************/ |
| 26 | + |
| 27 | +void drawVU(DspCore *dsp); |
| 28 | + |
| 29 | +GFXcanvas16 gfxc(VU_BW*2+VU_BS,VU_BH); |
| 30 | + |
| 31 | +void drawVU(DspCore *dsp){ |
| 32 | + if((display.mode!=PLAYER && display.mode!=VOL)) return; |
| 33 | + player.getVUlevel(); |
| 34 | + static uint16_t samples_cnt, measL, measR; |
| 35 | + samples_cnt++; |
| 36 | + uint16_t dimension = VU_HOR?VU_BW:VU_BH; |
| 37 | + uint8_t L = map((VS1053_CS!=255)?player.vuLeft:log(player.vuLeft)*38+45, 255, 0, 0, dimension); |
| 38 | + uint8_t R = map((VS1053_CS!=255)?player.vuRight:log(player.vuRight)*38+45, 255, 0, 0, dimension); |
| 39 | + if(player.isRunning()){ |
| 40 | + if(L>measL) measL=L; |
| 41 | + if(R>measR) measR=R; |
| 42 | + }else{ |
| 43 | + if(measL<255) measL+=2; |
| 44 | + if(measR<255) measR+=2; |
| 45 | + } |
| 46 | +#if VS1053_CS==255 |
| 47 | + if(samples_cnt<VU_BMS) return; |
| 48 | +#endif |
| 49 | + samples_cnt=0; |
| 50 | + uint8_t h=(dimension/VU_NB)-2; |
| 51 | + for(int i=0; i<dimension; i++){ |
| 52 | + if(i%(dimension/VU_NB)==0){ |
| 53 | + if(VU_HOR){ |
| 54 | + uint16_t bandColor = (i>VU_BW-(VU_BW/VU_NB)*4)?VU_COLOR_MAX:VU_COLOR_MIN; |
| 55 | + gfxc.fillRect(i, 0, h, VU_BH, bandColor); |
| 56 | + gfxc.fillRect(i+VU_BW+VU_BS, 0, h, VU_BH, bandColor); |
| 57 | + }else{ |
| 58 | + uint16_t bandColor = (i<(VU_BH/VU_NB)*3)?VU_COLOR_MAX:VU_COLOR_MIN; |
| 59 | + gfxc.fillRect(0, i, VU_BW, h, bandColor); |
| 60 | + gfxc.fillRect(VU_BW+VU_BS, i, VU_BW, h, bandColor); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + if(VU_HOR){ |
| 65 | + gfxc.fillRect(VU_BW-measL, 0, measL, VU_BW, TFT_BG); |
| 66 | + gfxc.fillRect(VU_BW*2+VU_BS-measR, 0, measR, VU_BW, TFT_BG); |
| 67 | + dsp->drawRGBBitmap (VU_X, VU_Y, gfxc.getBuffer(), 120, VU_BH); |
| 68 | + }else{ |
| 69 | + gfxc.fillRect(0, 0, VU_BW, measL, TFT_BG); |
| 70 | + gfxc.fillRect(VU_BW+VU_BS, 0, VU_BW, measR, TFT_BG); |
| 71 | + dsp->drawRGBBitmap (VU_X, VU_Y, gfxc.getBuffer(), VU_BW*2+VU_BS, VU_BH); |
| 72 | + } |
| 73 | + if(player.isRunning()){ |
| 74 | + measL=0; |
| 75 | + measR=0; |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +#endif |
| 80 | +#endif |
0 commit comments