123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906 |
- #include <ctype.h>
- #include <math.h>
- #include "esp_dsp.h"
- #include "squeezelite.h"
- #include "slimproto.h"
- #include "display.h"
- #include "gds.h"
- #include "gds_text.h"
- #include "gds_draw.h"
- #pragma pack(push, 1)
- struct grfb_packet {
- char opcode[4];
- s16_t brightness;
- };
- struct grfe_packet {
- char opcode[4];
- u16_t offset;
- u8_t transition;
- u8_t param;
- };
- struct grfs_packet {
- char opcode[4];
- u8_t screen;
- u8_t direction;
- u32_t pause;
- u32_t speed;
- u16_t by;
- u16_t mode;
- u16_t width;
- u16_t offset;
- };
- struct grfg_packet {
- char opcode[4];
- u16_t screen;
- u16_t width;
- };
- struct visu_packet {
- char opcode[4];
- u8_t which;
- u8_t count;
- union {
- struct {
- u32_t bars;
- u32_t spectrum_scale;
- } full;
- struct {
- u32_t width;
- u32_t height;
- s32_t col;
- s32_t row;
- u32_t border;
- u32_t bars;
- u32_t spectrum_scale;
- };
- };
- };
- struct ANIC_header {
- char opcode[4];
- u32_t length;
- u8_t mode;
- };
- #pragma pack(pop)
- static struct {
- TaskHandle_t task;
- SemaphoreHandle_t mutex;
- int width, height;
- bool dirty;
- bool owned;
- } displayer = { .dirty = true, .owned = true };
- #define LONG_WAKE (10*1000)
- #define SB_HEIGHT 32
- #define FFT_LEN_BIT 6
- #define FFT_LEN (1 << FFT_LEN_BIT)
- #define RMS_LEN_BIT 6
- #define RMS_LEN (1 << RMS_LEN_BIT)
- #define DISPLAY_BW 20000
- static struct scroller_s {
-
- u8_t screen;
- u32_t pause, speed;
- int wake;
- u16_t mode;
- s16_t by;
-
- bool active, first;
- int scrolled;
- struct {
- u8_t *frame;
- u32_t width;
- u32_t max, size;
- } scroll;
- struct {
- u8_t *frame;
- u32_t width;
- } back;
- u8_t *frame;
- u32_t width;
- } scroller;
- #define MAX_BARS 32
- static EXT_RAM_ATTR struct {
- int bar_gap, bar_width, bar_border;
- struct {
- int current, max;
- int limit;
- } bars[MAX_BARS];
- float spectrum_scale;
- int n, col, row, height, width, border;
- enum { VISU_BLANK, VISU_VUMETER, VISU_SPECTRUM, VISU_WAVEFORM } mode;
- int speed, wake;
- float fft[FFT_LEN*2], samples[FFT_LEN*2], hanning[FFT_LEN];
- } visu;
- #define ANIM_NONE 0x00
- #define ANIM_TRANSITION 0x01
- #define ANIM_SCROLL_ONCE 0x02
- #define ANIM_SCREEN_1 0x04
- #define ANIM_SCREEN_2 0x08
- static u8_t ANIC_resp = ANIM_NONE;
- static u8_t SETD_width;
- #define SCROLL_STACK_SIZE (3*1024)
- #define LINELEN 40
- static log_level loglevel = lINFO;
- static bool (*slimp_handler_chain)(u8_t *data, int len);
- static void (*slimp_loop_chain)(void);
- static void (*notify_chain)(in_addr_t ip, u16_t hport, u16_t cport);
- static bool (*display_bus_chain)(void *from, enum display_bus_cmd_e cmd);
- #define max(a,b) (((a) > (b)) ? (a) : (b))
- static void server(in_addr_t ip, u16_t hport, u16_t cport);
- static void send_server(void);
- static bool handler(u8_t *data, int len);
- static bool display_bus_handler(void *from, enum display_bus_cmd_e cmd);
- static void vfdc_handler( u8_t *_data, int bytes_read);
- static void grfe_handler( u8_t *data, int len);
- static void grfb_handler(u8_t *data, int len);
- static void grfs_handler(u8_t *data, int len);
- static void grfg_handler(u8_t *data, int len);
- static void visu_handler(u8_t *data, int len);
- static void displayer_task(void* arg);
- bool sb_display_init(void) {
- static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
- static EXT_RAM_ATTR StackType_t xStack[SCROLL_STACK_SIZE] __attribute__ ((aligned (4)));
-
-
- if (!display || GDS_GetWidth(display) <= 0 || GDS_GetHeight(display) <= 0) {
- LOG_INFO("no display for LMS");
- return false;
- }
-
-
- displayer.width = GDS_GetWidth(display);
- displayer.height = min(GDS_GetHeight(display), SB_HEIGHT);
- SETD_width = displayer.width;
-
- visu.bar_gap = 1;
- visu.speed = 100;
- dsps_fft2r_init_fc32(visu.fft, FFT_LEN);
- dsps_wind_hann_f32(visu.hanning, FFT_LEN);
-
-
- displayer.mutex = xSemaphoreCreateMutex();
- displayer.task = xTaskCreateStatic( (TaskFunction_t) displayer_task, "displayer_thread", SCROLL_STACK_SIZE, NULL, ESP_TASK_PRIO_MIN + 1, xStack, &xTaskBuffer);
-
-
- scroller.scroll.max = (displayer.width * displayer.height / 8) * 10;
- scroller.scroll.frame = malloc(scroller.scroll.max);
- scroller.back.frame = malloc(displayer.width * displayer.height / 8);
- scroller.frame = malloc(displayer.width * displayer.height / 8);
-
- slimp_handler_chain = slimp_handler;
- slimp_handler = handler;
-
- slimp_loop_chain = slimp_loop;
- slimp_loop = send_server;
-
- notify_chain = server_notify;
- server_notify = server;
-
- display_bus_chain = display_bus;
- display_bus = display_bus_handler;
-
- return true;
- }
- static bool display_bus_handler(void *from, enum display_bus_cmd_e cmd) {
-
- if (from == &displayer) return false ;
-
- LOG_INFO("Display bus command %d", cmd);
-
- xSemaphoreTake(displayer.mutex, portMAX_DELAY);
-
- switch (cmd) {
- case DISPLAY_BUS_TAKE:
- displayer.owned = false;
- break;
- case DISPLAY_BUS_GIVE:
- displayer.owned = true;
- break;
- }
-
- xSemaphoreGive(displayer.mutex);
-
-
- if (display_bus_chain) return (*display_bus_chain)(from, cmd);
- else return true;
- }
- static void send_server(void) {
-
-
- if (ANIC_resp != ANIM_NONE) {
- struct ANIC_header pkt_header;
- memset(&pkt_header, 0, sizeof(pkt_header));
- memcpy(&pkt_header.opcode, "ANIC", 4);
- pkt_header.length = htonl(sizeof(pkt_header) - 8);
- pkt_header.mode = ANIC_resp;
- send_packet((u8_t *)&pkt_header, sizeof(pkt_header));
-
- ANIC_resp = ANIM_NONE;
- }
-
- if (SETD_width) {
- struct SETD_header pkt_header;
-
- LOG_INFO("sending width %u", SETD_width);
-
- memset(&pkt_header, 0, sizeof(pkt_header));
- memcpy(&pkt_header.opcode, "SETD", 4);
- pkt_header.id = 0xfe;
- pkt_header.length = htonl(sizeof(pkt_header) + 2 - 8);
- send_packet((u8_t *)&pkt_header, sizeof(pkt_header));
- send_packet(&SETD_width, 2);
- SETD_width = 0;
- }
-
- if (slimp_loop_chain) (*slimp_loop_chain)();
- }
- static void server(in_addr_t ip, u16_t hport, u16_t cport) {
- char msg[32];
- sprintf(msg, "%s:%hu", inet_ntoa(ip), hport);
- if (displayer.owned) GDS_TextPos(display, GDS_FONT_DEFAULT, GDS_TEXT_CENTERED, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, msg);
- SETD_width = displayer.width;
- displayer.dirty = true;
- if (notify_chain) (*notify_chain)(ip, hport, cport);
- }
- static bool handler(u8_t *data, int len){
- bool res = true;
-
- if (!strncmp((char*) data, "vfdc", 4)) {
- vfdc_handler(data, len);
- } else if (!strncmp((char*) data, "grfe", 4)) {
- grfe_handler(data, len);
- } else if (!strncmp((char*) data, "grfb", 4)) {
- grfb_handler(data, len);
- } else if (!strncmp((char*) data, "grfs", 4)) {
- grfs_handler(data, len);
- } else if (!strncmp((char*) data, "grfg", 4)) {
- grfg_handler(data, len);
- } else if (!strncmp((char*) data, "visu", 4)) {
- visu_handler(data, len);
- } else {
- res = false;
- }
-
-
- if (*slimp_handler_chain) res |= (*slimp_handler_chain)(data, len);
-
- return res;
- }
- static void makeprintable(unsigned char * line) {
- for (int n = 0; n < LINELEN; n++) {
- switch (line[n]) {
- case 11:
- line[n] = '#';
- break;;
- case 16:
- line[n] = '>';
- break;;
- case 22:
- line[n] = '@';
- break;;
- case 145:
- line[n] = ' ';
- break;;
- case 152:
- line[n] = 'o';
- break;
- default:
- break;
- }
- }
- }
- static bool charisok(unsigned char c) {
- switch (c) {
- case 11:
- case 16:
- case 22:
- case 145:
- case 152:
- return true;
- break;;
- default:
- return isprint(c);
- }
- }
- static void show_display_buffer(char *ddram) {
- char line1[LINELEN+1];
- char *line2;
- memset(line1, 0, LINELEN+1);
- strncpy(line1, ddram, LINELEN);
- line2 = &(ddram[LINELEN]);
- line2[LINELEN] = '\0';
-
- makeprintable((unsigned char *)line1);
- makeprintable((unsigned char *)line2);
- LOG_DEBUG("\n\t%.40s\n\t%.40s", line1, line2);
- GDS_TextLine(display, 1, GDS_TEXT_LEFT, GDS_TEXT_CLEAR, line1);
- GDS_TextLine(display, 2, GDS_TEXT_LEFT, GDS_TEXT_CLEAR | GDS_TEXT_UPDATE, line2);
- }
- static void vfdc_handler( u8_t *_data, int bytes_read) {
- unsigned short *data = (unsigned short*) _data, *display_data;
- char ddram[(LINELEN + 1) * 2];
- int n, addr = 0;
- bytes_read -= 4;
- if (bytes_read % 2) bytes_read--;
-
- display_data = &(data[5]);
- memset(ddram, ' ', LINELEN * 2);
- for (n = 0; n < (bytes_read/2); n++) {
- unsigned short d;
- unsigned char t, c;
- d = ntohs(display_data[n]);
- t = (d & 0x00ff00) >> 8;
- c = (d & 0x0000ff);
- switch (t) {
- case 0x03:
- if (!charisok(c)) c = ' ';
- if (addr <= LINELEN * 2) {
- ddram[addr++] = c;
- }
- break;
- case 0x02:
- switch (c) {
- case 0x06:
- memset(ddram, ' ', LINELEN * 2);
- break;
- case 0x02:
- addr = 0;
- break;
- case 0xc0:
- addr = LINELEN;
- break;
- }
- }
- }
- show_display_buffer(ddram);
- }
- static void grfe_handler( u8_t *data, int len) {
-
- xSemaphoreTake(displayer.mutex, portMAX_DELAY);
-
- scroller.active = false;
-
-
- if (visu.mode && !visu.col && visu.row < SB_HEIGHT) {
- xSemaphoreGive(displayer.mutex);
- return;
- }
-
- if (displayer.owned) {
-
- if (displayer.dirty) {
- GDS_ClearExt(display, true);
- displayer.dirty = false;
- }
-
-
- GDS_DrawBitmapCBR(display, data + sizeof(struct grfe_packet), displayer.width, displayer.height);
- GDS_Update(display);
- }
-
- xSemaphoreGive(displayer.mutex);
-
- LOG_DEBUG("grfe frame %u", len);
- }
- static void grfb_handler(u8_t *data, int len) {
- struct grfb_packet *pkt = (struct grfb_packet*) data;
-
- pkt->brightness = htons(pkt->brightness);
-
- LOG_INFO("brightness %hu", pkt->brightness);
- if (pkt->brightness < 0) {
- GDS_DisplayOff(display);
- } else {
- GDS_DisplayOn(display);
- GDS_SetContrast(display, pkt->brightness);
- }
- }
- static void grfs_handler(u8_t *data, int len) {
- struct grfs_packet *pkt = (struct grfs_packet*) data;
- int size = len - sizeof(struct grfs_packet);
- int offset = htons(pkt->offset);
-
- LOG_DEBUG("gfrs s:%u d:%u p:%u sp:%u by:%hu m:%hu w:%hu o:%hu",
- (int) pkt->screen,
- (int) pkt->direction,
- htonl(pkt->pause),
- htonl(pkt->speed),
- htons(pkt->by),
- htons(pkt->mode),
- htons(pkt->width),
- htons(pkt->offset)
- );
-
-
- if (!offset) {
-
- xSemaphoreTake(displayer.mutex, portMAX_DELAY);
-
- scroller.screen = pkt->screen;
- scroller.pause = htonl(pkt->pause);
- scroller.speed = htonl(pkt->speed);
- scroller.mode = htons(pkt->mode);
- scroller.scroll.width = htons(pkt->width);
- scroller.first = true;
-
-
- scroller.back.width = displayer.width - ((visu.mode && visu.row < SB_HEIGHT) ? visu.width : 0);
-
- if (pkt->direction == 1) {
- scroller.scrolled = 0;
- scroller.by = htons(pkt->by);
- } else {
- scroller.scrolled = scroller.scroll.width;
- scroller.by = -htons(pkt->by);
- }
- xSemaphoreGive(displayer.mutex);
- }
-
- if (scroller.scroll.size + size < scroller.scroll.max) {
- memcpy(scroller.scroll.frame + offset, data + sizeof(struct grfs_packet), size);
- scroller.scroll.size = offset + size;
- LOG_INFO("scroller current size %u", scroller.scroll.size);
- } else {
- LOG_INFO("scroller too larger %u/%u", scroller.scroll.size + size, scroller.scroll.max);
- }
- }
- static void grfg_handler(u8_t *data, int len) {
- struct grfg_packet *pkt = (struct grfg_packet*) data;
-
- LOG_DEBUG("gfrg s:%hu w:%hu (len:%u)", htons(pkt->screen), htons(pkt->width), len);
-
- xSemaphoreTake(displayer.mutex, portMAX_DELAY);
-
-
- scroller.width = htons(pkt->width);
- memcpy(scroller.back.frame, data + sizeof(struct grfg_packet), len - sizeof(struct grfg_packet));
-
-
- memcpy(scroller.frame, scroller.back.frame, scroller.back.width * displayer.height / 8);
- for (int i = 0; i < scroller.width * displayer.height / 8; i++) scroller.frame[i] |= scroller.scroll.frame[scroller.scrolled * displayer.height / 8 + i];
-
-
- if (displayer.owned) {
- GDS_DrawBitmapCBR(display, scroller.frame, scroller.back.width, displayer.height);
- GDS_Update(display);
- }
-
-
- if (!visu.mode || visu.col || visu.row >= SB_HEIGHT) scroller.active = true;
-
-
- LOG_DEBUG("resuming scrolling task");
-
- xSemaphoreGive(displayer.mutex);
-
-
- vTaskResume(displayer.task);
- }
- static void visu_update(void) {
-
- if (pthread_mutex_trylock(&visu_export.mutex)) return;
-
-
- if (visu_export.level < (visu.mode == VISU_VUMETER ? RMS_LEN : FFT_LEN) * 2 && visu_export.running) {
- pthread_mutex_unlock(&visu_export.mutex);
- return;
- }
-
-
- for (int i = visu.n; --i >= 0;) visu.bars[i].current = 0;
-
- if (visu_export.running && visu_export.running) {
-
- if (visu.mode == VISU_VUMETER) {
- s16_t *iptr = visu_export.buffer;
-
-
- for (int i = RMS_LEN; --i >= 0;) {
- visu.bars[0].current += (*iptr * *iptr + (1 << (RMS_LEN_BIT - 2))) >> (RMS_LEN_BIT - 1);
- iptr++;
- visu.bars[1].current += (*iptr * *iptr + (1 << (RMS_LEN_BIT - 2))) >> (RMS_LEN_BIT - 1);
- iptr++;
- }
-
-
- for (int i = visu.n; --i >= 0;) {
- visu.bars[i].current = 32 * (0.01667f*10*log10f(0.0000001f + (visu.bars[i].current >> 1)) - 0.2543f);
- if (visu.bars[i].current > 31) visu.bars[i].current = 31;
- else if (visu.bars[i].current < 0) visu.bars[i].current = 0;
- }
- } else {
-
- for (int i = 0 ; i < FFT_LEN ; i++) {
-
- visu.samples[i * 2 + 0] = (float) (visu_export.buffer[2*i] + visu_export.buffer[2*i + 1]) * visu.hanning[i];
- visu.samples[i * 2 + 1] = 0;
- }
-
- dsps_fft2r_fc32_ae32(visu.samples, FFT_LEN);
- dsps_bit_rev_fc32_ansi(visu.samples, FFT_LEN);
- float rate = visu_export.rate;
-
-
- for (int i = 0, j = 1; i < visu.n && j < (FFT_LEN / 2); i++) {
- float power, count;
-
- for (count = 0, power = 0; j * visu_export.rate < visu.bars[i].limit * FFT_LEN && j < FFT_LEN / 2; j++, count += 1) {
- power += visu.samples[2*j] * visu.samples[2*j] + visu.samples[2*j+1] * visu.samples[2*j+1];
- }
-
- if (j >= (FFT_LEN / 2)) {
-
- if (count) power /= count * 2.;
- } else if (count) {
-
- float ratio = j - (visu.bars[i].limit * FFT_LEN) / rate;
- power += (visu.samples[2*j] * visu.samples[2*j] + visu.samples[2*j+1] * visu.samples[2*j+1]) * ratio;
-
-
- power /= (count + ratio) * 2;
- } else {
-
- power = (visu.samples[2*j] * visu.samples[2*j] + visu.samples[2*j+1] * visu.samples[2*j+1]) / 2.;
- }
-
-
- if (power) visu.bars[i].current = 32 * (0.01667f*10*(log10f(power) - log10f(FFT_LEN/2*2)) - 0.2543f);
- if (visu.bars[i].current > 31) visu.bars[i].current = 31;
- else if (visu.bars[i].current < 0) visu.bars[i].current = 0;
- }
- }
- }
-
-
- visu_export.level = 0;
- pthread_mutex_unlock(&visu_export.mutex);
- GDS_ClearExt(display, false, false, visu.col, visu.row, visu.col + visu.width - 1, visu.row + visu.height - 1);
-
- for (int i = visu.n; --i >= 0;) {
- int x1 = visu.col + visu.border + visu.bar_border + i*(visu.bar_width + visu.bar_gap);
- int y1 = visu.row + visu.height - 1;
-
- if (visu.bars[i].current > visu.bars[i].max) visu.bars[i].max = visu.bars[i].current;
- else if (visu.bars[i].max) visu.bars[i].max--;
-
- for (int j = 0; j <= visu.bars[i].current; j += 2)
- GDS_DrawLine(display, x1, y1 - j, x1 + visu.bar_width - 1, y1 - j, GDS_COLOR_WHITE);
-
- if (visu.bars[i].max > 2) {
- GDS_DrawLine(display, x1, y1 - visu.bars[i].max, x1 + visu.bar_width - 1, y1 - visu.bars[i].max, GDS_COLOR_WHITE);
- GDS_DrawLine(display, x1, y1 - visu.bars[i].max + 1, x1 + visu.bar_width - 1, y1 - visu.bars[i].max + 1, GDS_COLOR_WHITE);
- }
- }
- }
- void spectrum_limits(int min, int n, int pos) {
- if (n / 2) {
- int step = ((DISPLAY_BW - min) * visu.spectrum_scale * 2) / n;
- visu.bars[pos].limit = min + step;
- for (int i = 1; i < n/2; i++) visu.bars[pos+i].limit = visu.bars[pos+i-1].limit + step;
- spectrum_limits(visu.bars[pos + n/2 - 1].limit, n/2, pos + n/2);
- } else {
- visu.bars[pos].limit = DISPLAY_BW;
- }
- }
- static void visu_handler( u8_t *data, int len) {
- struct visu_packet *pkt = (struct visu_packet*) data;
- int bars = 0;
- LOG_DEBUG("visu %u with %u parameters", pkt->which, pkt->count);
-
-
-
-
- xSemaphoreTake(displayer.mutex, portMAX_DELAY);
- visu.mode = pkt->which;
-
-
- if (visu.row >= SB_HEIGHT) GDS_ClearExt(display, false, true, visu.col, visu.row, visu.col + visu.width - 1, visu.row - visu.height - 1);
-
- if (visu.mode) {
- if (pkt->count >= 4) {
-
- pkt->height = htonl(pkt->height);
- pkt->row = htonl(pkt->row);
- pkt->col = htonl(pkt->col);
- visu.width = htonl(pkt->width);
- visu.height = pkt->height ? pkt->height : SB_HEIGHT;
- visu.col = pkt->col < 0 ? displayer.width + pkt->col : pkt->col;
- visu.row = pkt->row < 0 ? GDS_GetHeight(display) + pkt->row : pkt->row;
- visu.border = htonl(pkt->border);
- bars = htonl(pkt->bars);
- visu.spectrum_scale = htonl(pkt->spectrum_scale) / 100.;
- } else {
-
- visu.width = displayer.width;
- visu.height = GDS_GetHeight(display) > SB_HEIGHT ? GDS_GetHeight(display) - SB_HEIGHT : GDS_GetHeight(display);
- visu.col = visu.border = 0;
- visu.row = GDS_GetHeight(display) - visu.height;
- bars = htonl(pkt->full.bars);
- visu.spectrum_scale = htonl(pkt->full.spectrum_scale) / 100.;
- }
-
-
- if (visu.mode == VISU_SPECTRUM) {
- visu.n = bars ? bars : MAX_BARS;
- if (visu.spectrum_scale <= 0 || visu.spectrum_scale > 0.5) visu.spectrum_scale = 0.5;
- spectrum_limits(0, visu.n, 0);
- } else {
- visu.n = 2;
- }
-
- do {
- visu.bar_width = (visu.width - visu.border - visu.bar_gap * (visu.n - 1)) / visu.n;
- if (visu.bar_width > 0) break;
- } while (--visu.n);
- visu.bar_border = (visu.width - visu.border - (visu.bar_width + visu.bar_gap) * visu.n + visu.bar_gap) / 2;
-
-
- if (visu.bar_width < 0) {
- visu.mode = VISU_BLANK;
- LOG_WARN("Not enough room for displaying visu");
- } else {
-
- if (visu.row < SB_HEIGHT) scroller.active = false;
- vTaskResume(displayer.task);
- }
- visu.wake = 0;
-
-
- for (int i = visu.n; --i >= 0;) visu.bars[i].max = 0;
-
- GDS_ClearExt(display, false, true, visu.col, visu.row, visu.col + visu.width - 1, visu.row - visu.height - 1);
-
- LOG_INFO("Visualizer with %u bars of width %d:%d:%d:%d (%w:%u,h:%u,c:%u,r:%u,s:%.02f)", visu.n, visu.bar_border, visu.bar_width, visu.bar_gap, visu.border, visu.width, visu.height, visu.col, visu.row, visu.spectrum_scale);
- } else {
- LOG_INFO("Stopping visualizer");
- }
-
- xSemaphoreGive(displayer.mutex);
- }
- static void displayer_task(void *args) {
- int sleep;
-
- while (1) {
- xSemaphoreTake(displayer.mutex, portMAX_DELAY);
-
-
- if (!scroller.active && !visu.mode) {
- xSemaphoreGive(displayer.mutex);
- vTaskSuspend(NULL);
- xSemaphoreTake(displayer.mutex, portMAX_DELAY);
- scroller.wake = visu.wake = 0;
- }
-
-
- if (!visu.mode) visu.wake = LONG_WAKE;
- if (!scroller.active) scroller.wake = LONG_WAKE;
-
-
- if (scroller.active && scroller.wake <= 0) {
-
- scroller.wake = LONG_WAKE;
-
-
- if (scroller.by > 0 ? (scroller.scrolled <= scroller.scroll.width) : (scroller.scrolled >= 0)) {
- memcpy(scroller.frame, scroller.back.frame, scroller.back.width * displayer.height / 8);
- for (int i = 0; i < scroller.width * displayer.height / 8; i++) scroller.frame[i] |= scroller.scroll.frame[scroller.scrolled * displayer.height / 8 + i];
- scroller.scrolled += scroller.by;
- if (displayer.owned) GDS_DrawBitmapCBR(display, scroller.frame, scroller.width, displayer.height);
-
-
- scroller.wake = scroller.speed;
- } else if (scroller.first || !scroller.mode) {
-
- scroller.first = false;
-
-
- if (scroller.mode) {
-
- ANIC_resp = ANIM_SCROLL_ONCE | ANIM_SCREEN_1;
- LOG_INFO("scroll-once terminated");
- } else {
- scroller.wake = scroller.pause;
- LOG_DEBUG("scroll cycle done, pausing for %u (ms)", scroller.pause);
- }
-
-
- scroller.scrolled = scroller.by < 0 ? scroller.scroll.width : 0;
- }
- }
-
- if (visu.mode && visu.wake <= 0) {
- visu_update();
- visu.wake = 100;
- }
-
-
- if (displayer.owned) GDS_Update(display);
-
-
- xSemaphoreGive(displayer.mutex);
-
- sleep = min(visu.wake, scroller.wake);
- vTaskDelay(sleep / portTICK_PERIOD_MS);
- scroller.wake -= sleep;
- visu.wake -= sleep;
- }
- }
-
|