Jumprun-Foo in Verzeichnis auf Badge.
[hackover2013-badge-firmware.git] / tools / examples / lcd / tft / basic_ui / main.c
1 /**************************************************************************/
2 /*!
3 @file main.c
4 @author K. Townsend (microBuilder.eu)
5
6 @section LICENSE
7
8 Software License Agreement (BSD License)
9
10 Copyright (c) 2011, microBuilder SARL
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 1. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 3. Neither the name of the copyright holders nor the
21 names of its contributors may be used to endorse or promote products
22 derived from this software without specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35 /**************************************************************************/
36 #include <stdio.h>
37
38 #include "projectconfig.h"
39 #include "sysinit.h"
40
41 #include "core/gpio/gpio.h"
42 #include "core/adc/adc.h"
43 #include "core/systick/systick.h"
44
45 #include "drivers/displays/tft/lcd.h"
46 #include "drivers/displays/tft/bmp.h"
47 #include "drivers/displays/tft/drawing.h"
48 #include "drivers/displays/tft/touchscreen.h"
49 #include "drivers/displays/tft/fonts/dejavusans9.h"
50 #include "drivers/displays/tft/fonts/dejavusansbold9.h"
51 #include "drivers/displays/tft/fonts/dejavusansmono8.h"
52
53 #include "drivers/displays/icons16.h"
54
55 // Color scheme
56 #define FONT_REGULAR &dejaVuSans9ptFontInfo
57 #define FONT_BOLD &dejaVuSansBold9ptFontInfo
58 #define COL_BACKGROUND COLOR_GRAY_80
59 #define COL_TEXT COLOR_WHITE
60
61 #define COL_BUTTON COLOR_GRAY_50
62 #define COL_BUTTONBORDER COLOR_GRAY_50
63 #define COL_BUTTONTEXT COLOR_WHITE
64 #define COL_BUTTONACTIVE COLOR_THEME_DEFAULT_BASE
65 #define COL_BUTTONACTIVEBORDER COLOR_THEME_DEFAULT_DARKER
66 #define COL_BUTTONACTIVETEXT COLOR_BLACK
67
68 #define COL_MENU COLOR_GRAY_30
69 #define COL_MENULIGHTER COLOR_GRAY_50
70 #define COL_MENUTEXT COLOR_WHITE
71 #define COL_MENUACTIVE COLOR_THEME_DEFAULT_DARKER
72 #define COL_MENUACTIVELIGHTER COLOR_THEME_DEFAULT_BASE
73 #define COL_MENUACTIVETEXT COLOR_BLACK
74
75 /**************************************************************************/
76 /*!
77 Draws a single entry in the menu (adjusting the display depending
78 on whether the item is currently active or not)
79 */
80 /**************************************************************************/
81 void renderMenuItem(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t headerWidth, bool active, char* headerText, char* bodyText)
82 {
83 drawRectangleRounded(x, y, x+headerWidth, y+height, active ? COL_MENUACTIVE : COL_MENU, 10, DRAW_ROUNDEDCORNERS_NONE);
84 drawRectangleRounded(x+headerWidth, y, x+width, y+height, active ? COL_MENUACTIVELIGHTER : COL_MENULIGHTER, 10, DRAW_ROUNDEDCORNERS_NONE);
85 fontsDrawString(x+10, y+height/2, active ? COL_MENUACTIVETEXT : COL_MENUTEXT, FONT_BOLD, headerText);
86 fontsDrawString(x+headerWidth+25, y+height/2, active ? COL_MENUACTIVETEXT: COL_MENUTEXT, FONT_REGULAR, bodyText);
87
88 if (active)
89 {
90 drawArrow(x+headerWidth+5, y+height/2, 7, DRAW_DIRECTION_LEFT, COL_MENUACTIVETEXT);
91 drawArrow(x+width-5, y+height/2, 7, DRAW_DIRECTION_RIGHT, COL_MENUACTIVETEXT);
92 }
93 }
94
95 /**************************************************************************/
96 /*!
97 Renders the 16x16 icons found in "/drivers/displays/icons16.h"
98 */
99 /**************************************************************************/
100 void renderIcons(void)
101 {
102 // Cross/Failed
103 drawRectangleRounded(10, 190, 30, 210, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
104 drawIcon16(12, 192, COLOR_RED, icons16_failed);
105 drawRectangleRounded(10, 220, 30, 240, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
106 drawIcon16(12, 222, COLOR_RED, icons16_failed);
107 drawIcon16(12, 222, COLOR_WHITE, icons16_failed_interior);
108 drawRectangleRounded(10, 250, 30, 270, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
109 drawIcon16(12, 252, COLOR_WHITE, icons16_failed_interior);
110
111 // Alert
112 drawRectangleRounded(40, 190, 60, 210, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
113 drawIcon16(42, 192, COLOR_YELLOW, icons16_alert);
114 drawRectangleRounded(40, 220, 60, 240, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
115 drawIcon16(42, 222, COLOR_YELLOW, icons16_alert);
116 drawIcon16(42, 222, COLOR_WHITE, icons16_alert_interior);
117 drawRectangleRounded(40, 250, 60, 270, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
118 drawIcon16(42, 252, COLOR_WHITE, icons16_alert_interior);
119
120 // Checkmark/Passed
121 drawRectangleRounded(70, 190, 90, 210, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
122 drawIcon16(72, 192, COLOR_GREEN, icons16_passed);
123 drawRectangleRounded(70, 220, 90, 240, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
124 drawIcon16(72, 222, COLOR_GREEN, icons16_passed);
125 drawIcon16(72, 222, COLOR_WHITE, icons16_passed_interior);
126 drawRectangleRounded(70, 250, 90, 270, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
127 drawIcon16(72, 252, COLOR_WHITE, icons16_passed_interior);
128
129 // Info
130 drawRectangleRounded(100, 190, 120, 210, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
131 drawIcon16(102, 192, COLOR_BLUE, icons16_info);
132 drawRectangleRounded(100, 220, 120, 240, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
133 drawIcon16(102, 222, COLOR_BLUE, icons16_info);
134 drawIcon16(102, 222, COLOR_WHITE, icons16_info_interior);
135 drawRectangleRounded(100, 250, 120, 270, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
136 drawIcon16(102, 252, COLOR_WHITE, icons16_info_interior);
137
138 // Tools/Config
139 drawRectangleRounded(130, 190, 150, 210, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
140 drawIcon16(132, 192, COLOR_GREEN, icons16_tools);
141
142 // Pointer
143 drawRectangleRounded(160, 190, 180, 210, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
144 drawIcon16(162, 192, COLOR_MAGENTA, icons16_pointer);
145 drawRectangleRounded(160, 220, 180, 240, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
146 drawIcon16(162, 222, COLOR_MAGENTA, icons16_pointer);
147 drawIcon16(162, 222, COLOR_WHITE, icons16_pointer_dot);
148 drawRectangleRounded(160, 250, 180, 270, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
149 drawIcon16(162, 252, COLOR_WHITE, icons16_pointer_dot);
150
151 // Tag
152 drawRectangleRounded(190, 190, 210, 210, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
153 drawIcon16(192, 192, COLOR_CYAN, icons16_tag);
154 drawRectangleRounded(190, 220, 210, 240, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
155 drawIcon16(192, 222, COLOR_CYAN, icons16_tag);
156 drawIcon16(192, 222, COLOR_WHITE, icons16_tag_dot);
157 drawRectangleRounded(190, 250, 210, 270, COL_BUTTON, 5, DRAW_ROUNDEDCORNERS_ALL);
158 drawIcon16(192, 252, COLOR_WHITE, icons16_tag_dot);
159 }
160
161 /**************************************************************************/
162 /*!
163 Main program entry point. After reset, normal code execution will
164 begin here.
165 */
166 /**************************************************************************/
167 int main(void)
168 {
169 #if !defined CFG_TFTLCD
170 #error "CFG_TFTLCD must be enabled in projectconfig.h for this test"
171 #endif
172
173 // Configure cpu and mandatory peripherals
174 systemInit();
175
176 // Background
177 drawFill(COL_BACKGROUND);
178
179 // Top/bottom action bars
180 drawRectangleFilled(0, 0, 239, 19, COL_MENU);
181 drawRectangleFilled(0, 280, 239, 319, COL_MENU);
182
183 // Menu
184 drawRectangleRounded(6, 30, 232, 160, COL_MENU, 10, DRAW_ROUNDEDCORNERS_ALL);
185 fontsDrawString(20, 45, COL_MENUTEXT, FONT_BOLD, "SYSTEM SETTINGS");
186 renderMenuItem(8, 65, 222, 23, 90, false, "LANGUAGE", "English");
187 renderMenuItem(8, 90, 222, 23, 90, false, "TIMEZONE", "GMT+1");
188 renderMenuItem(8, 115, 222, 23, 90, true, "SLEEP", "5 Minutes");
189
190 // Progress bar
191 drawProgressBar (70, 165, 160, 15, DRAW_ROUNDEDCORNERS_ALL, DRAW_ROUNDEDCORNERS_ALL, COL_MENU, COL_MENULIGHTER, COL_MENUACTIVE, COL_MENUACTIVELIGHTER, 72 );
192
193 // Render some icons
194 renderIcons();
195
196 // Action bar buttons
197 drawButton(5, 285, 75, 29, FONT_BOLD, COL_BUTTONBORDER, COL_BUTTON, COL_BUTTONTEXT, "CANCEL");
198 drawButton(160, 285, 75, 29, FONT_BOLD, COL_BUTTONBORDER, COL_BUTTON, COL_BUTTONTEXT, "SAVE");
199
200 tsTouchData_t touch;
201 tsTouchError_t error;
202
203 // Draw pixels whenever a touch screen event is detected
204 while (1)
205 {
206 // Wait for a valid touch event
207 error = tsWaitForEvent(&touch, 0);
208 if (!error)
209 {
210 drawPixel(touch.xlcd, touch.ylcd, COLOR_WHITE);
211 }
212 }
213
214 return 0;
215 }
This page took 0.068036 seconds and 5 git commands to generate.