Merge branch 'emulator' of github.com:t-moe/discoverpixy into emulator
This commit is contained in:
150
common/app/app.c
150
common/app/app.c
@@ -1,14 +1,47 @@
|
||||
#include "app.h"
|
||||
#include "tft.h"
|
||||
#include "system.h"
|
||||
#include "touch.h"
|
||||
#include "pixy.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() {
|
||||
system_init();
|
||||
tft_init();
|
||||
touch_init();
|
||||
|
||||
pixy_init();
|
||||
pixy_connected = (pixy_init()==0); //try to connect to pixy
|
||||
|
||||
//only testwise
|
||||
tft_clear(WHITE);
|
||||
@@ -18,22 +51,53 @@ void app_init() {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pixy_led_test();
|
||||
void pixy_frame_test();
|
||||
|
||||
int pixy_led_test();
|
||||
int pixy_frame_test();
|
||||
|
||||
//app event loop
|
||||
void app_process() {
|
||||
pixy_service(); //send/receive event data
|
||||
|
||||
system_process(); //Let the system handle it's pending events
|
||||
|
||||
//Code for tests see below
|
||||
pixy_led_test();
|
||||
pixy_frame_test();
|
||||
|
||||
//system_delay(500);
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +107,7 @@ int colorind;
|
||||
const uint32_t colors [] = {0xFF0000, 0x00FF00,0x0000FF,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF,0x000000};
|
||||
const int num_colors = sizeof(colors)/sizeof(uint32_t);
|
||||
|
||||
void pixy_led_test() {
|
||||
int pixy_led_test() {
|
||||
if(colorind==0) {
|
||||
pixy_led_set_max_current(5);
|
||||
}
|
||||
@@ -52,6 +116,12 @@ void pixy_led_test() {
|
||||
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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -59,7 +129,7 @@ void pixy_led_test() {
|
||||
int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t frameLen, uint8_t *frame);
|
||||
|
||||
|
||||
void pixy_frame_test() {
|
||||
int pixy_frame_test() {
|
||||
|
||||
uint8_t* videodata;
|
||||
int32_t response;
|
||||
@@ -86,15 +156,16 @@ void pixy_frame_test() {
|
||||
&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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void interpolateBayer(uint16_t width, uint16_t x, uint16_t y, uint8_t *pixel, uint8_t* r, uint8_t* g, uint8_t* b)
|
||||
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)
|
||||
{
|
||||
@@ -143,24 +214,41 @@ int renderBA81(uint8_t renderFlags, uint16_t width, uint16_t height, uint32_t fr
|
||||
// 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[(width-2)*(height-2)];
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user