#include "display.h"
#include "avr/pgmspace.h"
Defines | |
#define | BkColor BLACK |
#define | FgColor YELLOW |
#define | ShColor BLUE |
#define | SPACELEFT 6 |
#define | DISP_PROP_W 33 |
#define | GR_W 20 |
#define | GR_H 20 |
#define | GR_WW 128 |
#define | GR_HH 144 |
#define | GR_X 2 |
#define | GR_Y 15 |
#define | INFO_X GR_X+GR_WW-55 |
#define | INFO_Y GR_Y+GR_HH-25 |
Functions | |
void | disp_init (void) |
initialises display | |
void | disp_off (void) |
switches the display off | |
void | disp_refresh (void) |
refreshes the display | |
void | disp_menu (void) |
displays the menu | |
void | disp_prop (void) |
displays the properties | |
void | disp_clean (void) |
clean the display | |
void | disp_debugging (void) |
displays a debugging screen | |
void | disp_terminal (void) |
displays a terminal | |
void | disp_graph (void) |
displays the osci graph | |
void | disp_drawGrid (volatile uint8_t toDraw[], uint8_t xaxis, uint8_t yaxis) |
draws the grid and the data in the argument | |
Variables | |
volatile uint8_t | min [4] = {255,255,255,255} |
volatile uint8_t | max [4] = {0,0,0,0} |
volatile uint8_t | mid [4] = {0,0,0,0} |
volatile double | freq [4] = {0,0,0,0} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clean the display
00165 { 00166 glcdSetAddr(0,0, 131, 175); // set RAM access pointer of display 00167 //glcdSetBkColor(BkColor); 00168 00169 //width and height also defined in header 00170 for(uint8_t x = 0; x < 132; x++){ 00171 for(uint8_t y = 0; y < 176; y++){ 00172 glcdPutPixel(BkColor); 00173 } 00174 } 00175 }
|
|
displays a debugging screen
00187 { 00188 glcdSetColors(WHITE,BkColor); 00189 00190 static uint16_t count = 0; 00191 int8_t y = 30; 00192 glcdMoveTo(20,y+=11); printf(" Count: %d \n",count++); 00193 glcdMoveTo(20,y+=11); printf(" Menue: %d \n",(uint16_t)ADCSRA); 00194 glcdMoveTo(20,y+=11); printf(" Presc: %d \n",(uint16_t)(ADCSRA & ADIF)); 00195 glcdMoveTo(20,y+=11); printf(" spi_control: %d \n",SPCR); 00196 glcdMoveTo(20,y+=11); printf(" spi_status: %d \n",SPSR); 00197 }
|
|
draws the grid and the data in the argument
00308 { 00309 //draw grid 00310 glcdSetColors(ShColor, BkColor); 00311 00312 glcdLine(GR_X+xaxis, GR_Y, GR_X+xaxis, GR_Y+GR_HH); //horizontal 00313 glcdLine(GR_X, GR_Y+yaxis, GR_X+GR_WW, GR_Y+yaxis); //vertical 00314 00315 /* x and y need to be signed, because for small xaxis and yaxis, the start 00316 * can be negative */ 00317 for(int16_t x = GR_X+xaxis+GR_W; x <= GR_X+GR_WW; x+=GR_W) glcdLine(x, GR_Y-3+yaxis, x, GR_Y+3+yaxis); 00318 for(int16_t x = GR_X+xaxis-GR_W; x >= GR_X ; x-=GR_W) glcdLine(x, GR_Y-3+yaxis, x, GR_Y+3+yaxis); 00319 00320 for(int16_t y = GR_Y+yaxis+GR_H; y <= GR_Y+GR_HH; y+=GR_H) glcdLine(GR_X-3+xaxis, y, GR_X+3+xaxis, y); 00321 for(int16_t y = GR_Y+yaxis-GR_H; y >= GR_Y ; y-=GR_H) glcdLine(GR_X-3+xaxis, y, GR_X+3+xaxis, y); 00322 00323 00324 //replot data 00325 //init 00326 static uint8_t buffer[4][GR_HH]; 00327 uint8_t old_coord[4] = {buffer[0][0], buffer[1][0], buffer[2][0], buffer[3][0]}; 00328 static uint8_t old_adc_nr_channels = 1; 00329 for(uint8_t ch=0; ch < adc_channels; ch++) 00330 buffer[ch][0] = toDraw[ch] >> 1; 00331 glcdSetBkColor(BkColor); 00332 //start 00333 for(uint8_t y = 1; y < GR_HH; y++){ 00334 //erase old lines 00335 glcdSetFgColor(BkColor); 00336 for(uint8_t ch=0; ch < old_adc_nr_channels; ch++){ //old_number!!! 00337 glcdLine(GR_X + old_coord[ch], y-1 + GR_Y, GR_X + buffer[ch][y], y + GR_Y); 00338 old_coord[ch] = buffer[ch][y]; 00339 buffer[ch][y] = toDraw[y*adc_channels+ch] >> 1; 00340 } 00341 //draw new lines 00342 for(uint8_t ch=0; ch < adc_channels; ch++){ 00343 switch(ch){ 00344 case 0: 00345 glcdSetFgColor(WHITE); 00346 break; 00347 case 1: 00348 glcdSetFgColor(FgColor); 00349 break; 00350 case 2: 00351 glcdSetFgColor(GREEN); 00352 break; 00353 case 3: 00354 glcdSetFgColor(RED); 00355 break; 00356 } 00357 glcdLine(GR_X + buffer[ch][y-1], y-1 + GR_Y, GR_X + buffer[ch][y], y + GR_Y); 00358 } 00359 } 00360 old_adc_nr_channels = adc_channels; 00361 00362 //info box 00363 #define INFO_X GR_X+GR_WW-55 00364 #define INFO_Y GR_Y+GR_HH-25 00365 glcdSetColors(FgColor, BkColor); 00366 int y = INFO_Y - 9; 00367 glcdMoveTo(INFO_X+2, y+=11); printf("td:"); 00368 glcdMoveTo(INFO_X+2, y+=11); printf("fq:"); 00369 y = INFO_Y - 9; 00370 uint32_t time = adc_duration*GR_H; 00371 if(time < 10000){ 00372 glcdMoveTo(INFO_X+15, y+=11); printf(" %4dus ",(int16_t)(time)); 00373 }else{ 00374 glcdMoveTo(INFO_X+15, y+=11); printf(" %4dms ",(int16_t)(time/1000)); 00375 } 00376 if(freq[0] < 10000){ 00377 glcdMoveTo(INFO_X+15, y+=11); printf(" %4dHz ",(int16_t)(freq[0])); 00378 }else{ 00379 glcdMoveTo(INFO_X+15, y+=11); printf(" %3dkHz ",(int16_t)(freq[0]/1000)); 00380 } 00381 }
|
|
displays the osci graph
00230 { 00231 if(adc_stopped() == 0) return; 00232 00233 #define GR_W 20 //width of sub ... dash? unterteilung 00234 #define GR_H 20 //height of ??? 00235 #define GR_WW 128 //width 00236 #define GR_HH 144 //height 00237 #define GR_X 2 //x-coord: upper-left 00238 #define GR_Y 15 //y-coord: upper-left 00239 00240 00241 //trigger 00242 uint16_t trigger_shift = 72*adc_channels; 00243 uint16_t GR_TRIG_BEFORE = ADC_BUF_SIZE - (GR_HH*adc_channels) + trigger_shift; 00244 00245 int8_t trigger_old = 0; 00246 int8_t trigger_new = 0; 00247 int8_t trigger_highest = 0; 00248 uint16_t offset = 0; 00249 00250 for(uint16_t x = trigger_shift; x < GR_TRIG_BEFORE; x+=adc_channels){ 00251 trigger_old = adc[x] >> 1; 00252 trigger_new = adc[x + 3*adc_channels] >> 1; 00253 if((trigger_new-trigger_old) > trigger_highest){ 00254 offset = x - trigger_shift; 00255 trigger_highest = trigger_new-trigger_old; 00256 } 00257 } 00258 00259 min[0] = 255; min[1] = 255; min[2] = 255; min[3] = 255; 00260 max[0] = 0; max[1] = 0; max[2] = 0; max[3] = 0; 00261 mid[0] = 0; mid[1] = 0; mid[2] = 0; mid[3] = 0; 00262 freq[0] = 0; freq[1] = 0; freq[2] = 0; freq[3] = 0; 00263 for(uint8_t ch = 0; ch < adc_channels; ch++){ 00264 for(uint16_t x = ch; x < ADC_BUF_SIZE; x+=adc_channels){ 00265 if(adc[x] < min[ch]) min[ch] = adc[x]; 00266 if(adc[x] > max[ch]) max[ch] = adc[x]; 00267 } 00268 } 00269 for(uint8_t x = 0; x < adc_channels; x++) mid[x] = (max[x]-min[x])/2 + min[x]; 00270 00271 00272 for(uint8_t ch = 0; ch < adc_channels; ch++){ 00273 uint16_t old_pos = 0; 00274 int8_t under; //currently under mid? 0 for no, 1 for yes 00275 int8_t old_under; 00276 double period = 0.0; 00277 00278 if(adc[ch] < mid[ch]){ under = 0; old_under = 0; } 00279 else { under = 1; old_under = 1; } 00280 00281 for(uint16_t x = ch; x < ADC_BUF_SIZE; x+=adc_channels){ 00282 if(adc[x] > mid[ch]) under = 0; 00283 if(adc[x] < mid[ch]) under = 1; 00284 00285 if(old_under == 1 && under == 0){ 00286 period = (double)(x - old_pos)*adc_duration /adc_channels/ 1000000.0; 00287 if(old_pos != 0 && period != 0.0){ 00288 if(freq[ch] == 0.0) freq[ch] = 1.0 / period; 00289 else freq[ch] = 0.8*freq[ch] + 0.2/period; 00290 } 00291 old_pos = x; 00292 } 00293 00294 old_under = under; 00295 } 00296 00297 } 00298 00299 00300 //draw in the display 00301 disp_drawGrid(&adc[offset], 64, trigger_shift/adc_channels); 00302 00303 adc_init(1); 00304 }
|
|
initialises display Calls the lib's routine to init the display. Displays the splash-screen. Sets the font. Sets the window for text-output. 00026 { 00027 //**** Hardware **** 00028 #ifndef USE_AUTOINIT 00029 glcdDisplayInit(); 00030 #endif 00031 00032 #ifdef DISP_SPLASH 00033 disp_load_bitmap(); 00034 #else 00035 disp_clean(); 00036 #endif 00037 00038 glcd_Flags.AutoLineFeed = 0; 00039 glcdSelectFont(f8x11, 0); // font is stored in FLASH, thus no need for own read callback 00040 fdevopen(glcdPut,NULL,0); 00041 00042 //window for text-output 00043 glcd_Window.X1 = 5; 00044 glcd_Window.X2 = 110; 00045 glcd_Window.Y1 = 16; 00046 glcd_Window.Y2 = 162; 00047 }
|
|
displays the menu Refreshes the menu bar when the menu has changed. 00075 { 00076 static int8_t main_old = 0; 00077 00078 //*** left *** 00079 if(menu_now != main_old){ 00080 main_old = menu_now; 00081 disp_clean(); 00082 00083 00084 glcdFillRect(0,0,132,13,ShColor); //shadow color for menu bg 00085 #define SPACELEFT 6 00086 for(uint8_t x=0; x < MENU_ANZ_MAIN; x++){ 00087 if(menu_now == (x+1)){ 00088 glcdFillRect(SPACELEFT+x*40,1, SPACELEFT+(x+1)*40,12, BkColor); 00089 glcdSetColors(FgColor, BkColor); 00090 }else{ 00091 glcdSetColors(FgColor, ShColor); 00092 } 00093 uint8_t w = glcdCharsWidth(menu_mains[x].name, 0); 00094 glcdMoveTo(SPACELEFT+21+x*40 - w/2, 2); 00095 printf(menu_mains[x].name); 00096 } 00097 } 00098 }
|
|
switches the display off The original shutdown sequence for the display is not known. The current workaround is to activate the stand-by for the display. 00051 { 00052 bk_LED(1); 00053 //for(uint32_t x=0; x < 5000000; x++) asm("nop"); 00054 00055 //clean 00056 glcdSetAddr(0,0, 131, 175); // set RAM access pointer of display 00057 //width and height also defined in header 00058 for(uint8_t x = 0; x < 132; x++){ 00059 for(uint8_t y = 0; y < 176; y++){ 00060 glcdPutPixel(WHITE); 00061 } 00062 } 00063 for(uint32_t x=0; x < 500000; x++) asm("nop"); 00064 glcdDisplayOff(); 00065 glcdWait(100); 00066 }
|
|
displays the properties Refreshes the property bar if the menu, the property or the value of the property has changed. 00102 { 00103 static int8_t main_old = 0; 00104 static int8_t prop_old = 0; 00105 static int8_t value_old = 0; 00106 00107 if( menu_now != main_old || 00108 MENU_CURRENT_PROP_NR != prop_old || 00109 MENU_PROP_NOW.current_value != value_old){ 00110 00111 main_old = menu_now; 00112 prop_old = MENU_CURRENT_PROP_NR; 00113 value_old = MENU_PROP_NOW.current_value; 00114 00115 #define DISP_PROP_W 33 00116 glcdFillRect(0, 162, 132, 176, ShColor); 00117 for(uint8_t x=0; x < 3; x++){ 00118 if(x == 1){ 00119 glcdFillRect(SPACELEFT+x*DISP_PROP_W,163, SPACELEFT+(x+1)*DISP_PROP_W,174, BkColor); 00120 glcdSetColors(FgColor, BkColor); 00121 }else{ 00122 glcdSetColors(FgColor, ShColor); 00123 } 00124 int8_t current_value = value_old-1+x; 00125 char *label; 00126 if(current_value < 1) 00127 label = "=>"; 00128 else if(current_value > MENU_PROP_NOW.nr_values) 00129 label = "<="; 00130 else 00131 label = MENU_PROP_NOW.value_name[current_value-1]; 00132 uint8_t w = glcdCharsWidth(label, 0); 00133 glcdMoveTo(SPACELEFT+21+x*DISP_PROP_W - w, 164); 00134 printf(label); 00135 00136 //prop-name 00137 w = glcdCharsWidth(MENU_PROP_NOW.prop_name, 0); 00138 glcdFillRect(132 - 2*SPACELEFT - w, 163, 130, 174, BkColor); 00139 glcdSetColors(FgColor, BkColor); 00140 glcdMoveTo(132 - SPACELEFT - w, 164); 00141 printf(MENU_PROP_NOW.prop_name); 00142 } 00143 } 00144 }
|
|
refreshes the display
00068 { 00069 disp_menu(); 00070 menu_mains[menu_now-1].disp_func(); 00071 disp_prop(); 00072 }
|
|
displays a terminal The terminal for the serial interface.
00201 { 00202 // if(glcd_Cursor.X < 5 || glcd_Cursor.Y < 16 || glcd_Cursor.Y > 162) glcdMoveTo(5,16); 00203 if(glcd_Cursor.X < 5 || glcd_Cursor.Y < 16 || glcd_Cursor.Y > 162 || glcd_Cursor.X > 100) glcdMoveTo(5,16); 00204 glcdSetColors(WHITE,BkColor); 00205 00206 uint16_t rx_data; 00207 while(! ((rx_data=uart_getc()) & UART_NO_DATA)){ 00208 //glcdPut(rx_data & 255); 00209 glcdDrawChar((uint8_t)rx_data); 00210 } 00211 while(! ((rx_data=uart1_getc()) & UART_NO_DATA)){ 00212 //glcdPut(rx_data & 255); 00213 glcdDrawChar((uint8_t)rx_data); 00214 } 00215 00216 // if(glcd_Cursor.X < 5 || glcd_Cursor.Y < 16 || glcd_Cursor.Y > 162 || glcd_Cursor.X > 120) glcdMoveTo(5,16); 00217 //printf("%c",(rx_data & 255)); 00218 00219 //glcdWait(100); 00220 }
|
|
|
|
|
|
|
|
Reads the input buffer from the ADC. Searches for the best trigger point. Calls disp_drawGrid() to display the output. |