discoverpixy
screen_main.c
Go to the documentation of this file.
1 /**************************************************************************************************************************************
2 * Project: discoverpixy
3 * Website: https://github.com/t-moe/discoverpixy
4 * Authors: Aaron Schmocker, Timo Lang
5 * Institution: BFH Bern University of Applied Sciences
6 * File: common/app/screen_main.c
7 *
8 * Version History:
9 * Date Autor Email SHA Changes
10 * 2015-04-27 timolang@gmail.com cf72baa Introduced a Screen (sub) module and divided app into multiple screens.
11 * 2015-05-10 timolang@gmail.com e2bce8f Added filesystem module, tests and implementation for it in emulator.
12 * 2015-05-15 timolang@gmail.com 27c09ba Redesigned main menu. Moved stuff from pixytest to a new helper file and to the new "photo mode"-screen.
13 * 2015-05-16 timolang@gmail.com e46314b Added Tracking Screen and implemented "Reference Tracking" and "Color Region Selection"
14 * 2015-06-01 aaron@duckpond.ch caa7b5c Added IRQ for user button, fixed some touchproblems.
15 * 2015-06-01 timolang@gmail.com 3155f42 Fixed mainscreen layout.
16 *
17 **************************************************************************************************************************************/
18 
19 #include "screen_main.h"
20 #include "screen_guitest.h"
21 #include "screen_pixytest.h"
22 #include "screen_filetest.h"
23 #include "screen_photomode.h"
24 #include "screen_tracking.h"
25 #include "button.h"
26 #include "tft.h"
27 #include "filesystem.h"
28 
32 
36 
37 
38 static void b_our_tracking_cb(void* button)
39 {
42 }
43 
44 static void b_ref_tracking_cb(void* button)
45 {
48 }
49 
50 static void b_photo_mode_cb(void* button)
51 {
53 }
54 
55 static void b_guitest_cb(void* button)
56 {
58 }
59 
60 static void b_filetest_cb(void* button)
61 {
63 }
64 
65 static void b_pixytest_cb(void* button)
66 {
68 }
69 
70 
71 static void enter(void* screen)
72 {
74 
75  //Heading
76  tft_print_line(10, 10, BLUE, TRANSPARENT, 1, "Discoverpixy");
77  tft_draw_line(0, 40, 319, 40, BLACK);
78 
79 #define X_TAB 97
80 #define BUTTON_SPACING 7
81 
82  //First line of buttons
83 #define Y_FIRST 60
84  tft_print_line(10, Y_FIRST, BLACK, TRANSPARENT, 0, "Tracking:");
85 
86  b_our_tracking.base.x1 = X_TAB; //Start X of Button
87  b_our_tracking.base.y1 = Y_FIRST - 3; //Start Y of Button
88  b_our_tracking.base.x2 = AUTO; //Auto Calculate X2 with String Width
89  b_our_tracking.base.y2 = AUTO; //Auto Calculate Y2 with String Height
90  b_our_tracking.txtcolor = WHITE; //Set foreground color
91  b_our_tracking.bgcolor = HEX(0xE30535); //Set background color (Don't take 255 or 0 on at least one channel, to make shadows possible)
92  b_our_tracking.font = 0; //Select Font
93  b_our_tracking.text = "Our Tracking"; //Set Text (For formatted strings take sprintf)
94  b_our_tracking.callback = b_our_tracking_cb; //Call b_our_tracking when the button get's pressed
95  gui_button_add(&b_our_tracking); //Register Button (and run the callback from now on)
96 
97 
98  b_ref_tracking.base.x1 = b_our_tracking.base.x2 + BUTTON_SPACING;
99  b_ref_tracking.base.y1 = Y_FIRST - 3;
100  b_ref_tracking.base.x2 = AUTO;
101  b_ref_tracking.base.y2 = AUTO;
102  b_ref_tracking.txtcolor = WHITE;
103  b_ref_tracking.bgcolor = HEX(0xFF2151);
104  b_ref_tracking.font = 0;
105  b_ref_tracking.text = "Ref Tracking";
106  b_ref_tracking.callback = b_ref_tracking_cb;
107  gui_button_add(&b_ref_tracking);
108 
109  //Second line of buttons
110 #define Y_SECOND Y_FIRST+25
111  tft_print_line(10, Y_SECOND, BLACK, TRANSPARENT, 0, "Photo mode:");
112 
113  b_photo_mode.base.x1 = X_TAB;
114  b_photo_mode.base.y1 = Y_SECOND - 3;
115  b_photo_mode.base.x2 = AUTO;
116  b_photo_mode.base.y2 = AUTO;
117  b_photo_mode.txtcolor = WHITE;
118  b_photo_mode.bgcolor = HEX(0x21B1FF);
119  b_photo_mode.font = 0;
120  b_photo_mode.text = "Photo Mode";
121  b_photo_mode.callback = b_photo_mode_cb;
122  gui_button_add(&b_photo_mode);
123 
124 
125  //Third line of buttons
126 #define Y_THIRD Y_SECOND+25
127  tft_print_line(10, Y_THIRD, BLACK, TRANSPARENT, 0, "Tests:");
128 
129  b_guitest.base.x1 = X_TAB;
130  b_guitest.base.y1 = Y_THIRD - 3;
131  b_guitest.base.x2 = AUTO;
132  b_guitest.base.y2 = AUTO;
133  b_guitest.txtcolor = BLACK;
134  b_guitest.bgcolor = HEX(0x00FA21);
135  b_guitest.font = 0;
136  b_guitest.text = "Gui & Tft";
137  b_guitest.callback = b_guitest_cb;
138  gui_button_add(&b_guitest);
139 
140 
141  b_pixytest.base.x1 = b_guitest.base.x2 + BUTTON_SPACING;
142  b_pixytest.base.y1 = Y_THIRD - 3;
143  b_pixytest.base.x2 = AUTO;
144  b_pixytest.base.y2 = AUTO;
145  b_pixytest.txtcolor = BLACK;
146  b_pixytest.bgcolor = HEX(0x00FA96);
147  b_pixytest.font = 0;
148  b_pixytest.text = "Pixy";
149  b_pixytest.callback = b_pixytest_cb;
150  gui_button_add(&b_pixytest);
151 
152 
153  b_filetest.base.x1 = b_pixytest.base.x2 + BUTTON_SPACING;
154  b_filetest.base.y1 = Y_THIRD - 3;
155  b_filetest.base.x2 = AUTO;
156  b_filetest.base.y2 = AUTO;
157  b_filetest.txtcolor = BLACK;
158  b_filetest.bgcolor = HEX(0x00FAC4);
159  b_filetest.font = 0;
160  b_filetest.text = "File";
161  b_filetest.callback = b_filetest_cb;
162  gui_button_add(&b_filetest);
163 
164 
165  //Bottom line
166  tft_draw_line(0, 145, 319, 145, BLACK);
167  tft_print_line(10, 150, BLUE, TRANSPARENT, 0, "Powered by");
168  tft_draw_bitmap_file_unscaled(10, 165, "pixy_small.bmp");
169  tft_draw_bitmap_file_unscaled(165, 165, "stm_small.bmp");
170 
171 }
172 
173 static void leave(void* screen)
174 {
175  gui_button_remove(&b_our_tracking);
176  gui_button_remove(&b_ref_tracking);
177  gui_button_remove(&b_photo_mode);
178  gui_button_remove(&b_guitest);
179  gui_button_remove(&b_pixytest);
180  gui_button_remove(&b_filetest);
181 }
182 
183 static void update(void* screen)
184 {
185  //gui_button_redraw(&b_guitest); //only needed if button is overdrawn by others
186 }
187 
188 
190  enter,
191  leave,
192  update
193 };
194 
195 
197 {
198  return &screen;
199 }
const char * text
The label of the button.
Definition: button.h:61
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
static SCREEN_STRUCT screen
Definition: screen_main.c:189
void tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:50
static void enter(void *screen)
Definition: screen_main.c:71
uint16_t y1
Top Left Y-Coordinate of Area.
Definition: touch.h:75
static void b_our_tracking_cb(void *button)
Definition: screen_main.c:38
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
void tracking_set_mode(enum Tracking_Implementation impl)
static void leave(void *screen)
Definition: screen_main.c:173
uint16_t x1
Top Left X-Coordinate of Area.
Definition: touch.h:74
BUTTON_STRUCT b_guitest
Definition: screen_main.c:29
static void b_photo_mode_cb(void *button)
Definition: screen_main.c:50
#define TRANSPARENT
Definition: tft.h:66
uint16_t bgcolor
The 16-bit background color of the button.
Definition: button.h:57
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
#define X_TAB
#define Y_SECOND
#define HEX(h)
Definition: tft.h:60
BUTTON_STRUCT b_photo_mode
Definition: screen_main.c:35
uint16_t y2
Bottom Right Y-Coordinate of Area.
Definition: touch.h:77
Pixy's internal tracking implementation.
SCREEN_STRUCT * get_screen_filetest()
bool tft_draw_bitmap_file_unscaled(uint16_t x, uint16_t y, const char *filename)
Definition: tft.c:123
SCREEN_STRUCT * get_screen_pixytest()
static void update(void *screen)
Definition: screen_main.c:183
SCREEN_STRUCT * get_screen_main()
Definition: screen_main.c:196
void tft_clear(uint16_t color)
Definition: tft.c:45
uint16_t x2
Bottom Right X-Coordinate of Area.
Definition: touch.h:76
BUTTON_STRUCT b_ref_tracking
Definition: screen_main.c:34
void gui_button_remove(BUTTON_STRUCT *button)
Definition: button.c:184
static void b_guitest_cb(void *button)
Definition: screen_main.c:55
bool gui_screen_navigate(SCREEN_STRUCT *screen)
Definition: screen.c:74
SCREEN_STRUCT * get_screen_photomode()
#define WHITE
Definition: tft.h:53
#define Y_FIRST
BUTTON_STRUCT b_filetest
Definition: screen_main.c:31
BUTTON_STRUCT b_our_tracking
Definition: screen_main.c:33
SCREEN_STRUCT * get_screen_tracking()
static void b_pixytest_cb(void *button)
Definition: screen_main.c:65
#define BLUE
Definition: tft.h:52
SCREEN_STRUCT * get_screen_guitest()
BUTTON_CALLBACK callback
Callback which is executed when the button is pressed.
Definition: button.h:58
static void b_ref_tracking_cb(void *button)
Definition: screen_main.c:44
uint8_t font
The number of the font to use.
Definition: button.h:60
Our own tracking PID implementation.
static void b_filetest_cb(void *button)
Definition: screen_main.c:60
#define Y_THIRD
#define BUTTON_SPACING
BUTTON_STRUCT b_pixytest
Definition: screen_main.c:30
#define BLACK
Definition: tft.h:54