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