Merge remote-tracking branch 'origin/emulator' into dev_aaron
This commit is contained in:
236
common/app/app.c
236
common/app/app.c
@@ -2,253 +2,23 @@
|
|||||||
#include "tft.h"
|
#include "tft.h"
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
#include "pixy.h"
|
#include "screen_main.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
bool pixy_connected = false;
|
|
||||||
|
|
||||||
TOUCH_AREA_STRUCT a1;
|
|
||||||
|
|
||||||
|
|
||||||
void touchCB(void* touchArea, TOUCH_ACTION triggeredAction) {
|
|
||||||
|
|
||||||
switch(triggeredAction) {
|
|
||||||
case PEN_DOWN:
|
|
||||||
printf("action PEN_DOWN\n");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PEN_UP:
|
|
||||||
printf("action PEN_UP\n");
|
|
||||||
break;
|
|
||||||
case PEN_MOVE:
|
|
||||||
printf("action PEN_MOVE\n");
|
|
||||||
break;
|
|
||||||
case PEN_ENTER:
|
|
||||||
printf("action PEN_ENTER\n");
|
|
||||||
break;
|
|
||||||
case PEN_LEAVE:
|
|
||||||
printf("action PEN_LEAVE\n");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
printf("action %s\n",triggeredAction);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void app_init() {
|
void app_init() {
|
||||||
system_init();
|
system_init();
|
||||||
tft_init();
|
tft_init();
|
||||||
touch_init();
|
touch_init();
|
||||||
|
|
||||||
pixy_connected = (pixy_init()==0); //try to connect to pixy
|
gui_screen_navigate(get_screen_main());
|
||||||
|
|
||||||
//only testwise
|
|
||||||
tft_clear(WHITE);
|
|
||||||
tft_draw_pixel(10,210,BLUE);
|
|
||||||
tft_draw_pixel(12,210,BLUE);
|
|
||||||
tft_draw_rectangle(40,210,60,235,BLUE);
|
|
||||||
tft_fill_rectangle(100,215,200,225,GREEN);
|
|
||||||
tft_draw_line(10,215,310,225,RGB(0xFF,0,0xFF));
|
|
||||||
tft_draw_circle(10,10,100, RED);
|
|
||||||
|
|
||||||
a1.hookedActions = PEN_DOWN | PEN_UP | PEN_MOVE | PEN_ENTER | PEN_LEAVE;
|
|
||||||
a1.x1 = 30;
|
|
||||||
a1.y1 = 30;
|
|
||||||
a1.x2 = 100;
|
|
||||||
a1.y2 = 60;
|
|
||||||
a1.callback = touchCB;
|
|
||||||
touch_register_area(&a1);
|
|
||||||
|
|
||||||
tft_draw_rectangle(30,30,100,60,BLUE);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int pixy_led_test();
|
|
||||||
int pixy_frame_test();
|
|
||||||
|
|
||||||
//app event loop
|
//app event loop
|
||||||
void app_process() {
|
void app_process() {
|
||||||
|
|
||||||
system_process(); //Let the system handle it's pending events
|
system_process(); //Let the system handle it's pending events
|
||||||
|
gui_screen_update(); //update the currently active screen
|
||||||
|
|
||||||
//Note: The only way to detect that pixy has been disconnected is if a command fails. There's no pixy_is_connected method yet :'(
|
|
||||||
|
|
||||||
if(!pixy_connected) { //Pixy not connected
|
|
||||||
pixy_close(); //Ensure that all pixy resources are freed (failsafe)
|
|
||||||
if(pixy_init()==0) { //try to connect to pixy
|
|
||||||
pixy_connected=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pixy_connected) {
|
|
||||||
pixy_service(); //Send/receive event data from/to pixy failed
|
|
||||||
|
|
||||||
//Code for tests see below
|
|
||||||
if(pixy_led_test()!=0) {
|
|
||||||
pixy_connected=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*if(pixy_frame_test()!=0) {
|
|
||||||
pixy_connected=false;
|
|
||||||
}*/
|
|
||||||
system_delay(500);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
int colorind;
|
|
||||||
const uint32_t colors [] = {0xFF0000, 0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF,0x000000};
|
|
||||||
const int num_colors = sizeof(colors)/sizeof(uint32_t);
|
|
||||||
|
|
||||||
int pixy_led_test() {
|
|
||||||
if(colorind==0) {
|
|
||||||
pixy_led_set_max_current(5);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t response;
|
|
||||||
int return_value;
|
|
||||||
return_value = pixy_command("led_set", INT32(colors[colorind++]), END_OUT_ARGS, &response, END_IN_ARGS);
|
|
||||||
colorind%=num_colors;
|
|
||||||
|
|
||||||
if(return_value!=0) {
|
|
||||||
colorind=0; //reset color ind, to start at zero when plugging pixy in again
|
|
||||||
}
|
|
||||||
|
|
||||||
return return_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame);
|
|
||||||
|
|
||||||
|
|
||||||
int pixy_frame_test() {
|
|
||||||
|
|
||||||
uint8_t* videodata;
|
|
||||||
int32_t response;
|
|
||||||
int32_t fourccc;
|
|
||||||
int8_t renderflags;
|
|
||||||
uint16_t xwidth;
|
|
||||||
uint16_t ywidth;
|
|
||||||
uint32_t size;
|
|
||||||
|
|
||||||
|
|
||||||
int return_value = pixy_command("cam_getFrame", // String id for remote procedure
|
|
||||||
INT8(0x21), // mode
|
|
||||||
INT16(0), // xoffset
|
|
||||||
INT16(0), // yoffset
|
|
||||||
INT16(320), // width
|
|
||||||
INT16(200), // height
|
|
||||||
END_OUT_ARGS, // separator
|
|
||||||
&response, // pointer to mem address for return value
|
|
||||||
&fourccc,
|
|
||||||
&renderflags,
|
|
||||||
&xwidth,
|
|
||||||
&ywidth,
|
|
||||||
&size,
|
|
||||||
&videodata, // pointer to mem address for returned frame
|
|
||||||
END_IN_ARGS);
|
|
||||||
|
|
||||||
if(return_value==0) {
|
|
||||||
return_value = renderBA81(renderflags,xwidth,ywidth,size,videodata);
|
|
||||||
}
|
|
||||||
|
|
||||||
return return_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t* r, uint8_t* g, uint8_t* b)
|
|
||||||
{
|
|
||||||
if (y&1)
|
|
||||||
{
|
|
||||||
if (x&1)
|
|
||||||
{
|
|
||||||
*r = *pixel;
|
|
||||||
*g = (*(pixel-1)+*(pixel+1)+*(pixel+width)+*(pixel-width))>>2;
|
|
||||||
*b = (*(pixel-width-1)+*(pixel-width+1)+*(pixel+width-1)+*(pixel+width+1))>>2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*r = (*(pixel-1)+*(pixel+1))>>1;
|
|
||||||
*g = *pixel;
|
|
||||||
*b = (*(pixel-width)+*(pixel+width))>>1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (x&1)
|
|
||||||
{
|
|
||||||
*r = (*(pixel-width)+*(pixel+width))>>1;
|
|
||||||
*g = *pixel;
|
|
||||||
*b = (*(pixel-1)+*(pixel+1))>>1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*r = (*(pixel-width-1)+*(pixel-width+1)+*(pixel+width-1)+*(pixel+width+1))>>2;
|
|
||||||
*g = (*(pixel-1)+*(pixel+1)+*(pixel+width)+*(pixel-width))>>2;
|
|
||||||
*b = *pixel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame)
|
|
||||||
{
|
|
||||||
uint16_t x, y;
|
|
||||||
uint8_t r, g, b;
|
|
||||||
|
|
||||||
|
|
||||||
// skip first line
|
|
||||||
frame += width;
|
|
||||||
|
|
||||||
// don't render top and bottom rows, and left and rightmost columns because of color
|
|
||||||
// interpolation
|
|
||||||
//uint32_t decodedimage[(width-2)*(height-2)];
|
|
||||||
uint16_t* decodedimage = malloc(sizeof(uint16_t)*(width-2)*(height-2));
|
|
||||||
|
|
||||||
if(decodedimage==NULL) { //not enough free space to decode image in memory
|
|
||||||
//decode & render image pixel by pixel
|
|
||||||
uint16_t* line = decodedimage;
|
|
||||||
for (y=1; y<height-1; y++)
|
|
||||||
{
|
|
||||||
frame++;
|
|
||||||
for (x=1; x<width-1; x++, frame++)
|
|
||||||
{
|
|
||||||
interpolateBayer(width, x, y, frame, &r, &g, &b);
|
|
||||||
tft_draw_pixel(x-1,y-1,RGB(r,g,b));
|
|
||||||
}
|
|
||||||
frame++;
|
|
||||||
}
|
|
||||||
} else { //enough space
|
|
||||||
uint16_t* line = decodedimage;
|
|
||||||
for (y=1; y<height-1; y++)
|
|
||||||
{
|
|
||||||
//line = (unsigned int *)img.scanLine(y-1);
|
|
||||||
frame++;
|
|
||||||
for (x=1; x<width-1; x++, frame++)
|
|
||||||
{
|
|
||||||
interpolateBayer(width, x, y, frame, &r, &g, &b);
|
|
||||||
//*line++ = (0xff<<24) | (r<<16) | (g<<8) | (b<<0);
|
|
||||||
*line++ = RGB(r,g,b);
|
|
||||||
}
|
|
||||||
frame++;
|
|
||||||
}
|
|
||||||
|
|
||||||
tft_draw_bitmap_unscaled(0,0,width-2,height-2,decodedimage);
|
|
||||||
|
|
||||||
free(decodedimage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
133
common/app/screen_guitest.c
Normal file
133
common/app/screen_guitest.c
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
#include "screen_guitest.h"
|
||||||
|
#include "button.h"
|
||||||
|
#include "tft.h"
|
||||||
|
#include "checkbox.h"
|
||||||
|
#include "numupdown.h"
|
||||||
|
|
||||||
|
static BUTTON_STRUCT b_back;
|
||||||
|
static TOUCH_AREA_STRUCT a_area;
|
||||||
|
static CHECKBOX_STRUCT c_cbox;
|
||||||
|
static NUMUPDOWN_STRUCT n_updown;
|
||||||
|
|
||||||
|
static void checkboxCB(void *checkbox, bool checked) {
|
||||||
|
printf("Checkbox %s\n",(checked?"checked":"unchecked"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void b_back_cb(void* button) {
|
||||||
|
gui_screen_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void n_updown_cb(void* numupdown, int16_t value) {
|
||||||
|
printf("New NumUpDown Value %d\n",value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void touchCB(void* touchArea, TOUCH_ACTION triggeredAction) {
|
||||||
|
|
||||||
|
switch(triggeredAction) {
|
||||||
|
case PEN_DOWN:
|
||||||
|
printf("action PEN_DOWN\n");
|
||||||
|
break;
|
||||||
|
case PEN_UP:
|
||||||
|
printf("action PEN_UP\n");
|
||||||
|
break;
|
||||||
|
case PEN_MOVE:
|
||||||
|
printf("action PEN_MOVE\n");
|
||||||
|
break;
|
||||||
|
case PEN_ENTER:
|
||||||
|
printf("action PEN_ENTER\n");
|
||||||
|
break;
|
||||||
|
case PEN_LEAVE:
|
||||||
|
printf("action PEN_LEAVE\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("action %s\n",triggeredAction);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void enter(void* screen) {
|
||||||
|
tft_clear(HEX(0xA6FD9A));
|
||||||
|
|
||||||
|
//Back button
|
||||||
|
b_back.base.x1=10; //Start X of Button
|
||||||
|
b_back.base.y1=10; //Start Y of Button
|
||||||
|
b_back.base.x2=AUTO; //b_back.base.x1+160; //Auto Calculate X2 with String Width
|
||||||
|
b_back.base.y2=AUTO; //Auto Calculate Y2 with String Height
|
||||||
|
b_back.txtcolor=WHITE; //Set foreground color
|
||||||
|
b_back.bgcolor=HEX(0xAE1010); //Set background color (Don't take 255 or 0 on at least one channel, to make shadows possible)
|
||||||
|
b_back.font=0; //Select Font
|
||||||
|
b_back.text="Back"; //Set Text (For formatted strings take sprintf)
|
||||||
|
b_back.callback=b_back_cb; //Call b_back_cb as Callback
|
||||||
|
gui_button_add(&b_back); //Register Button (and run the callback from now on)
|
||||||
|
|
||||||
|
|
||||||
|
//tft test
|
||||||
|
tft_draw_pixel(10,210,BLUE);
|
||||||
|
tft_draw_pixel(12,210,BLUE);
|
||||||
|
tft_draw_rectangle(40,100,60,235,BLUE);
|
||||||
|
tft_fill_rectangle(100,215,200,225,GREEN);
|
||||||
|
tft_draw_line(10,50,310,225,RGB(0xFF,0,0xFF));
|
||||||
|
tft_draw_circle(10,10,100, RED);
|
||||||
|
tft_print_line(30, 130, RED, BLUE, 0, "Hallo");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Area test
|
||||||
|
a_area.hookedActions = PEN_DOWN | PEN_UP | PEN_MOVE | PEN_ENTER | PEN_LEAVE;
|
||||||
|
a_area.x1 = 130;
|
||||||
|
a_area.y1 = 30;
|
||||||
|
a_area.x2 = 200;
|
||||||
|
a_area.y2 = 60;
|
||||||
|
a_area.callback = touchCB;
|
||||||
|
touch_register_area(&a_area);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Checkbox test
|
||||||
|
c_cbox.base.x1=220;
|
||||||
|
c_cbox.base.y1=45;
|
||||||
|
c_cbox.base.x2=c_cbox.base.x1+16;
|
||||||
|
c_cbox.base.y2=c_cbox.base.y1+16;
|
||||||
|
c_cbox.fgcolor = GREEN;
|
||||||
|
c_cbox.checked = true;
|
||||||
|
c_cbox.callback = checkboxCB;
|
||||||
|
gui_checkbox_add(&c_cbox);
|
||||||
|
|
||||||
|
|
||||||
|
//Num up down test
|
||||||
|
n_updown.x=200;
|
||||||
|
n_updown.y=120;
|
||||||
|
n_updown.fgcolor=RED;
|
||||||
|
n_updown.value = -3;
|
||||||
|
n_updown.max=11;
|
||||||
|
n_updown.min =-5;
|
||||||
|
n_updown.callback=n_updown_cb;
|
||||||
|
gui_numupdown_add(&n_updown);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void leave(void* screen) {
|
||||||
|
gui_button_remove(&b_back);
|
||||||
|
gui_checkbox_remove(&c_cbox);
|
||||||
|
gui_numupdown_remove(&n_updown);
|
||||||
|
touch_unregister_area(&a_area);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update(void* screen) {
|
||||||
|
//gui_button_redraw(&b_back); //only needed if button is overdrawn by others
|
||||||
|
//.... for the other elements as well
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static SCREEN_STRUCT screen = {
|
||||||
|
enter,
|
||||||
|
leave,
|
||||||
|
update
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
SCREEN_STRUCT* get_screen_guitest() {
|
||||||
|
return &screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
3
common/app/screen_guitest.h
Normal file
3
common/app/screen_guitest.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#include "screen.h"
|
||||||
|
|
||||||
|
SCREEN_STRUCT* get_screen_guitest();
|
||||||
72
common/app/screen_main.c
Normal file
72
common/app/screen_main.c
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#include "screen_main.h"
|
||||||
|
#include "screen_guitest.h"
|
||||||
|
#include "screen_pixytest.h"
|
||||||
|
#include "button.h"
|
||||||
|
#include "tft.h"
|
||||||
|
|
||||||
|
BUTTON_STRUCT b_guitest;
|
||||||
|
BUTTON_STRUCT b_pixytest;
|
||||||
|
|
||||||
|
|
||||||
|
static void b_guitest_cb(void* button) {
|
||||||
|
gui_screen_navigate(get_screen_guitest());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void b_pixytest_cb(void* button) {
|
||||||
|
gui_screen_navigate(get_screen_pixytest());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void enter(void* screen) {
|
||||||
|
tft_clear(WHITE);
|
||||||
|
|
||||||
|
//button to reach guitest
|
||||||
|
b_guitest.base.x1=25; //Start X of Button
|
||||||
|
b_guitest.base.y1=45; //Start Y of Button
|
||||||
|
b_guitest.base.x2=AUTO; //b_guitest.base.x1+160; //Auto Calculate X2 with String Width
|
||||||
|
b_guitest.base.y2=AUTO; //Auto Calculate Y2 with String Height
|
||||||
|
b_guitest.txtcolor=WHITE; //Set foreground color
|
||||||
|
b_guitest.bgcolor=HEX(0xDE1010); //Set background color (Don't take 255 or 0 on at least one channel, to make shadows possible)
|
||||||
|
b_guitest.font=0; //Select Font
|
||||||
|
b_guitest.text="Gui/Tft Test"; //Set Text (For formatted strings take sprintf)
|
||||||
|
b_guitest.callback=b_guitest_cb; //Call b_guitest_cb as Callback
|
||||||
|
gui_button_add(&b_guitest); //Register Button (and run the callback from now on)
|
||||||
|
|
||||||
|
//button to reach pixy test
|
||||||
|
b_pixytest.base.x1=200; //Start X of Button
|
||||||
|
b_pixytest.base.y1=45; //Start Y of Button
|
||||||
|
b_pixytest.base.x2=AUTO; //b_pixytest.base.x1+160; //Auto Calculate X2 with String Width
|
||||||
|
b_pixytest.base.y2=AUTO; //Auto Calculate Y2 with String Height
|
||||||
|
b_pixytest.txtcolor=BLUE; //Set foreground color
|
||||||
|
b_pixytest.bgcolor=HEX(0x10DE10); //Set background color (Don't take 255 or 0 on at least one channel, to make shadows possible)
|
||||||
|
b_pixytest.font=0; //Select Font
|
||||||
|
b_pixytest.text="Pixy Test"; //Set Text (For formatted strings take sprintf)
|
||||||
|
b_pixytest.callback=b_pixytest_cb; //Call b_pixytest_cb as Callback
|
||||||
|
gui_button_add(&b_pixytest); //Register Button (and run the callback from now on)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void leave(void* screen) {
|
||||||
|
gui_button_remove(&b_guitest);
|
||||||
|
gui_button_remove(&b_pixytest);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void update(void* screen) {
|
||||||
|
//gui_button_redraw(&b_guitest); //only needed if button is overdrawn by others
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static SCREEN_STRUCT screen = {
|
||||||
|
enter,
|
||||||
|
leave,
|
||||||
|
update
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
SCREEN_STRUCT* get_screen_main() {
|
||||||
|
return &screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
3
common/app/screen_main.h
Normal file
3
common/app/screen_main.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#include "screen.h"
|
||||||
|
|
||||||
|
SCREEN_STRUCT* get_screen_main();
|
||||||
297
common/app/screen_pixytest.c
Normal file
297
common/app/screen_pixytest.c
Normal file
@@ -0,0 +1,297 @@
|
|||||||
|
#include "screen_pixytest.h"
|
||||||
|
#include "button.h"
|
||||||
|
#include "tft.h"
|
||||||
|
#include "touch.h"
|
||||||
|
#include "pixy.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
|
static volatile bool pixy_connected = false;
|
||||||
|
|
||||||
|
|
||||||
|
static BUTTON_STRUCT b_back;
|
||||||
|
static TOUCH_AREA_STRUCT a_area;
|
||||||
|
|
||||||
|
static void b_back_cb(void* button) {
|
||||||
|
gui_screen_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
POINT_STRUCT pixy_pos;
|
||||||
|
POINT_STRUCT old_pos;
|
||||||
|
static void touchCB(void* touchArea, TOUCH_ACTION triggeredAction) {
|
||||||
|
POINT_STRUCT p = touch_get_last_point();
|
||||||
|
switch(triggeredAction) {
|
||||||
|
case PEN_ENTER:
|
||||||
|
case PEN_DOWN:
|
||||||
|
old_pos = p;
|
||||||
|
break;
|
||||||
|
case PEN_MOVE:
|
||||||
|
{
|
||||||
|
int16_t deltaX = p.x - old_pos.x;
|
||||||
|
int16_t deltaY = p.y - old_pos.y;
|
||||||
|
old_pos=p;
|
||||||
|
printf("%d %d\n",deltaX,deltaY);
|
||||||
|
if(pixy_connected) {
|
||||||
|
int16_t new_x = pixy_pos.x+deltaX*2;
|
||||||
|
int16_t new_y = pixy_pos.y-deltaY*2;
|
||||||
|
if(new_x<0) new_x=0;
|
||||||
|
if(new_x>1000) new_x=1000;
|
||||||
|
if(new_y<0) new_y=0;
|
||||||
|
if(new_y>1000) new_y=1000;
|
||||||
|
pixy_pos.x = new_x;
|
||||||
|
pixy_pos.y= new_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PEN_UP:
|
||||||
|
case PEN_LEAVE:
|
||||||
|
printf("Leave/up\n");
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void enter(void* screen) {
|
||||||
|
tft_clear(WHITE);
|
||||||
|
|
||||||
|
//Back button
|
||||||
|
b_back.base.x1=10; //Start X of Button
|
||||||
|
b_back.base.y1=210; //Start Y of Button
|
||||||
|
b_back.base.x2=AUTO; //b_back.base.x1+160; //Auto Calculate X2 with String Width
|
||||||
|
b_back.base.y2=AUTO; //Auto Calculate Y2 with String Height
|
||||||
|
b_back.txtcolor=WHITE; //Set foreground color
|
||||||
|
b_back.bgcolor=HEX(0xAE1010); //Set background color (Don't take 255 or 0 on at least one channel, to make shadows possible)
|
||||||
|
b_back.font=0; //Select Font
|
||||||
|
b_back.text="Back"; //Set Text (For formatted strings take sprintf)
|
||||||
|
b_back.callback=b_back_cb; //Call b_back_cb as Callback
|
||||||
|
gui_button_add(&b_back); //Register Button (and run the callback from now on)
|
||||||
|
|
||||||
|
//Area test
|
||||||
|
a_area.hookedActions = PEN_DOWN | PEN_MOVE | PEN_ENTER | PEN_UP | PEN_LEAVE;
|
||||||
|
a_area.x1 = 0;
|
||||||
|
a_area.y1 = 0;
|
||||||
|
a_area.x2 = 317;
|
||||||
|
a_area.y2 = 197;
|
||||||
|
a_area.callback = touchCB;
|
||||||
|
touch_register_area(&a_area);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Pixy stuff
|
||||||
|
pixy_connected = (pixy_init()==0); //try to connect to pixy
|
||||||
|
if(pixy_connected) {
|
||||||
|
pixy_pos.x=pixy_pos.y=500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void leave(void* screen) {
|
||||||
|
gui_button_remove(&b_back);
|
||||||
|
touch_unregister_area(&a_area);
|
||||||
|
}
|
||||||
|
|
||||||
|
int pixy_led_test();
|
||||||
|
int pixy_frame_test();
|
||||||
|
|
||||||
|
static void update(void* screen) {
|
||||||
|
|
||||||
|
//Note: The only way to detect that pixy has been disconnected is if a command fails. There's no pixy_is_connected method yet :'(
|
||||||
|
|
||||||
|
if(!pixy_connected) { //Pixy not connected
|
||||||
|
pixy_close(); //Ensure that all pixy resources are freed (failsafe)
|
||||||
|
if(pixy_init()==0) { //try to connect to pixy
|
||||||
|
pixy_connected=true;
|
||||||
|
pixy_pos.x=pixy_pos.y=500;
|
||||||
|
printf("pixy reinitialized\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pixy_connected) {
|
||||||
|
pixy_service(); //Send/receive event data from/to pixy failed
|
||||||
|
|
||||||
|
//Code for tests see below
|
||||||
|
if(pixy_led_test()!=0) {
|
||||||
|
pixy_connected=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pixy_frame_test()!=0) {
|
||||||
|
pixy_connected=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pixy_rcs_set_position(0,pixy_pos.x);
|
||||||
|
pixy_rcs_set_position(1,pixy_pos.y);
|
||||||
|
|
||||||
|
//system_delay(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static SCREEN_STRUCT screen = {
|
||||||
|
enter,
|
||||||
|
leave,
|
||||||
|
update
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
SCREEN_STRUCT* get_screen_pixytest() {
|
||||||
|
return &screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int colorind;
|
||||||
|
const uint32_t colors [] = {0xFF0000, 0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF,0x000000};
|
||||||
|
const int num_colors = sizeof(colors)/sizeof(uint32_t);
|
||||||
|
|
||||||
|
int pixy_led_test() {
|
||||||
|
if(colorind==0) {
|
||||||
|
pixy_led_set_max_current(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t response;
|
||||||
|
int return_value;
|
||||||
|
return_value = pixy_command("led_set", INT32(colors[colorind++]), END_OUT_ARGS, &response, END_IN_ARGS);
|
||||||
|
colorind%=num_colors;
|
||||||
|
|
||||||
|
if(return_value!=0) {
|
||||||
|
colorind=0; //reset color ind, to start at zero when plugging pixy in again
|
||||||
|
}
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame);
|
||||||
|
|
||||||
|
|
||||||
|
int pixy_frame_test() {
|
||||||
|
|
||||||
|
uint8_t* videodata;
|
||||||
|
int32_t response;
|
||||||
|
int32_t fourccc;
|
||||||
|
int8_t renderflags;
|
||||||
|
uint16_t xwidth;
|
||||||
|
uint16_t ywidth;
|
||||||
|
uint32_t size;
|
||||||
|
|
||||||
|
|
||||||
|
int return_value = pixy_command("cam_getFrame", // String id for remote procedure
|
||||||
|
INT8(0x21), // mode
|
||||||
|
INT16(0), // xoffset
|
||||||
|
INT16(0), // yoffset
|
||||||
|
INT16(320), // width
|
||||||
|
INT16(200), // height
|
||||||
|
END_OUT_ARGS, // separator
|
||||||
|
&response, // pointer to mem address for return value
|
||||||
|
&fourccc,
|
||||||
|
&renderflags,
|
||||||
|
&xwidth,
|
||||||
|
&ywidth,
|
||||||
|
&size,
|
||||||
|
&videodata, // pointer to mem address for returned frame
|
||||||
|
END_IN_ARGS);
|
||||||
|
|
||||||
|
if(return_value==0) {
|
||||||
|
return_value = renderBA81(renderflags,xwidth,ywidth,size,videodata);
|
||||||
|
}
|
||||||
|
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t* r, uint8_t* g, uint8_t* b)
|
||||||
|
{
|
||||||
|
if (y&1)
|
||||||
|
{
|
||||||
|
if (x&1)
|
||||||
|
{
|
||||||
|
*r = *pixel;
|
||||||
|
*g = (*(pixel-1)+*(pixel+1)+*(pixel+width)+*(pixel-width))>>2;
|
||||||
|
*b = (*(pixel-width-1)+*(pixel-width+1)+*(pixel+width-1)+*(pixel+width+1))>>2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*r = (*(pixel-1)+*(pixel+1))>>1;
|
||||||
|
*g = *pixel;
|
||||||
|
*b = (*(pixel-width)+*(pixel+width))>>1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (x&1)
|
||||||
|
{
|
||||||
|
*r = (*(pixel-width)+*(pixel+width))>>1;
|
||||||
|
*g = *pixel;
|
||||||
|
*b = (*(pixel-1)+*(pixel+1))>>1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*r = (*(pixel-width-1)+*(pixel-width+1)+*(pixel+width-1)+*(pixel+width+1))>>2;
|
||||||
|
*g = (*(pixel-1)+*(pixel+1)+*(pixel+width)+*(pixel-width))>>2;
|
||||||
|
*b = *pixel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame)
|
||||||
|
{
|
||||||
|
uint16_t x, y;
|
||||||
|
uint8_t r, g, b;
|
||||||
|
|
||||||
|
|
||||||
|
// skip first line
|
||||||
|
frame += width;
|
||||||
|
|
||||||
|
// don't render top and bottom rows, and left and rightmost columns because of color
|
||||||
|
// interpolation
|
||||||
|
//uint32_t decodedimage[(width-2)*(height-2)];
|
||||||
|
uint16_t* decodedimage = malloc(sizeof(uint16_t)*(width-2)*(height-2));
|
||||||
|
|
||||||
|
if(decodedimage==NULL) { //not enough free space to decode image in memory
|
||||||
|
//decode & render image pixel by pixel
|
||||||
|
uint16_t* line = decodedimage;
|
||||||
|
for (y=1; y<height-1; y++)
|
||||||
|
{
|
||||||
|
frame++;
|
||||||
|
for (x=1; x<width-1; x++, frame++)
|
||||||
|
{
|
||||||
|
interpolateBayer(width, x, y, frame, &r, &g, &b);
|
||||||
|
tft_draw_pixel(x-1,y-1,RGB(r,g,b));
|
||||||
|
}
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
|
} else { //enough space
|
||||||
|
uint16_t* line = decodedimage;
|
||||||
|
for (y=1; y<height-1; y++)
|
||||||
|
{
|
||||||
|
//line = (unsigned int *)img.scanLine(y-1);
|
||||||
|
frame++;
|
||||||
|
for (x=1; x<width-1; x++, frame++)
|
||||||
|
{
|
||||||
|
interpolateBayer(width, x, y, frame, &r, &g, &b);
|
||||||
|
//*line++ = (0xff<<24) | (r<<16) | (g<<8) | (b<<0);
|
||||||
|
*line++ = RGB(r,g,b);
|
||||||
|
}
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
|
|
||||||
|
tft_draw_bitmap_unscaled(0,0,width-2,height-2,decodedimage);
|
||||||
|
|
||||||
|
free(decodedimage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
3
common/app/screen_pixytest.h
Normal file
3
common/app/screen_pixytest.h
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
#include "screen.h"
|
||||||
|
|
||||||
|
SCREEN_STRUCT* get_screen_pixytest();
|
||||||
189
common/gui/button.c
Normal file
189
common/gui/button.c
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
#include "tft.h"
|
||||||
|
#include "touch.h"
|
||||||
|
#include "button.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define BRIGHTNESS_VAL 3 //How much the Brightness is in/decreased for button shadows (3 -> Add 1/3 off Full Value)
|
||||||
|
|
||||||
|
void buttons_cb(void* touchArea, TOUCH_ACTION triggeredAction)
|
||||||
|
//Method shared between normal Buttons and Bitmap Buttons-> Look at comment in headerfile for explanation.
|
||||||
|
{
|
||||||
|
TOUCH_AREA_STRUCT * area = (TOUCH_AREA_STRUCT*)touchArea;
|
||||||
|
BUTTON_STRUCT* button = (BUTTON_STRUCT*)touchArea;
|
||||||
|
unsigned int c1,c2;
|
||||||
|
unsigned char r,g,b;
|
||||||
|
r=(button->bgcolor&0xF800)>>11;
|
||||||
|
g=(button->bgcolor&0x07E0)>>5;
|
||||||
|
b=(button->bgcolor&0x001F)>>0;
|
||||||
|
if((r + 0x1F/BRIGHTNESS_VAL) >0x1F)
|
||||||
|
c1=0xF800;
|
||||||
|
else
|
||||||
|
c1=(r+0x1F/BRIGHTNESS_VAL)<<11;
|
||||||
|
if((g + 0x3F/BRIGHTNESS_VAL) >0x3F)
|
||||||
|
c1|=0x07E0;
|
||||||
|
else
|
||||||
|
c1|=(g+0x3F/BRIGHTNESS_VAL)<<5;
|
||||||
|
if((b + 0x1F/BRIGHTNESS_VAL) >0x1F)
|
||||||
|
c1|=0x0018;
|
||||||
|
else
|
||||||
|
c1|=(b+0x1F/BRIGHTNESS_VAL)<<0;
|
||||||
|
if(r > (0x1F/BRIGHTNESS_VAL))
|
||||||
|
c2=(r-0x1F/BRIGHTNESS_VAL)<<11;
|
||||||
|
else
|
||||||
|
c2=0x0000;
|
||||||
|
if(g > (0x3F/BRIGHTNESS_VAL))
|
||||||
|
c2|=(g-0x3F/BRIGHTNESS_VAL)<<5;
|
||||||
|
if(b > (0x1F/BRIGHTNESS_VAL))
|
||||||
|
c2|=(b-0x1F/BRIGHTNESS_VAL)<<0;
|
||||||
|
switch(triggeredAction)
|
||||||
|
{
|
||||||
|
case PEN_DOWN:
|
||||||
|
area->hookedActions=PEN_UP|PEN_LEAVE;
|
||||||
|
tft_draw_line(button->base.x1+1,button->base.y1,button->base.x2-1,button->base.y1,c2); //Nord
|
||||||
|
tft_draw_line(button->base.x1,button->base.y1+1,button->base.x1,button->base.y2-1,c2);//West
|
||||||
|
tft_draw_line(button->base.x1+1,button->base.y2,button->base.x2-1,button->base.y2,c1); //S<>d
|
||||||
|
tft_draw_line(button->base.x2,button->base.y1+1,button->base.x2,button->base.y2-1,c1); //Ost
|
||||||
|
break;
|
||||||
|
case PEN_UP:
|
||||||
|
case PEN_LEAVE:
|
||||||
|
area->hookedActions=PEN_DOWN;
|
||||||
|
tft_draw_line(button->base.x1+1,button->base.y1,button->base.x2-1,button->base.y1,c1); //Nord
|
||||||
|
tft_draw_line(button->base.x1,button->base.y1+1,button->base.x1,button->base.y2-1,c1);//West
|
||||||
|
tft_draw_line(button->base.x1+1,button->base.y2,button->base.x2-1,button->base.y2,c2); //S<>d
|
||||||
|
tft_draw_line(button->base.x2,button->base.y1+1,button->base.x2,button->base.y2-1,c2); //Ost
|
||||||
|
if(triggeredAction==PEN_UP && button->callback!=NULL)
|
||||||
|
button->callback(button);
|
||||||
|
break;
|
||||||
|
default:break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool gui_button_add(BUTTON_STRUCT* button)//Registers a button (fill Struct first). Return false if no more Space in the Pointertable (-->Change NUM_AREAS).
|
||||||
|
{
|
||||||
|
if(touch_have_empty(1))
|
||||||
|
{
|
||||||
|
unsigned int strwidth=tft_font_width(button->font)*strlen(button->text);
|
||||||
|
unsigned char strheight=tft_font_height(button->font);
|
||||||
|
button->base.hookedActions=PEN_DOWN;
|
||||||
|
button->base.callback = buttons_cb;
|
||||||
|
if(button->base.x2==AUTO)
|
||||||
|
button->base.x2= button->base.x1 -1 + strwidth+(tft_font_width(button->font)/2);
|
||||||
|
else if((button->base.x2-button->base.x1+1)<(strwidth+2))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(button->base.y2==AUTO)
|
||||||
|
button->base.y2=button->base.y1 -1 +strheight+(strheight/2);
|
||||||
|
else if((button->base.y2-button->base.y1+1)<(strheight+2))
|
||||||
|
return false;
|
||||||
|
gui_button_redraw(button);
|
||||||
|
return touch_register_area(&button->base);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_button_redraw(BUTTON_STRUCT* button)
|
||||||
|
{
|
||||||
|
unsigned int strwidth=tft_font_width(button->font)*strlen(button->text);
|
||||||
|
unsigned char strheight=tft_font_height(button->font);
|
||||||
|
unsigned char r,g,b;
|
||||||
|
unsigned int c;
|
||||||
|
r=(button->bgcolor&0xF800)>>11;
|
||||||
|
g=(button->bgcolor&0x07E0)>>5;
|
||||||
|
b=(button->bgcolor&0x001F)>>0;
|
||||||
|
tft_fill_rectangle(button->base.x1+1,button->base.y1+1,button->base.x2-1,button->base.y2-1,button->bgcolor);
|
||||||
|
if((r + 0x1F/BRIGHTNESS_VAL) >0x1F)
|
||||||
|
c=0xF800;
|
||||||
|
else
|
||||||
|
c=(r+0x1F/BRIGHTNESS_VAL)<<11;
|
||||||
|
if((g + 0x3F/BRIGHTNESS_VAL) >0x3F)
|
||||||
|
c|=0x07E0;
|
||||||
|
else
|
||||||
|
c|=(g+0x3F/BRIGHTNESS_VAL)<<5;
|
||||||
|
if((b + 0x1F/BRIGHTNESS_VAL) >0x1F)
|
||||||
|
c|=0x0018;
|
||||||
|
else
|
||||||
|
c|=(b+0x1F/BRIGHTNESS_VAL)<<0;
|
||||||
|
tft_draw_line(button->base.x1+1,button->base.y1,button->base.x2-1,button->base.y1,c); //Nord
|
||||||
|
tft_draw_line(button->base.x1,button->base.y1+1,button->base.x1,button->base.y2-1,c);//West
|
||||||
|
if(r > (0x1F/BRIGHTNESS_VAL))
|
||||||
|
c=(r-0x1F/BRIGHTNESS_VAL)<<11;
|
||||||
|
else
|
||||||
|
c=0x0000;
|
||||||
|
if(g > (0x3F/BRIGHTNESS_VAL))
|
||||||
|
c|=(g-0x3F/BRIGHTNESS_VAL)<<5;
|
||||||
|
if(b > (0x1F/BRIGHTNESS_VAL))
|
||||||
|
c|=(b-0x1F/BRIGHTNESS_VAL)<<0;
|
||||||
|
tft_draw_line(button->base.x1+1,button->base.y2,button->base.x2-1,button->base.y2,c); //S<>d
|
||||||
|
tft_draw_line(button->base.x2,button->base.y1+1,button->base.x2,button->base.y2-1,c); //Ost
|
||||||
|
tft_print_line(button->base.x1+(button->base.x2-button->base.x1+1-strwidth)/2,button->base.y1+(button->base.y2-button->base.y1+1-strheight)/2,button->txtcolor,button->bgcolor,button->font,button->text);
|
||||||
|
|
||||||
|
}
|
||||||
|
void gui_button_remove(BUTTON_STRUCT* button)
|
||||||
|
{
|
||||||
|
touch_unregister_area((TOUCH_AREA_STRUCT*)button);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
bool guiAddBitmapButton (BITMAPBUTTON_STRUCT* button)
|
||||||
|
{
|
||||||
|
if(touchHaveEmpty(1))
|
||||||
|
{
|
||||||
|
button->base.hookedActions=PEN_DOWN;
|
||||||
|
button->base.callback = buttons_cb;
|
||||||
|
if(button->base.x2==AUTO)
|
||||||
|
button->base.x2= button->base.x1 -1 + button->imgwidth + button->imgwidth/4;
|
||||||
|
else if((button->base.x2-button->base.x1+1)<(button->imgwidth+2))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(button->base.y2==AUTO)
|
||||||
|
button->base.y2=button->base.y1 -1 +button->imgheight + button->imgheight/4;
|
||||||
|
else if((button->base.y2-button->base.y1+1)<(button->imgheight+2))
|
||||||
|
return false;
|
||||||
|
guiRedrawBitmapButton(button);
|
||||||
|
return touchRegisterArea(&button->base);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void guiRedrawBitmapButton(BITMAPBUTTON_STRUCT* button)
|
||||||
|
{
|
||||||
|
|
||||||
|
unsigned char r,g,b;
|
||||||
|
unsigned int c;
|
||||||
|
r=(button->bgcolor&0xF800)>>11;
|
||||||
|
g=(button->bgcolor&0x07E0)>>5;
|
||||||
|
b=(button->bgcolor&0x001F)>>0;
|
||||||
|
tftFillRectangle(button->base.x1+1,button->base.y1+1,button->base.x2-1,button->base.y2-1,button->bgcolor);
|
||||||
|
if((r + 0x1F/BRIGHTNESS_VAL) >0x1F)
|
||||||
|
c=0xF800;
|
||||||
|
else
|
||||||
|
c=(r+0x1F/BRIGHTNESS_VAL)<<11;
|
||||||
|
if((g + 0x3F/BRIGHTNESS_VAL) >0x3F)
|
||||||
|
c|=0x07E0;
|
||||||
|
else
|
||||||
|
c|=(g+0x3F/BRIGHTNESS_VAL)<<5;
|
||||||
|
if((b + 0x1F/BRIGHTNESS_VAL) >0x1F)
|
||||||
|
c|=0x0018;
|
||||||
|
else
|
||||||
|
c|=(b+0x1F/BRIGHTNESS_VAL)<<0;
|
||||||
|
tft_draw_line(button->base.x1+1,button->base.y1,button->base.x2-1,button->base.y1,c); //Nord
|
||||||
|
tft_draw_line(button->base.x1,button->base.y1+1,button->base.x1,button->base.y2-1,c);//West
|
||||||
|
if(r > (0x1F/BRIGHTNESS_VAL))
|
||||||
|
c=(r-0x1F/BRIGHTNESS_VAL)<<11;
|
||||||
|
else
|
||||||
|
c=0x0000;
|
||||||
|
if(g > (0x3F/BRIGHTNESS_VAL))
|
||||||
|
c|=(g-0x3F/BRIGHTNESS_VAL)<<5;
|
||||||
|
if(b > (0x1F/BRIGHTNESS_VAL))
|
||||||
|
c|=(b-0x1F/BRIGHTNESS_VAL)<<0;
|
||||||
|
tft_draw_line(button->base.x1+1,button->base.y2,button->base.x2-1,button->base.y2,c); //S<>d
|
||||||
|
tft_draw_line(button->base.x2,button->base.y1+1,button->base.x2,button->base.y2-1,c); //Ost
|
||||||
|
tftDrawBitmapUnscaledStreamedRaw(button->base.x1+(button->base.x2-button->base.x1+1-button->imgwidth)/2,button->base.y1+(button->base.y2-button->base.y1+1-button->imgheight)/2,button->imgwidth,button->imgheight,button->filename);
|
||||||
|
}
|
||||||
|
void guiRemoveBitmapButton(BITMAPBUTTON_STRUCT* button)
|
||||||
|
{
|
||||||
|
touchUnregisterArea((TOUCH_AREA_STRUCT*)button);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
44
common/gui/button.h
Normal file
44
common/gui/button.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#ifndef BUTTON_H
|
||||||
|
#define BUTTON_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "touch.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef void (*BUTTON_CALLBACK)(void *button); //!< Function pointer used...
|
||||||
|
typedef struct {
|
||||||
|
TOUCH_AREA_STRUCT base;
|
||||||
|
uint16_t bgcolor;
|
||||||
|
BUTTON_CALLBACK callback; //Callback
|
||||||
|
uint16_t txtcolor;
|
||||||
|
uint8_t font;
|
||||||
|
const char *text;
|
||||||
|
|
||||||
|
} BUTTON_STRUCT;
|
||||||
|
/*
|
||||||
|
typedef struct {
|
||||||
|
TOUCH_AREA_STRUCT base;
|
||||||
|
unsigned int bgcolor;
|
||||||
|
BUTTON_CALLBACK callback; //Callback
|
||||||
|
unsigned char imgwidth;
|
||||||
|
unsigned char imgheight;
|
||||||
|
char* filename;
|
||||||
|
} BITMAPBUTTON_STRUCT;
|
||||||
|
*/
|
||||||
|
//Notice that the first 3 Members are Equal, so it's possible to cast it to a BUTTON_STRUCT even if it's a BITMAPBUTTON_STRUCT (when changeing only the first 3 Members).
|
||||||
|
|
||||||
|
#define AUTO 0
|
||||||
|
|
||||||
|
bool gui_button_add(BUTTON_STRUCT* button);
|
||||||
|
void gui_button_remove(BUTTON_STRUCT* button);
|
||||||
|
void gui_button_redraw(BUTTON_STRUCT* button);
|
||||||
|
|
||||||
|
/*
|
||||||
|
bool guiAddBitmapButton(BITMAPBUTTON_STRUCT* button);
|
||||||
|
void guiRemoveBitmapButton(BITMAPBUTTON_STRUCT* button);
|
||||||
|
void guiRedrawBitmapButton(BITMAPBUTTON_STRUCT* button);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* BUTTON_H */
|
||||||
88
common/gui/checkbox.c
Normal file
88
common/gui/checkbox.c
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "tft.h"
|
||||||
|
#include "touch.h"
|
||||||
|
#include "checkbox.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define BRIGHTNESS_VAL 2 //How much the Brightness is in/decreased for checkbox shadows (3 -> Add 1/3 off Full Value)
|
||||||
|
#define ACTIVE_COLOR RGB(251,208,123)
|
||||||
|
#define BORDER_COLOR RGB(29,82,129)
|
||||||
|
#define BACKGROUND_COLOR WHITE
|
||||||
|
|
||||||
|
void checkboxes_cb(void* touchArea, TOUCH_ACTION triggeredAction)
|
||||||
|
{
|
||||||
|
TOUCH_AREA_STRUCT * area = (TOUCH_AREA_STRUCT*)touchArea;
|
||||||
|
CHECKBOX_STRUCT* checkbox = (CHECKBOX_STRUCT*)touchArea;
|
||||||
|
switch(triggeredAction)
|
||||||
|
{
|
||||||
|
case PEN_DOWN:
|
||||||
|
area->hookedActions=PEN_UP|PEN_LEAVE;
|
||||||
|
tft_draw_rectangle(checkbox->base.x1+1,checkbox->base.y1+1,checkbox->base.x2-1,checkbox->base.y2-1,ACTIVE_COLOR);
|
||||||
|
tft_draw_rectangle(checkbox->base.x1+2,checkbox->base.y1+2,checkbox->base.x2-2,checkbox->base.y2-2,ACTIVE_COLOR);
|
||||||
|
break;
|
||||||
|
case PEN_UP:
|
||||||
|
checkbox->checked=!checkbox->checked;
|
||||||
|
gui_checkbox_update(checkbox);
|
||||||
|
if(checkbox->callback!=NULL)
|
||||||
|
checkbox->callback(checkbox,checkbox->checked);
|
||||||
|
case PEN_LEAVE:
|
||||||
|
area->hookedActions=PEN_DOWN;
|
||||||
|
tft_draw_rectangle(checkbox->base.x1+1,checkbox->base.y1+1,checkbox->base.x2-1,checkbox->base.y2-1,BACKGROUND_COLOR);
|
||||||
|
tft_draw_rectangle(checkbox->base.x1+2,checkbox->base.y1+2,checkbox->base.x2-2,checkbox->base.y2-2,BACKGROUND_COLOR);
|
||||||
|
break;
|
||||||
|
default:break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool gui_checkbox_add(CHECKBOX_STRUCT* checkbox)
|
||||||
|
{
|
||||||
|
if(touch_have_empty(1))
|
||||||
|
{
|
||||||
|
unsigned char size=0;
|
||||||
|
checkbox->base.hookedActions=PEN_DOWN;
|
||||||
|
checkbox->base.callback = checkboxes_cb;
|
||||||
|
if(checkbox->base.x2>checkbox->base.x1)
|
||||||
|
size = checkbox->base.x2 - checkbox->base.x1;
|
||||||
|
if(checkbox->base.y2>checkbox->base.y1)
|
||||||
|
{
|
||||||
|
if((checkbox->base.y2 - checkbox->base.y1)>size)
|
||||||
|
size = checkbox->base.y2 - checkbox->base.y1;
|
||||||
|
}
|
||||||
|
if((size&0x01))
|
||||||
|
size++;
|
||||||
|
checkbox->base.x2 = checkbox->base.x1 + size;
|
||||||
|
checkbox->base.y2 = checkbox->base.y1 + size;
|
||||||
|
gui_checkbox_redraw(checkbox);
|
||||||
|
return touch_register_area(&checkbox->base);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_checkbox_redraw(CHECKBOX_STRUCT* checkbox)
|
||||||
|
{
|
||||||
|
tft_fill_rectangle(checkbox->base.x1+1,checkbox->base.y1+1,checkbox->base.x2-1,checkbox->base.y2-1,BACKGROUND_COLOR);
|
||||||
|
tft_draw_rectangle(checkbox->base.x1,checkbox->base.y1,checkbox->base.x2,checkbox->base.y2,BORDER_COLOR);
|
||||||
|
if(checkbox->checked)
|
||||||
|
gui_checkbox_update(checkbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_checkbox_remove(CHECKBOX_STRUCT* checkbox)
|
||||||
|
{
|
||||||
|
touch_unregister_area((TOUCH_AREA_STRUCT*)checkbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_checkbox_update(CHECKBOX_STRUCT* checkbox)
|
||||||
|
{
|
||||||
|
unsigned int c = (checkbox->checked)? checkbox->fgcolor:BACKGROUND_COLOR;
|
||||||
|
unsigned int xcent = checkbox->base.x1+(checkbox->base.x2-checkbox->base.x1)*6/14;
|
||||||
|
unsigned int yleft = checkbox->base.y2 - (xcent- checkbox->base.x1) - 1 ;
|
||||||
|
unsigned int yright = checkbox->base.y2 - (checkbox->base.x2 - xcent) - 1 ;
|
||||||
|
unsigned int ybot = checkbox->base.y2 - 4;
|
||||||
|
tft_draw_line(checkbox->base.x1+3,yleft-1,xcent,ybot -1,c);
|
||||||
|
tft_draw_line(checkbox->base.x1+3,yleft,xcent,ybot ,c);
|
||||||
|
tft_draw_line(checkbox->base.x1+3,yleft+1,xcent,ybot + 1,c);
|
||||||
|
xcent++;
|
||||||
|
ybot--;
|
||||||
|
tft_draw_line(xcent,ybot-1,checkbox->base.x2-3,yright-1,c);
|
||||||
|
tft_draw_line(xcent,ybot,checkbox->base.x2-3,yright+0,c);
|
||||||
|
tft_draw_line(xcent,ybot+1,checkbox->base.x2-3,yright+1,c);
|
||||||
|
}
|
||||||
15
common/gui/checkbox.h
Normal file
15
common/gui/checkbox.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
typedef void (*CHECKBOX_CALLBACK)(void *checkbox, bool checked); //!< Function pointer used...
|
||||||
|
typedef struct {
|
||||||
|
TOUCH_AREA_STRUCT base;
|
||||||
|
uint16_t fgcolor;
|
||||||
|
bool checked;
|
||||||
|
CHECKBOX_CALLBACK callback; //Callback
|
||||||
|
} CHECKBOX_STRUCT;
|
||||||
|
|
||||||
|
|
||||||
|
bool gui_checkbox_add(CHECKBOX_STRUCT* checkbox);
|
||||||
|
void gui_checkbox_remove(CHECKBOX_STRUCT* checkbox);
|
||||||
|
void gui_checkbox_update(CHECKBOX_STRUCT* checkbox);
|
||||||
|
void gui_checkbox_redraw(CHECKBOX_STRUCT* checkbox);
|
||||||
|
#define CHECKBOX_WIN_FG_COLOR RGB(32,161,34)
|
||||||
120
common/gui/numupdown.c
Normal file
120
common/gui/numupdown.c
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
#include "tft.h"
|
||||||
|
#include "touch.h"
|
||||||
|
#include "button.h"
|
||||||
|
#include "numupdown.h"
|
||||||
|
#include <stdio.h> //for sprintf
|
||||||
|
#include <stddef.h> //for offsetof macro
|
||||||
|
#include <stdlib.h> //for abs
|
||||||
|
|
||||||
|
|
||||||
|
#define BASE_COLOR RGB(90,90,90)
|
||||||
|
void button_up_cb(void* button)
|
||||||
|
{
|
||||||
|
NUMUPDOWN_STRUCT* element = button-offsetof(NUMUPDOWN_STRUCT,buttonUp);
|
||||||
|
if(element->value<element->max) {
|
||||||
|
element->value++;
|
||||||
|
gui_numupdown_update(element);
|
||||||
|
if(element->callback!=NULL) {
|
||||||
|
element->callback(element,element->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void button_down_cb(void* button)
|
||||||
|
{
|
||||||
|
NUMUPDOWN_STRUCT* element = button-offsetof(NUMUPDOWN_STRUCT,buttonDown);
|
||||||
|
if(element->value>element->min) {
|
||||||
|
element->value--;
|
||||||
|
gui_numupdown_update(element);
|
||||||
|
if(element->callback!=NULL) {
|
||||||
|
element->callback(element,element->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static uint8_t calc_text_width(int16_t val) {
|
||||||
|
uint8_t width = 1 + (val<0); //1 if positive, 2 if negative (to let space for sign)
|
||||||
|
val=abs(val);
|
||||||
|
while(val>=10) {
|
||||||
|
val/=10;
|
||||||
|
width++;
|
||||||
|
}
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool gui_numupdown_add(NUMUPDOWN_STRUCT* numupdown)
|
||||||
|
{
|
||||||
|
if(touch_have_empty(2)) //We require 2 TouchAreas (for Buttons)
|
||||||
|
{
|
||||||
|
if(numupdown->min > numupdown->max) return false;
|
||||||
|
|
||||||
|
if(numupdown->value > numupdown->max) {
|
||||||
|
numupdown->value = numupdown->max;
|
||||||
|
}
|
||||||
|
if(numupdown->value < numupdown->min) {
|
||||||
|
numupdown->value = numupdown->min;
|
||||||
|
} else if(numupdown->value > numupdown->max) {
|
||||||
|
numupdown->value = numupdown->max;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t tw1 = calc_text_width(numupdown->max);
|
||||||
|
uint8_t tw2 = calc_text_width(numupdown->min);
|
||||||
|
if(tw2 > tw1) tw1 = tw2;
|
||||||
|
uint8_t width= tft_font_width(0)*(tw1+1);
|
||||||
|
|
||||||
|
numupdown->buttonDown.base.x1=numupdown->x;
|
||||||
|
numupdown->buttonDown.base.y1=numupdown->y;
|
||||||
|
numupdown->buttonDown.base.x2=AUTO;
|
||||||
|
numupdown->buttonDown.base.y2=numupdown->y+tft_font_height(0)*2;
|
||||||
|
numupdown->buttonDown.text="-";
|
||||||
|
numupdown->buttonDown.font=0;
|
||||||
|
numupdown->buttonDown.bgcolor=BASE_COLOR;
|
||||||
|
numupdown->buttonDown.txtcolor=WHITE;
|
||||||
|
numupdown->buttonDown.callback = button_down_cb;
|
||||||
|
gui_button_add(&numupdown->buttonDown);
|
||||||
|
numupdown->buttonUp.base.x1=numupdown->buttonDown.base.x2+width+2;
|
||||||
|
numupdown->buttonUp.base.y1=numupdown->y;
|
||||||
|
numupdown->buttonUp.base.x2=AUTO;
|
||||||
|
numupdown->buttonUp.base.y2=numupdown->y +tft_font_height(0)*2;
|
||||||
|
numupdown->buttonUp.text="+";
|
||||||
|
numupdown->buttonUp.font=0;
|
||||||
|
numupdown->buttonUp.bgcolor=BASE_COLOR;
|
||||||
|
numupdown->buttonUp.txtcolor=WHITE;
|
||||||
|
numupdown->buttonUp.callback = button_up_cb;
|
||||||
|
gui_button_add(&numupdown->buttonUp);
|
||||||
|
|
||||||
|
tft_fill_rectangle(numupdown->buttonDown.base.x2+2,numupdown->y,numupdown->buttonDown.base.x2+width,numupdown->buttonUp.base.y2,BASE_COLOR);
|
||||||
|
tft_print_formatted(numupdown->buttonDown.base.x2+2+tft_font_width(0)/2,numupdown->y+tft_font_height(0)/2,numupdown->fgcolor,BASE_COLOR,0,"%*d",tw1,numupdown->value);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_numupdown_remove(NUMUPDOWN_STRUCT* numupdown)
|
||||||
|
{
|
||||||
|
gui_button_remove(&numupdown->buttonUp);
|
||||||
|
gui_button_remove(&numupdown->buttonDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_numupdown_update(NUMUPDOWN_STRUCT* numupdown)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t tw1 = calc_text_width(numupdown->max);
|
||||||
|
uint8_t tw2 = calc_text_width(numupdown->min);
|
||||||
|
if(tw2 > tw1) tw1 = tw2;
|
||||||
|
uint8_t width= tft_font_width(0)*(tw1+1);
|
||||||
|
|
||||||
|
tft_fill_rectangle(numupdown->buttonDown.base.x2+2,numupdown->y,numupdown->buttonDown.base.x2+width,numupdown->buttonUp.base.y2,BASE_COLOR);
|
||||||
|
tft_print_formatted(numupdown->buttonDown.base.x2+2+tft_font_width(0)/2,numupdown->y+tft_font_height(0)/2,numupdown->fgcolor,BASE_COLOR,0,"%*d",tw1,numupdown->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_numupdown_redraw(NUMUPDOWN_STRUCT* numupdown)
|
||||||
|
{
|
||||||
|
gui_button_redraw(&numupdown->buttonUp);
|
||||||
|
gui_button_redraw(&numupdown->buttonDown);
|
||||||
|
gui_numupdown_update(numupdown);
|
||||||
|
}
|
||||||
22
common/gui/numupdown.h
Normal file
22
common/gui/numupdown.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "button.h"
|
||||||
|
|
||||||
|
typedef void (*NUMUPDOWN_CALLBACK)(void *numupdown, int16_t value); //!< Function pointer used...
|
||||||
|
typedef struct {
|
||||||
|
uint16_t x;
|
||||||
|
uint16_t y;
|
||||||
|
uint16_t fgcolor;
|
||||||
|
int16_t value;
|
||||||
|
int16_t min;
|
||||||
|
int16_t max;
|
||||||
|
NUMUPDOWN_CALLBACK callback; //Callback
|
||||||
|
|
||||||
|
//Internally used:
|
||||||
|
BUTTON_STRUCT buttonUp;
|
||||||
|
BUTTON_STRUCT buttonDown;
|
||||||
|
} NUMUPDOWN_STRUCT;
|
||||||
|
|
||||||
|
|
||||||
|
bool gui_numupdown_add(NUMUPDOWN_STRUCT* numupdown);
|
||||||
|
void gui_numupdown_remove(NUMUPDOWN_STRUCT* numupdown);
|
||||||
|
void gui_numupdown_update(NUMUPDOWN_STRUCT* numupdown);
|
||||||
|
void gui_numupdown_redraw(NUMUPDOWN_STRUCT* numupdown);
|
||||||
68
common/gui/screen.c
Normal file
68
common/gui/screen.c
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#include "screen.h"
|
||||||
|
|
||||||
|
|
||||||
|
static volatile SCREEN_STRUCT* screen_list = NULL;
|
||||||
|
static volatile SCREEN_STRUCT* screen_current = NULL;
|
||||||
|
static volatile SCREEN_STRUCT* screen_goto = NULL;
|
||||||
|
|
||||||
|
SCREEN_STRUCT* gui_screen_get_current() {
|
||||||
|
return screen_current;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gui_screen_update() {
|
||||||
|
if(screen_goto!=NULL) { //we received the task to switch the screen
|
||||||
|
SCREEN_STRUCT* go = screen_goto; //Backup volatile variable
|
||||||
|
screen_goto=NULL;
|
||||||
|
if(go->next!=NULL) { //we're going back
|
||||||
|
if(go->next!=screen_current) return; //list corrupted?
|
||||||
|
screen_current->on_leave(screen_current);
|
||||||
|
go->next=NULL;
|
||||||
|
} else { //we're going forward
|
||||||
|
if(screen_current!=NULL) { //this is not the first screen
|
||||||
|
screen_current->on_leave(screen_current);
|
||||||
|
screen_current->next = go;
|
||||||
|
} else { //first screen ever seen
|
||||||
|
screen_list=go;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
go->on_enter(go);
|
||||||
|
screen_current = go;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(screen_current!=NULL) { //A screen has been set
|
||||||
|
screen_current->on_update(screen_current); //Update current screen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool gui_screen_navigate(SCREEN_STRUCT* screen) {
|
||||||
|
if(screen==NULL) return false;
|
||||||
|
screen->next = NULL;
|
||||||
|
screen_goto=screen; //send message to main loop, to switch the screen
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool gui_screen_back() {
|
||||||
|
if(screen_list==NULL) return false;
|
||||||
|
SCREEN_STRUCT* current = screen_list;
|
||||||
|
SCREEN_STRUCT* last = NULL;
|
||||||
|
//Find second last element in list
|
||||||
|
while(current->next != NULL) {
|
||||||
|
last = current;
|
||||||
|
current = current->next;
|
||||||
|
}
|
||||||
|
if(last==NULL) return false; //There's only a single screen.
|
||||||
|
if(current!=screen_current) return false; //List corrupted?
|
||||||
|
screen_goto=last; //send message to main loop, to switch the screen
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
33
common/gui/screen.h
Normal file
33
common/gui/screen.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef SCREEN_H
|
||||||
|
#define SCREEN_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
typedef void (*SCREEN_CALLBACK)(void* screen); //!< Function pointer used...
|
||||||
|
|
||||||
|
typedef struct SCREEN_S{
|
||||||
|
SCREEN_CALLBACK on_enter;
|
||||||
|
SCREEN_CALLBACK on_leave;
|
||||||
|
SCREEN_CALLBACK on_update;
|
||||||
|
|
||||||
|
|
||||||
|
struct SCREEN_S* next; //Used internally. do not modify
|
||||||
|
|
||||||
|
} SCREEN_STRUCT;
|
||||||
|
|
||||||
|
|
||||||
|
//Navigate to the given string as soon as the app enters the main loop again. Method can be called from an interrupt
|
||||||
|
bool gui_screen_navigate(SCREEN_STRUCT* screen);
|
||||||
|
|
||||||
|
//Navigate one screen back as soon as the app enters the main loop again. Method can be called from an interrupt
|
||||||
|
bool gui_screen_back();
|
||||||
|
|
||||||
|
//Returns the current active screen
|
||||||
|
SCREEN_STRUCT* gui_screen_get_current();
|
||||||
|
|
||||||
|
//Updates/switches the screens. Call this from the app main loop, as fast as you can.
|
||||||
|
void gui_screen_update();
|
||||||
|
|
||||||
|
#endif /* SCREEN_H */
|
||||||
@@ -12,3 +12,13 @@ void ll_tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint
|
|||||||
void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
void ll_tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
||||||
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat);
|
void ll_tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat);
|
||||||
void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t ll_tft_num_fonts();
|
||||||
|
uint8_t ll_tft_font_height(uint8_t fontnum);
|
||||||
|
uint8_t ll_tft_font_width(uint8_t fontnum);
|
||||||
|
void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, char c);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "tft.h"
|
#include "tft.h"
|
||||||
#include "ll_tft.h"
|
#include "ll_tft.h"
|
||||||
|
#include <string.h>
|
||||||
//it might seems pointless to forward all the functions but we might also introduce functions which have some logic here
|
#include <stdarg.h>
|
||||||
|
|
||||||
bool tft_init() {
|
bool tft_init() {
|
||||||
return ll_tft_init();
|
return ll_tft_init();
|
||||||
@@ -37,3 +37,32 @@ void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t h
|
|||||||
void tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color) {
|
void tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color) {
|
||||||
ll_tft_draw_circle(x, y, r, color);
|
ll_tft_draw_circle(x, y, r, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t tft_num_fonts() {
|
||||||
|
return ll_tft_num_fonts();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t tft_font_height(uint8_t fontnum) {
|
||||||
|
return ll_tft_font_height(fontnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t tft_font_width(uint8_t fontnum) {
|
||||||
|
return ll_tft_font_width(fontnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tft_print_line(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char* text) {
|
||||||
|
if(font>=ll_tft_num_fonts()) return;
|
||||||
|
for(int i=0; i<strlen(text); i++) {
|
||||||
|
ll_tft_draw_char(x,y,color,bgcolor, font, text[i]);
|
||||||
|
x+=ll_tft_font_width(font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void tft_print_formatted(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char* format, ...) {
|
||||||
|
static char buffer[256]; //not sure if that's the best solution. It would propbably better to implement putchar and use vprintf
|
||||||
|
va_list args;
|
||||||
|
va_start (args, format);
|
||||||
|
vsprintf(buffer,format,args);
|
||||||
|
tft_print_line(x,y,color,bgcolor,font,buffer);
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#define WHITE 0xF7BE
|
#define WHITE 0xF7BE
|
||||||
#define BLACK RGB(0,0,0)
|
#define BLACK RGB(0,0,0)
|
||||||
#define HEX(h) (RGB(((h)>>16),((h)>>8),(h)))
|
#define HEX(h) (RGB(((h)>>16),((h)>>8),(h)))
|
||||||
|
#define TRANSPARENT ((uint16_t)0x80C2)
|
||||||
|
|
||||||
|
|
||||||
bool tft_init();
|
bool tft_init();
|
||||||
@@ -19,3 +20,10 @@ void tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_
|
|||||||
void tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
void tft_fill_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color);
|
||||||
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat);
|
void tft_draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t* dat);
|
||||||
void tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
void tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t tft_num_fonts();
|
||||||
|
uint8_t tft_font_height(uint8_t fontnum);
|
||||||
|
uint8_t tft_font_width(uint8_t fontnum);
|
||||||
|
void tft_print_line(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char* text);
|
||||||
|
void tft_print_formatted(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char* format, ...);
|
||||||
|
|||||||
@@ -5,8 +5,7 @@
|
|||||||
#define NUM_AREAS 50 //Number of Structs Reserved in Memory for TouchAreas (e.g Buttons)
|
#define NUM_AREAS 50 //Number of Structs Reserved in Memory for TouchAreas (e.g Buttons)
|
||||||
TOUCH_AREA_STRUCT* areas[NUM_AREAS] = {NULL};
|
TOUCH_AREA_STRUCT* areas[NUM_AREAS] = {NULL};
|
||||||
|
|
||||||
volatile int touchY=0; //Last Y Coordinate in pixels
|
volatile POINT_STRUCT pos;
|
||||||
volatile int touchX=0; //Last X Coordinate in pixels
|
|
||||||
volatile TOUCH_STATE oldState=TOUCH_UP;
|
volatile TOUCH_STATE oldState=TOUCH_UP;
|
||||||
|
|
||||||
bool touch_init() {
|
bool touch_init() {
|
||||||
@@ -14,12 +13,12 @@ bool touch_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool touch_add_raw_event(uint16_t x, uint16_t y, TOUCH_STATE state) {
|
bool touch_add_raw_event(uint16_t touchX, uint16_t touchY, TOUCH_STATE state) {
|
||||||
bool penDown = (state==TOUCH_DOWN);
|
bool penDown = (state==TOUCH_DOWN);
|
||||||
bool oldPenDown = (oldState==TOUCH_DOWN);
|
bool oldPenDown = (oldState==TOUCH_DOWN);
|
||||||
oldState=state;
|
oldState=state;
|
||||||
uint16_t touchX = x;
|
pos.x=touchX;
|
||||||
uint16_t touchY = y;
|
pos.y=touchY;
|
||||||
if(penDown)
|
if(penDown)
|
||||||
{
|
{
|
||||||
// tftDrawPixel(touchX,touchY,WHITE);
|
// tftDrawPixel(touchX,touchY,WHITE);
|
||||||
@@ -127,3 +126,10 @@ void touch_unregister_area(TOUCH_AREA_STRUCT* area)//Unregisters an Area
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
POINT_STRUCT touch_get_last_point() {
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
#ifndef TOUCH_H
|
||||||
|
#define TOUCH_H
|
||||||
|
|
||||||
|
|
||||||
#include<stdbool.h>
|
#include<stdbool.h>
|
||||||
#include<stdint.h>
|
#include<stdint.h>
|
||||||
|
|
||||||
@@ -9,19 +13,27 @@ typedef void (*TOUCH_CALLBACK)(void* touchArea, TOUCH_ACTION triggeredAction);
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
TOUCH_ACTION hookedActions; //Actions to listen to
|
TOUCH_ACTION hookedActions; //Actions to listen to
|
||||||
unsigned int x1; //Top Left X Coordiate of Area
|
uint16_t x1; //Top Left X Coordiate of Area
|
||||||
unsigned int y1; //Top Left Y Coordiate of Area
|
uint16_t y1; //Top Left Y Coordiate of Area
|
||||||
unsigned int x2; //Bottom Right X Coordiate of Area
|
uint16_t x2; //Bottom Right X Coordiate of Area
|
||||||
unsigned int y2; //Bottom Right Y Coordiate of Area
|
uint16_t y2; //Bottom Right Y Coordiate of Area
|
||||||
TOUCH_CALLBACK callback; //Callback
|
TOUCH_CALLBACK callback; //Callback
|
||||||
uint8_t flags; //Internal Used, don't change
|
uint8_t flags; //Internal Used, don't change
|
||||||
} TOUCH_AREA_STRUCT;
|
} TOUCH_AREA_STRUCT;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t x;
|
||||||
|
uint16_t y;
|
||||||
|
} POINT_STRUCT;
|
||||||
|
|
||||||
|
|
||||||
bool touch_init();
|
bool touch_init();
|
||||||
bool touch_add_raw_event(uint16_t x, uint16_t y,TOUCH_STATE state);
|
bool touch_add_raw_event(uint16_t x, uint16_t y,TOUCH_STATE state);
|
||||||
bool touch_have_empty(unsigned char num);
|
bool touch_have_empty(unsigned char num);
|
||||||
bool touch_register_area(TOUCH_AREA_STRUCT* area);
|
bool touch_register_area(TOUCH_AREA_STRUCT* area);
|
||||||
void touch_unregister_area(TOUCH_AREA_STRUCT* area);
|
void touch_unregister_area(TOUCH_AREA_STRUCT* area);
|
||||||
|
POINT_STRUCT touch_get_last_point();
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* TOUCH_H */
|
||||||
|
|||||||
@@ -490,6 +490,23 @@ void ll_tft_draw_pixel(uint16_t x,uint16_t y,uint16_t color)
|
|||||||
TFT_RAM = color;
|
TFT_RAM = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t ll_tft_num_fonts() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ll_tft_font_height(uint8_t fontnum) {
|
||||||
|
return 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ll_tft_font_width(uint8_t fontnum) {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, char c) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ll_tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color)
|
void ll_tft_draw_rectangle(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2, uint16_t color)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
|||||||
BIN
doc/docu.odt
BIN
doc/docu.odt
Binary file not shown.
@@ -21,7 +21,8 @@ HEADERS += \
|
|||||||
|
|
||||||
|
|
||||||
INCLUDEPATH+= ../../common/lowlevel/ \
|
INCLUDEPATH+= ../../common/lowlevel/ \
|
||||||
../../common/touch/
|
../../common/touch/ \
|
||||||
|
../../common/tft/
|
||||||
|
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
|
|||||||
@@ -43,4 +43,37 @@ void ll_tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color) {
|
|||||||
mainwindow->draw_circle(x,y,r,color);
|
mainwindow->draw_circle(x,y,r,color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t ll_tft_num_fonts() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFont get_font(uint8_t fontnum) {
|
||||||
|
switch(fontnum) {
|
||||||
|
case 0:
|
||||||
|
return QFont("Monospace",8);
|
||||||
|
default:
|
||||||
|
return QFont();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t ll_tft_font_height(uint8_t fontnum) {
|
||||||
|
QFont f = get_font(fontnum);
|
||||||
|
if(f == QFont()) return -1;
|
||||||
|
QFontMetrics m(f);
|
||||||
|
return m.height();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ll_tft_font_width(uint8_t fontnum) {
|
||||||
|
QFont f = get_font(fontnum);
|
||||||
|
if(f == QFont()) return -1;
|
||||||
|
QFontMetrics m(f);
|
||||||
|
return m.averageCharWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ll_tft_draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, char c) {
|
||||||
|
QFont f = get_font(font);
|
||||||
|
if(f == QFont()) return;
|
||||||
|
mainwindow->draw_char(x,y,color,bgcolor,f,c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
|
#include "tft.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISPLAY_WIDTH 320
|
#define DISPLAY_WIDTH 320
|
||||||
@@ -110,6 +111,24 @@ void MainWindow::draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, QFont font, char c)
|
||||||
|
{
|
||||||
|
//render_mutex.lock();
|
||||||
|
QPainter painter(&(image));
|
||||||
|
painter.setFont(font);
|
||||||
|
|
||||||
|
if(bgcolor!=TRANSPARENT) {
|
||||||
|
painter.setBackgroundMode(Qt::OpaqueMode);
|
||||||
|
painter.setBackground(QColorFromRGB565(bgcolor));
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.setPen(QColorFromRGB565(color));
|
||||||
|
y+=QFontMetrics(font).ascent(); //use y pos as highest point of char, instead of baseline
|
||||||
|
painter.drawText(QPoint(x,y), QString(QChar(c)));
|
||||||
|
//render_mutex.unlock();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::paintEvent(QPaintEvent *)
|
void MainWindow::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
//render_mutex.lock();
|
//render_mutex.lock();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public:
|
|||||||
void fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
void fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
|
||||||
void draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat);
|
void draw_bitmap_unscaled(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *dat);
|
||||||
void draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
void draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color);
|
||||||
|
void draw_char(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, QFont font, char c);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent * evt);
|
void paintEvent(QPaintEvent * evt);
|
||||||
|
|||||||
Reference in New Issue
Block a user