src/display.cpp

changeset 37
07e8ca2bdf6d
child 44
b3c3d54d2c7c
equal deleted inserted replaced
36:a6c7292742a0 37:07e8ca2bdf6d
1 #include "stdio.h"
2 #include <mbed.h>
3 #include <rtos.h>
4 #include "display.h"
5
6
7 Display::Display(int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC,
8 const char* name)
9 : SSD1322(Hz, mosi, miso, sclk, CS, reset, DC, name)
10 {
11 must_refresh = 0;
12 }
13
14 Display::~Display()
15 {
16 }
17
18 void Display::show_splashscreen()
19 {
20 locate(30, 10);
21 set_font((unsigned char*)Mono19x27);
22 this->printf("HP34970A");
23 set_font((unsigned char*)Terminal6x8);
24 locate(90, 40);
25 this->printf("David Douard");
26 locate(0, 52);
27 this->printf("Clock = %ld ", SystemCoreClock);
28
29 RCC_OscInitTypeDef cfg;
30 HAL_RCC_GetOscConfig(&cfg);
31 if (cfg.HSEState == RCC_HSE_BYPASS)
32 this->printf("HSE:EXT ");
33 else if (cfg.HSEState == RCC_HSE_ON)
34 this->printf("HSE:XTAL ");
35 else
36 this->printf("HSE:OFF ");
37
38 if (cfg.HSIState == RCC_HSI_ON)
39 this->printf("HSI:ON ");
40 else
41 this->printf("HSI:OFF ");
42
43 copy_to_lcd();
44 }
45
46
47 void Display::show(uint8_t cmd, const char *intxt, uint8_t nchar=0)
48 {
49 uint8_t i;
50 // uint8_t len;
51 uint16_t bgcolor, fgcolor;
52 char *oldv;
53 // char *txt;
54 char *txtp;
55 static char txt[256];
56
57
58 if (cmd == 0xFF) // cls
59 {
60 clrbuff();
61 }
62 else
63 {
64 //txt = (char *)malloc(strlen(intxt)+1);
65 strcpy(txt, intxt);
66 txtp = txt;
67
68 for (i=0; i<sizeof(table)/sizeof(table[0]); ++i) {
69 if (table[i].cmd == cmd) {
70 bgcolor = table[i].bgcolor;
71 fgcolor = table[i].color;
72 background(bgcolor);
73 foreground(fgcolor);
74 set_font((unsigned char*) table[i].font);
75 oldv = table[i].buffer;
76
77 locate(table[i].x0, table[i].y0);
78
79 if (table[i].fmt & 0x01) // ASCII text
80 {
81 if (strncmp(oldv, txt, table[i].maxsize) != 0)
82 {
83 if (table[i].width > 0)
84 fillrect(table[i].x0,
85 table[i].y0,
86 table[i].x0 + table[i].width,
87 table[i].y0 + table[i].font[2],
88 bgcolor);
89 for (uint8_t k=0; ;k++)
90 {
91 if (txtp[k] == 0x00)
92 {
93 this->printf(txtp);
94 break;
95 }
96 if (txtp[k] == 0x09)
97 { // \t is a special char for 'unselected' display value
98 txtp[k] = 0x00;
99 this->printf(txtp);
100
101 if (fgcolor == table[i].color)
102 fgcolor /= 2;
103 else
104 fgcolor = table[i].color;
105 foreground(fgcolor);
106 txtp = &(txtp[k+1]);
107 k = 0;
108 }
109 }
110 if (cmd == 0x00) // main area
111 must_refresh |= 0x01;
112 if (cmd == 0x0C) // channels area
113 must_refresh |= 0x04;
114 }
115 }
116 /*
117 if (table[i].fmt & 0x02 ) {
118 // hex
119 for (uint8_t j=0;; j++) {
120 if (txt[j] == 0x00)
121 break;
122 this->printf("%02X ", txt[j]);
123 }
124 for (uint8_t j=3*strlen(txt); j<table[i].maxsize; j++)
125 this->printf(" ");
126 }
127 */
128 if (table[i].fmt & 0x08 ) // flag indicators
129 {
130 // flags
131 for (uint8_t j=0; j<max(nchar, table[i].maxsize) ; j++)
132 {
133 for (uint8_t k=0; k<8; k++)
134 {
135 if (1)
136 { //(txt[j] & (1 << k) ) != (oldv[j] & (1 << k))) {
137 for (uint8_t l=0;
138 l<(sizeof(flags)/sizeof(flags[0])); ++l)
139 {
140 if (flags[l].flag == ((j<<4) + k)) {
141 if (txtp[j] & (1 << k))
142 {
143 foreground(flags[l].reverse ? bgcolor : fgcolor);
144 background(flags[l].reverse ? fgcolor : bgcolor);
145 }
146 else
147 {
148 foreground(bgcolor);
149 background(bgcolor);
150 }
151 if (flags[l].msg != NULL)
152 { // a string
153 locate(flags[l].x, flags[l].y);
154 this->printf(flags[l].msg);}
155 else
156 { // an icon
157 Bitmap_s pic = {9, 10, 2, (char*) flags[l].icon};
158 Bitmap_BW(pic, flags[l].x, flags[l].y);
159 }
160 must_refresh = 1; //|= zones[m].flag;
161 break;
162 }
163 }
164 }
165 }
166 }
167
168 // draw frames (Alarm and Channel)
169 for (uint8_t l=0;
170 l<(sizeof(frames)/sizeof(frames[0])); ++l)
171 {
172 uint16_t color;
173 if (frames[l].flag & txt[0]) // frame flags are on the 1st byte only
174 color = fgcolor/6;
175 else
176 color = bgcolor;
177 hline(frames[l].x0+1, frames[l].x0+3, frames[l].y0, color);
178 hline(frames[l].x1-3, frames[l].x1-1, frames[l].y0, color);
179 hline(frames[l].x0+1, frames[l].x1-1, frames[l].y1, color);
180
181 vline(frames[l].x0, frames[l].y0+1, frames[l].y1-1, color);
182 vline(frames[l].x1, frames[l].y0+1, frames[l].y1-1, color);
183 }
184 }
185
186 for(uint8_t j=0; j<table[i].maxsize; j++)
187 oldv[j] = txt[j];
188 break;
189 }
190 }
191 //free(txt);
192 //this->copy_to_lcd();
193 }
194 }
195
196
197 void Display::test_dsp()
198 {
199 const FRAME *z;
200 printf("TEST DSP\r\n");
201 cls();
202 printf("TEST DSP #2\r\n");
203 show(0x00, "8g8g8g8g8g8g8", 13); // main dsp
204 show(0x0C, "888", 3); // channel dsp
205 show(0x0A, "\xFF\xFF\xFF\xFF", 4); // all flags
206 copy_to_lcd();
207 ThisThread::sleep_for(3ms);
208 cls();
209 printf("TEST DSP #3\r\n");
210
211 for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++)
212 {
213 z = &zones[i];
214 fillrect(z->x0, z->y0, z->x1, z->y1, 4+i);
215 locate(z->x0+1, z->y0+1);
216 this->printf("%d", i);
217 }
218
219 /*
220 for (uint8_t i=0; i<(sizeof(zones)/sizeof(zones[0])); i++)
221 {
222 z = &zones[i];
223 printf("Zone %d [%x]: %d, %d, %d, %d\n", i, z->flag,
224 z->x0, z->y0, z->x1, z->y1);
225 must_refresh = z->flag;
226 wait(1);
227 }
228 printf("Done\n");
229 wait(2);
230 printf("Copy ALL\n");
231 copy_to_lcd();
232 */
233 ThisThread::sleep_for(2ms);
234 cls();
235 printf("TEST DSP DONE\r\n");
236 }

mercurial