discoverpixy
Functions | Variables
screen_photomode.c File Reference
#include "screen_photomode.h"
#include "screen_photomode_save.h"
#include "button.h"
#include "tft.h"
#include "touch.h"
#include "pixy.h"
#include "system.h"
#include "pixy_frame.h"
Include dependency graph for screen_photomode.c:

Go to the source code of this file.

Functions

static void b_back_cb (void *button)
 
static void b_save_cb (void *button)
 
static void touchCB (void *touchArea, TOUCH_ACTION triggeredAction)
 
static void enter (void *screen)
 
static void leave (void *screen)
 
static void update (void *screen)
 
SCREEN_STRUCTget_screen_photomode ()
 

Variables

static bool pixy_connected = false
 
static BUTTON_STRUCT b_back
 
static BUTTON_STRUCT b_save
 
static TOUCH_AREA_STRUCT a_area
 
static bool subMenu = false
 
static POINT_STRUCT pixy_pos
 
static POINT_STRUCT old_pos
 
static SCREEN_STRUCT screen
 

Function Documentation

static void b_back_cb ( void *  button)
static

Definition at line 33 of file screen_photomode.c.

34 {
35  subMenu = false; //we're not entering a submenu
36  gui_screen_back(); //navigate back to the previous screen
37 }
static bool subMenu
bool gui_screen_back()
Definition: screen.c:85

Here is the call graph for this function:

Here is the caller graph for this function:

static void b_save_cb ( void *  button)
static

Definition at line 40 of file screen_photomode.c.

41 {
42  subMenu = true; //we're entering a submenu
43  gui_screen_navigate(get_screen_photomodesave()); //navigate to the save screen
44 }
SCREEN_STRUCT * get_screen_photomodesave()
static bool subMenu
bool gui_screen_navigate(SCREEN_STRUCT *screen)
Definition: screen.c:74

Here is the call graph for this function:

Here is the caller graph for this function:

static void enter ( void *  screen)
static

Definition at line 107 of file screen_photomode.c.

