discoverpixy
screen_guitest.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_guitest.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-04-30 timolang@gmail.com 76ea9d8 Added num up down support.
12 * 2015-05-09 timolang@gmail.com c652b6b Improved Emulator Gui
13 * 2015-05-29 aaron@duckpond.ch 7d2d1a1 Implemented basic sampling and averaging of touch coordinates using timer7
14 * 2015-06-01 timolang@gmail.com eb573bc Finalized calibration. Fixed a bug in screen module.
15 * 2015-06-02 timolang@gmail.com da34bce Fixed all printf related problems on discovery using workarounds and newlib nano-instead of newlib
16 *
17 **************************************************************************************************************************************/
18 
19 #include "screen_guitest.h"
20 #include "button.h"
21 #include "tft.h"
22 #include "checkbox.h"
23 #include "numupdown.h"
24 
29 
30 static void checkboxCB(void* checkbox, bool checked)
31 {
32  printf("Checkbox %s\n", (checked ? "checked" : "unchecked"));
33 }
34 
35 static void b_back_cb(void* button)
36 {
38 }
39 
40 static void n_updown_cb(void* numupdown, int16_t value)
41 {
42  printf("New NumUpDown Value %d\n", value);
43 }
44 
45 static void touchCB(void* touchArea, TOUCH_ACTION triggeredAction)
46 {
47 
48  switch (triggeredAction) {
49  case PEN_DOWN:
50  printf("action PEN_DOWN\n");
51  break;
52 
53  case PEN_UP:
54  printf("action PEN_UP\n");
55  break;
56 
57  case PEN_MOVE:
58  printf("action PEN_MOVE\n");
59  break;
60 
61  case PEN_ENTER:
62  printf("action PEN_ENTER\n");
63  break;
64 
65  case PEN_LEAVE:
66  printf("action PEN_LEAVE\n");
67  break;
68 
69  default:
70  printf("action %s\n", triggeredAction);
71  break;
72  }
73 }
74 
75 static void enter(void* screen)
76 {
77  tft_clear(HEX(0xA6FD9A));
78 
79  //Back button
80  b_back.base.x1 = 10; //Start X of Button
81  b_back.base.y1 = 10; //Start Y of Button
82  b_back.base.x2 = AUTO; //b_back.base.x1+160; //Auto Calculate X2 with String Width
83  b_back.base.y2 = AUTO; //Auto Calculate Y2 with String Height
84  b_back.txtcolor = WHITE; //Set foreground color
85  b_back.bgcolor = HEX(0xAE1010); //Set background color (Don't take 255 or 0 on at least one channel, to make shadows possible)
86  b_back.font = 0; //Select Font
87  b_back.text = "Back"; //Set Text (For formatted strings take sprintf)
88  b_back.callback = b_back_cb; //Call b_back_cb as Callback
89  gui_button_add(&b_back); //Register Button (and run the callback from now on)
90 
91 
92  //tft test
93  tft_draw_pixel(0, 0, BLACK);
94  tft_draw_pixel(319, 239, BLACK);
95  tft_draw_pixel(10, 210, BLUE);
96  tft_draw_pixel(12, 210, BLUE);
97  tft_draw_rectangle(40, 100, 60, 235, BLUE);
98  tft_fill_rectangle(100, 215, 200, 225, GREEN);
99  tft_draw_line(10, 50, 310, 225, RGB(0xFF, 0, 0xFF));
100  tft_draw_circle(10, 10, 100, RED);
101  tft_print_line(30, 130, RED, BLUE, 0, "Hallo");
102 
103 
104 
105  //Area test
107  a_area.x1 = 130;
108  a_area.y1 = 30;
109  a_area.x2 = 200;
110  a_area.y2 = 60;
111  a_area.callback = touchCB;
112  touch_register_area(&a_area);
113 
114 
115 
116  //Checkbox test
117  c_cbox.base.x1 = 220;
118  c_cbox.base.y1 = 45;
119  c_cbox.base.x2 = c_cbox.base.x1 + 16;
120  c_cbox.base.y2 = c_cbox.base.y1 + 16;
121  c_cbox.fgcolor = GREEN;
122  c_cbox.checked = true;
123  c_cbox.callback = checkboxCB;
124  gui_checkbox_add(&c_cbox);
125 
126 
127  //Num up down test
128  n_updown.x = 200;
129  n_updown.y = 120;
130  n_updown.fgcolor = RED;
131  n_updown.value = -3;
132  n_updown.max = 11;
133  n_updown.min = -5;
134  n_updown.callback = n_updown_cb;
135  gui_numupdown_add(&n_updown);
136 
137 }
138 
139 static void leave(void* screen)
140 {
141  gui_button_remove(&b_back);
142  gui_checkbox_remove(&c_cbox);
143  gui_numupdown_remove(&n_updown);
144  touch_unregister_area(&a_area);
145 }
146 
147 static void update(void* screen)
148 {
149  //gui_button_redraw(&b_back); //only needed if button is overdrawn by others
150  //.... for the other elements as well
151 }
152 
153 
155  enter,
156  leave,
157  update
158 };
159 
160 
162 {
163  return &screen;
164 }
TOUCH_ACTION
Definition: touch.h:52
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
bool gui_checkbox_add(CHECKBOX_STRUCT *checkbox)
Definition: checkbox.c:70
void tft_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color)
Definition: tft.c:77
void tft_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:50
uint16_t x
The x-Coordinate of the Top-Left Starting Point.
Definition: numupdown.h:49
uint16_t y1
Top Left Y-Coordinate of Area.
Definition: touch.h:75
static void update(void *screen)
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
#define RGB(r, g, b)
Definition: tft.h:48
void gui_checkbox_remove(CHECKBOX_STRUCT *checkbox)
Definition: checkbox.c:119
uint16_t x1
Top Left X-Coordinate of Area.
Definition: touch.h:74
bool checked
A boolean which indicates whether or not the checkbox is currently checked.
Definition: checkbox.h:53
uint16_t bgcolor
The 16-bit background color of the button.
Definition: button.h:57
static void touchCB(void *touchArea, TOUCH_ACTION triggeredAction)
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
NUMUPDOWN_CALLBACK callback
Callback which is executed when the value changes.
Definition: numupdown.h:55
void touch_unregister_area(TOUCH_AREA_STRUCT *area)
Definition: touch.c:195
#define HEX(h)
Definition: tft.h:60
uint16_t y2
Bottom Right Y-Coordinate of Area.
Definition: touch.h:77
uint16_t y
The y-Coordinate of the Top-Left Starting Point.
Definition: numupdown.h:50
static void enter(void *screen)
int16_t max
The maximum possible value (inclusive)
Definition: numupdown.h:54
void tft_draw_pixel(uint16_t x, uint16_t y, uint16_t color)
Definition: tft.c:56
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
void gui_numupdown_remove(NUMUPDOWN_STRUCT *numupdown)
Definition: numupdown.c:136
uint16_t x2
Bottom Right X-Coordinate of Area.
Definition: touch.h:76
void gui_button_remove(BUTTON_STRUCT *button)
Definition: button.c:184
Receive an event when the pen enters the region (pen was down before)
Definition: touch.h:56
int16_t min
The minimum possible value (inclusive)
Definition: numupdown.h:53
#define RED
Definition: tft.h:50
static void leave(void *screen)
#define WHITE
Definition: tft.h:53
void tft_fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:67
static TOUCH_AREA_STRUCT a_area
TOUCH_ACTION hookedActions
Actions to listen to.
Definition: touch.h:73
static void checkboxCB(void *checkbox, bool checked)
uint16_t fgcolor
The 16-bit color of the value-text.
Definition: numupdown.h:51
void tft_draw_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:61
#define BLUE
Definition: tft.h:52
static void n_updown_cb(void *numupdown, int16_t value)
SCREEN_STRUCT * get_screen_guitest()
static SCREEN_STRUCT screen
TOUCH_AREA_STRUCT base
Basic geometry of the Checkbox. You only need to set the x1, y1, x2, y2 members of this struct...
Definition: checkbox.h:51
static NUMUPDOWN_STRUCT n_updown
int16_t value
The current/default value.
Definition: numupdown.h:52
uint16_t fgcolor
The 16-bit color of the tickmark.
Definition: checkbox.h:52
static BUTTON_STRUCT b_back
BUTTON_CALLBACK callback
Callback which is executed when the button is pressed.
Definition: button.h:58
bool gui_screen_back()
Definition: screen.c:85
CHECKBOX_CALLBACK callback
Callback which is executed when the checkbox changes state.
Definition: checkbox.h:54
uint8_t font
The number of the font to use.
Definition: button.h:60
#define GREEN
Definition: tft.h:51
static void b_back_cb(void *button)
static CHECKBOX_STRUCT c_cbox
#define BLACK
Definition: tft.h:54
Receive an event when the pen leaves the region (pen was inside region before)
Definition: touch.h:57
bool gui_numupdown_add(NUMUPDOWN_STRUCT *numupdown)
Definition: numupdown.c:80