| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

FrontPage

This version was saved 15 years, 7 months ago View current version     Page history
Saved by Matt
on September 9, 2008 at 10:51:29 pm
 

TouchShield data types and function wiki

This is a little wiki to describe all the major data types and functions that are available on the TouchShield (www.liquidware.com).

 

 

Data types

Point

This is the data type the TouchShield uses to provide x and y coordinates of a touchscreen press (like with a finger or stylus).

 

typedef struct Point

{

    unsigned char x; /*!< X coordinate, 8-bit */

    unsigned char y; /*!< X coordinate, 8-bit */

} POINT;

 

An example of using this in the Arduino code is:

 

POINT my_point; //defined anywhere in global memory space, or in loop, for instance

 

while (1) {

    if (touch_get_cursor(&my_point)) {

//touch_get_cursor stores the value of the touchscreen touch, and then you can read my_point.x and my_point.y below

     my_point.x; //x coordinates

     my_point.y; //y coordinates

     }

 

COLOR

This data type is how you define a color, which can then be used by a drawing function to make colored lines. It takes a standard RGB value, which can be hex or decimal, just as long as it's typed correctly, like the example below.

 

typedef struct Color

    {

    unsigned char red;

    unsigned char green;

    unsigned char blue;

    } COLOR;

 

An example of using this in the Arduino code is:

 

COLOR blue =  {40, 153, 224}; //each one is passed as Red, then Green, then Blue (hence RGB!)

COLOR red = {255, 0, 0};

COLOR black = {0, 0, 0};

COLOR white = {255, 255, 255};

COLOR gray = {200, 200, 200};

COLOR orange = {255, 153, 0};

COLOR green = {102, 153, 0};

COLOR dimred = {201, 84, 84};

 

lcd_line(8, 10, 50, 10, blue); //then you can use the colors in drawing functions

lcd_pixel(40, 40, red); //or pixel functions

 

Lcd_rect

A lot of graphics functions, and GUI programs use rectangles, so I thought it would be convenient to create a simple "rect" data type and use it throughout the functions (hopefully to simplify code a little bit).

 

typedef struct Lcd_rect   

{

    unsigned char left;     /*!< The left side of the rectangle */

    unsigned char top;         /*!< The top position of the rectangle */

    unsigned char right;     /*!< The right side of the rectangle */

    unsigned char bottom;     /*!< The bottom position of the rectangle */

}LCD_RECT;

 

You could use this data type with functions like:

 

char pointInRect(POINT p, LCD_RECT r);

 

Bmp

Probably you won't need to use this data type directly, but if you're really adventurous, it's here. This is the way pictures are stored on the TouchShield, as bitmaps.

 

typedef struct Bmp

    {

    unsigned char     width;

    unsigned char     height;

    unsigned int     length;

    COLOR            pixels[];

    } BMP;

 

I'll need to expand the how-to-use this section, but for the most part, it's all accessible through the functions below, and it's pretty simple to use pictures if you follow the instructions over here.

 

Most of the time, the Bmp data structure is handled behind the scenes, and you just work with bitmaps by calling a function like:

 

bmp_draw(“burn005”,0,0);

 


 

Commonly used functions

char touch_get_cursor(POINT* p)

This function checks to see if a press has happened on the touchscreen, and if so, it stores the value of the x and y coordinates to a POINT variable. You have to pass the address of the POINT variable, by calling the function like this:

touch_get_cursor(&my_point)

 

 

An example of using this in the Arduino code is:

 

POINT my_point; //defined anywhere in global memory space, or in loop, for instance

 

while (1) {

    if (touch_get_cursor(&my_point)) {

//touch_get_cursor stores the value of the touchscreen touch, and then you can read my_point.x and my_point.y below

     my_point.x; //x coordinates

     my_point.y; //y coordinates

     }

}

 

void lcd_clear(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2, COLOR * color)

This function takes the x and y coordinates of the upper left hand corner of a rectangle (x1, y1), and the lower right hand corner of a rectangle (x2, y2), and fills it with colored pixels.

 

An example of using this function in an Arduino progam is:

 

COLOR white = {255, 255, 255}; //define the color to fill the rectangular space with

lcd_clear(10,10,20,20,white); //fill the space

 

 

 

void lcd_clearScreen(COLOR c)

This function just clears the screen and fills it all up with a single color.

 

It's really simple to use, for instance:

 

COLOR white = {255, 255, 255}; //define the color to fill the screen with

lcd_clearScreen(white); //fill the screen with that color!

 

 

 

void lcd_setBrightness(unsigned char brightnessLevel)

This is a simple function that takes a number between 1 and 10, and sets the brightness of the screen accordingly. This was one of the first things I ever did when I got a computer,... turn the brightness of the screen up and down with a software control panel, rather than those retro controls on the front of the screen.

 

Here's an example of how you'd use it in the Arduino code:

 

int brightness = 5;

 

void BrightUp ( void) {

  if (brightness < 10) {

    brightness++;

  }

  lcd_setBrightness(brightness);

}

void BrightDown ( void) {

  if (brightness > 1) {

    brightness--;

  }

  lcd_setBrightness(brightness);

}

 

 

void lcd_setContrast(unsigned char red, unsigned char green, unsigned char blue)

 

 

 

 

void lcd_pixel(unsigned char x, unsigned char y, COLOR pixel_color)

 

 

void lcd_circle(unsigned char x, unsigned char y, unsigned char radius, COLOR outline_color, COLOR fill_color)

 

 

void lcd_rectangle(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, COLOR outline_color, COLOR fill_color)

 

 

void lcd_line(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, COLOR line_color)

 

 

void lcd_putc(unsigned char ch, unsigned char x_pos,unsigned char y_pos,COLOR fc, COLOR bc)

 

 

void lcd_puts(char * string,unsigned char x_pos, unsigned char y_pos, COLOR fc, COLOR bc)

 

 

void lcd_dimWindow(unsigned char left, unsigned char top, unsigned char right, unsigned char bottom)

 

 

void lcd_rect(LCD_RECT r, COLOR outline_color, COLOR fill_color)

 

 

char pointInRect(POINT p, LCD_RECT r)

 

 


Miscellaneous cool functions

Here's some source code for functions that fade the TouchScreen off, kind of like an iPod or some of the more advanced cell phones. This makes a sort of neat effect where the screen fades down to black, and then you can draw some stuff, and then fade the screen back up.

 

int fader=10; //making this number higher makes the fade take longer, whereas small numbers make it speed up

int brightness=5; //when fading back up, this tells the fadeIn function how bright to go before stopping

 

void fadeOut (void) {

  for (int i = brightness; i>0; i--) {

    lcd_setBrightness(i);

    delay(fader);

  }

 

  CLRBIT(PORTE, PE3);

}

void fadeIn(void) {

  SETBIT(PORTE, PE3);

 

  for (int i = 0; i<(brightness+1); i++) {

    lcd_setBrightness(i);

    delay(fader);

  }

}

 


Really low end functions

 

void lcd_init()

 

 

void lcd_setRow(unsigned char start, unsigned char end)

 

 

void lcd_setColumn(unsigned char start, unsigned char end)

 

 

void lcd_write_C(unsigned char command)

 

 

void lcd_write_D(unsigned char data)

 

 

void lcd_pix()

 

 

unsigned char lcd_read_status(void)

 

 

 

   

 

 

 

 

 

 

 

Comments (0)

You don't have permission to comment on this page.