108 {
109  tft_clear(WHITE);
110 
111  tft_print_line(5, 5, BLACK, TRANSPARENT, 0, "Drag the image around and ");
112 
113  //Back button
114  b_back.base.x1 = 5; //Start X of Button
115  b_back.base.y1 = 19; //Start Y of Button
116  b_back.base.x2 = AUTO; //Auto Calculate X2 with String Width
117  b_back.base.y2 = AUTO; //Auto Calculate Y2 with String Height
118  b_back.txtcolor = WHITE; //Set foreground color
119  b_back.bgcolor = HEX(0xAE1010); //Set background color (Don't take 255 or 0 on at least one channel, to make shadows possible)
120  b_back.font = 0; //Select Font
121  b_back.text = "Back"; //Set Text (For formatted strings take sprintf)
122  b_back.callback = b_back_cb; //Call b_back_cb as Callback
123  gui_button_add(&b_back); //Register Button (and run the callback from now on)
124 
125  //Save button
126  b_save.base.x1 = 190;
127  b_save.base.y1 = 3;
128  b_save.base.x2 = AUTO;
129  b_save.base.y2 = AUTO;
131  b_save.bgcolor = HEX(0x1010AE);
132  b_save.font = 0;
133  b_save.text = "Save it!";
136 
137  //Frame Coordinates: topleft = (1,40); bottomright = (318,238)
138  //Leave a 10px border for the area
139 
140  //Area to drag the image around
142  a_area.x1 = 11;
143  a_area.y1 = 50;
144  a_area.x2 = 308;
145  a_area.y2 = 228;
148 
149  //Pixy stuff
150  pixy_connected = (pixy_init() == 0); //try to connect to pixy
151 
152  if (pixy_connected && !subMenu) { //pixy is connected, but we are not coming from a submenu
153  pixy_pos.x = pixy_pos.y = 500; //reset servo positions to center
154  }
155 }
bool touch_register_area(TOUCH_AREA_STRUCT *area)
Definition: touch.c:181
const char * text
The label of the button.
Definition: button.h:61
Receive an event when the pen moves inside the region (pen is down)
Definition: touch.h:58
uint16_t txtcolor
The 16-bit text color.
Definition: button.h:59
#define AUTO
Use this value instead of x2, y2 in the BUTTON_STRUCT to autocalculate the button width/height...
Definition: button.h:65
Receive an event when the pen goes down inside the region.
Definition: touch.h:54
Receive an event when the pen goes up inside the region.
Definition: touch.h:55
uint16_t y1
Top Left Y-Coordinate of Area.
Definition: touch.h:75
uint16_t y
The Y-Coordinate of the point.
Definition: touch.h:88
static void touchCB(void *touchArea, TOUCH_ACTION triggeredAction)
bool gui_button_add(BUTTON_STRUCT *button)
Definition: button.c:133
void tft_print_line(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char *text)
Definition: tft.c:98
uint16_t x
The X-Coordinate of the point.
Definition: touch.h:87
static bool subMenu
uint16_t x1
Top Left X-Coordinate of Area.
Definition: touch.h:74
#define TRANSPARENT
Definition: tft.h:66
static BUTTON_STRUCT b_back
uint16_t bgcolor
The 16-bit background color of the button.
Definition: button.h:57
static POINT_STRUCT pixy_pos
TOUCH_AREA_STRUCT base
Basic geometry of the button. You only need to set the x1, y1, x2, y2 members of this struct...
Definition: button.h:56
static void b_save_cb(void *button)
#define HEX(h)
Definition: tft.h:60
uint16_t y2
Bottom Right Y-Coordinate of Area.
Definition: touch.h:77
static BUTTON_STRUCT b_save
TOUCH_CALLBACK callback
Callback which is executed when an event occurred in this Area.
Definition: touch.h:78
void tft_clear(uint16_t color)
Definition: tft.c:45
static void b_back_cb(void *button)
uint16_t x2
Bottom Right X-Coordinate of Area.
Definition: touch.h:76
static TOUCH_AREA_STRUCT a_area
Receive an event when the pen enters the region (pen was down before)
Definition: touch.h:56
#define WHITE
Definition: tft.h:53
int pixy_init()
Creates a connection with Pixy and listens for Pixy messages.
TOUCH_ACTION hookedActions
Actions to listen to.
Definition: touch.h:73
static bool pixy_connected
BUTTON_CALLBACK callback
Callback which is executed when the button is pressed.
Definition: button.h:58
uint8_t font
The number of the font to use.
Definition: button.h:60
#define BLACK
Definition: tft.h:54
Receive an event when the pen leaves the region (pen was inside region before)
Definition: touch.h:57

Here is the call graph for this function:

static void leave ( void *  screen)
static

Definition at line 158 of file screen_photomode.c.

159 {
160  //remove buttons and touch area.
164 }
static BUTTON_STRUCT b_back
void touch_unregister_area(TOUCH_AREA_STRUCT *area)
Definition: touch.c:195
static BUTTON_STRUCT b_save
static TOUCH_AREA_STRUCT a_area
void gui_button_remove(BUTTON_STRUCT *button)
Definition: button.c:184

Here is the call graph for this function:

static void touchCB ( void *  touchArea,
TOUCH_ACTION  triggeredAction 
)
static

Definition at line 50 of file screen_photomode.c.

