apps/graphics/ft80x: Add more touchscreen interfaces. apps/examples/ft80x: Add an interactive example using buttons, keys, and touchscreen input.

This commit is contained in:
Gregory Nutt 2018-02-25 11:20:39 -06:00
parent 9b1b912861
commit e15526f683
8 changed files with 788 additions and 4 deletions

View file

@ -169,6 +169,7 @@ int ft80x_coproc_spinner(int fd, FAR struct ft80x_dlbuffer_s *buffer);
#endif
int ft80x_coproc_screensaver(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_coproc_logo(int fd, FAR struct ft80x_dlbuffer_s *buffer);
int ft80x_coproc_interactive(int fd, FAR struct ft80x_dlbuffer_s *buffer);
#undef EXTERN
#ifdef __cplusplus

View file

@ -49,6 +49,12 @@
#include "graphics/ft80x.h"
#include "ft80x.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define INTERACTIVE_TEXTSIZE (512)
/****************************************************************************
* Public Functions
****************************************************************************/
@ -4099,3 +4105,370 @@ int ft80x_coproc_logo(int fd, FAR struct ft80x_dlbuffer_s *buffer)
return ret;
}
/****************************************************************************
* Name: ft80x_coproc_interactive
*
* Description:
* Demonstrate the keys HMI interactions
*
****************************************************************************/
int ft80x_coproc_interactive(int fd, FAR struct ft80x_dlbuffer_s *buffer)
{
int16_t fontid;
int16_t width ;
int16_t height;
int16_t ydist;
int16_t yoffset;
char text[INTERACTIVE_TEXTSIZE];
char ch = '|';
uint8_t currtag = 0;
uint8_t prevtag = 0;
int32_t textndx = 0;
int ret;
int i;
/* Formatted output chunks */
union
{
struct
{
struct ft80x_cmd32_s clearrgb;
struct ft80x_cmd32_s clear;
struct ft80x_cmd32_s colorrgb;
} a;
struct
{
struct ft80x_cmd32_s tagmask;
struct ft80x_cmd_text_s text;
} b;
struct
{
struct ft80x_cmd32_s tagmask;
struct ft80x_cmd_gradcolor_s gradcolor;
struct ft80x_cmd_keys_s keys;
} c;
struct
{
struct ft80x_cmd_gradcolor_s gradcolor;
struct ft80x_cmd_keys_s keys;
} d;
struct
{
struct ft80x_cmd32_s tag;
struct ft80x_cmd_button_s button;
} e;
struct
{
struct ft80x_cmd32_s colora;
struct ft80x_cmd_keys_s keys;
} f;
struct ft80x_cmd_keys_s keys;
} cmds;
#ifdef CONFIG_LCD_FT80X_QVGA
fontid = 27;
width = 22;
height = 22;
ydist = 3;
#else
fontid = 29;
width = 30;
height = 30;
ydist = 5;
#endif
for (i = 0; i < 600; i++)
{
/* Check the user input and then add the characters into array.
* Hmmm... a better example might use the FT80X_IOC_EVENTNOTIFY ioctl
* command to wait for a touch event.
*/
currtag = ft80x_touch_tag(fd);
ch = currtag;
if (currtag == 0)
{
/* No touch */
ch = '|';
/* Check if we lost the touch */
if (prevtag != 0)
{
textndx++;
/* Clear all the characters after 100 are pressed */
if (textndx > 24)
{
textndx = 0;
}
}
}
/* Create the hardware display list */
ret = ft80x_dl_start(fd, buffer, true);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_start failed: %d\n", ret);
return ret;
}
cmds.a.clearrgb.cmd = FT80X_CLEAR_COLOR_RGB(64, 64, 64);
cmds.a.clear.cmd = FT80X_CLEAR(1 ,1, 1);
cmds.a.colorrgb.cmd = FT80X_COLOR_RGB(0xff, 0xff, 0xff);
/* Copy the commands into the display list */
ret = ft80x_dl_data(fd, buffer, &cmds.a, sizeof(cmds.a));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
/* Draw text entered by user */
/* Make sure the array is a NUL terminated string */
text[textndx] = ch;
text[textndx + 1] = '\0';
cmds.b.tagmask.cmd = FT80X_TAG_MASK(0);
cmds.b.text.cmd = FT80X_CMD_TEXT; /* Text */
cmds.b.text.x = FT80X_DISPLAY_WIDTH / 2;
cmds.b.text.y = 40;
cmds.b.text.font = fontid;
cmds.b.text.options = FT80X_OPT_CENTER;
ret = ft80x_dl_data(fd, buffer, &cmds.b, sizeof(cmds.b));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, text);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
cmds.c.tagmask.cmd = FT80X_TAG_MASK(1);
/* Construct a simple keyboard - note that the tags associated with
* the keys are the character values given in the arguments.
*/
yoffset = 80 + 10;
cmds.c.gradcolor.cmd = FT80X_CMD_GRADCOLOR; /* Gradient color */
cmds.c.gradcolor.c = 0x00ffff;
cmds.c.keys.cmd = FT80X_CMD_KEYS; /* Keys */
cmds.c.keys.x = ydist;
cmds.c.keys.y = yoffset;
cmds.c.keys.w = 10 * width;
cmds.c.keys.h = height;
cmds.c.keys.font = fontid;
cmds.c.keys.options = (FT80X_OPT_CENTER | currtag);
ret = ft80x_dl_data(fd, buffer, &cmds.c, sizeof(cmds.c));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, "qwertyuiop");
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
yoffset += height + ydist;
cmds.d.gradcolor.cmd = FT80X_CMD_GRADCOLOR; /* Gradient color */
cmds.d.gradcolor.c = 0x00ffff;
cmds.d.keys.cmd = FT80X_CMD_KEYS; /* Keys */
cmds.d.keys.x = ydist;
cmds.d.keys.y = yoffset;
cmds.d.keys.w = 10 * width;
cmds.d.keys.h = height;
cmds.d.keys.font = fontid;
cmds.d.keys.options = (FT80X_OPT_CENTER | currtag);
ret = ft80x_dl_data(fd, buffer, &cmds.d, sizeof(cmds.d));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, "asdfghijkl");
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
yoffset += height + ydist;
cmds.d.gradcolor.c = 0xffff00;
cmds.d.keys.y = yoffset;
ret = ft80x_dl_data(fd, buffer, &cmds.d, sizeof(cmds.d));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, "zxcvbnm");
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
yoffset += height + ydist;
cmds.e.tag.cmd = FT80X_TAG(' ');
cmds.e.button.cmd = FT80X_CMD_BUTTON;
cmds.e.button.x = ydist;
cmds.e.button.y = yoffset;
cmds.e.button.w = 10 *width;
cmds.e.button.h = height;
cmds.e.button.font = fontid;
if (currtag == ' ')
{
cmds.e.button.options = (FT80X_OPT_CENTER | FT80X_OPT_FLAT);
}
else
{
cmds.e.button.options = FT80X_OPT_CENTER;
}
ret = ft80x_dl_data(fd, buffer, &cmds.e, sizeof(cmds.e));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, " ");
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
yoffset = 80 + 10;
cmds.keys.cmd = FT80X_CMD_KEYS; /* Keys */
cmds.keys.x = 11 * width;
cmds.keys.y = yoffset;
cmds.keys.w = 3 * width;
cmds.keys.h = height;
cmds.keys.font = fontid;
cmds.keys.options = (0 | currtag);
ret = ft80x_dl_data(fd, buffer, &cmds.keys, sizeof(cmds.keys));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, "789");
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
yoffset += height + ydist;
cmds.keys.y = yoffset;
ret = ft80x_dl_data(fd, buffer, &cmds.keys, sizeof(cmds.keys));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, "456");
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
yoffset += height + ydist;
cmds.keys.y = yoffset;
ret = ft80x_dl_data(fd, buffer, &cmds.keys, sizeof(cmds.keys));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, "123");
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
yoffset += height + ydist;
cmds.f.colora.cmd = FT80X_COLOR_A(255);
cmds.f.keys.cmd = FT80X_CMD_KEYS; /* Keys */
cmds.f.keys.x = 11 * width;
cmds.f.keys.y = yoffset;
cmds.f.keys.w = 3 * width;
cmds.f.keys.h = height;
cmds.f.keys.font = fontid;
cmds.f.keys.options = (9 | currtag);
ret = ft80x_dl_data(fd, buffer, &cmds.f, sizeof(cmds.f));
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_data failed: %d\n", ret);
return ret;
}
ret = ft80x_dl_string(fd, buffer, "0.");
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_string failed: %d\n", ret);
return ret;
}
/* Terminate the display list */
ret = ft80x_dl_end(fd, buffer);
if (ret < 0)
{
ft80x_err("ERROR: ft80x_dl_end failed: %d\n", ret);
return ret;
}
usleep(10 * 1000);
prevtag = currtag;
}
return OK;
}

View file

@ -126,6 +126,7 @@ static const struct ft80x_exampleinfo_s g_primitives[] =
* (To be provided) CMD_SNAPSHOT Take a snapshot of the current
screen
* ft80x_coproc_logo CMD_LOGO Play device log animation
* ft80x_coproc_interactive CMD_KEYS Interactive keys
*/
static const struct ft80x_exampleinfo_s g_coproc[] =
@ -145,7 +146,8 @@ static const struct ft80x_exampleinfo_s g_coproc[] =
#ifndef CONFIG_EXAMPLES_FT80X_EXCLUDE_BITMAPS
{ "Screen Saver", ft80x_coproc_screensaver },
#endif
{ "Logo", ft80x_coproc_logo }
{ "Logo", ft80x_coproc_logo },
{ "Interactive", ft80x_coproc_interactive },
};
#define NCOPROC (sizeof(g_primitives) / sizeof(ft80x_example_t))