This is a fork of a functional ILI9341 display with a functional Seeed touch screen library.

Dependencies:   BMP180 UniGraphic mbed BNO055_fusionI_fixed HTU21D GPSISR Compass Fonts uGUI

Fork of TFT_test_NUCLEO-F411RE by Motoo Tanaka

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed main.cpp to test adafruit 2.8" TFT LCD shiled w Touchscreen
00002  * Copyright (c) 2014, 2015 Motoo Tanaka @ Design Methodology Lab
00003  *
00004  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00005  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00006  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00007  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00008  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00009  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00010  * THE SOFTWARE.
00011  */
00012 
00013 /*
00014  * Note: This program is derived from the SeeeStudioTFTv2 program.
00015  * Although both program share same ILI9341 TFT driver,
00016  * the touch sensor was not same with the Display I purchased from Akizuki.
00017  * http://akizukidenshi.com/catalog/g/gM-07747/
00018  * The touch sensor on the display is STMPE610,
00019  * so I hacked the minimum spi driver for it (polling mode only).
00020  */
00021 
00022 #include "mbed.h"
00023 #include <math.h>
00024 #include "ILI9341.h"
00025 // Graphics GUI Library
00026 #include    "ugui.h"
00027 // Include all devices on sensor board. 
00028 #include "SeeedStudioTFTv2.h"
00029 #include "BNO055.h"
00030 #include "HTU21D.h"
00031 #include "BMP180.h"
00032 #include "GPSISR.h"
00033 #include "nav.h"
00034 // Include all fonts used on display.
00035 #include "ArialR16x17.h"
00036 #include "Arial24x23i.h"
00037 #include "Arial28x28.h"
00038 #include "Neu44x36.h"
00039 #include "SCProSB31x55.h"
00040 #include "Arial12x12.h"
00041 #include "ArialR20x20.h"
00042 #include "compass.h"
00043 
00044 // Define screen SPI and memory card SPI hardware pins.
00045 #define PIN_RESET_TFT   PC_13 /* place holder */
00046 //ILI9341 SPI PINS
00047 #define PIN_XP          A3
00048 #define PIN_XM          A1
00049 #define PIN_YP          A2
00050 #define PIN_YM          A0
00051 #define PIN_MOSI_SPI1   D11 //SPI 1 MOSI
00052 #define PIN_MISO_SPI1   D12 //SPI 1 MISO
00053 #define PIN_SCLK_SPI1   D13 //SPI 1 SLCK
00054 #define PIN_CS_SPI1     D5 // SPI CS D10 Was D5
00055 #define PIN_DC_TFT      D6
00056 #define PIN_CS_SD       D4
00057 #define PIN_RESET       D7
00058 // SD Card on GPS shield PINS
00059 #define PIN_MOSI_SPI3   PB_15 //SPI 3 MOSI
00060 #define PIN_MISO_SPI3   PB_14 //SPI 3 MISO
00061 #define PIN_SCLK_SPI3   PB_13 //SPI 3 SLCK
00062 #define PIN_CS_SPI3     D2 // SPI CS
00063 #define PIN_RX_GPS      PA_12 //GPS Shield RX pin
00064 #define PIN_TX_GPS      PA_11 //GPS Shield TX pin
00065 //PI
00066 #define PI                  3.14159265358979f
00067 //BN055 compass module classes definitions.
00068 BNO055_ID_INF_TypeDef       bno055_id_inf;
00069 BNO055_EULER_TypeDef        euler_angles;
00070 BNO055_QUATERNION_TypeDef   quaternion;
00071 BNO055_LIN_ACC_TypeDef      linear_acc;
00072 BNO055_GRAVITY_TypeDef      gravity;
00073 BNO055_TEMPERATURE_TypeDef  chip_temp;
00074 // Compiler processor name.
00075 #define DEVICE_NAME     "F411RE"
00076 
00077 #ifndef TARGET_NECLEO_F411RE
00078 #define TARGET_NECLEO_F411RE
00079 #endif
00080 
00081 //DigitalOut backlight(PB_3) ;
00082 
00083 /** Height of display using default orientation */
00084 #define ILI9341_DEFAULT_HEIGHT   240
00085 
00086 /** Width of display using default orientation */
00087 #define ILI9341_DEFAULT_WIDTH    320
00088 
00089 /** Height of display using swapped X/Y orientation */
00090 #define ILI9341_SWITCH_XY_HEIGHT 320
00091 
00092 /** Width of display using swapped X/Y orientation */
00093 #define ILI9341_SWITCH_XY_WIDTH  240
00094 
00095 Serial pc(USBTX, USBRX);
00096 
00097 // Display
00098 ILI9341 TFT(SPI_8, 20000000,
00099             PIN_MOSI_SPI1, PIN_MISO_SPI1,  PIN_SCLK_SPI1,
00100             PIN_CS_SPI1, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
00101 
00102 // TouchScreen
00103 TouchScreen TSC(PIN_XP, PIN_XM, PIN_YP, PIN_YM);
00104 
00105 // 3 Axis IMU
00106 BNO055 imu(I2C_SDA, I2C_SCL, PIN_RESET);  // Reset =D7, addr = BNO055_G_CHIP_ADDR, mode = MODE_NDOF <- as default
00107 // Humidity and Temperature
00108 HTU21D humid(I2C_SDA, I2C_SCL);
00109 
00110 // Pressure
00111 BMP180 bmp180(I2C_SDA, I2C_SCL);
00112 
00113 // Set up serial interrupe service handler for gps characters.
00114 GPS MyGPS(PIN_TX_GPS,PIN_RX_GPS, 9600);
00115 
00116 //Navigation Class. Perry Michigan coordinates.
00117 NAV nav;
00118 double plat = 42.826420;
00119 double plon = -84.219413;
00120 
00121 // Graphics library declarations. 
00122 void arrow(int x2, int y2, int x1, int y1, int alength, int awidth, int colour);
00123 void ili9341_pset(UG_S16 ul_x,UG_S16 ul_y, UG_COLOR ul_color);
00124 void window_1_callback( UG_MESSAGE* msg );
00125 void window_2_callback( UG_MESSAGE* msg );
00126 void window_3_callback( UG_MESSAGE* msg );
00127 void cb1(void);
00128 
00129 // Compass graphic screen placement.
00130 const int centreX = 120; // e compass indicator
00131 const int centreY = 136;
00132 const int radius  = 104;
00133 float last_dx;
00134 float last_dy;
00135 
00136 // Bike computer page setup.
00137 int pageid = 1;
00138 bool pageinit = false;
00139 
00140 // Touch screen point structer.
00141 struct pt {
00142     int x;
00143     int y;
00144     bool z;
00145 };
00146 pt ptouch;
00147 
00148 // Page constants.
00149 #define PAGE1       1
00150 #define PAGE2       2
00151 #define PAGE3       3
00152 
00153 // Instance of GUI.
00154 UG_GUI   gui;
00155 
00156 // Main routine.
00157 int main()
00158 {
00159     // Initialize touch screen.    
00160     TFT.BusEnable(true) ;
00161     TFT.FastWindow(true) ;
00162     wait(0.1);
00163     TFT.cls();
00164     wait(0.1);
00165     // Initialize graphics library.
00166     UG_Init(&gui,ili9341_pset,ILI9341_DEFAULT_HEIGHT,ILI9341_DEFAULT_WIDTH);
00167 
00168     // Sets up a timer for use in loop; how often do we print GPS info?
00169     // How often screen is updated.
00170     Timer refresh_Timer;
00171     const int refresh_Time = 2000; //refresh time in ms
00172     refresh_Timer.start();  //starts the clock on the timer
00173     wait(0.1);
00174    
00175     /* Window 1 Bike Computer */
00176     #define MAX_OBJECTS 10
00177     UG_WINDOW window_1 ; /* Window */
00178     UG_BUTTON button_1; /* Button container */
00179     UG_BUTTON button_2; /* Button container */
00180     UG_OBJECT obj_buff_wnd_1 [MAX_OBJECTS] ; /* Object buffer */
00181     UG_WindowCreate ( &window_1 , obj_buff_wnd_1 , MAX_OBJECTS, window_1_callback);
00182     UG_WindowSetTitleTextFont ( &window_1 , &FONT_8X8 ) ;
00183     UG_WindowSetTitleText ( &window_1 , "Bike Computer" ) ;
00184     UG_WindowSetBackColor( &window_1 , C_GRAY ) ;
00185     UG_ButtonCreate (&window_1, &button_1, BTN_ID_0, 10 , 230 , 115 , 290 );
00186     UG_ButtonCreate (&window_1, &button_2, BTN_ID_1, 125 , 230 , 225 , 290 );
00187     UG_ButtonSetBackColor (&window_1 ,BTN_ID_0 , C_BLUE ) ;
00188     UG_ButtonSetForeColor (&window_1 ,BTN_ID_0 , C_WHITE ) ;
00189     UG_ButtonSetBackColor (&window_1 ,BTN_ID_1 , C_BLUE ) ;
00190     UG_ButtonSetForeColor (&window_1 ,BTN_ID_1 , C_WHITE ) ;
00191     UG_ButtonSetFont (&window_1 , BTN_ID_0 , &FONT_8X8) ;
00192     UG_ButtonSetFont (&window_1 , BTN_ID_1 , &FONT_8X8) ;
00193     UG_ButtonSetText (&window_1 , BTN_ID_0 , "Prev" );
00194     UG_ButtonSetText (&window_1 , BTN_ID_1 , "Next" );
00195 
00196     /* Window 2 e-Compass */
00197     UG_WINDOW window_2 ; /* Window */
00198     UG_BUTTON button_3; /* Button container */
00199     UG_BUTTON button_4; /* Button container */
00200     UG_OBJECT obj_buff_wnd_2 [MAX_OBJECTS] ; /* Object buffer */
00201     UG_WindowCreate ( &window_2 , obj_buff_wnd_2 , MAX_OBJECTS, window_2_callback);
00202     UG_WindowSetTitleTextFont ( &window_2 , &FONT_8X8 ) ;
00203     UG_WindowSetTitleText ( &window_2 , "e-Compass" ) ;
00204     UG_WindowSetBackColor( &window_2 , C_GRAY ) ;
00205     UG_ButtonCreate (&window_2, &button_3, BTN_ID_2, 10 , 230 , 115 , 290 );
00206     UG_ButtonCreate (&window_2, &button_4, BTN_ID_3, 125 , 230 , 225 , 290 );
00207     UG_ButtonSetBackColor (&window_2 ,BTN_ID_2 , C_BLUE ) ;
00208     UG_ButtonSetForeColor (&window_2 ,BTN_ID_2 , C_WHITE ) ;
00209     UG_ButtonSetBackColor (&window_2 ,BTN_ID_3 , C_BLUE ) ;
00210     UG_ButtonSetForeColor (&window_2 ,BTN_ID_3 , C_WHITE ) ;
00211     UG_ButtonSetFont (&window_2 , BTN_ID_2 , &FONT_8X8) ;
00212     UG_ButtonSetFont (&window_2 , BTN_ID_3 , &FONT_8X8) ;
00213     UG_ButtonSetText (&window_2 , BTN_ID_2 , "Prev" );
00214     UG_ButtonSetText (&window_2 , BTN_ID_3 , "Next" );
00215     
00216     /* Window 3 GSP */
00217     UG_WINDOW window_3 ; /* Window */
00218     UG_BUTTON button_5; /* Button container */
00219     UG_BUTTON button_6; /* Button container */
00220     UG_OBJECT obj_buff_wnd_3 [MAX_OBJECTS] ; /* Object buffer */
00221     UG_WindowCreate ( &window_3 , obj_buff_wnd_3 , MAX_OBJECTS, window_3_callback);
00222     UG_WindowSetTitleTextFont ( &window_3 , &FONT_8X8 ) ;
00223     UG_WindowSetTitleText ( &window_3 , "GPS Waypoints" ) ;
00224     UG_WindowSetBackColor( &window_3 , C_GRAY ) ;
00225     UG_ButtonCreate (&window_3, &button_5, BTN_ID_4, 10 , 230 , 115 , 290 );
00226     UG_ButtonCreate (&window_3, &button_6, BTN_ID_5, 125 , 230 , 225 , 290 );
00227     UG_ButtonSetBackColor (&window_3 ,BTN_ID_4 , C_BLUE ) ;
00228     UG_ButtonSetForeColor (&window_3 ,BTN_ID_4 , C_WHITE ) ;
00229     UG_ButtonSetBackColor (&window_3 ,BTN_ID_5 , C_BLUE ) ;
00230     UG_ButtonSetForeColor (&window_3 ,BTN_ID_5 , C_WHITE ) ;
00231     UG_ButtonSetFont (&window_3 , BTN_ID_4 , &FONT_8X8) ;
00232     UG_ButtonSetFont (&window_3 , BTN_ID_5 , &FONT_8X8) ;
00233     UG_ButtonSetText (&window_3 , BTN_ID_4 , "Prev" );
00234     UG_ButtonSetText (&window_3 , BTN_ID_5 , "Next" );
00235 
00236     while (1) {
00237         //Read touch screen every 0.2 seconds and pass it to uGUI
00238         cb1();
00239 
00240         TFT.set_font((unsigned char*) ArialR20x20);
00241         TFT.foreground(White);
00242         TFT.background(UG_WindowGetBackColor(&window_1));
00243         // Sets up a timer for use in loop; how often do we print GPS info?
00244         if (refresh_Timer.read_ms() >= refresh_Time) {
00245             refresh_Timer.reset();
00246             //This is screen one of bike computer. It is executed every 2 seconds. Ie...refresh_Time
00247             switch ( pageid ) {
00248                 case PAGE1: {
00249                     if (!pageinit) {
00250                         UG_WindowHide(&window_2);
00251                         UG_WindowHide(&window_3);
00252                         UG_WindowShow(&window_1);
00253                         UG_Update();
00254                     }
00255                     pageinit = 1;
00256                     if (bmp180.init() != 0) {
00257                     //pc.printf("Error communicating with BMP180\n");
00258                     } else {
00259                         //pc.printf("Initialized BMP180\n");
00260                         bmp180.startTemperature();
00261                         wait(0.1);     // Wait for conversion to complete
00262                         float temp;
00263                         if(bmp180.getTemperature(&temp) != 0) {
00264                             //pc.printf("Error getting temperature\n");
00265                         }
00266                         TFT.set_font((unsigned char*) Arial12x12);
00267                         TFT.locate(10, 65) ;
00268                         TFT.printf("Temperature");
00269                         TFT.set_font((unsigned char*) ArialR20x20);
00270                         TFT.locate(10, 80);
00271                         TFT.printf("%.1f*", ((temp* 9.0) / 5.0 + 32));
00272                     }
00273                     int ftemp = humid.sample_ftemp();
00274                     int humidity = humid.sample_humid();
00275                     TFT.set_font((unsigned char*) Arial12x12);
00276                     TFT.locate(150, 65) ;
00277                     TFT.printf("Humidity");
00278                     TFT.set_font((unsigned char*) ArialR20x20);
00279                     TFT.locate(150, 80) ;
00280                     TFT.printf("%d%%",humidity);
00281                     if (MyGPS.dataready()) {
00282                         MyGPS.read();
00283                         TFT.locate(10, 40) ;
00284                         TFT.foreground(UG_WindowGetBackColor(&window_1));
00285                         TFT.printf("No GPS Data");
00286                         TFT.foreground(White);
00287                         TFT.set_font((unsigned char*) Arial12x12);
00288                         TFT.locate(12, 25) ;
00289                         TFT.printf("Time");
00290                         TFT.locate(150, 25) ;
00291                         TFT.printf("Date");
00292                         TFT.set_font((unsigned char*) ArialR20x20);
00293                         TFT.locate(10, 40) ;
00294                         TFT.printf("%d:%d:%d", MyGPS.buffer.hours, MyGPS.buffer.minutes, MyGPS.buffer.seconds);
00295                         TFT.set_font((unsigned char*) ArialR20x20);
00296                         TFT.locate(150, 40) ;
00297                         TFT.printf("%d-%d-%d", MyGPS.buffer.month, MyGPS.buffer.day, MyGPS.buffer.year);
00298                         TFT.set_font((unsigned char*) SCProSB31x55);
00299                         TFT.locate(125, 180) ;
00300                         TFT.printf("%.1f", MyGPS.buffer.speed);
00301                         TFT.locate(10, 180);
00302                         TFT.printf("%d", 6); //Cadence
00303                         TFT.set_font((unsigned char*) Arial12x12);
00304                         TFT.locate(45, 212) ;
00305                         TFT.printf("rpm");
00306                         TFT.locate(10, 170) ;
00307                         TFT.printf("Cadence");
00308                         TFT.locate(207, 212) ;
00309                         TFT.printf("mph");
00310                         TFT.locate(125, 170) ;
00311                         TFT.printf("Speed");
00312                         TFT.set_font((unsigned char*) ArialR20x20);
00313                         //TFT.locate(10, 50) ;
00314                         //double waypoint = nav.CalculateDistance(MyGPS.buffer.latitude,MyGPS.buffer.longitude,plat,plon)/double(1609.344);
00315                         //TFT.printf("%.1fMI From Perry", waypoint);
00316                     } else {
00317                         TFT.locate(10, 40) ;
00318                         TFT.printf("No GPS Data     ");
00319                         //pc.printf("NMEA has no valid data");
00320                     }
00321                     break;
00322                 }
00323                 //This is screen two of bike computer. It is executed every 2 seconds. Ie...refresh_Time
00324                 case PAGE2: {
00325                     if (!pageinit) {
00326                         UG_WindowHide(&window_1);
00327                         UG_WindowHide(&window_3);
00328                         UG_WindowShow(&window_2);
00329                         UG_Update();
00330                         TFT.drawXBitmap(20,35,compass,compass_width,compass_height,C_WHITE);
00331                     }
00332                     pageinit = 1;
00333                     // Need to fix this. Documentation states that this is bitwise status. 
00334                     if (imu.read_calib_status() > 0x0) {
00335                         imu.get_Euler_Angles(&euler_angles);
00336                         float angle = euler_angles.h; // Convert radians to degrees for more a more usual result
00337 
00338                         TFT.set_font((unsigned char*) ArialR20x20);
00339                         TFT.foreground(White);
00340                         TFT.background(UG_WindowGetBackColor(&window_1));
00341                         TFT.locate(10, 224) ;
00342                         TFT.printf("%.1f*", euler_angles.h);
00343 
00344                         // For the screen -X = up and +X = down and -Y = left and +Y = right, so does not follow coordinate conventions
00345                         float dx = (radius * cos((angle-90)*PI/180)) + centreX;  // calculate X position for the screen coordinates - can be confusing!
00346                         float dy = (radius * sin((angle-90)*PI/180)) + centreY;  // calculate Y position for the screen coordinates - can be confusing!
00347                         arrow(last_dx,last_dy, centreX, centreY, 2,2,UG_WindowGetBackColor(&window_2));      // Erase last arrow
00348                         arrow(dx,dy, centreX, centreY, 2, 2,C_WHITE);               // Draw arrow in new position
00349                         last_dx = dx;
00350                         last_dy = dy;
00351                     }
00352 
00353 
00354                     break;
00355                 }
00356                  //This is screen three of bike computer. It is executed every 2 seconds. Ie...refresh_Time
00357                 case PAGE3: {
00358                     if (!pageinit) {
00359                         UG_WindowHide(&window_1);
00360                         UG_WindowHide(&window_2);
00361                         UG_WindowShow(&window_3);
00362                         UG_Update();
00363                     }
00364                     pageinit = 1;
00365                     break;
00366                 }
00367             }
00368         }
00369     
00370         /*  Add Nav back onto screen 3
00371             TFT.locate(140, 260) ;
00372         TFT.printf("%.1fft", MyGPS.buffer.altitude/0.3048);
00373             TFT.locate(4, 280) ;
00374             int degree;
00375             int minutes;
00376             int seconds;
00377             degree = (int)abs(MyGPS.buffer.longitude);
00378         minutes = (int) ( (abs(MyGPS.buffer.longitude) - (double)degree) * 60.0);
00379         seconds = (int) ( (abs(MyGPS.buffer.longitude) - (double)degree - (double)minutes / 60.0) * 60.0 * 60.0 );
00380         TFT.printf("%d %d' %d\" %c lon", degree, minutes,seconds, MyGPS.buffer.lonc);
00381             TFT.locate(4, 300) ;
00382             TFT.locate(4, 300) ;
00383         degree = (int)abs(MyGPS.buffer.latitude);
00384         minutes = (int) ( (abs(MyGPS.buffer.latitude) - (double)degree) * 60.0);
00385         seconds = (int) ( (abs(MyGPS.buffer.latitude) - (double)degree - (double)minutes / 60.0) * 60.0 * 60.0 );
00386         TFT.printf("%d %d' %d\" %c lat", degree, minutes,seconds, MyGPS.buffer.latc);
00387 
00388 
00389 
00390             //pc.printf("Dist to Perry %.4f ", nav.CalculateDistance(MyGPS.buffer.latitude,MyGPS.buffer.longitude,plat,plon));
00391 
00392 
00393         }
00394 
00395 
00396         if (imu.chip_ready() == 0){
00397         pc.printf("Bosch BNO055 is NOT avirable!!\r\n");
00398         } else {
00399 
00400         if (imu.read_calib_status() > 0x0){
00401             TFT.foreground(White);
00402             TFT.locate(4, 260) ;
00403             TFT.printf("No Data");
00404             TFT.foreground(Blue);
00405             imu.get_Euler_Angles(&euler_angles);
00406             TFT.locate(4, 260) ;
00407             TFT.printf("%.1f @ %.1f",euler_angles.h, euler_angles.p);
00408             //pc.printf("H %d",(int)euler_angles.h);
00409             //pc.printf("R %.1f",euler_angles.r);
00410             //pc.printf("P %.1f",euler_angles.p);
00411 
00412         } else {
00413                 TFT.locate(4, 260) ;
00414                 TFT.printf("No Data");
00415         }
00416         }
00417 
00418 
00419 
00420 
00421         }
00422         */
00423     }
00424 }
00425 
00426 void arrow(int x2, int y2, int x1, int y1, int alength, int awidth, int colour)
00427 {
00428     float distance;
00429     int dx, dy, x2o, y2o, x3, y3, x4, y4, k;
00430     distance = sqrt(pow((double)(x1 - x2),2) + pow((double)(y1 - y2), 2));
00431     dx = x2 + (x1 - x2) * alength / distance;
00432     dy = y2 + (y1 - y2) * alength / distance;
00433     k = awidth / alength;
00434     x2o = x2 - dx;
00435     y2o = dy - y2;
00436     x3 = y2o * k + dx;
00437     y3 = x2o * k + dy;
00438     x4 = dx - y2o * k;
00439     y4 = dy - x2o * k;
00440     TFT.fillcircle(x3,y3,2,colour);
00441     TFT.set_font((unsigned char*) ArialR20x20);
00442 }
00443 
00444 void ili9341_pset(UG_S16 ul_x,UG_S16 ul_y, UG_COLOR ul_color)
00445 {
00446     TFT.pixel(ul_x, ul_y, ul_color);
00447 }
00448 
00449 void window_1_callback( UG_MESSAGE* msg )
00450 {
00451     if ( msg->type == MSG_TYPE_OBJECT ) {
00452         if ( msg->id == OBJ_TYPE_BUTTON ) {
00453             switch ( msg->sub_id ) {
00454                 case BTN_ID_0: {
00455                     pageid--;
00456                     if (pageid < 1) {
00457                         pageid = 3;
00458                     }
00459                     pageinit = 0;
00460                     break;
00461                 }
00462                 case BTN_ID_1: {
00463                     pageid++;
00464                     if (pageid > 3) {
00465                         pageid = 1;
00466                     }
00467                     pageinit = 0;
00468                     break;
00469                 }
00470             }
00471         }
00472     }
00473 }
00474 
00475 void window_2_callback( UG_MESSAGE* msg )
00476 {
00477     if ( msg->type == MSG_TYPE_OBJECT ) {
00478         if ( msg->id == OBJ_TYPE_BUTTON ) {
00479             switch ( msg->sub_id ) {
00480                 case BTN_ID_2: {
00481                     pageid--;
00482                     if (pageid < 1) {
00483                         pageid = 3;
00484                     }
00485                     pageinit = 0;
00486                     break;
00487                 }
00488                 case BTN_ID_3: {
00489                     pageid++;
00490                     if (pageid > 3) {
00491                         pageid = 1;
00492                     }
00493                     pageinit = 0;
00494                     break;
00495                 }
00496             }
00497         }
00498     }
00499 }
00500 
00501 void window_3_callback( UG_MESSAGE* msg )
00502 {
00503     if ( msg->type == MSG_TYPE_OBJECT ) {
00504         if ( msg->id == OBJ_TYPE_BUTTON ) {
00505             switch ( msg->sub_id ) {
00506                 case BTN_ID_4: {
00507                     pageid--;
00508                     if (pageid < 1) {
00509                         pageid = 3;
00510                     }
00511                     pageinit = 0;
00512                     break;
00513                 }
00514                 case BTN_ID_5: {
00515                     pageid++;
00516                     if (pageid > 3) {
00517                         pageid = 1;
00518                     }
00519                     pageinit = 0;
00520                     break;
00521                 }
00522             }
00523         }
00524     }
00525 }
00526 
00527 void cb1(void)
00528 {
00529     point p;
00530     TSC.getTouch(p);
00531     // Only update uGui when screen has been released
00532     if (p.z >= __PRESURE) {
00533         ptouch.x = p.x;
00534         ptouch.y = p.y;
00535         ptouch.z = true;
00536     }    
00537     if (p.z < __NOPRESURE and ptouch.z) { 
00538         UG_TouchUpdate ( ptouch.x, ptouch.y, TOUCH_STATE_PRESSED ) ;
00539         ptouch.z = false;
00540     } else {
00541         UG_TouchUpdate (-1, -1, TOUCH_STATE_RELEASED ) ;
00542     }
00543     UG_Update();
00544 }