51 {
52  POINT_STRUCT p = touch_get_last_point(); //get the last touched point
53 
54  switch (triggeredAction) {
55  case PEN_ENTER:
56  case PEN_DOWN:
57  old_pos = p; //If the user "newly" enters the touch area, we set the "last" position to the current
58  break;
59 
60  case PEN_MOVE: { //the user is moving around, he entered the screen a while ago (old_pos is set)
61  int16_t deltaX = p.x - old_pos.x; //Calculate x difference between last and current touch
62  int16_t deltaY = p.y - old_pos.y; //Calculate y difference between last and current touch
63  old_pos = p; //store the current touch point for the next time
64 
65  //printf("%d %d\n",deltaX,deltaY);
66  if (pixy_connected) {
67  //Calculate new servo coordinates. 2 is just a proportional factor
68  int16_t new_x = pixy_pos.x + deltaX * 2;
69  int16_t new_y = pixy_pos.y - deltaY * 2;
70 
71  //check limits
72  if (new_x < 0) {
73  new_x = 0;
74  }
75 
76  if (new_x > 1000) {
77  new_x = 1000;
78  }
79 
80  if (new_y < 0) {
81  new_y = 0;
82  }
83 
84  if (new_y > 1000) {
85  new_y = 1000;
86  }
87 
88  //set pixy_pos so that the main routine can send it to the servos
89  pixy_pos.x = new_x;
90  pixy_pos.y = new_y;
91  }
92  }
93  break;
94 
95  case PEN_UP:
96  case PEN_LEAVE:
97  //printf("Leave/up\n");
98  break;
99 
100  default:
101  break;
102  }
103 
104 }
Receive an event when the pen moves inside the region (pen is down)
Definition: touch.h:58
Receive an event when the pen goes down inside the region.
Definition: touch.h:54
Receive an event when the pen goes up inside the region.
Definition: touch.h:55
uint16_t y
The Y-Coordinate of the point.
Definition: touch.h:88
uint16_t x
The X-Coordinate of the point.
Definition: touch.h:87
static POINT_STRUCT pixy_pos
Receive an event when the pen enters the region (pen was down before)
Definition: touch.h:56
POINT_STRUCT touch_get_last_point()
Definition: touch.c:211
static POINT_STRUCT old_pos
static bool pixy_connected
Receive an event when the pen leaves the region (pen was inside region before)
Definition: touch.h:57

Here is the call graph for this function:

Here is the caller graph for this function:

static void update ( void *  screen)
static

Definition at line 168 of file screen_photomode.c.

169 {
170  //Note: The only way to detect that pixy has been disconnected is if a command fails. There's no pixy_is_connected method yet :'(
171 
172  if (!pixy_connected) { //Pixy not connected
173  pixy_close(); //Ensure that all pixy resources are freed (failsafe)
174 
175  if (pixy_init() == 0) { //try to connect to pixy
176  pixy_connected = true;
177 
178  if (!subMenu) { //we're not coming from a submenu
179  pixy_pos.x = pixy_pos.y = 500; //reset servo positions to center
180  }
181 
182  printf("pixy (re)initialized\n");
183  }
184  }
185 
186  if (pixy_connected) { //If we are connected (now)
187  pixy_service(); //Handle pending pixy events (e.g. color info retrival)
188 
189  pixy_render_full_frame(1, 40); //render the pixy video at point (1,40)
190 
191  //set the servo positions to the coordinates form the touch interrupt
194  }
195 }
uint16_t y
The Y-Coordinate of the point.
Definition: touch.h:88
uint16_t x
The X-Coordinate of the point.
Definition: touch.h:87
static bool subMenu
static POINT_STRUCT pixy_pos
int pixy_service()
int pixy_init()
Creates a connection with Pixy and listens for Pixy messages.
static bool pixy_connected
int pixy_rcs_set_position(uint8_t channel, uint16_t position)
Set pixy servo axis position.
void pixy_close()
Terminates connection with Pixy.
int pixy_render_full_frame(uint16_t x, uint16_t y)
Definition: pixy_frame.c:25

Here is the call graph for this function:

Variable Documentation

TOUCH_AREA_STRUCT a_area
static

Definition at line 29 of file screen_photomode.c.

BUTTON_STRUCT b_back
static

Definition at line 27 of file screen_photomode.c.

BUTTON_STRUCT b_save
static

Definition at line 28 of file screen_photomode.c.

POINT_STRUCT old_pos
static

Definition at line 47 of file screen_photomode.c.

bool pixy_connected = false
static

Definition at line 25 of file screen_photomode.c.

POINT_STRUCT pixy_pos
static

Definition at line 46 of file screen_photomode.c.

SCREEN_STRUCT screen
static
Initial value:
= {
}
static void leave(void *screen)
static void enter(void *screen)
static void update(void *screen)

Definition at line 198 of file screen_photomode.c.

bool subMenu = false
static

Definition at line 30 of file screen_photomode.c.