diff -r 74e85b34d26b -r f6774bd0d570 src/display.cpp --- a/src/display.cpp Thu Nov 12 20:26:35 2020 +0100 +++ b/src/display.cpp Fri Nov 13 19:35:46 2020 +0100 @@ -4,11 +4,92 @@ #include "display.h" +static DSP table[] = +{ // cmd, fg, bg, x0, y0, fmt, maxsize, width, font + { 0x00, 0xF, 0x0, 0, 0, FMT_ASCII, MAX_BUFF, 255, Mono19x27}, // main display + { 0x0C, 0xF, 0x0,194, 38, FMT_ASCII, 3, 45, Mono15x22}, // channels display + { 0x0A, 0xF, 0x0, 0, 57, FMT_FLAGS, 4, 0, Terminal6x8}, // flags + bits +}; + +// 9x10 +const unsigned char icon_alarm[] __attribute__((aligned (2))) = +{ + 0x1c, 0x0, + 0x3e, 0x0, + 0x7f, 0x0, + 0x7f, 0x0, + 0x7f, 0x0, + 0x7f, 0x0, + 0x7f, 0x0, + 0x7f, 0x0, + 0xff, 0x80, + 0x10, 0x0 +}; + +const unsigned char icon_curve[] __attribute__((aligned (2))) = +{ + 0x80, 0x0, + 0x80, 0x0, + 0x80, 0x80, + 0x81, 0x0, + 0x9e, 0x0, + 0xa0, 0x0, + 0xc0, 0x0, + 0x80, 0x0, + 0x80, 0x0, + 0xff, 0x80 +}; + +static const flags_map flags = { + // id x0 y0 rev. msg icon + { 0x00, {246, 27, 0, 0, false, NULL, icon_alarm}}, // F1.0 01 00 00 00 + { 0x01, {246, 38, 0, 0, false, NULL, icon_curve}}, // F1.1 02 00 00 00 + { 0x02, {192, 32, 240, 60, false, NULL, NULL}}, // F1.2 04 00 00 00 - Channel frame + { 0x03, {195, 29, 0, 0, false, "CHANNEL", NULL}}, // F1.3 08 00 00 00 + { 0x1c, {0, 38, 0, 0, false, "MON", NULL}}, // F4.4 00 00 00 10 + { 0x1b, {0, 47, 0, 0, false, "VIEW", NULL}}, // F4.3 00 00 00 08 + { 0x1d, {0, 29, 0, 0, true, "SCAN", NULL}}, // F4.5 00 00 00 20 + { 0x1e, {0, 56, 0, 0, true, "CONFIG", NULL}}, // F4.6 00 00 00 40 + { 0x1a, {40, 56, 0, 0, false, "*", NULL}}, // F4.2 00 00 00 04 + { 0x19, {50, 56, 0, 0, false, "ADRS", NULL}}, // F4.1 00 00 00 02 + { 0x18, {80, 56, 0, 0, false, "RMT", NULL}}, // F4.0 00 00 00 01 + { 0x17, {104, 56, 0, 0, true, "ERROR", NULL}}, // F3.7 00 00 80 00 + { 0x16, {86, 38, 0, 0, false, "EXT", NULL}}, // F3.6 00 00 40 00 + { 0x15, {60, 38, 0, 0, false, "ONCE", NULL}}, // F3.5 00 00 20 00 + { 0x13, {40, 38, 0, 0, false, "MEM", NULL}}, // F3.3 00 00 08 00 + { 0x0c, {244, 47, 0, 0, false, "4W", NULL}}, // F2.4 00 10 00 00 + { 0x0d, {244, 56, 0, 0, false, "OC", NULL}}, // F2.5 00 20 00 00 + { 0x12, {40, 47, 0, 0, false, "LAST", NULL}}, // F3.2 00 00 04 00 + { 0x11, {66, 47, 0, 0, false, "MIN", NULL}}, // F3.1 00 00 02 00 + { 0x10, {86, 47, 0, 0, false, "MAX", NULL}}, // F3.0 00 00 01 00 + { 0x0f, {106, 47, 0, 0, false, "AVG", NULL}}, // F2.7 00 80 00 00 + { 0x05, {152, 29, 0, 0, false, "Alarm", NULL}}, // F1.5 20 00 00 00 + { 0x08, {152, 39, 0, 0, false, "H", NULL}}, // F1.6 40 00 00 00 + { 0x07, {158, 39, 0, 0, false, "1", NULL}}, // F2.3 00 08 00 00 + { 0x06, {164, 39, 0, 0, false, "2", NULL}}, // F2.0 00 01 00 00 + { 0x04, {170, 39, 0, 0, false, "3", NULL}}, // F2.2 00 04 00 00 + { 0x09, {176, 39, 0, 0, false, "4", NULL}}, // F2.1 00 02 00 00 + { 0x0a, {182, 39, 0, 0, false, "L", NULL}}, // F1.4 00 10 00 00 + { 0x0b, {149, 32, 190, 50, false, NULL, NULL}}, // F1.7 - alarm frame + + { 0x0e, {152, 56, 0, 0, true, "SHIFT", NULL}}, // not an actual command, managed by the front panel + + { 0x14, {0xFF, 0xFF, 0xFF, 0xFF, false, NULL, NULL}}, // not an actual command, for the sake of completeness + { 0x1f, {0xFF, 0xFF, 0xFF, 0xFF, false, NULL, NULL}}, // not an actual command, for the sake of completeness + +}; + + Display::Display(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name) : SSD1322(Hz, mosi, miso, sclk, CS, reset, DC, name) { must_refresh = 0; + for (flags_map::const_iterator it=flags.cbegin(); it!=flags.cend(); ++it) + { + flags_status[it->first] = false; + flags_dim[it->first] = false; + } } Display::~Display() @@ -37,9 +118,9 @@ copy_to_lcd(); } -void Display::dimm_char(uint8_t n) +void Display::dim_char(uint8_t n) { - // dimm the char number of the currently displayed string of the main area; + // dim the char number of the currently displayed string of the main area; // do this by printing a modifed version of the last displayed string // but only alphanumeric chars should be counted (not the punctuation) char c; @@ -56,8 +137,6 @@ len = strlen(table[i].buffer); if (n >= len) break; // nothing to do - //::printf("DIMM CHAR %d\n", n); - //::printf(" in (len=%d) '%s'\n", len, table[i].buffer); for (j=0; (jprintf("%02X ", txt[j]); - } - for (uint8_t j=3*strlen(txt); jprintf(" "); - } - */ + if (table[i].fmt & FMT_FLAGS ) // flag indicators { - uint8_t nbyte; - uint8_t nbit; - uint16_t color; - // flags - for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l) + uint8_t id; + uint8_t c; + id = 0; + for (uint8_t nc=0; nc<4; nc++) { - nbyte = flags[l].flag / 8; - nbit = flags[l].flag % 8; - if (flags[l].dimm) - color = fgcolor/4; - else - color = fgcolor; - - if (intxt[nbyte] & (1 << nbit)) - { // draw the flag, possibly reversed fg/bg - foreground(flags[l].reverse ? bgcolor : color); - background(flags[l].reverse ? color : bgcolor); - } - else - { // erase the flag - foreground(bgcolor); - background(bgcolor); - } - if (flags[l].msg != NULL) - { // flag is a string - locate(flags[l].x, flags[l].y); - this->printf(flags[l].msg);} - else - { // flag is an icon - Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon}; - Bitmap_BW(pic, flags[l].x, flags[l].y); + c = intxt[nc]; + for (uint8_t nb=0; nb<8; nb++) + { + if (c & (0x01 << nb)) + set_flag_status(id, true); + else + set_flag_status(id, false); + draw_flag(id); + id++; } } - - // draw frames (Alarm and Channel) - for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l) - { - nbyte = frames[l].flag / 8; - nbit = frames[l].flag % 8; - if (intxt[nbyte] & (1 << nbit)) - color = fgcolor/6; - else - color = bgcolor; - hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color); - hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color); - hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color); - - vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color); - vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color); - } - must_refresh = 1; //|= zones[m].flag; } for(uint8_t j=0; jcopy_to_lcd(); } } -void Display::set_flag(uint8_t flag, bool show, bool dimm) +void Display::set_flag_status(uint8_t flagid, bool show) +{ + flags_status[flagid] = show; +} + +void Display::set_flag_dim(uint8_t flagid, bool dim) +{ + flags_dim[flagid] = dim; +} + +void Display::draw_flag(uint8_t flagid) { uint8_t i; uint8_t bgcolor = 0x00, fgcolor = 0x0F; - if (dimm) - fgcolor = fgcolor / 4; + ::printf(" FLAG %X:", flagid); + const FLAG flag = flags.at(flagid); // can't use the [] operator on a const map... + if (flag.msg != NULL) + ::printf("%s ", flag.msg); + else if (flag.icon != NULL) + ::printf("ICN "); + else if (flag.x0 > 0) + ::printf("FR[%dx%d] ", flag.x0, flag.y0); + else + ::printf(" WTF? "); - for (uint8_t l=0; l<(sizeof(flags)/sizeof(flags[0])); ++l) + if (flags_status[flagid]) { - if (flag == flags[l].flag) - { - set_font((unsigned char*)Terminal6x8); - ::printf(" %s flag %x %s\n", show ? "show": "hide", flag, dimm ? "dimmed":"bright"); - if (show) - { - foreground(flags[l].reverse ? bgcolor : fgcolor); - background(flags[l].reverse ? fgcolor : bgcolor); - } - else - { - foreground(bgcolor); - background(bgcolor); - } - if (flags[l].msg != NULL) - { // flag is a string - locate(flags[l].x, flags[l].y); - ::printf("Move cursor at %dx%d\n", flags[l].x, flags[l].y); - ::printf(" using fgcolor=%x\n", fgcolor); - this->printf(flags[l].msg);} - else - { // flag is an icon - Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon}; - Bitmap_BW(pic, flags[l].x, flags[l].y); - } - } + if (flags_dim[flagid]) + ::printf(" DIM\n"); + else + ::printf(" ON\n"); + } + else + ::printf(" OFF\n"); + + if ((flag.msg == NULL) && (flag.icon == NULL) && (flag.x0 == 0xFF) && (flag.y0 == 0xFF)) + // noop command + return; + + if (flags_dim[flagid]) + fgcolor = fgcolor / 4; + else if ((flag.msg == NULL) && (flag.icon == NULL)) + fgcolor = fgcolor / 6; // it's a frame + + if (flags_status[flagid]) + { + foreground(flag.reverse ? bgcolor : fgcolor); + background(flag.reverse ? fgcolor : bgcolor); + } + else + { + foreground(bgcolor); + background(bgcolor); } - // draw frames (Alarm and Channel) - for (uint8_t l=0; l<(sizeof(frames)/sizeof(frames[0])); ++l) + if (flag.msg != NULL) { - if (flag == frames[l].flag) - { - uint16_t color; - if (show) - color = fgcolor/6; - else - color = bgcolor; - hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color); - hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color); - hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color); + set_font((unsigned char*)Terminal6x8); + locate(flag.x0, flag.y0); + this->printf(flag.msg); + } + else if (flag.icon != NULL) + { // flag is an icon + Bitmap_s pic = {9, 10, 2, (char*) flag.icon}; + Bitmap_BW(pic, flag.x0, flag.y0); + } + else + { // draw frames (Alarm and Channel) + hline(flag.x0+1, flag.x0+3, flag.y0, foreground()); + hline(flag.x1-3, flag.x1-1, flag.y0, foreground()); + hline(flag.x0+1, flag.x1-1, flag.y1, foreground()); - vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color); - vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color); - } + vline(flag.x0, flag.y0+1, flag.y1-1, foreground()); + vline(flag.x1, flag.y0+1, flag.y1-1, foreground()); } + must_refresh = 1; } - - -void Display::test_dsp() -{ - const FRAME *z; - printf("TEST DSP\r\n"); - cls(); - printf("TEST DSP #2\r\n"); - show(0x00, "8g8g8g8g8g8g8", 13); // main dsp - show(0x0C, "888", 3); // channel dsp - show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags - copy_to_lcd(); - ThisThread::sleep_for(3ms); - cls(); - printf("TEST DSP #3\r\n"); - /* - for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) - { - z = &zones[i]; - fillrect(z->x0, z->y0, z->x1, z->y1, 4+i); - locate(z->x0+1, z->y0+1); - this->printf("%d", i); - } - */ - /* - for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++) - { - z = &zones[i]; - printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag, - z->x0, z->y0, z->x1, z->y1); - must_refresh = z->flag; - wait(1); - } - printf("Done\n"); - wait(2); - printf("Copy ALL\n"); - copy_to_lcd(); - */ - ThisThread::sleep_for(2ms); - cls(); - printf("TEST DSP DONE\r\n"); -}