SmartGPU2 Hardware Objects Demo - MBED + SmartGPU2 board

Dependencies:   SMARTGPU2 mbed

Committer:
emmanuelchio
Date:
Thu Apr 17 23:50:03 2014 +0000
Revision:
1:66322a7f180a
Parent:
0:c95df289dc58
SmartGPU2 Objects_SG2 demo- Please select(uncomment) your smartGPU2 board under SMARTGPU2.h file before compiling!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emmanuelchio 1:66322a7f180a 1 /**************************************************************************************/
emmanuelchio 0:c95df289dc58 2 /**************************************************************************************/
emmanuelchio 0:c95df289dc58 3 /*SMARTGPU2 intelligent embedded graphics processor unit
emmanuelchio 1:66322a7f180a 4 those examples are for using the SMARTGPU2 with the mbed microcontoller, just connect tx,rx,and reset
emmanuelchio 0:c95df289dc58 5 Board:
emmanuelchio 1:66322a7f180a 6 http://www.vizictechnologies.com/
emmanuelchio 0:c95df289dc58 7
emmanuelchio 0:c95df289dc58 8 www.vizictechnologies.com
emmanuelchio 1:66322a7f180a 9 Vizic Technologies copyright 2014 */
emmanuelchio 1:66322a7f180a 10 /**************************************************************************************/
emmanuelchio 0:c95df289dc58 11 /**************************************************************************************/
emmanuelchio 0:c95df289dc58 12
emmanuelchio 0:c95df289dc58 13 #include "mbed.h"
emmanuelchio 0:c95df289dc58 14 #include "SMARTGPU2.h"
emmanuelchio 0:c95df289dc58 15
emmanuelchio 0:c95df289dc58 16 SMARTGPU2 lcd(TXPIN,RXPIN,RESETPIN); //create our object called "lcd"
emmanuelchio 0:c95df289dc58 17
emmanuelchio 0:c95df289dc58 18
emmanuelchio 0:c95df289dc58 19 /***************************************************/
emmanuelchio 0:c95df289dc58 20 /***************************************************/
emmanuelchio 0:c95df289dc58 21 void initializeSmartGPU2(void){ //Initialize SMARTGPU2 Board
emmanuelchio 0:c95df289dc58 22 lcd.reset(); //physically reset SMARTGPU2
emmanuelchio 0:c95df289dc58 23 lcd.start(); //initialize the SMARTGPU2 processor
emmanuelchio 0:c95df289dc58 24 }
emmanuelchio 0:c95df289dc58 25
emmanuelchio 0:c95df289dc58 26 /***************************************************/
emmanuelchio 0:c95df289dc58 27 /***************************************************/
emmanuelchio 0:c95df289dc58 28 /***************************************************/
emmanuelchio 0:c95df289dc58 29 /***************************************************/
emmanuelchio 0:c95df289dc58 30 int main() {
emmanuelchio 0:c95df289dc58 31 POINT point;
emmanuelchio 0:c95df289dc58 32 unsigned char progress=0;
emmanuelchio 0:c95df289dc58 33 char sliderPosition=49, scrollPosition=4;
emmanuelchio 0:c95df289dc58 34
emmanuelchio 0:c95df289dc58 35 initializeSmartGPU2(); //Init communication with SmartGPU2 board
emmanuelchio 0:c95df289dc58 36
emmanuelchio 1:66322a7f180a 37 lcd.baudChange(BAUD6); //set a fast baud! for fast drawing
emmanuelchio 0:c95df289dc58 38
emmanuelchio 0:c95df289dc58 39 //DRAW INITIAL STATE/VALUES OBJECTS
emmanuelchio 0:c95df289dc58 40 //draw the object window
emmanuelchio 0:c95df289dc58 41 lcd.objWindow(0,0,MAX_X_LANDSCAPE,MAX_Y_LANDSCAPE, FONT1, SELECTEDGRAY, "objects window");
emmanuelchio 0:c95df289dc58 42 //draw the object slider
emmanuelchio 0:c95df289dc58 43 lcd.objSlider(10, 80, 309, 115, sliderPosition, 100, HORIZONTAL); //draw the slider with 100 divisions and 49 as current position
emmanuelchio 0:c95df289dc58 44 //draw the object scroll bar
emmanuelchio 0:c95df289dc58 45 lcd.objScrollBar(10, 125, 309, 160, scrollPosition, 10, HORIZONTAL, DESELECTED); //draw the scroll bar with 10 divisions and 4 as current position
emmanuelchio 0:c95df289dc58 46 //draw the object button1 and button2
emmanuelchio 0:c95df289dc58 47 lcd.objButton(10, 170, 150, 220, DESELECTED, "button 1");
emmanuelchio 0:c95df289dc58 48 lcd.objButton(170, 170, 309, 220, DESELECTED, "button 2");
emmanuelchio 0:c95df289dc58 49
emmanuelchio 0:c95df289dc58 50 //LOOP FOREVER AND DRAW ONLY IF TOUCH ON OBJECT
emmanuelchio 0:c95df289dc58 51 while(1){
emmanuelchio 0:c95df289dc58 52 //draw the object progress bar - this is the only object that doesn't wait for a touch, it just updates automatically each delay cycle
emmanuelchio 0:c95df289dc58 53 lcd.objProgressBar(10, 40, 309, 70, progress++); //draw the progress bar with the "progress" variable value
emmanuelchio 0:c95df289dc58 54 if(progress>100) progress = 0;
emmanuelchio 0:c95df289dc58 55
emmanuelchio 0:c95df289dc58 56 //ask for a touch
emmanuelchio 0:c95df289dc58 57 if(lcd.touchScreen(&point)==VALID){ //if a touch on screen is valid
emmanuelchio 0:c95df289dc58 58 //IF SLIDER
emmanuelchio 0:c95df289dc58 59 if(point.y>80 && point.y<115){ //if the touch on the slider
emmanuelchio 0:c95df289dc58 60 sliderPosition = ((point.x*100)/(309-10)); //scale the value and set it to sliderPosition
emmanuelchio 0:c95df289dc58 61 //draw the object slider with currently obtained scaled touch value
emmanuelchio 0:c95df289dc58 62 lcd.objSlider(10, 80, 309, 115, sliderPosition, 100, HORIZONTAL); //draw the slider with 100 divisions and "sliderPosition" variable value
emmanuelchio 0:c95df289dc58 63 }
emmanuelchio 0:c95df289dc58 64 //IF SCROLLBAR
emmanuelchio 0:c95df289dc58 65 if(point.y>125 && point.y<160){ //if the touch on the scroll bar
emmanuelchio 0:c95df289dc58 66 if(point.x>(MAX_X_LANDSCAPE-SCROLLBUTTONSIZE)){ //if touch is on the right > button
emmanuelchio 0:c95df289dc58 67 scrollPosition++;
emmanuelchio 0:c95df289dc58 68 if(scrollPosition>9) scrollPosition=9;
emmanuelchio 0:c95df289dc58 69 //draw the object scroll bar as SELECTED
emmanuelchio 0:c95df289dc58 70 lcd.objScrollBar(10, 125, 309, 160, scrollPosition, 10, HORIZONTAL, SELECTED); //draw the scroll bar with 10 divisions and "scrollPosition" variable value
emmanuelchio 0:c95df289dc58 71 }else if(point.x<SCROLLBUTTONSIZE){ //if touch is on the left < button
emmanuelchio 0:c95df289dc58 72 scrollPosition--;
emmanuelchio 0:c95df289dc58 73 if(scrollPosition<0) scrollPosition=0;
emmanuelchio 0:c95df289dc58 74 //draw the object scroll bar as SELECTED
emmanuelchio 0:c95df289dc58 75 lcd.objScrollBar(10, 125, 309, 160, scrollPosition, 10, HORIZONTAL, SELECTED); //draw the scroll bar with 10 divisions and "scrollPosition" variable value
emmanuelchio 0:c95df289dc58 76 }
emmanuelchio 0:c95df289dc58 77 wait_ms(50);
emmanuelchio 0:c95df289dc58 78 lcd.objScrollBar(10, 125, 309, 160, scrollPosition, 10, HORIZONTAL, DESELECTED); //draw the scroll bar with 10 divisions and "scrollPosition" variable value
emmanuelchio 0:c95df289dc58 79 }
emmanuelchio 0:c95df289dc58 80 //IF BUTTON1
emmanuelchio 0:c95df289dc58 81 if(point.y>170 && point.y<220 && point.x<160){ //if the touch on button1
emmanuelchio 0:c95df289dc58 82 //draw the object button1 as SELECTED
emmanuelchio 0:c95df289dc58 83 lcd.objButton(10, 170, 150, 220, SELECTED, "button 1");
emmanuelchio 0:c95df289dc58 84 wait_ms(50);
emmanuelchio 0:c95df289dc58 85 lcd.objButton(10, 170, 150, 220, DESELECTED, "button 1");
emmanuelchio 0:c95df289dc58 86 }
emmanuelchio 0:c95df289dc58 87 //IF BUTTON2
emmanuelchio 0:c95df289dc58 88 if(point.y>170 && point.y<220 && point.x>160){ //if the touch on button2
emmanuelchio 0:c95df289dc58 89 //draw the object button2 as SELECTED
emmanuelchio 0:c95df289dc58 90 lcd.objButton(170, 170, 309, 220, SELECTED, "button 2");
emmanuelchio 0:c95df289dc58 91 wait_ms(50);
emmanuelchio 0:c95df289dc58 92 lcd.objButton(170, 170, 309, 220, DESELECTED, "button 2");
emmanuelchio 0:c95df289dc58 93 }
emmanuelchio 0:c95df289dc58 94 }
emmanuelchio 0:c95df289dc58 95 //update objects each 100 milliseconds
emmanuelchio 0:c95df289dc58 96 wait_ms(100);
emmanuelchio 0:c95df289dc58 97 }
emmanuelchio 0:c95df289dc58 98 }