@@ 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 @@ void Display::show_byescreen()
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 @@ void Display::dimm_char(uint8_t n)
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; (j<len); j++)
{
@@ 68,13 147,11 @@ void Display::dimm_char(uint8_t n)
n++;
if (n == 0)
{
- //::printf(" Found at pos %d char '%c'\n", j, c);
// found it
character(c);
break;
}
// otherwise, just advance the char_x
- //::printf(" move %d for '%c' [%X]\n", , c, c);
char_width(c, true);
n--;
}
@@ 99,7 176,7 @@ void Display::show(uint8_t cmd, const ch
}
else if (cmd == 0x0D)
{ // dimm a character of the main area
- dimm_char(intxt[0]);
+ dim_char(intxt[0]);
}
else
{
@@ 158,71 235,25 @@ void Display::show(uint8_t cmd, const ch
must_refresh = 1;
}
}
- /*
- if (table[i].fmt & FMT_HEX ) {
- // hex
- for (uint8_t j=0;; j++) {
- if (txt[j] == 0x00)
- break;
- this->printf("%02X ", txt[j]);
- }
- for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
- this->printf(" ");
- }
- */
+
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; j<table[i].maxsize; j++)
@@ 231,110 262,86 @@ void Display::show(uint8_t cmd, const ch
}
}
pixel_buffer_mutex.unlock();
-
- //free(txt);
- //this->copy_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");
-}
@@ 8,6 8,8 @@
#include "SSD1322.h"
#include "hp34comm.h"
+#include <map>
+
//typedef enum {
#define FMT_ASCII 0x01
#define FMT_HEX 0x02
@@ 32,153 34,42 @@ typedef struct _DSP
} DSP;
-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
-};
-
typedef struct _FLAG
{
- uint8_t flag;
- uint8_t x;
- uint8_t y;
- bool reverse;
- bool dimm;
- const char* msg;
- const unsigned char* icon;
-} FLAG;
-
-typedef struct _FRAME
-{
- uint8_t flag;
uint8_t x0;
uint8_t y0;
uint8_t x1;
uint8_t y1;
-} FRAME;
-
-
-
-static const FLAG flags[] =
-{
- // flag, x0, y0, reverse, dimm, msg, icon
- // right-side icons area
- // flag is the bit index in the 4 bytes viewed as a 32bits value
- { 0x00, 246, 27, false, false, NULL, icon_alarm}, // F1.0 01 00 00 00
- { 0x01, 246, 38, false, false, NULL, icon_curve}, // F1.1 02 00 00 00
- // F1.2 04 00 00 00 - Channel frame
- { 0x03, 195, 29, false, false, "CHANNEL"}, // F1.3 08 00 00 00
- // F1.7 80 00 00 00 - Alarm frame
- { 0x1c, 0, 38, false, false, "MON"}, // F4.4 00 00 00 10
- { 0x1b, 0, 47, false, false, "VIEW"}, // F4.3 00 00 00 08
- { 0x1d, 0, 29, true, false, "SCAN"}, // F4.5 00 00 00 20
- { 0x1e, 0, 56, true, false, "CONFIG"}, // F4.6 00 00 00 40
-
- { 0x1a, 40, 56, false, false, "*"}, // F4.2 00 00 00 04
- { 0x19, 50, 56, false, false, "ADRS"}, // F4.1 00 00 00 02
- { 0x18, 80, 56, false, false, "RMT"}, // F4.0 00 00 00 01
- { 0x17, 104, 56, true, false, "ERROR"}, // F3.7 00 00 80 00
-
- { 0x16, 86, 38, false, false, "EXT"}, // F3.6 00 00 40 00
- { 0x15, 60, 38, false, false, "ONCE"}, // F3.5 00 00 20 00
-
- { 0x13, 40, 38, false, false, "MEM"}, // F3.3 00 00 08 00
-
-
- // col 5
- { 0x0c, 244, 47, false, false, "4W"}, // F2.4 00 10 00 00
- { 0x0d, 244, 56, false, false, "OC"}, // F2.5 00 20 00 00
+ bool reverse;
+ const char* msg;
+ const unsigned char* icon;
+} FLAG;
- { 0x12, 40, 47, false, true, "LAST"}, // F3.2 00 00 04 00
- { 0x11, 66, 47, false, true, "MIN"}, // F3.1 00 00 02 00
- { 0x10, 86, 47, false, true, "MAX"}, // F3.0 00 00 01 00
- { 0x0f, 106, 47, false, true, "AVG"}, // F2.7 00 80 00 00
-
- { 0x05, 152+0, 29, false, false, "Alarm"}, // F1.5 20 00 00 00
- { 0x08, 152+0, 39, false, false, "H"}, // F1.6 40 00 00 00
- { 0x07, 152+6, 39, false, false, "1"}, // F2.3 00 08 00 00
- { 0x06, 152+12, 39, false, false, "2"}, // F2.0 00 01 00 00
- { 0x04, 152+18, 39, false, false, "3"}, // F2.2 00 04 00 00
- { 0x09, 152+24, 39, false, false, "4"}, // F2.1 00 02 00 00
- { 0x0a, 152+30, 39, false, false, "L"}, // F1.4 00 10 00 00
-
- { 0x80, 152, 56, true, false, "SHIFT"}, // not an actual command, managed by the front panel
-};
-
-
-static const FRAME frames[] =
-{
- { 0x02, 192, 32, 240, 60}, // F1.2 - channel frame
- { 0x0b, 149, 32, 190, 50}, // F1.7 - alarm frame
-};
-
-
-typedef enum {
- FLAG_OFF,
- FLAG_ON,
- FLAG_DIM
-} flag_status_t;
-
-typedef struct _FLAG_STATUS
-{
- uint8_t flag;
- flag_status_t status;
-} FLAG_STATUS;
-
+typedef std::map<uint8_t, FLAG> flags_map;
+typedef std::map<uint8_t, bool> flag_status_map;
class Display: public SSD1322
{
public:
Display(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC,
- const char* name);
+ const char* name);
virtual ~Display();
- void test_dsp();
void show(uint8_t, const char*, uint8_t);
- void dimm_char(uint8_t);
+ void dim_char(uint8_t);
void show_splashscreen();
void show_byescreen();
- void set_flag(uint8_t flag, bool show=true, bool dimm=false);
- void show_flag(uint8_t flag) {set_flag(flag, true);};
- void hide_flag(uint8_t flag) {set_flag(flag, false);};
- void shift_on() {set_flag(0x80, true);};
- void shift_off() {set_flag(0x80, false);};
+ void set_flag_status(uint8_t flagid, bool show);
+ void set_flag_dim(uint8_t flagid, bool dim);
+
+ void draw_flag(uint8_t flagid);
private:
uint8_t must_refresh;
+ flag_status_map flags_status;
+ flag_status_map flags_dim;
};