Vizic Technologies
/
PaintPro
SMARTGPU professional paint application! Be sure to load the image to the micro SD card first!
main.cpp@0:d6ede4c39036, 2011-09-14 (annotated)
- Committer:
- emmanuelchio
- Date:
- Wed Sep 14 05:34:45 2011 +0000
- Revision:
- 0:d6ede4c39036
Rev 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emmanuelchio | 0:d6ede4c39036 | 1 | /**************************************************************************************/ |
emmanuelchio | 0:d6ede4c39036 | 2 | /*SMARTGPU intelligent embedded graphics processor unit |
emmanuelchio | 0:d6ede4c39036 | 3 | those examples are for use the SMARTGPU with the mbed microcontoller, just connect tx,rx,and reset |
emmanuelchio | 0:d6ede4c39036 | 4 | Board: |
emmanuelchio | 0:d6ede4c39036 | 5 | http://www.vizictechnologies.com/#/desarrollo/4554296549 |
emmanuelchio | 0:d6ede4c39036 | 6 | |
emmanuelchio | 0:d6ede4c39036 | 7 | This example requires pre-loaded content, an image to the micro SD card! |
emmanuelchio | 0:d6ede4c39036 | 8 | |
emmanuelchio | 0:d6ede4c39036 | 9 | www.vizictechnologies.com |
emmanuelchio | 0:d6ede4c39036 | 10 | Vizic Technologies copyright 2011 */ |
emmanuelchio | 0:d6ede4c39036 | 11 | /**************************************************************************************/ |
emmanuelchio | 0:d6ede4c39036 | 12 | /**************************************************************************************/ |
emmanuelchio | 0:d6ede4c39036 | 13 | |
emmanuelchio | 0:d6ede4c39036 | 14 | #include "mbed.h" |
emmanuelchio | 0:d6ede4c39036 | 15 | #include "SMARTGPU.h" |
emmanuelchio | 0:d6ede4c39036 | 16 | |
emmanuelchio | 0:d6ede4c39036 | 17 | SMARTGPU lcd(p13,p14,p15); //(TX,RX,Reset); |
emmanuelchio | 0:d6ede4c39036 | 18 | |
emmanuelchio | 0:d6ede4c39036 | 19 | //Each time we use the touchscreen we must define a int array that stores the X and Y readed or touched coordinates. |
emmanuelchio | 0:d6ede4c39036 | 20 | int touch[2]; |
emmanuelchio | 0:d6ede4c39036 | 21 | //Each time we use the touchicon we must define a char array that stores the name of the touched icon. |
emmanuelchio | 0:d6ede4c39036 | 22 | char icon[3]; |
emmanuelchio | 0:d6ede4c39036 | 23 | |
emmanuelchio | 0:d6ede4c39036 | 24 | char pixelArray[3]; //Array to store the RGB888 pixel obtained with memoryRead() |
emmanuelchio | 0:d6ede4c39036 | 25 | |
emmanuelchio | 0:d6ede4c39036 | 26 | |
emmanuelchio | 0:d6ede4c39036 | 27 | /**************************************************/ |
emmanuelchio | 0:d6ede4c39036 | 28 | //Funcion to convert a 3 byte array to an int RGB565 |
emmanuelchio | 0:d6ede4c39036 | 29 | int RGB888ToRGB565(char pixBuffer[]){ //get an array of 3 bytes( red, green, blue), and convert them to RGB565 returned in an int |
emmanuelchio | 0:d6ede4c39036 | 30 | unsigned char R,G,B; |
emmanuelchio | 0:d6ede4c39036 | 31 | unsigned int col; |
emmanuelchio | 0:d6ede4c39036 | 32 | unsigned long colour; |
emmanuelchio | 0:d6ede4c39036 | 33 | |
emmanuelchio | 0:d6ede4c39036 | 34 | R=pixBuffer[0]; |
emmanuelchio | 0:d6ede4c39036 | 35 | G=pixBuffer[1]; |
emmanuelchio | 0:d6ede4c39036 | 36 | B=pixBuffer[2]; |
emmanuelchio | 0:d6ede4c39036 | 37 | ((unsigned char *) &colour)[1]=(R & 0xF8); |
emmanuelchio | 0:d6ede4c39036 | 38 | R=G; |
emmanuelchio | 0:d6ede4c39036 | 39 | G=G>>5; |
emmanuelchio | 0:d6ede4c39036 | 40 | ((unsigned char *) &colour)[1]|=G; |
emmanuelchio | 0:d6ede4c39036 | 41 | G=(R<<3)& 0xE0; |
emmanuelchio | 0:d6ede4c39036 | 42 | ((unsigned char *) &colour)[0]=B; |
emmanuelchio | 0:d6ede4c39036 | 43 | ((unsigned char *) &colour)[0]=((unsigned char *) &colour)[0]>>3; |
emmanuelchio | 0:d6ede4c39036 | 44 | ((unsigned char *) &colour)[0]|=G; |
emmanuelchio | 0:d6ede4c39036 | 45 | col=colour; |
emmanuelchio | 0:d6ede4c39036 | 46 | return col; |
emmanuelchio | 0:d6ede4c39036 | 47 | } |
emmanuelchio | 0:d6ede4c39036 | 48 | |
emmanuelchio | 0:d6ede4c39036 | 49 | |
emmanuelchio | 0:d6ede4c39036 | 50 | int main() { |
emmanuelchio | 0:d6ede4c39036 | 51 | lcd.reset(); //physically reset SMARTGPU |
emmanuelchio | 0:d6ede4c39036 | 52 | lcd.start(); //initialize the SMARTGPU processor |
emmanuelchio | 0:d6ede4c39036 | 53 | |
emmanuelchio | 0:d6ede4c39036 | 54 | unsigned char penSize=1; |
emmanuelchio | 0:d6ede4c39036 | 55 | int colPaint=BLACK; |
emmanuelchio | 0:d6ede4c39036 | 56 | char pen[4]={'x','0','1',0x00}; //Array that show the current penSize |
emmanuelchio | 0:d6ede4c39036 | 57 | |
emmanuelchio | 0:d6ede4c39036 | 58 | lcd.baudChange(2000000); // Set a fast baud!, always that we use touch functions is recommended to use fast baud rates |
emmanuelchio | 0:d6ede4c39036 | 59 | |
emmanuelchio | 0:d6ede4c39036 | 60 | //Load paint design |
emmanuelchio | 0:d6ede4c39036 | 61 | lcd.imageSD(0,0,"paint"); |
emmanuelchio | 0:d6ede4c39036 | 62 | lcd.string(7,54,48,65,GREEN,FONT1,FILL,"Erase"); //draw Erase word |
emmanuelchio | 0:d6ede4c39036 | 63 | lcd.string(77,54,110,65,GREEN,FONT1,FILL,pen); //draw penSize |
emmanuelchio | 0:d6ede4c39036 | 64 | |
emmanuelchio | 0:d6ede4c39036 | 65 | while(1){ //Start the Paint application |
emmanuelchio | 0:d6ede4c39036 | 66 | |
emmanuelchio | 0:d6ede4c39036 | 67 | while(!lcd.touchScreen(touch)); //Wait for a touch on the screen to do something |
emmanuelchio | 0:d6ede4c39036 | 68 | //Once we get a touch somewhere on the screen: |
emmanuelchio | 0:d6ede4c39036 | 69 | if((touch[YCOORD]-penSize)<67){ //the touch was on the menu |
emmanuelchio | 0:d6ede4c39036 | 70 | if(touch[XCOORD]<45){ //touch on erase circle |
emmanuelchio | 0:d6ede4c39036 | 71 | lcd.drawRectangle(0,67,319,239,WHITE,1); //Draw a white rectangle on drawing area |
emmanuelchio | 0:d6ede4c39036 | 72 | }else if(touch[XCOORD]<75){ //touch to select the eraser |
emmanuelchio | 0:d6ede4c39036 | 73 | colPaint=WHITE; |
emmanuelchio | 0:d6ede4c39036 | 74 | lcd.drawCircle(25,34,14,colPaint,FILL); //draw WHITE colour circle on top left corner |
emmanuelchio | 0:d6ede4c39036 | 75 | }else if(touch[XCOORD]<108){ //touch to change pen Size |
emmanuelchio | 0:d6ede4c39036 | 76 | penSize=penSize*2; //double the penSize |
emmanuelchio | 0:d6ede4c39036 | 77 | if(penSize==16){ //maximum pen size = 8, if we reach 16 we set to 1. |
emmanuelchio | 0:d6ede4c39036 | 78 | penSize=1; |
emmanuelchio | 0:d6ede4c39036 | 79 | } |
emmanuelchio | 0:d6ede4c39036 | 80 | pen[1]=(penSize/10)+0x30; //get the tens of penSize and convert them to ascii |
emmanuelchio | 0:d6ede4c39036 | 81 | pen[2]=(penSize%10)+0x30; //get the ones of penSize and convert them to ascii |
emmanuelchio | 0:d6ede4c39036 | 82 | lcd.string(77,54,110,65,GREEN,FONT1,FILL,pen);//draw penSize |
emmanuelchio | 0:d6ede4c39036 | 83 | wait_ms(500); //delay to avoid fast penSize changing |
emmanuelchio | 0:d6ede4c39036 | 84 | }else if(touch[XCOORD]<312 & touch[YCOORD]>20 & touch[YCOORD]<59){ //touch on the colours bar |
emmanuelchio | 0:d6ede4c39036 | 85 | lcd.memoryRead(touch[XCOORD],touch[YCOORD],touch[XCOORD],touch[YCOORD],pixelArray); //assign new colour based on touch coordinates and memory read, this function return a 24 bit pixel array, |
emmanuelchio | 0:d6ede4c39036 | 86 | colPaint=RGB888ToRGB565(pixelArray); |
emmanuelchio | 0:d6ede4c39036 | 87 | lcd.drawCircle(25,34,14,colPaint,FILL); //draw new selected colour on top left corner |
emmanuelchio | 0:d6ede4c39036 | 88 | } |
emmanuelchio | 0:d6ede4c39036 | 89 | }else{ //Touch on drawing area |
emmanuelchio | 0:d6ede4c39036 | 90 | lcd.drawCircle(touch[XCOORD],touch[YCOORD],penSize,colPaint,FILL); //Draw |
emmanuelchio | 0:d6ede4c39036 | 91 | } |
emmanuelchio | 0:d6ede4c39036 | 92 | } |
emmanuelchio | 0:d6ede4c39036 | 93 | } |