void rectTest() { uint32_t i,start; Rectangle rc; prompt("Rectangle test"); for(i=0,start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;i++) { rc.X=(rand() % _gl->getXmax()/2); rc.Y=(rand() % _gl->getYmax()/2); rc.Width=rand() % (_gl->getXmax()-rc.X); rc.Height=rand() % (_gl->getYmax()-rc.Y); _gl->setForeground(rand()); _gl->fillRectangle(rc); } _gl->clearScreen(); for(i=0,start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;i++) { rc.X=(rand() % _gl->getXmax()/2); rc.Y=(rand() % _gl->getYmax()/2); rc.Width=rand() % (_gl->getXmax()-rc.X); rc.Height=rand() % (_gl->getYmax()-rc.Y); _gl->setForeground(rand()); _gl->drawRectangle(rc); if(i % 1000 ==0) _gl->clearScreen(); } }
void rectTest() { int i; Rectangle rc; prompt("Rectangle test"); for(i=0;i<1500;i++) { rc.X=(rand() % _gl->getXmax()/2); rc.Y=(rand() % _gl->getXmax()/2); rc.Width=rand() % (_gl->getXmax()-rc.X); rc.Height=rand() % (_gl->getYmax()-rc.Y); _gl->setForeground(rand()); _gl->fillRectangle(rc); } _gl->clearScreen(); for(i=0;i<10000;i++) { rc.X=(rand() % _gl->getXmax()/2); rc.Y=(rand() % _gl->getXmax()/2); rc.Width=rand() % (_gl->getXmax()-rc.X); rc.Height=rand() % (_gl->getYmax()-rc.Y); _gl->setForeground(rand()); _gl->drawRectangle(rc); if(i % 1000 ==0) _gl->clearScreen(); } }
void ellipseTest() { int16_t i; Point p; Size s; uint32_t start; prompt("Ellipse test"); _gl->setBackground(0); for(start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;) { p.X=_gl->getXmax()/4+(rand() % (_gl->getXmax()/2)); p.Y=_gl->getYmax()/4+(rand() % (_gl->getYmax()/2)); if(p.X<_gl->getXmax()/2) s.Width=rand() % p.X; else s.Width=rand() % (_gl->getXmax()-p.X); if(p.Y<_gl->getYmax()/2) s.Height=rand() % p.Y; else s.Height=rand() % (_gl->getYmax()-p.Y); _gl->setForeground(rand()); _gl->fillEllipse(p,s); } _gl->clearScreen(); for(i=0,start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;i++) { p.X=_gl->getXmax()/4+(rand() % (_gl->getXmax()/2)); p.Y=_gl->getYmax()/4+(rand() % (_gl->getYmax()/2)); if(p.X<_gl->getXmax()/2) s.Width=rand() % p.X; else s.Width=rand() % (_gl->getXmax()-p.X); if(p.Y<_gl->getYmax()/2) s.Height=rand() % p.Y; else s.Height=rand() % (_gl->getYmax()-p.Y); if(s.Height>0 && s.Width>0 && p.X+s.Width<_gl->getXmax() && p.Y+s.Height<_gl->getYmax()) { _gl->setForeground(rand()); _gl->drawEllipse(p,s); } if(i % 1000==0) _gl->clearScreen(); } }
void prompt(const char *prompt) { _gl->setBackground(ColourNames::BLACK); _gl->clearScreen(); _gl->setForeground(ColourNames::GHOSTWHITE); *_gl << Point(0,0) << prompt; MillisecondTimer::delay(2000); _gl->clearScreen(); }
void drawCompressedBitmap(uint8_t *pixels,uint32_t size,uint16_t width,uint16_t height,bool useDma,DmaFsmcLcdMemoryCopyFeature<LcdAccessMode>& dma) { _gl->setBackground(ColourNames::WHITE); _gl->clearScreen(); LinearBufferInputOutputStream compressedData(pixels,size); LzgDecompressionStream decompressor(compressedData,size); if(useDma) { _gl->drawBitmap( Rectangle(((_gl->getXmax()+1)-width)/2, ((_gl->getYmax()+1)-height)/2, width,height), decompressor, dma); } else { _gl->drawBitmap( Rectangle(((_gl->getXmax()+1)-width)/2, ((_gl->getYmax()+1)-height)/2, width,height), decompressor); } MillisecondTimer::delay(3000); }
void rectTest() { Rectangle rc; uint32_t start; prompt("Rectangle test"); for(start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;) { rc.X=(rand() % _gl->getXmax()/2); rc.Y=(rand() % _gl->getXmax()/2); rc.Width=rand() % (_gl->getXmax()-rc.X); rc.Height=rand() % (_gl->getYmax()-rc.Y); if(rc.Width>0 && rc.Height>0) { _gl->setForeground(rand()); _gl->fillRectangle(rc); } } _gl->clearScreen(); for(start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;) { rc.X=(rand() % _gl->getXmax()/2); rc.Y=(rand() % _gl->getXmax()/2); rc.Width=rand() % (_gl->getXmax()-rc.X); rc.Height=rand() % (_gl->getYmax()-rc.Y); _gl->setForeground(rand()); _gl->drawRectangle(rc); } }
void run() { // reset is on PE1 and RS (D/CX) is on PD11 GpioE<DefaultDigitalOutputFeature<1> > pe; GpioD<DefaultFsmcAlternateFunctionFeature<11>> pd; // set up the FSMC with RS=A16 (PD11). The 60Mhz FSMC bus on the F4 needs // slower timings. #if defined(STM32PLUS_F1) Fsmc8080LcdTiming fsmcTiming(0,2); #else Fsmc8080LcdTiming fsmcTiming(2,10); #endif _accessMode=new LcdAccessMode(fsmcTiming,16,pe[1]); // declare a panel _gl=new LcdPanel(*_accessMode); // apply gamma settings ILI9481Gamma gamma(0,0xf3,0,0xbc,0x50,0x1f,0,7,0x7f,0x7,0xf,0); _gl->applyGamma(gamma); // clear to black while the lights are out _gl->setBackground(0); _gl->clearScreen(); // create the backlight on timer4, channel2 (PD13) DefaultBacklight backlight; // fade up to 100% in 4ms steps backlight.fadeTo(100,4); // create a font _font=new Font_VOLTER__28GOLDFISH_299; *_gl << *_font; for(;;) { jpegTest(); lzgTest(); basicColoursTest(); textTest(); scrollTest(); ellipseTest(); gradientTest(); rectTest(); lineTest(); clearTest(); sleepTest(); } }
void run() { // reset is on PE1 and RS (D/CX) is on PE3 GpioE<DefaultDigitalOutputFeature<1>, DefaultFsmcAlternateFunctionFeature<3> > pe; // set up the FSMC timing. these numbers (particularly the data setup time) are dependent on // both the FSMC bus speed and the panel timing parameters. Fsmc8080LcdTiming fsmcTiming(2,4); // set up the FSMC with RS=A19 (PE3) _accessMode=new LcdAccessMode(fsmcTiming,19,pe[1]); _gl=new LcdPanel(*_accessMode); // apply gamma settings ST7783Gamma gamma(0,0x0107,0,0x0203,0x0402,0,0x0207,0,0x0203,0x0403); _gl->applyGamma(gamma); // clear to black while the lights are out _gl->setBackground(0); _gl->clearScreen(); // create the backlight on timer4, channel2 (PD13) DefaultBacklight backlight; // fade up to 100% in 4ms steps backlight.fadeTo(100,4); // Create a font. A wide range of sample fonts are available. See the // "lib/include/display/graphic/fonts" directory for a full list and // you can always download and convert your own using the FontConv utility. _font=new Font_VOLTER__28GOLDFISH_299; *_gl << *_font; _gl->setForeground(ColourNames::RED); _gl->fillRectangle(Rectangle(10,20,30,40)); for(;;) { jpegTest(); lzgTest(); basicColoursTest(); textTest(); ellipseTest(); gradientTest(); rectTest(); lineTest(); clearTest(); sleepTest(); } }
void clearTest() { uint32_t start; prompt("Clear screen test"); for(start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;) { _gl->setBackground(rand()); _gl->clearScreen(); } }
void run() { // reset is on PE1 and RS (D/CX) is on PD11 GpioE<DefaultDigitalOutputFeature<1> > pe; GpioD<DefaultFsmcAlternateFunctionFeature<11> > pd; // set up the FSMC timing. these numbers (particularly the data setup time) are dependent on // both the FSMC bus speed and the panel timing parameters. Fsmc8080LcdTiming fsmcTiming(0,3); // set up the FSMC with RS=A16 (PD11) _accessMode=new LcdAccessMode(fsmcTiming,16,pe[1]); _gl=new LcdPanel(*_accessMode); // clear to black while the lights are out _gl->setBackground(0); _gl->clearScreen(); // create the backlight on timer4, channel2 (PD13) DefaultBacklight backlight; // fade up to 100% in 4ms steps backlight.fadeTo(100,4); // create a font _font=new Font_VOLTER__28GOLDFISH_299; *_gl << *_font; _gl->setForeground(ColourNames::RED); _gl->fillRectangle(Rectangle(10,20,5,10)); for(;;) { jpegTest(); lzgTest(); basicColoursTest(); textTest(); scrollTest(); ellipseTest(); gradientTest(); rectTest(); lineTest(); clearTest(); sleepTest(); } }
void error(const std::string& str) { _tft->setBackground(ColourNames::WHITE); _tft->setForeground(ColourNames::BLACK); _tft->clearScreen(); LinearBufferInputOutputStream compressedData((uint8_t *)&ErrorPixels,(uint32_t)&ErrorPixelsSize); _tft->drawJpeg(Rectangle(95,135,50,50),compressedData); *_tft << Point(2,2) << str.c_str(); errorRestart(); }
void run() { // declare the access mode LcdAccessMode accessMode; // declare a panel _gl=new LcdPanel(accessMode); // apply the gamma curve. Note that gammas are panel specific. This curve is appropriate // to a replacement (non-original) panel obtained from ebay. uint8_t levels[13]={ 0xe,0,1,1,0,0,0,0,0,0,3,4,0 }; R61523Gamma gamma(levels); _gl->applyGamma(gamma); // clear to black while the lights are out _gl->setBackground(0); _gl->clearScreen(); // create the backlight using default template parameters _backlight=new LcdBacklight(accessMode); // fade up the backlight to 100% using the hardware to do the smooth fade _backlight->setPercentage(100); // A wide range of sample fonts are available. See the "lib/include/display/graphic/fonts" // directory for a full list and you can always download and convert your own using the // FontConv utility. *_gl << _font; for(;;) { textTest(); lzgTest(); basicColoursTest(); backlightTest(); gradientTest(); rectTest(); lineTest(); ellipseTest(); clearTest(); sleepTest(); } }
void clearTest() { int i; uint32_t start; prompt("Clear screen test"); for(i=0;i<200;i++) { _gl->setBackground(rand()); start=MillisecondTimer::millis(); _gl->clearScreen(); stopTimer(" to clear",MillisecondTimer::millis()-start); } }
void drawCompressedBitmap(uint8_t *pixels,uint32_t size,uint16_t width,uint16_t height) { _gl->setBackground(ColourNames::WHITE); _gl->clearScreen(); LinearBufferInputOutputStream compressedData(pixels,size); LzgDecompressionStream decompressor(compressedData,size); _gl->drawBitmap( Rectangle((_gl->getWidth()-width)/2, (_gl->getHeight()-height)/2, width,height), decompressor); MillisecondTimer::delay(3000); }
void sleepTest() { prompt("Sleep test"); // go to sleep *_gl << Point::Origin << "Sleeping now..."; MillisecondTimer::delay(1000); _gl->sleep(); MillisecondTimer::delay(3000); // wake up _gl->wake(); _gl->clearScreen(); *_gl << Point::Origin << "Woken up again..."; MillisecondTimer::delay(3000); }
void textTest() { int i; const char *str="The quick brown fox"; Size size; Point p; uint32_t start,before,elapsed,chars; prompt("Stream operators test"); *_gl << Point::Origin << "Let's see PI:"; for(i=0;i<=7;i++) *_gl << Point(0,(1+i)*_font->getHeight()) << DoublePrecision(3.1415926535,i); MillisecondTimer::delay(5000); prompt("Opaque text test"); size=_gl->measureString(*_font,str); before=MillisecondTimer::millis(); chars=0; for(start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;) { p.X=rand() % (_gl->getXmax()-size.Width); p.Y=rand() % (_gl->getYmax()-size.Height); _gl->setForeground(rand()); _gl->writeString(p,*_font,str); chars+=19; } elapsed=MillisecondTimer::millis()-before; _gl->clearScreen(); _gl->setForeground(ColourNames::WHITE); *_gl << Point::Origin << (chars*1000/elapsed) << " characters/sec"; MillisecondTimer::delay(3000); }
void processEvents() { //event 1: click on the touch panel // check if there's a click if(touch->_clicked){ // a click happened! do { touch->panel->getCoordinates(hitPoint); // event: calibrate button tap if(calibrate_box.containsPoint(hitPoint)){ MillisecondTimer::delay(500); touch->calibrate(); } // event: send AT commands button tap else if (ATcommands.containsPoint(hitPoint)){ // NEXT STEP: start usart, send AT+RST COMMAND AND GET THE ANSWER //debug purpose *lcd << Point(20,160); *lcd << "sending reset commands"; MillisecondTimer::delay(1000); // } } while(!touch->_penIrqPin.read()); //reset clicked flag touch->_clicked=false; // back to main menu lcd->clearScreen(); lcd->setForeground(fgcolor); drawMenu(); } }
void initialiseLcd() { // reset is on PE1 and RS (D/CX) is on PE3 GpioE<DefaultDigitalOutputFeature<1>, DefaultFsmcAlternateFunctionFeature<3>> pe; // set up the FSMC timing. these numbers (particularly the data setup time) are dependent on // both the FSMC bus speed and the panel timing parameters. Fsmc8080LcdTiming fsmcTiming(2,4); // set up the FSMC with RS=A19 (PE3) _accessMode=new LcdAccessMode(fsmcTiming,19,pe[1]); _tft=new LcdPanel(*_accessMode); // apply gamma settings ST7783Gamma gamma(0,0x0107,0,0x0203,0x0402,0,0x0207,0,0x0203,0x0403); _tft->applyGamma(gamma); // clear to black while the lights are out _tft->setBackground(ColourNames::BLACK); _tft->setForeground(ColourNames::WHITE); _tft->clearScreen(); // fade up to 100% in 4ms steps _backlight=new DefaultBacklight; _backlight->fadeTo(100,4); // create a font _font=new Font_VOLTER__28GOLDFISH_299; *_tft << *_font; _line=0; }
void scrollTest() { int32_t i,j,numRows; Point p; prompt("Hardware scrolling test"); _gl->setForeground(0xffffff); _gl->setBackground(0); _gl->clearScreen(); numRows=((_gl->getYmax()+1)/_font->getHeight())/3; p.X=0; for(i=0;i<numRows;i++) { p.Y=(numRows+i)*_font->getHeight(); *_gl << p << "Test row " << i; } for(j=0;j<15;j++) { numRows=(_gl->getYmax()+1)/4; for(i=0;i<numRows;i++) { _gl->setScrollPosition(i); MillisecondTimer::delay(5); } for(i=0;i<numRows;i++) { _gl->setScrollPosition(numRows-i); MillisecondTimer::delay(5); } } _gl->setScrollPosition(0); }
void lineTest() { Point p1,p2; uint32_t i,start; prompt("Line test"); for(i=0,start=MillisecondTimer::millis();MillisecondTimer::millis()-start<5000;i++) { p1.X=rand() % _gl->getXmax(); p1.Y=rand() % _gl->getYmax(); p2.X=rand() % _gl->getXmax(); p2.Y=rand() % _gl->getYmax(); _gl->setForeground(rand()); _gl->drawLine(p1,p2); } _gl->setForeground(ColourNames::WHITE); _gl->clearScreen(); *_gl << Point::Origin << i << " lines in 5 seconds"; MillisecondTimer::delay(3000); }
void basicColoursTest() { uint16_t i; static const uint32_t colours[7]={ ColourNames::RED, ColourNames::GREEN, ColourNames::BLUE, ColourNames::CYAN, ColourNames::MAGENTA, ColourNames::YELLOW, ColourNames::BLACK, }; prompt("Basic colours test"); for(i=0;i<sizeof(colours)/sizeof(colours[0]);i++) { _gl->setBackground(colours[i]); _gl->clearScreen(); MillisecondTimer::delay(500); } }
void run() { // reset is on PE1 and RS (D/CX) is on PD11 GpioE<DefaultDigitalOutputFeature<1> > pe; GpioD<DefaultFsmcAlternateFunctionFeature<11>> pd; // Set up the FSMC timing. These numbers (particularly the data setup time) are dependent on // both the FSMC bus speed and the panel timing parameters. If you see corrupted graphics then // you may need to adjust these to uit the characteristics of your particular panel. #if defined(STM32PLUS_F4) Fsmc8080LcdTiming fsmcTiming(3,6); #elif defined(STM32PLUS_F1) Fsmc8080LcdTiming fsmcTiming(0,2); #else #error Invalid MCU #endif // set up the FSMC with RS=A16 (PD11) _accessMode=new LcdAccessMode(fsmcTiming,16,pe[1]); // declare a panel _gl=new LcdPanel(*_accessMode); // apply gamma settings HX8352AGamma gamma(0xA0,0x03,0x00,0x45,0x03,0x47,0x23,0x77,0x01,0x1F,0x0F,0x03); _gl->applyGamma(gamma); // clear to black while the lights are out _gl->setBackground(0); _gl->clearScreen(); // create the backlight on timer4, channel2 (PD13) DefaultBacklight backlight; // fade up to 100% in 4ms steps backlight.fadeTo(100,4); // create a font _font=new Font_VOLTER__28GOLDFISH_299; *_gl << *_font; for(;;) { lzgTest(); rectTest(); jpegTest(); basicColoursTest(); lineTest(); textTest(); scrollTest(); ellipseTest(); gradientTest(); clearTest(); sleepTest(); } }
void showPicture(const std::string& uri) { // fade down the backlight to 10%, 4ms per step _backlight->fadeTo(10,4); // clear the screen _tft->setBackground(ColourNames::BLACK); _tft->clearScreen(); // we're using a custom TCP client connection that processes incoming data on the receive IRQ // so that we avoid advertising a zero receive window back to the server with the performance // hit that we would take MyTcpClientConnection *conn; if(!_net->tcpConnect<MyTcpClientConnection>(_serverAddress,WEB_SERVER_PORT,conn)) error("Failed to connect to web server"); // manage the connection pointer in a scoped_ptr so it's automatically deleted (and closed) // when it goes out of scope HttpClient httpClient(*conn); // set the parameters for the HTTP GET httpClient.setUri(uri); httpClient.setHost(WEB_SERVER); httpClient.setVersion(HttpVersion::HTTP_1_0); // connection to close after we get the image if(!httpClient.sendRequest()) { delete conn; error("Failed to send the request to the server"); } // use a read-ahead input stream wrapped around a TCP input stream // with a read-ahead buffer of 256 bytes TcpInputStream tcis(*conn); // if the JPEG will fit then display it centered on screen, otherwise ignore it Size size; JpegDecoder<LcdPanel> jpeg; if(!jpeg.beginDecode(tcis,size)) { delete conn; error("Failed to decode JPEG image"); } if(size.Height<=_tft->getHeight() && size.Width<=_tft->getWidth()) { // it fits, stream it in Point pt; pt.X=(_tft->getWidth()-size.Width)/2; pt.Y=(_tft->getHeight()-size.Height)/2; jpeg.endDecode(pt,*_tft); } delete conn; // fade up the backklight to 100%, 4ms per step _backlight->fadeTo(100,4); }
void run() { // reset is on PE1 and RS (D/CX) is on PD11 GpioE<DefaultDigitalOutputFeature<1> > pe; GpioD<DefaultFsmcAlternateFunctionFeature<11>> pd; // set up the FSMC timing. these numbers (particularly the data setup time) are dependent on // both the FSMC bus speed and the panel timing parameters. #if defined(STM32PLUS_F1) Fsmc8080LcdTiming fsmcTiming(0,2); #elif defined(STM32PLUS_F4) Fsmc8080LcdTiming fsmcTiming(1,15); #else #error Unsupported MCU #endif // set up the FSMC with RS=A16 (PD11) _accessMode=new LcdAccessMode(fsmcTiming,16,pe[1]); // declare a panel _gl=new LcdPanel(*_accessMode); // apply gamma settings HX8347AGamma gamma(0,7,0,0,0x10,0,0,0x16,0,0,0,0); _gl->applyGamma(gamma); // clear to black while the lights are out _gl->setBackground(0); _gl->clearScreen(); // create the backlight on timer4, channel2 (PD13) DefaultBacklight backlight; // fade up to 100% in 4ms steps backlight.fadeTo(100,4); // Create a font. A wide range of sample fonts are available. See the // "lib/include/display/graphic/fonts" directory for a full list and // you can always download and convert your own using the FontConv utility. _font=new Font_VOLTER__28GOLDFISH_299; *_gl << *_font; for(;;) { jpegTest(); lzgTest(); basicColoursTest(); textTest(); scrollTest(); ellipseTest(); gradientTest(); rectTest(); lineTest(); clearTest(); sleepTest(); } }