TO CHECKOUT
Embed:
(wiki syntax)
Show/hide line numbers
lab.cpp
00001 /*************************************************************************** 00002 * Titel : LAB.C 00003 * 00004 * Description : Labormodul "DIBI" 00005 * 00006 * Revision List: 00007 -------------------------------------------------------------------------- 00008 Date | Author | Change 00009 -------------------------------------------------------------------------- 00010 15.11.13 | J. Altenburg | Ersterstellung 00011 -------------------------------------------------------------------------- 00012 | | 00013 -------------------------------------------------------------------------- 00014 ****************************************************************************/ 00015 00016 /*************************************************************************** 00017 * HEADER-FILES (Only those that are needed in this file) 00018 ****************************************************************************/ 00019 /* Own header */ 00020 #include "lab.h" 00021 00022 /* Foreign headerfiles */ 00023 #include "lcd.h" 00024 #include "picture.h" 00025 #include "mbed.h" 00026 00027 DigitalOut bLed2(LED4); 00028 DigitalIn bBtn1(p8); 00029 AnalogIn fpAnalog(p15); /* Analogeingang */ 00030 00031 #define PROF 00032 00033 /*************************************************************************** 00034 * Variablen 00035 ****************************************************************************/ 00036 byte abPicture[160][120]; /* 00037 Description: Bildspeicher fuer Grauwertbild 00038 */ 00039 00040 word awHisto[64] = {0}; /* 00041 Description : Histogramm-Vektor 00042 */ 00043 00044 lcd_t myLCD; /* 00045 * Description : Zugriffstruktur für LCD 00046 */ 00047 00048 spi_t mySPI; /* 00049 * Description : dito. fuer SPI 00050 */ 00051 00052 float fpAdcValue; /* 00053 * Description : analoger Messwert 00054 */ 00055 00056 /*************************************************************************** 00057 * lokale Funktionsprototypen 00058 ***************************************************************************/ 00059 00060 00061 /*************************************************************************** 00062 * Defines und Makros * 00063 ***************************************************************************/ 00064 00065 00066 /*************************************************************************** 00067 * lokale Funktionen 00068 ****************************************************************************/ 00069 /* Umrechnen eines Farbwertes in einen Grauwert */ 00070 byte bRGB565ToGray(word wColor){ 00071 byte bGray = 0; 00072 byte r,g,b; 00073 00074 r = (wColor & 0xf800)>>11; 00075 g = (wColor & 0x07E0) >>5; 00076 b = (wColor & 0x001F) ; 00077 #if 1 00078 bGray = ((r+b)*2 + g)/3; 00079 00080 #else 00081 00082 bGray = (byte) 00083 #endif 00084 /* 00085 .... hier eigenen Code eintragen 00086 */ 00087 return bGray; 00088 } 00089 00090 /* Umrechnen eines Grauwert in einen "unbunten" RGB565-Wert */ 00091 word wGrayToRGB565(byte bGray){ 00092 word wNoColor; 00093 byte r,g,b; 00094 r = bGray /2; 00095 g= bGray; 00096 b = bGray / 2; 00097 wNoColor = (r <<11) + (g << 5) + b; 00098 return wNoColor; 00099 } 00100 00101 00102 /* Umrechnen des Farbbildes in ein Grauwertbild 00103 Parameterübergabe erfolgt über Zeiger 00104 */ 00105 void vColorToGray(word *pColor, byte *pGray){ 00106 word w; 00107 for(w = 0; w < 19200; w++){ 00108 *pGray = bRGB565ToGray(*pColor); 00109 pGray++; 00110 pColor++; 00111 } 00112 } 00113 00114 /* Grauwertbild in Sektor 2 plazieren */ 00115 void vGrayToScreen2(byte *pGray){ 00116 word wColor, v; 00117 byte x, y; 00118 x = y = 0; 00119 for(v = 0; v < 19200; v++){ 00120 wColor = wGrayToRGB565(*pGray); 00121 pGray++; 00122 lcd_setPixel(&myLCD, 120 + y, 160 + x, wColor); 00123 y++; 00124 if(y > 119){ 00125 y = 0; 00126 x++; 00127 } 00128 } 00129 } 00130 00131 /* Grauwertbild in Sektor 3 plazieren */ 00132 void vGrayToScreen3(byte *pGray){ 00133 00134 word wColor, v; 00135 byte x, y; 00136 x = y = 0; 00137 for(v = 0; v < 19200; v++){ 00138 wColor = wGrayToRGB565(*pGray); 00139 pGray++; 00140 lcd_setPixel(&myLCD, y, 160 + x, wColor); 00141 y++; 00142 if(y > 119){ 00143 y = 0; 00144 x++; 00145 } 00146 } 00147 } 00148 00149 00150 00151 /* Histogramm in Sektor 4 zeichnen */ 00152 void vDrawHisto(byte *pGray){ 00153 word y, wMax = 0; 00154 byte i, j, n; 00155 /* Histogrammvektor initialisieren ... ihre Sache */ 00156 00157 /* Histogrammvektor berechnen ... bitte tun */ 00158 /* Werte normieren ... wenn notwendig */ 00159 00160 //word awHisto[64] = {0}; /* 00161 //byte abPicture[160][120]; /* 00162 00163 for(i=0;i<64;i++) awHisto[i] = 0; 00164 00165 00166 for(i=0;i<120;i++){ 00167 for(j=0;j<160;j++)awHisto[abPicture[i][j]] +=1; 00168 } 00169 00170 00171 /**ERmittlung des Maximalwertes */ 00172 wMax = awHisto[0]; 00173 for(i=1;i<64;i++){ 00174 if( awHisto[i] > wMax)wMax = awHisto[i]; 00175 } 00176 00177 /* ab hier Bildaufbau */ 00178 LCD_vFillRectangle(&myLCD, 10, 140, 128, 84, GRAY1); /* grauer Hintergrund */ 00179 //LCD_vSetPixel(&myLCD, 200,300, BRIGHT_RED) 00180 // y x 00181 00182 for(i = 0; i < 128; i = i + 16){ 00183 LCD_vDrawVline(&myLCD, 20+i, 140, 84, GRAY2); 00184 } 00185 for(i = 0; i < 64; i++){ /* die möglichen Werte darstellen */ 00186 n = i*2; 00187 y = i; // erzeugt einen Keil 00188 for(j = 0; j < ( awHisto[i] * 64 / wMax) ; j++){ 00189 LCD_vSetPixel(&myLCD, 20+j, 10+n, BRIGHT_RED); 00190 // LCD_vSetPixel(&myLCD, 20+j, 11+n, BRIGHT_RED); 00191 } 00192 } 00193 00194 00195 // for(i = 0; i < 128; i = i + 16){ 00196 // LCD_vDrawVline(&myLCD, 20+i, 140, 84, GRAY2); 00197 // } 00198 for(i = 0; i < 128; i++){ 00199 LCD_vSetPixel(&myLCD, 84, 10+i, BLUE); 00200 } 00201 } 00202 00203 00204 00205 /* Grauwerte manipulieren 00206 *pGray zeigt auf die Grauwerte 00207 bValue bestimmt die Größenmanipulation 00208 */ 00209 void vChangeGray(byte *pGray, byte bValue){ 00210 byte bGMin, bGMax, bWMax,bWMin; 00211 word x,y,l,h; 00212 word wColor ; 00213 bWMax = 63; 00214 bWMin = 0; 00215 00216 for(x=0;x<64;x++)if( awHisto[x] > 0){ bGMin = x; break;} 00217 // Ermittlung von gMax 00218 for(x=63;x>=0;x--)if( awHisto[x] > 0){ bGMax = x; break;} 00219 00220 lcd_drawNumber(&myLCD, bGMin, 1, 230, 1, BLACK); 00221 lcd_drawNumber(&myLCD, bGMax, 50, 230, 1, BLACK); 00222 00223 00224 byte abOnePiktureLine[160]; 00225 // Jetzt Ermittlung der Neuen Werte mit Transferfunktion 00226 // gneu (g) = (g- gmin) * ( (wmax+ wmin) / ( gmax - gmin ) ) 00227 byte *ab= &abPicture[0][0]; 00228 #if 1 00229 /**Überschreiben des Grauwertbildes Mit neuem Bild */ 00230 for(x = 0; x <19200; x++){ 00231 if( ( ( *(ab + x) - bGMin) * (bWMax/(bGMax-bGMin)) ) >=0) 00232 *(pGray + x) = ( *(ab + x) - bGMin) * (bWMax/(bGMax-bGMin)) * bValue ; 00233 else 00234 *(pGray+x) =0; 00235 } 00236 00237 #else 00238 /** Keine Speicherung des Korregierten Bildes sondern Direkte Ausgabe aus screen */ 00239 // l = x h = y 00240 l=0; 00241 h=0; 00242 for(x = 0; x <19200; x++){ 00243 if( ( ( *(ab + x) - bGMin) * (bWMax/(bGMax-bGMin)) ) >=0) 00244 wColor = wGrayToRGB565(( *(ab + x) - bGMin) * (bWMax/(bGMax-bGMin)) ) /*bValue */ ; 00245 else 00246 wColor = wGrayToRGB565(0); 00247 00248 lcd_setPixel(&myLCD, h, 160 + l, wColor); 00249 h++; 00250 if(h > 119){ 00251 h= 0; 00252 l++; 00253 } 00254 } 00255 #endif 00256 00257 } 00258 00259 00260 /*************************************************************************** 00261 * Initialisierung 00262 * angeschlossene Hardware aktivieren 00263 * Bildsektoren 1, 2 initialsieren 00264 * Histogramm aufbauen 00265 ****************************************************************************/ 00266 void LAB_vInit( void ){ 00267 spi_init(&mySPI, p11, p12, p13, NC); 00268 spi_format(&mySPI, 8, 0, 0); 00269 spi_frequency(&mySPI, 25000000); 00270 LCD_vInit(&myLCD, &mySPI, p22, p23); 00271 LCD_vSetMode(&myLCD, LANDSCAPE); 00272 /* Blume in Sektor 1 zeichnen */ 00273 LCD_vFillSprite(&myLCD, 0, 0, 159, 119, (short int*)&awBlume[0]); 00274 /* Grauwerte aus Farbbild ermitteln */ 00275 vColorToGray((word*)&awBlume[0], &abPicture[0][0]); 00276 /* Grauwertbild in Sektor 2 zeichnen */ 00277 vGrayToScreen2(&abPicture[0][0]); 00278 /* Histogramm in Sektor 4 zeichen */ 00279 vDrawHisto(&abPicture[0][0]); 00280 } 00281 00282 00283 00284 00285 /*************************************************************************** 00286 * MMI-Main 00287 * diese Funktion wird alle 100 ms aufgerufen 00288 ****************************************************************************/ 00289 void LAB_vMain( void ){ 00290 bLed2 = !bLed2; 00291 // float bADCDATA; 00292 byte i; 00293 00294 /* heir die Anzeige des Analogwertes einbauen */ 00295 byte abPictureCorrektet[120][160]; 00296 00297 fpAdcValue = fpAnalog.read(); 00298 lcd_drawFloat(&myLCD,fpAdcValue*10, 3, 20, 125, 1, RED); 00299 if(!bBtn1) { 00300 00301 // vChangeGray(&abPictureCorrektet[0][0], 4); 00302 #if 0 00303 vGrayToScreen3(&abPictureCorrektet[0][0]); 00304 #else 00305 vChangeGray(&abPicture[0][0], fpAdcValue*10); 00306 vGrayToScreen3(&abPicture[0][0]); 00307 vDrawHisto(&abPicture[0][0]); 00308 00309 #endif 00310 } 00311 } 00312 00313 00314 /*************************************************************************** 00315 * EOF: TEMPLATE.C 00316 ****************************************************************************/ 00317 00318
Generated on Sat Jul 16 2022 01:28:41 by
1.7.2