From 3a4d8a99f885909119362e3b9b9b587315d74ad7 Mon Sep 17 00:00:00 2001 From: Kevin Townsend Date: Tue, 3 Apr 2012 23:34:05 +0200 Subject: [PATCH] Prep for v1.1.0 --- ChangeLog.txt | 48 ++- Makefile | 8 +- build/crossworks/LPC1343_CodeBase.hzp | 64 ++- build/crossworks/LPC1343_CodeBase.hzs | 19 +- drivers/displays/tft/aafonts.c | 24 ++ drivers/displays/tft/aafonts.h | 1 + .../aa2/DejaVuSansCondensedBold14_AA2.h | 1 - drivers/displays/tft/bmp.c | 30 +- drivers/displays/tft/colors.c | 3 +- drivers/displays/tft/colors.h | 32 -- drivers/displays/tft/controls/button.c | 91 +++++ drivers/displays/tft/controls/button.h | 44 ++ drivers/displays/tft/controls/hsbchart.c | 81 ++++ drivers/displays/tft/controls/hsbchart.h | 44 ++ drivers/displays/tft/controls/huechart.c | 71 ++++ drivers/displays/tft/controls/huechart.h | 44 ++ drivers/displays/tft/controls/label.c | 74 ++++ drivers/displays/tft/controls/label.h | 44 ++ drivers/displays/tft/controls/labelcentered.c | 76 ++++ drivers/displays/tft/controls/labelcentered.h | 44 ++ drivers/displays/tft/controls/progressbar.c | 97 +++++ drivers/displays/tft/controls/progressbar.h | 44 ++ drivers/displays/tft/drawing.c | 379 ++++++------------ drivers/displays/tft/drawing.h | 58 +-- drivers/displays/tft/touchscreen.c | 4 +- main.c | 4 +- project/cmd_tbl.h | 6 +- project/commands/drawing/cmd_bmp.c | 3 +- project/commands/drawing/cmd_button.c | 20 +- project/commands/drawing/cmd_progress.c | 12 +- project/commands/drawing/cmd_rectangle.c | 2 +- project/commands/drawing/cmd_text.c | 45 +-- project/commands/drawing/cmd_textw.c | 29 +- projectconfig.h | 14 +- 34 files changed, 1115 insertions(+), 445 deletions(-) create mode 100644 drivers/displays/tft/controls/button.c create mode 100644 drivers/displays/tft/controls/button.h create mode 100644 drivers/displays/tft/controls/hsbchart.c create mode 100644 drivers/displays/tft/controls/hsbchart.h create mode 100644 drivers/displays/tft/controls/huechart.c create mode 100644 drivers/displays/tft/controls/huechart.h create mode 100644 drivers/displays/tft/controls/label.c create mode 100644 drivers/displays/tft/controls/label.h create mode 100644 drivers/displays/tft/controls/labelcentered.c create mode 100644 drivers/displays/tft/controls/labelcentered.h create mode 100644 drivers/displays/tft/controls/progressbar.c create mode 100644 drivers/displays/tft/controls/progressbar.h diff --git a/ChangeLog.txt b/ChangeLog.txt index 0f05637..979788a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,5 +1,51 @@ +v1.1.0 - Ongoing +============================================================================== +BREAKING CHANGES +------------------------------------------------------------------------------ +- Rewrote corner and rounded rectangle code. Only one corner enum is now used + (drawCorners_t) +- Renamed drawRectangleRounded to drawRoundedRectangleFilled +- Removed drawProgressBar and drawButton from drawing.c, since drawing should + only contain drawing primitives +- Reorganised a lot of the TFT drawing library to support external controls, + and dynamically switch between bitmap and anti-aliased fonts. In the future + everything that isn't a basic drawing primitive will be placed in it's own + control. The main benefit of this is that it's much easier to customize the + look and feel of your UI without having to modify drawing.c and the basic + drawing primitives, and to be able to switch from bitmap to anti-aliased + fonts depending on how much flash space you have free, etc. +- Removed bmp_error_t drawBitmapImage(uint16_t x, uint16_t y, char *filename) + to keep better seperation of primitives and more complex features, and + reduce external dependencies in drawing.c. Call bmpDrawImage (bmp.c) + directly instead. + +NEW FEATURES +------------------------------------------------------------------------------ +- Added drawCorner to graphics.c +- Added new 'controls/' folder to the GFX library, and added a number of + controls that will render correctly with the theme settings, as well as + using bitmap or anti-aliased fonts, depending on projectconfig.h +- New controls: + - button + - hsbchart (Hue/saturation/brightness chart for color pickers) + - huechart (Hue selection gradient for color pickers) + - label + - labelcentered + - progressbar +- Added theme.h to try to define all of the color and font settings used by + the controls in one location to make it easier to update or modify +- Added aafontsCenterString to aafonts.c + +BUG FIXES/OPTIMISATION/ETC. +------------------------------------------------------------------------------ +- Updated Crossworks Project to use LPC1000 Lib 1.19 (uses CMSIS 3.0) +- Some performance improvements to core/gpio/gpio.c (thanks Tom for the + suggestion) +- Fixed alpha blending when alpha = 100% +- Change gpioSetValue to be inline (should optimise to a single operation) + v1.0.0 - 23 March 2012 -====================== +=========================================================== - Added support for LPCXpresso IDE - *** Moved '/drivers/chibi' to '/drivers/rf/chibi' *** - *** Moved '/drivers/sensors/pn532' to '/drivers/rf/pn532' *** diff --git a/Makefile b/Makefile index aa26d89..379faa6 100644 --- a/Makefile +++ b/Makefile @@ -70,8 +70,12 @@ OBJS += isl12022m.o # TFT LCD support VPATH += drivers/displays/tft drivers/displays/tft/hw -VPATH += drivers/displays/tft/dialogues -OBJS += drawing.o touchscreen.o colors.o bmp.o alphanumeric.o +OBJS += drawing.o touchscreen.o colors.o bmp.o + +# GUI Controls +VPATH += drivers/displays/tft/controls +OBJS += button.o hsbchart.o huechart.o label.o +OBJS += labelcentered.o progressbar.o # Bitmap (non-AA) fonts VPATH += drivers/displays/tft/fonts diff --git a/build/crossworks/LPC1343_CodeBase.hzp b/build/crossworks/LPC1343_CodeBase.hzp index c01ad87..c05e75e 100644 --- a/build/crossworks/LPC1343_CodeBase.hzp +++ b/build/crossworks/LPC1343_CodeBase.hzp @@ -1,7 +1,7 @@ - + @@ -132,10 +132,6 @@ - - - - @@ -173,21 +169,40 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -212,6 +227,15 @@ + + + + + + + + + diff --git a/build/crossworks/LPC1343_CodeBase.hzs b/build/crossworks/LPC1343_CodeBase.hzs index d980ed8..e77a2dd 100644 --- a/build/crossworks/LPC1343_CodeBase.hzs +++ b/build/crossworks/LPC1343_CodeBase.hzs @@ -9,7 +9,7 @@ - + @@ -26,11 +26,11 @@ - - + + - + @@ -47,10 +47,10 @@ - - - + + + @@ -63,7 +63,8 @@ - + + - + diff --git a/drivers/displays/tft/aafonts.c b/drivers/displays/tft/aafonts.c index c425bf9..bc8875a 100644 --- a/drivers/displays/tft/aafonts.c +++ b/drivers/displays/tft/aafonts.c @@ -239,6 +239,30 @@ void aafontsDrawString(uint16_t x, uint16_t y, const uint16_t * colorTable, cons } } +/**************************************************************************/ +/*! + @brief Draws a string using the supplied anti-aliased font, centering + it on the specified X/Y co-ordinate + + @param[in] x + Center x co-ordinate + @param[in] y + Center y co-ordinate + @param[in] colorTable + The color lookup table to use for the antialiased pixels + @param[in] font + Pointer to the aafontsFont_t to use when drawing the string + @param[in] str + The string to render +*/ +/**************************************************************************/ +void aafontsCenterString(uint16_t x, uint16_t y, const uint16_t * colorTable, const aafontsFont_t *font, char *str) +{ + uint32_t stringWidth; + stringWidth = aafontsGetStringWidth(font, str); + aafontsDrawString(x - stringWidth/2, y, colorTable, font, str); +} + /**************************************************************************/ /*! @brief Returns the width in pixels of a string when it is rendered diff --git a/drivers/displays/tft/aafonts.h b/drivers/displays/tft/aafonts.h index 7d0ec34..e09f246 100644 --- a/drivers/displays/tft/aafonts.h +++ b/drivers/displays/tft/aafonts.h @@ -70,6 +70,7 @@ extern const uint16_t COLORTABLE_AA4_WHITEONBLACK[16]; extern const uint16_t COLORTABLE_AA4_BLACKONWHITE[16]; void aafontsDrawString ( uint16_t x, uint16_t y, const uint16_t * colorTable, const aafontsFont_t *font, char *str ); +void aafontsCenterString ( uint16_t x, uint16_t y, const uint16_t * colorTable, const aafontsFont_t *font, char *str ); uint16_t aafontsGetStringWidth ( const aafontsFont_t *font, char *str ); void aafontsCalculateColorTable ( uint16_t bgColor, uint16_t foreColor, uint16_t *colorTable, size_t tableSize ); diff --git a/drivers/displays/tft/aafonts/aa2/DejaVuSansCondensedBold14_AA2.h b/drivers/displays/tft/aafonts/aa2/DejaVuSansCondensedBold14_AA2.h index 2c217d4..7966d22 100644 --- a/drivers/displays/tft/aafonts/aa2/DejaVuSansCondensedBold14_AA2.h +++ b/drivers/displays/tft/aafonts/aa2/DejaVuSansCondensedBold14_AA2.h @@ -36,7 +36,6 @@ #ifndef __DEJAVUSANSCONDENSEDBOLD14_AA2_H__ #define __DEJAVUSANSCONDENSEDBOLD14_AA2_H__ -#include "projectconfig.h" #include "drivers/displays/tft/aafonts.h" extern aafontsFont_t DejaVuSansCondensedBold14_AA2; diff --git a/drivers/displays/tft/bmp.c b/drivers/displays/tft/bmp.c index 7554645..db55fe7 100644 --- a/drivers/displays/tft/bmp.c +++ b/drivers/displays/tft/bmp.c @@ -146,12 +146,34 @@ bmp_error_t bmpParseBitmap(uint16_t x, uint16_t y, FIL file) #include "drivers/displays/tft/bmp.h" - bmp_error_t error; - // Draw image.bmp (from the root folder) starting at pixel 0,0 - error = bmpDrawBitmap(0, 0, "/image.bmp"); + bmp_error_t error = bmpDrawBitmap(0, 0, "/image.bmp"); - // Check 'error' for problems such as BMP_ERROR_FILENOTFOUND + if (error) + { + switch (error) + { + case BMP_ERROR_SDINITFAIL: + break; + case BMP_ERROR_FILENOTFOUND: + break; + case BMP_ERROR_NOTABITMAP: + // First two bytes of image not 'BM' + break; + case BMP_ERROR_INVALIDBITDEPTH: + // Image is not 24-bits + break; + case BMP_ERROR_COMPRESSEDDATA: + // Image contains compressed data + break; + case BMP_ERROR_INVALIDDIMENSIONS: + // Width or Height is > LCD size + break; + case BMP_ERROR_PREMATUREEOF: + // EOF unexpectedly reached in pixel data + break; + } + } @endcode */ diff --git a/drivers/displays/tft/colors.c b/drivers/displays/tft/colors.c index e74f74a..5788948 100644 --- a/drivers/displays/tft/colors.c +++ b/drivers/displays/tft/colors.c @@ -156,6 +156,7 @@ uint16_t colorsBGR2RGB(uint16_t color) @code + #include "drivers/displays/tft/drawing.h" #include "drivers/displays/tft/colors.h" uint16_t newColor; @@ -225,7 +226,7 @@ uint16_t colorsDim(uint16_t color, uint8_t intensity) uint16_t bg = COLOR_GREEN; uint16_t fore = COLOR_WHITE; - // Calculate the intermediate color with 25% fading + // Calculate the intermediate color with 25% bg blending uint16_t result = colorsAlphaBlend(bg, fore, 25); drawRectangleFilled(10, 10, 50, 50, bg); diff --git a/drivers/displays/tft/colors.h b/drivers/displays/tft/colors.h index b2bb641..83cbf98 100644 --- a/drivers/displays/tft/colors.h +++ b/drivers/displays/tft/colors.h @@ -59,38 +59,6 @@ #define COLOR_GRAY_200 (uint16_t)(0xCE59) // 200 200 200 #define COLOR_GRAY_225 (uint16_t)(0xE71C) // 225 225 225 -// Color Palettes -#define COLOR_THEME_LIMEGREEN_BASE (uint16_t)(0xD7F0) // 211 255 130 -#define COLOR_THEME_LIMEGREEN_DARKER (uint16_t)(0x8DE8) // 137 188 69 -#define COLOR_THEME_LIMEGREEN_LIGHTER (uint16_t)(0xEFF9) // 238 255 207 -#define COLOR_THEME_LIMEGREEN_SHADOW (uint16_t)(0x73EC) // 119 127 103 -#define COLOR_THEME_LIMEGREEN_ACCENT (uint16_t)(0xAE6D) // 169 204 104 - -#define COLOR_THEME_VIOLET_BASE (uint16_t)(0x8AEF) // 143 94 124 -#define COLOR_THEME_VIOLET_DARKER (uint16_t)(0x4187) // 66 49 59 -#define COLOR_THEME_VIOLET_LIGHTER (uint16_t)(0xC475) // 194 142 174 -#define COLOR_THEME_VIOLET_SHADOW (uint16_t)(0x40E6) // 66 29 52 -#define COLOR_THEME_VIOLET_ACCENT (uint16_t)(0xC992) // 204 50 144 - -#define COLOR_THEME_EARTHY_BASE (uint16_t)(0x6269) // 97 79 73 -#define COLOR_THEME_EARTHY_DARKER (uint16_t)(0x3103) // 48 35 31 -#define COLOR_THEME_EARTHY_LIGHTER (uint16_t)(0x8C30) // 140 135 129 -#define COLOR_THEME_EARTHY_SHADOW (uint16_t)(0xAB29) // 173 102 79 -#define COLOR_THEME_EARTHY_ACCENT (uint16_t)(0xFE77) // 250 204 188 - -#define COLOR_THEME_SKYBLUE_BASE (uint16_t)(0x95BF) // 150 180 255 -#define COLOR_THEME_SKYBLUE_DARKER (uint16_t)(0x73B0) // 113 118 131 -#define COLOR_THEME_SKYBLUE_LIGHTER (uint16_t)(0xE75F) // 227 235 255 -#define COLOR_THEME_SKYBLUE_SHADOW (uint16_t)(0x4ACF) // 75 90 127 -#define COLOR_THEME_SKYBLUE_ACCENT (uint16_t)(0xB5F9) // 182 188 204 - -// Using these values allows you to update the entire UI color scheme in one location -#define COLOR_THEME_DEFAULT_BASE COLOR_THEME_LIMEGREEN_BASE -#define COLOR_THEME_DEFAULT_DARKER COLOR_THEME_LIMEGREEN_DARKER -#define COLOR_THEME_DEFAULT_LIGHTER COLOR_THEME_LIMEGREEN_LIGHTER -#define COLOR_THEME_DEFAULT_SHADOW COLOR_THEME_LIMEGREEN_SHADOW -#define COLOR_THEME_DEFAULT_ACCENT COLOR_THEME_LIMEGREEN_ACCENT - uint16_t colorsRGB24toRGB565 ( uint8_t r, uint8_t g, uint8_t b ); uint32_t colorsRGB565toBGRA32 ( uint16_t color ); uint16_t colorsBGR2RGB ( uint16_t color ); diff --git a/drivers/displays/tft/controls/button.c b/drivers/displays/tft/controls/button.c new file mode 100644 index 0000000..a3de42c --- /dev/null +++ b/drivers/displays/tft/controls/button.c @@ -0,0 +1,91 @@ +/**************************************************************************/ +/*! + @file button.c + @author K. Townsend (microBuilder.eu) + + @brief Renders a button + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include + +#include "button.h" + +/**************************************************************************/ +/*! + @brief Draws a simple button with centered text + + @param[in] x + Starting x co-ordinate + @param[in] y + Starting y co-ordinate + @param[in] width + Button width in pixels + @param[in] height + Button height in pixels + @param[in] fontColor + Color used when rendering the text + @param[in] text + Text to center inside the button +*/ +/**************************************************************************/ +void buttonRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t fontColor, char *text, theme_t theme) +{ + #if CFG_TFTLCD_USEAAFONTS + uint16_t ctable[4]; + + // Calculate 4 color lookup table using the appropriate fore and bg colors + // This should really be optimized out into theme.h! + aafontsCalculateColorTable(theme.colorFill, fontColor, &ctable[0], 4); + + // Draw the primitive shapes for the button + drawRoundedRectangleFilled(x, y, x+width, y+height, theme.colorBorder, 5, DRAW_CORNERS_ALL); + drawRoundedRectangleFilled(x+1, y+1, x+width-1, y+height-1, theme.colorFill, 5, DRAW_CORNERS_ALL); + + if (text != NULL) + { + aafontsCenterString(x + width / 2, y + 1 + (height / 2) - (THEME_FONT.fontHeight / 2), ctable, &THEME_FONT, text); + } + #else + // Draw the primitive shapes for the button + drawRoundedRectangleFilled(x, y, x+width, y+height, theme.colorBorder, 5, DRAW_CORNERS_ALL); + drawRoundedRectangleFilled(x+1, y+1, x+width-1, y+height-1, theme.colorFill, 5, DRAW_CORNERS_ALL); + + // Render text + if (text != NULL) + { + uint16_t textWidth = fontsGetStringWidth(&THEME_FONT, text); + uint16_t xStart = x + (width / 2) - (textWidth / 2); + uint16_t yStart = y + (height / 2) - (THEME_FONT.height / 2) + 1; + fontsDrawString(xStart, yStart, fontColor, &THEME_FONT, text); + } + #endif +} diff --git a/drivers/displays/tft/controls/button.h b/drivers/displays/tft/controls/button.h new file mode 100644 index 0000000..9401552 --- /dev/null +++ b/drivers/displays/tft/controls/button.h @@ -0,0 +1,44 @@ +/**************************************************************************/ +/*! + @file button.h + @author K. Townsend (microBuilder.eu) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __BUTTON_H__ +#define __BUTTON_H__ + +#include "projectconfig.h" +#include "drivers/displays/tft/drawing.h" + +void buttonRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t fontColor, char *text, theme_t theme); + +#endif diff --git a/drivers/displays/tft/controls/hsbchart.c b/drivers/displays/tft/controls/hsbchart.c new file mode 100644 index 0000000..ab061be --- /dev/null +++ b/drivers/displays/tft/controls/hsbchart.c @@ -0,0 +1,81 @@ +/**************************************************************************/ +/*! + @file hsbchart.c + @author K. Townsend (microBuilder.eu) + + @brief Renders a hue/saturation/brightness chart + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include + +#include "hsbchart.h" + +/**************************************************************************/ +/*! + @brief Draws a square HSB (hue, saturation, brightness) chart + + @param[in] x + Starting x co-ordinate + @param[in] y + Starting y co-ordinate + @param[in] size + Width/height of the chart + @param[in] baseColor + The fully saturated color to use for the chart +*/ +/**************************************************************************/ +void hsbchartRender(uint16_t x, uint16_t y, uint16_t size, uint16_t baseColor, theme_t theme) +{ + uint32_t delta; // Alpha channel difference per pixel + uint16_t colorS; // Alpha-blended color for saturation + uint16_t color; // Alpha-blended color for saturation + brightness + uint32_t b; // Brightness counter + uint32_t s; // Saturation counter + + drawRectangle(x, y, x+size, y+size, theme.colorBorderDarker); + + if (size > 2) + { + delta = 10000/(size-2); // Calculate difference in perfect per pixel (fixed point math, * 100) + for (b = 0; b + +#include "huechart.h" + +/**************************************************************************/ +/*! + @brief Draws a rectangular hue chart showing the full spectrum + of fully saturated colors + + @param[in] x + Starting x co-ordinate + @param[in] y + Starting y co-ordinate + @param[in] width + Width of the chart in pixels + @param[in] height + Width of the chart in pixels +*/ +/**************************************************************************/ +void huechartRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, theme_t theme) +{ + uint32_t delta = (height - 2) / 6; + + // Draw border + drawRectangle(x, y, x+width, y+height, theme.colorBorderDarker); + + // Draw gradient (R > M > B > C > G > Y > R) + drawGradient(x+1, y+1, x+width-1, y+delta-1, COLOR_RED, COLOR_MAGENTA); + drawGradient(x+1, y+delta, x+width-1, y+(delta*2)-1, COLOR_MAGENTA, COLOR_BLUE); + drawGradient(x+1, y+(delta*2), x+width-1, y+(delta*3)-1, COLOR_BLUE, COLOR_CYAN); + drawGradient(x+1, y+(delta*3), x+width-1, y+(delta*4)-1, COLOR_CYAN, COLOR_GREEN); + drawGradient(x+1, y+(delta*4), x+width-1, y+(delta*5)-1, COLOR_GREEN, COLOR_YELLOW); + drawGradient(x+1, y+(delta*5), x+width-1, y+height-1, COLOR_YELLOW, COLOR_RED); +} diff --git a/drivers/displays/tft/controls/huechart.h b/drivers/displays/tft/controls/huechart.h new file mode 100644 index 0000000..9f79c12 --- /dev/null +++ b/drivers/displays/tft/controls/huechart.h @@ -0,0 +1,44 @@ +/**************************************************************************/ +/*! + @file huechart.h + @author K. Townsend (microBuilder.eu) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __HUECHART_H__ +#define __HUECHART_H__ + +#include "projectconfig.h" +#include "drivers/displays/tft/drawing.h" + +void huechartRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, theme_t theme); + +#endif diff --git a/drivers/displays/tft/controls/label.c b/drivers/displays/tft/controls/label.c new file mode 100644 index 0000000..33bb9cd --- /dev/null +++ b/drivers/displays/tft/controls/label.c @@ -0,0 +1,74 @@ +/**************************************************************************/ +/*! + @file label.c + @author K. Townsend (microBuilder.eu) + + @brief Renders a label + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include + +#include "label.h" + +/**************************************************************************/ +/*! + @brief Draws a simple label + + @param[in] x + Starting x co-ordinate + @param[in] y + Starting y co-ordinate + @param[in] bgColor + Color used for the background (required for AA fonts) + @param[in] fontColor + Color used when rendering the text + @param[in] text + Text to center inside the label +*/ +/**************************************************************************/ +void labelRender(uint16_t x, uint16_t y, uint16_t bgColor, uint16_t fontColor, char *text, theme_t theme) +{ + #if CFG_TFTLCD_USEAAFONTS + uint16_t ctable[4]; + if (text != NULL) + { + aafontsCalculateColorTable(bgColor, fontColor, &ctable[0], 4); + aafontsDrawString(x, y, ctable, &THEME_FONT, text); + } + #else + // Render text + if (text != NULL) + { + fontsDrawString(x, y, fontColor, &THEME_FONT, text); + } + #endif +} diff --git a/drivers/displays/tft/controls/label.h b/drivers/displays/tft/controls/label.h new file mode 100644 index 0000000..864763b --- /dev/null +++ b/drivers/displays/tft/controls/label.h @@ -0,0 +1,44 @@ +/**************************************************************************/ +/*! + @file label.h + @author K. Townsend (microBuilder.eu) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __LABEL_H__ +#define __LABEL_H__ + +#include "projectconfig.h" +#include "drivers/displays/tft/drawing.h" + +void labelRender(uint16_t x, uint16_t y, uint16_t bgColor, uint16_t fontColor, char *text, theme_t theme); + +#endif diff --git a/drivers/displays/tft/controls/labelcentered.c b/drivers/displays/tft/controls/labelcentered.c new file mode 100644 index 0000000..1b549d7 --- /dev/null +++ b/drivers/displays/tft/controls/labelcentered.c @@ -0,0 +1,76 @@ +/**************************************************************************/ +/*! + @file labelcentered.c + @author K. Townsend (microBuilder.eu) + + @brief Renders a centered text label + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include + +#include "labelcentered.h" + +/**************************************************************************/ +/*! + @brief Draws a centered label + + @param[in] x + Starting x co-ordinate + @param[in] y + Starting y co-ordinate + @param[in] bgColor + Color used for the background (required for AA fonts) + @param[in] fontColor + Color used when rendering the text + @param[in] text + Text to center inside the label +*/ +/**************************************************************************/ +void labelcenteredRender(uint16_t x, uint16_t y, uint16_t bgColor, uint16_t fontColor, char *text, theme_t theme) +{ + #if CFG_TFTLCD_USEAAFONTS + uint16_t ctable[4]; + if (text != NULL) + { + aafontsCalculateColorTable(bgColor, fontColor, &ctable[0], 4); + aafontsCenterString(x, y, ctable, &THEME_FONT, text); + } + #else + // Render text + if (text != NULL) + { + uint16_t textWidth = fontsGetStringWidth(&THEME_FONT, text); + uint16_t xStart = x - (textWidth / 2); + fontsDrawString(xStart, y, fontColor, &THEME_FONT, text); + } + #endif +} diff --git a/drivers/displays/tft/controls/labelcentered.h b/drivers/displays/tft/controls/labelcentered.h new file mode 100644 index 0000000..9696d3d --- /dev/null +++ b/drivers/displays/tft/controls/labelcentered.h @@ -0,0 +1,44 @@ +/**************************************************************************/ +/*! + @file labelcentered.h + @author K. Townsend (microBuilder.eu) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __LABELCENTERED_H__ +#define __LABELCENTERED_H__ + +#include "projectconfig.h" +#include "drivers/displays/tft/drawing.h" + +void labelcenteredRender(uint16_t x, uint16_t y, uint16_t bgColor, uint16_t fontColor, char *text, theme_t theme); + +#endif diff --git a/drivers/displays/tft/controls/progressbar.c b/drivers/displays/tft/controls/progressbar.c new file mode 100644 index 0000000..8a46d21 --- /dev/null +++ b/drivers/displays/tft/controls/progressbar.c @@ -0,0 +1,97 @@ +/**************************************************************************/ +/*! + @file progressbar.c + @author K. Townsend (microBuilder.eu) + + @brief Renders a progress bar + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include + +#include "progressbar.h" + +/**************************************************************************/ +/*! + @brief Draws a simple (empty) rectangle + + @param[in] x + Starting x co-ordinate + @param[in] y + Starting y co-ordinate + @param[in] width + Button width in pixels + @param[in] height + Button height in pixels + @param[in] progress + Progress in percent from 0..100 + @param[in] color + Color used when rendering the progress bar + + @note Because all displays with built-in controllers and SRAM are + inherently single-buffered -- meaning you can see the updates + as you draw them -- you need to be very careful to try to avoid + tearing or 'blinking' effects. This is usually caused by + writing the same pixel twice with different colors (for example + filling a background and then drawing something on top of it). + + This progress bar avoids this blinking effect by only drawing + the background gradient where it is visible, and no beneath the + progress bar itself. +*/ +/**************************************************************************/ +void progressbarRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t progress, uint16_t color, theme_t theme) +{ + uint16_t brighter, darker; + uint16_t progressEnd; + + // Figure out the size of the progress bar + progressEnd = x + (((width-2) * progress)/100); + + // Make sure we don't end up in negative territory with really small values + if (progressEnd < x + 2) progressEnd = x+2; + + // Calculate slightly brighter and darker colors for the border and gradient + brighter = colorsAlphaBlend(COLOR_WHITE, color, 50); + darker = colorsAlphaBlend(COLOR_BLACK, color, 35); + + // Draw the outline and background gradient + drawRectangle(x, y, x+width, y+height, theme.colorBorderDarker); + drawRectangle(x+1, y+1, x+width-1, y+height-1, theme.colorFill); + drawGradient(progressEnd+1, y+2, x+width-2, y+height-2, theme.colorFill, theme.colorBorder); + + // Draw the progress gradient if required + if (progress) + { + drawRectangle(x+2, y+2, progressEnd, y+height-2, darker); + drawGradient(x+3, y+3, progressEnd-1, y+height-3, brighter, color); + } +} diff --git a/drivers/displays/tft/controls/progressbar.h b/drivers/displays/tft/controls/progressbar.h new file mode 100644 index 0000000..0f93fd1 --- /dev/null +++ b/drivers/displays/tft/controls/progressbar.h @@ -0,0 +1,44 @@ +/**************************************************************************/ +/*! + @file progressbar.h + @author K. Townsend (microBuilder.eu) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2012, K. Townsend + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#ifndef __PROGRESSBAR_H__ +#define __PROGRESSBAR_H__ + +#include "projectconfig.h" +#include "drivers/displays/tft/drawing.h" + +void progressbarRender(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t progress, uint16_t color, theme_t theme); + +#endif diff --git a/drivers/displays/tft/drawing.c b/drivers/displays/tft/drawing.c index 8161465..924c115 100644 --- a/drivers/displays/tft/drawing.c +++ b/drivers/displays/tft/drawing.c @@ -40,10 +40,6 @@ #include "drawing.h" -#ifdef CFG_SDCARD - #include "bmp.h" -#endif - /**************************************************************************/ /* */ /* ----------------------- Private Methods ------------------------------ */ @@ -109,40 +105,6 @@ void drawCharSmall(uint16_t x, uint16_t y, uint16_t color, uint8_t c, struct FON } #endif -/**************************************************************************/ -/*! - @brief Helper method to accurately draw individual circle points -*/ -/**************************************************************************/ -void drawCirclePoints(int cx, int cy, int x, int y, uint16_t color) -{ - if (x == 0) - { - drawPixel(cx, cy + y, color); - drawPixel(cx, cy - y, color); - drawPixel(cx + y, cy, color); - drawPixel(cx - y, cy, color); - } - else if (x == y) - { - drawPixel(cx + x, cy + y, color); - drawPixel(cx - x, cy + y, color); - drawPixel(cx + x, cy - y, color); - drawPixel(cx - x, cy - y, color); - } - else if (x < y) - { - drawPixel(cx + x, cy + y, color); - drawPixel(cx - x, cy + y, color); - drawPixel(cx + x, cy - y, color); - drawPixel(cx - x, cy - y, color); - drawPixel(cx + y, cy + x, color); - drawPixel(cx - y, cy + x, color); - drawPixel(cx + y, cy - x, color); - drawPixel(cx - y, cy - x, color); - } -} - /**************************************************************************/ /* */ /* ----------------------- Public Methods ------------------------------- */ @@ -163,14 +125,10 @@ void drawCirclePoints(int cx, int cy, int x, int y, uint16_t color) /**************************************************************************/ void drawPixel(uint16_t x, uint16_t y, uint16_t color) { - if ((x >= lcdGetWidth()) || (y >= lcdGetHeight())) + if ((x < lcdGetWidth()) && (y < lcdGetHeight())) { - // Pixel out of range - return; + lcdDrawPixel(x, y, color); } - - // Redirect to LCD - lcdDrawPixel(x, y, color); } /**************************************************************************/ @@ -422,25 +380,11 @@ void drawLineDotted ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16 /**************************************************************************/ void drawCircle (uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint16_t color) { - int x = 0; - int y = radius; - int p = (5 - radius*4)/4; - - drawCirclePoints(xCenter, yCenter, x, y, color); - while (x < y) - { - x++; - if (p < 0) - { - p += 2*x+1; - } - else - { - y--; - p += 2*(x-y)+1; - } - drawCirclePoints(xCenter, yCenter, x, y, color); - } + drawPixel(xCenter, yCenter+radius, color); + drawPixel(xCenter, yCenter-radius, color); + drawPixel(xCenter+radius, yCenter, color); + drawPixel(xCenter-radius, yCenter, color); + drawCorner(xCenter, yCenter, radius, DRAW_CORNERS_ALL, color); } /**************************************************************************/ @@ -497,6 +441,74 @@ void drawCircleFilled (uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint } } +/**************************************************************************/ +/*! + @brief Draws a single 1-pixel wide corner + + @note Code courtesy Adafruit's excellent GFX lib: + https://github.com/adafruit/Adafruit-GFX-Library + + @param[in] xCenter + The horizontal center of the circle + @param[in] yCenter + The vertical center of the circle + @param[in] corner + The drawCorners_t representing the corner(s) to draw + @param[in] color + Color used when drawing + + @section EXAMPLE + + @code + + // Draw a top-left corner with a 10 pixel radius, centered at 20, 20 + drawCorner(20, 20, 10, DRAW_CORNER_TOPLEFT, COLOR_GRAY_128); + + @endcode +*/ +/**************************************************************************/ +void drawCorner (uint16_t xCenter, uint16_t yCenter, uint16_t r, drawCorners_t corner, uint16_t color) +{ + int16_t f = 1 - r; + int16_t ddF_x = 1; + int16_t ddF_y = -2 * r; + int16_t x = 0; + int16_t y = r; + + while (x= 0) + { + y--; + ddF_y += 2; + f += ddF_y; + } + x++; + ddF_x += 2; + f += ddF_x; + if (corner & DRAW_CORNERS_BOTTOMRIGHT) + { + drawPixel(xCenter + x, yCenter + y, color); + drawPixel(xCenter + y, yCenter + x, color); + } + if (corner & DRAW_CORNERS_TOPRIGHT) + { + drawPixel(xCenter + x, yCenter - y, color); + drawPixel(xCenter + y, yCenter - x, color); + } + if (corner & DRAW_CORNERS_BOTTOMLEFT) + { + drawPixel(xCenter - y, yCenter + x, color); + drawPixel(xCenter - x, yCenter + y, color); + } + if (corner & DRAW_CORNERS_TOPLEFT) + { + drawPixel(xCenter - y, yCenter - x, color); + drawPixel(xCenter - x, yCenter - y, color); + } + } +} + /**************************************************************************/ /*! @brief Draws a filled rounded corner @@ -514,7 +526,7 @@ void drawCircleFilled (uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint Color used when drawing */ /**************************************************************************/ -void drawCornerFilled (uint16_t xCenter, uint16_t yCenter, uint16_t radius, drawCornerPosition_t position, uint16_t color) +void drawCornerFilled (uint16_t xCenter, uint16_t yCenter, uint16_t radius, drawCorners_t position, uint16_t color) { int16_t f = 1 - radius; int16_t ddF_x = 1; @@ -524,16 +536,14 @@ void drawCornerFilled (uint16_t xCenter, uint16_t yCenter, uint16_t radius, draw int16_t xc_px, yc_my, xc_mx, xc_py, yc_mx, xc_my; int16_t lcdWidth = lcdGetWidth(); - switch (position) + + if ((position & DRAW_CORNERS_TOPRIGHT) || (position & DRAW_CORNERS_TOPLEFT)) { - case DRAW_CORNERPOSITION_TOPRIGHT: - case DRAW_CORNERPOSITION_TOPLEFT: - if (xCenter < lcdWidth) drawLine(xCenter, yCenter-radius < 0 ? 0 : yCenter-radius, xCenter, yCenter, color); - break; - case DRAW_CORNERPOSITION_BOTTOMRIGHT: - case DRAW_CORNERPOSITION_BOTTOMLEFT: - if (xCenter < lcdWidth) drawLine(xCenter, yCenter-radius < 0 ? 0 : yCenter, xCenter, (yCenter-radius) + (2*radius), color); - break; + if (xCenter < lcdWidth) drawLine(xCenter, yCenter-radius < 0 ? 0 : yCenter-radius, xCenter, yCenter, color); + } + if ((position & DRAW_CORNERS_BOTTOMRIGHT) || (position & DRAW_CORNERS_BOTTOMLEFT)) + { + if (xCenter < lcdWidth) drawLine(xCenter, yCenter-radius < 0 ? 0 : yCenter, xCenter, (yCenter-radius) + (2*radius), color); } while (x= 0)) drawLine(xc_px, yc_my, xc_px, yCenter, color); if ((xc_py < lcdWidth) && (xc_py >= 0)) drawLine(xc_py, yc_mx, xc_py, yCenter, color); - break; - case DRAW_CORNERPOSITION_BOTTOMRIGHT: + } + if (position & DRAW_CORNERS_BOTTOMRIGHT) + { if ((xc_px < lcdWidth) && (xc_px >= 0)) drawLine(xc_px, yCenter, xc_px, yc_my + 2*y, color); if ((xc_py < lcdWidth) && (xc_py >= 0)) drawLine(xc_py, yCenter, xc_py, yc_mx + 2*x, color); - break; - case DRAW_CORNERPOSITION_TOPLEFT: + } + if (position & DRAW_CORNERS_TOPLEFT) + { if ((xc_mx < lcdWidth) && (xc_mx >= 0)) drawLine(xc_mx, yc_my, xc_mx, yCenter, color); if ((xc_my < lcdWidth) && (xc_my >= 0)) drawLine(xc_my, yc_mx, xc_my, yCenter, color); - break; - case DRAW_CORNERPOSITION_BOTTOMLEFT: + } + if (position & DRAW_CORNERS_BOTTOMLEFT) + { if ((xc_mx < lcdWidth) && (xc_mx >= 0)) drawLine(xc_mx, yCenter, xc_mx, yc_my + 2*y, color); if ((xc_my < lcdWidth) && (xc_my >= 0)) drawLine(xc_my, yCenter, xc_my, yc_mx + 2*x, color); - break; } } } @@ -740,12 +752,12 @@ void drawRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, u Which corners to round */ /**************************************************************************/ -void drawRectangleRounded ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color, uint16_t radius, drawRoundedCorners_t corners ) +void drawRoundedRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color, uint16_t radius, drawCorners_t corners ) { int height; uint16_t y; - if (corners == DRAW_ROUNDEDCORNERS_NONE) + if (corners == DRAW_CORNERS_NONE) { drawRectangleFilled(x0, y0, x1, y1, color); return; @@ -772,41 +784,41 @@ void drawRectangleRounded ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, switch (corners) { - case DRAW_ROUNDEDCORNERS_ALL: - drawCircleFilled(x0 + radius, y0 + radius, radius, color); - drawCircleFilled(x1 - radius, y0 + radius, radius, color); - drawCircleFilled(x0 + radius, y1 - radius, radius, color); - drawCircleFilled(x1 - radius, y1 - radius, radius, color); + case DRAW_CORNERS_ALL: + drawCornerFilled(x0 + radius, y0 + radius, radius, DRAW_CORNERS_TOPLEFT, color); + drawCornerFilled(x1 - radius, y0 + radius, radius, DRAW_CORNERS_TOPRIGHT, color); + drawCornerFilled(x0 + radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMLEFT, color); + drawCornerFilled(x1 - radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMRIGHT, color); if (radius*2+1 < height) { drawRectangleFilled(x0, y0 + radius, x0 + radius, y1 - radius, color); drawRectangleFilled(x1 - radius, y0 + radius, x1, y1 - radius, color); } break; - case DRAW_ROUNDEDCORNERS_TOP: - drawCircleFilled(x0 + radius, y0 + radius, radius, color); - drawCircleFilled(x1 - radius, y0 + radius, radius, color); + case DRAW_CORNERS_TOP: + drawCornerFilled(x0 + radius, y0 + radius, radius, DRAW_CORNERS_TOPLEFT, color); + drawCornerFilled(x1 - radius, y0 + radius, radius, DRAW_CORNERS_TOPRIGHT, color); drawRectangleFilled(x0, y0 + radius, x0 + radius, y1, color); drawRectangleFilled(x1 - radius, y0 + radius, x1, y1, color); break; - case DRAW_ROUNDEDCORNERS_BOTTOM: - drawCircleFilled(x0 + radius, y1 - radius, radius, color); - drawCircleFilled(x1 - radius, y1 - radius, radius, color); + case DRAW_CORNERS_BOTTOM: + drawCornerFilled(x0 + radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMLEFT, color); + drawCornerFilled(x1 - radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMRIGHT, color); drawRectangleFilled(x0, y0, x0 + radius, y1 - radius, color); drawRectangleFilled(x1 - radius, y0, x1, y1 - radius, color); break; - case DRAW_ROUNDEDCORNERS_LEFT: - drawCircleFilled(x0 + radius, y0 + radius, radius, color); - drawCircleFilled(x0 + radius, y1 - radius, radius, color); + case DRAW_CORNERS_LEFT: + drawCornerFilled(x0 + radius, y0 + radius, radius, DRAW_CORNERS_TOPLEFT, color); + drawCornerFilled(x0 + radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMLEFT, color); if (radius*2+1 < height) { drawRectangleFilled(x0, y0 + radius, x0 + radius, y1 - radius, color); } drawRectangleFilled(x1 - radius, y0, x1, y1, color); break; - case DRAW_ROUNDEDCORNERS_RIGHT: - drawCircleFilled(x1 - radius, y0 + radius, radius, color); - drawCircleFilled(x1 - radius, y1 - radius, radius, color); + case DRAW_CORNERS_RIGHT: + drawCornerFilled(x1 - radius, y0 + radius, radius, DRAW_CORNERS_TOPRIGHT, color); + drawCornerFilled(x1 - radius, y1 - radius, radius, DRAW_CORNERS_BOTTOMRIGHT, color); if (radius*2+1 < height) { drawRectangleFilled(x1 - radius, y0 + radius, x1, y1 - radius, color); @@ -1032,120 +1044,6 @@ void drawTriangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, ui } } -/**************************************************************************/ -/*! - @brief Draws a progress bar with rounded corners - - @param[in] x - Starting x location - @param[in] y - Starting y location - @param[in] width - Total width of the progress bar in pixels - @param[in] height - Total height of the progress bar in pixels - @param[in] borderCorners - The type of rounded corners to render with the progress bar border - @param[in] progressCorners - The type of rounded corners to render with the inner progress bar - @param[in] borderColor - 16-bit color for the outer border - @param[in] borderFillColor - 16-bit color for the interior of the outer border - @param[in] progressBorderColor - 16-bit color for the progress bar's border - @param[in] progressFillColor - 16-bit color for the inner bar's fill - @param[in] progress - Progress percentage (between 0 and 100) - - @section Example - - @code - #include "drivers/displays/tft/drawing.h" - - // Draw a the progress bar (150x15 pixels large, starting at X:10, Y:195 - // with rounded corners on the top and showing 72% progress) - drawProgressBar(10, 195, 150, 15, DRAW_ROUNDEDCORNERS_TOP, DRAW_ROUNDEDCORNERS_TOP, COLOR_DARKERGRAY, COLOR_DARKGRAY, COLOR_LIMEGREENDIM, COLOR_LIMEGREEN, 72 ); - - @endcode -*/ -/**************************************************************************/ -void drawProgressBar ( uint16_t x, uint16_t y, uint16_t width, uint16_t height, drawRoundedCorners_t borderCorners, drawRoundedCorners_t progressCorners, uint16_t borderColor, uint16_t borderFillColor, uint16_t progressBorderColor, uint16_t progressFillColor, uint8_t progress ) -{ - // Draw border with rounded corners - drawRectangleRounded(x, y, x + width, y + height, borderColor, 5, borderCorners); - drawRectangleRounded(x+1, y+1, x + width - 1, y + height - 1, borderFillColor, 5, borderCorners); - - // Progress bar - if (progress > 0 && progress <= 100) - { - // Calculate bar size - uint16_t bw; - bw = (width - 6); // bar at 100% - if (progress != 100) - { - bw = (bw * progress) / 100; - } - drawRectangleRounded(x + 3, y + 3, bw + x + 3, y + height - 3, progressBorderColor, 5, progressCorners); - drawRectangleRounded(x + 4, y + 4, bw + x + 3 - 1, y + height - 4, progressFillColor, 5, progressCorners); - } -} - -/**************************************************************************/ -/*! - @brief Draws a simple button - - @param[in] x - Starting x location - @param[in] y - Starting y location - @param[in] width - Total width of the button in pixels - @param[in] height - Total height of the button in pixels - @param[in] fontInfo - Pointer to the FONT_INFO used to render the button text - @param[in] borderclr - The rgb565 border color - @param[in] fillclr - The rgb565 background color - @param[in] fontclr - The rgb565 font color - @param[in] text - The text to render on the button - - @section Example - - @code - - #include "drivers/displays/tft/drawing.h" - #include "drivers/displays/tft/fonts/dejavusans9.h" - - // Draw two buttons using DejaVu Sans 9 - drawButton(20, 195, 200, 35, &dejaVuSans9ptFontInfo, COLOR_GRAY_80, COLOR_GRAY_80, COLOR_WHITE, "System Settings"); - drawButton(20, 235, 200, 35, &dejaVuSans9ptFontInfo, COLOR_THEME_LIMEGREEN_DARKER, COLOR_THEME_LIMEGREEN_BASE, COLOR_BLACK, "System Settings"); - - @endcode -*/ -/**************************************************************************/ -void drawButton(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const FONT_INFO *fontInfo, uint16_t borderclr, uint16_t fillclr, uint16_t fontclr, char* text) -{ - // Border - drawRectangleRounded(x, y, x + width, y + height, borderclr, 5, DRAW_ROUNDEDCORNERS_ALL); - // Fill - drawRectangleRounded(x+2, y+2, x+width-2, y+height-2, fillclr, 5, DRAW_ROUNDEDCORNERS_ALL); - - // Render text - if (text != NULL) - { - uint16_t textWidth = fontsGetStringWidth(&*fontInfo, text); - uint16_t xStart = x + (width / 2) - (textWidth / 2); - uint16_t yStart = y + (height / 2) - (fontInfo->height / 2) + 1; - fontsDrawString(xStart, yStart, fontclr, &*fontInfo, text); - } -} - /**************************************************************************/ /*! @brief Renders a 16x16 monochrome icon using the supplied uint16_t @@ -1199,54 +1097,3 @@ void drawIcon16(uint16_t x, uint16_t y, uint16_t color, uint16_t icon[]) if (icon[i] & (0X0001)) drawPixel(x+15, y+i, color); } } - -#ifdef CFG_SDCARD -/**************************************************************************/ -/*! - @brief Loads a 24-bit Windows bitmap image from an SD card and - renders it - - @section Example - - @code - - #include "drivers/displays/tft/drawing.h" - - // Draw image.bmp (from the root folder) starting at pixel 0,0 - bmp_error_t error = drawBitmapImage(0, 0, "/image.bmp"); - - if (error) - { - switch (error) - { - case BMP_ERROR_SDINITFAIL: - break; - case BMP_ERROR_FILENOTFOUND: - break; - case BMP_ERROR_NOTABITMAP: - // First two bytes of image not 'BM' - break; - case BMP_ERROR_INVALIDBITDEPTH: - // Image is not 24-bits - break; - case BMP_ERROR_COMPRESSEDDATA: - // Image contains compressed data - break; - case BMP_ERROR_INVALIDDIMENSIONS: - // Width or Height is > LCD size - break; - case BMP_ERROR_PREMATUREEOF: - // EOF unexpectedly reached in pixel data - break; - } - } - - @endcode -*/ -/**************************************************************************/ -bmp_error_t drawBitmapImage(uint16_t x, uint16_t y, char *filename) -{ - return bmpDrawBitmap(x, y, filename); -} - -#endif diff --git a/drivers/displays/tft/drawing.h b/drivers/displays/tft/drawing.h index 48a3c79..3b3257b 100644 --- a/drivers/displays/tft/drawing.h +++ b/drivers/displays/tft/drawing.h @@ -39,40 +39,31 @@ #include "projectconfig.h" #include "lcd.h" #include "colors.h" -#include "fonts.h" +#include "theme.h" -#if defined CFG_TFTLCD_INCLUDESMALLFONTS & CFG_TFTLCD_INCLUDESMALLFONTS == 1 - #include "drivers/displays/smallfonts.h" +#if CFG_TFTLCD_USEAAFONTS + #include "aafonts.h" +#else + #include "fonts.h" #endif -#ifdef CFG_SDCARD - #include "bmp.h" +#if CFG_TFTLCD_INCLUDESMALLFONTS + #include "drivers/displays/smallfonts.h" #endif -typedef struct -{ - uint8_t red; - uint8_t green; - uint8_t blue; -} drawColorRGB24_t; - typedef enum { - DRAW_ROUNDEDCORNERS_NONE = 0, - DRAW_ROUNDEDCORNERS_ALL = 1, - DRAW_ROUNDEDCORNERS_TOP = 2, - DRAW_ROUNDEDCORNERS_BOTTOM = 3, - DRAW_ROUNDEDCORNERS_LEFT = 4, - DRAW_ROUNDEDCORNERS_RIGHT = 5 -} drawRoundedCorners_t; - -typedef enum -{ - DRAW_CORNERPOSITION_TOPLEFT = 0, - DRAW_CORNERPOSITION_TOPRIGHT = 1, - DRAW_CORNERPOSITION_BOTTOMLEFT = 2, - DRAW_CORNERPOSITION_BOTTOMRIGHT = 3 -} drawCornerPosition_t; + DRAW_CORNERS_NONE = 0x00, + DRAW_CORNERS_TOPLEFT = 0x01, + DRAW_CORNERS_TOPRIGHT = 0x02, + DRAW_CORNERS_BOTTOMLEFT = 0x04, + DRAW_CORNERS_BOTTOMRIGHT = 0x08, + DRAW_CORNERS_ALL = 0x0F, // 0x01 + 0x02 + 0x04 + 0x08 + DRAW_CORNERS_TOP = 0x03, // 0x01 + 0x02 + DRAW_CORNERS_BOTTOM = 0x0C, // 0x04 + 0x08 + DRAW_CORNERS_LEFT = 0x05, // 0x01 + 0x04 + DRAW_CORNERS_RIGHT = 0x0A // 0x02 + 0x08 +} drawCorners_t; typedef enum { @@ -89,24 +80,19 @@ void drawLine ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t void drawLineDotted ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t space, uint16_t solid, uint16_t color ); void drawCircle ( uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint16_t color ); void drawCircleFilled ( uint16_t xCenter, uint16_t yCenter, uint16_t radius, uint16_t color ); -void drawCornerFilled (uint16_t xCenter, uint16_t yCenter, uint16_t radius, drawCornerPosition_t position, uint16_t color); +void drawCorner ( uint16_t xCenter, uint16_t yCenter, uint16_t r, drawCorners_t corner, uint16_t color ); +void drawCornerFilled ( uint16_t xCenter, uint16_t yCenter, uint16_t radius, drawCorners_t position, uint16_t color ); void drawArrow ( uint16_t x, uint16_t y, uint16_t size, drawDirection_t, uint16_t color ); void drawRectangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color ); void drawRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color ); -void drawRectangleRounded ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color, uint16_t radius, drawRoundedCorners_t corners ); +void drawRoundedRectangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color, uint16_t radius, drawCorners_t corners ); void drawGradient ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t startColor, uint16_t endColor ); void drawTriangle ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color ); void drawTriangleFilled ( uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color ); -void drawProgressBar ( uint16_t x, uint16_t y, uint16_t width, uint16_t height, drawRoundedCorners_t borderCorners, drawRoundedCorners_t progressCorners, uint16_t borderColor, uint16_t borderFillColor, uint16_t progressBorderColor, uint16_t progressFillColor, uint8_t progress ); -void drawButton ( uint16_t x, uint16_t y, uint16_t width, uint16_t height, const FONT_INFO *fontInfo, uint16_t borderclr, uint16_t fillclr, uint16_t fontclr, char* text ); void drawIcon16 ( uint16_t x, uint16_t y, uint16_t color, uint16_t icon[] ); -#if defined CFG_TFTLCD_INCLUDESMALLFONTS & CFG_TFTLCD_INCLUDESMALLFONTS == 1 +#if CFG_TFTLCD_INCLUDESMALLFONTS void drawStringSmall ( uint16_t x, uint16_t y, uint16_t color, char* text, struct FONT_DEF font ); #endif -#if defined CFG_SDCARD -bmp_error_t drawBitmapImage ( uint16_t x, uint16_t y, char *filename ); -#endif - #endif diff --git a/drivers/displays/tft/touchscreen.c b/drivers/displays/tft/touchscreen.c index 97f448b..6e31824 100644 --- a/drivers/displays/tft/touchscreen.c +++ b/drivers/displays/tft/touchscreen.c @@ -43,7 +43,7 @@ #include "drivers/storage/eeprom/eeprom.h" #include "drivers/displays/tft/lcd.h" #include "drivers/displays/tft/drawing.h" -#include "drivers/displays/tft/fonts/dejavusans9.h" +#include "drivers/displays/tft/controls/labelcentered.h" #define TS_LINE1 "Touch the center of" #define TS_LINE2 "the red circle using" @@ -170,7 +170,7 @@ uint32_t tsReadY(void) /**************************************************************************/ void tsCalibCenterText(char* text, uint16_t y, uint16_t color) { - fontsDrawString((lcdGetWidth() - fontsGetStringWidth(&dejaVuSans9ptFontInfo, text)) / 2, y, color, &dejaVuSans9ptFontInfo, text); + labelcenteredRender(lcdGetWidth()/2, y, COLOR_WHITE, color, text, THEME_DEFAULT); } /**************************************************************************/ diff --git a/main.c b/main.c index 99f192a..ba5cd42 100644 --- a/main.c +++ b/main.c @@ -61,7 +61,7 @@ int main(void) uint32_t currentSecond, lastSecond; currentSecond = lastSecond = 0; - + while (1) { // Toggle LED once per second @@ -69,7 +69,7 @@ int main(void) if (currentSecond != lastSecond) { lastSecond = currentSecond; - gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, !(gpioGetValue(CFG_LED_PORT, CFG_LED_PIN))); + gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, lastSecond % 2); } // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h diff --git a/project/cmd_tbl.h b/project/cmd_tbl.h index a775021..c305d07 100644 --- a/project/cmd_tbl.h +++ b/project/cmd_tbl.h @@ -118,7 +118,7 @@ cmd_t cmd_tbl[] = #endif #ifdef CFG_TFTLCD - { "b", 7, 99, 0, cmd_button , "Button" , "'b []'" }, + { "b", 5, 99, 0, cmd_button , "Button" , "'b []'" }, #ifdef CFG_SDCARD { "B", 3, 3, 0, cmd_bmp , "Bitmap (SD Card)" , "'B '" }, #endif @@ -131,11 +131,11 @@ cmd_t cmd_tbl[] = { "n", 5, 5, 0, cmd_roundedcorner , "Rounded Corner" , "'n '" }, { "o", 0, 1, 0, cmd_orientation , "LCD Orientation" , "'o [<0|1>]'" }, { "p", 3, 3, 0, cmd_pixel , "Draw Pixel" , "'p '" }, - { "P", 9, 9, 0, cmd_progress , "Progress Bar" , "'P <%> '" }, + { "P", 6, 6, 0, cmd_progress , "Progress Bar" , "'P <%> '" }, { "r", 5, 7, 0, cmd_rectangle , "Rectangle" , "'r [ ]'" }, { "R", 7, 7, 0, cmd_rectangleround , "Rounded Rectangle" , "'R '" }, { "s", 2, 99, 0, cmd_textw , "Text Width" , "'s '" }, - { "t", 5, 99, 0, cmd_text , "Text" , "'t '" }, + { "t", 6, 99, 0, cmd_text , "Text" , "'t '" }, { "v", 7, 8, 0, cmd_triangle , "Triangle" , "'v []'" }, { "W", 0, 1, 0, cmd_tswait , "Wait for Touch" , "'W []'" }, { "x", 0, 1, 0, cmd_tsthreshhold , "Touch Threshold" , "'x [<0..254>]'" }, diff --git a/project/commands/drawing/cmd_bmp.c b/project/commands/drawing/cmd_bmp.c index 4cb88d7..291b665 100644 --- a/project/commands/drawing/cmd_bmp.c +++ b/project/commands/drawing/cmd_bmp.c @@ -45,6 +45,7 @@ #if defined CFG_TFTLCD && defined CFG_SDCARD #include "drivers/displays/tft/lcd.h" #include "drivers/displays/tft/drawing.h" + #include "drivers/displays/tft/bmp.h" /**************************************************************************/ /*! @@ -63,7 +64,7 @@ void cmd_bmp(uint8_t argc, char **argv) // Render image bmp_error_t error; - error = drawBitmapImage(x, y, filename); + error = bmpDrawBitmap(x, y, filename); switch (error) { diff --git a/project/commands/drawing/cmd_button.c b/project/commands/drawing/cmd_button.c index 6dcd77c..bfa321b 100644 --- a/project/commands/drawing/cmd_button.c +++ b/project/commands/drawing/cmd_button.c @@ -47,7 +47,7 @@ #include "drivers/displays/tft/lcd.h" #include "drivers/displays/tft/drawing.h" #include "drivers/displays/tft/touchscreen.h" - #include "drivers/displays/tft/fonts/dejavusans9.h" + #include "drivers/displays/tft/controls/button.h" /**************************************************************************/ /*! @@ -60,7 +60,7 @@ /**************************************************************************/ void cmd_button(uint8_t argc, char **argv) { - int32_t x, y, w, h, border, fill, font; + int32_t x, y, w, h, fontcolor; // ToDo: Validate data! @@ -69,31 +69,29 @@ void cmd_button(uint8_t argc, char **argv) getNumber (argv[1], &y); getNumber (argv[2], &w); getNumber (argv[3], &h); - getNumber (argv[4], &border); - getNumber (argv[5], &fill); - getNumber (argv[6], &font); + getNumber (argv[4], &fontcolor); - if (argc == 7) + if (argc == 5) { // Render the button with no text - drawButton(x, y, w, h, &dejaVuSans9ptFontInfo, (uint16_t)border, (uint16_t)fill, (uint16_t)font, NULL); + buttonRender(x, y, w, h, (uint16_t)fontcolor, NULL, THEME_DEFAULT); } else { // Get text contents uint8_t i, len, *data_ptr, data[50]; data_ptr = data; - for (i = 0; i < argc - 7; i++) + for (i = 0; i < argc - 5; i++) { - len = strlen(argv[i + 7]); - strcpy((char *)data_ptr, (char *)argv[i + 7]); + len = strlen(argv[i + 5]); + strcpy((char *)data_ptr, (char *)argv[i + 5]); data_ptr += len; *data_ptr++ = ' '; } *data_ptr++ = '\0'; // Render the button with text - drawButton(x, y, w, h, &dejaVuSans9ptFontInfo, (uint16_t)border, (uint16_t)fill, (uint16_t)font, (char *)&data); + buttonRender(x, y, w, h, (uint16_t)fontcolor, (char *)&data, THEME_DEFAULT); } } diff --git a/project/commands/drawing/cmd_progress.c b/project/commands/drawing/cmd_progress.c index 0168e05..a8b9e56 100644 --- a/project/commands/drawing/cmd_progress.c +++ b/project/commands/drawing/cmd_progress.c @@ -45,6 +45,7 @@ #ifdef CFG_TFTLCD #include "drivers/displays/tft/lcd.h" #include "drivers/displays/tft/drawing.h" + #include "drivers/displays/tft/controls/progressbar.h" /**************************************************************************/ /*! @@ -53,7 +54,7 @@ /**************************************************************************/ void cmd_progress(uint8_t argc, char **argv) { - int32_t x, y, w, h, percent, border, borderfill, progressborder, progressfill; + int32_t x, y, w, h, percent, progressfill; // Convert supplied parameters getNumber (argv[0], &x); @@ -61,13 +62,10 @@ void cmd_progress(uint8_t argc, char **argv) getNumber (argv[2], &w); getNumber (argv[3], &h); getNumber (argv[4], &percent); - getNumber (argv[5], &border); - getNumber (argv[6], &borderfill); - getNumber (argv[7], &progressborder); - getNumber (argv[8], &progressfill); + getNumber (argv[5], &progressfill); // ToDo: Validate data! - if (border < 0 || border > 0xFFFF || borderfill < 0 || borderfill > 0xFFFF || progressborder < 0 || progressborder > 0xFFFF || progressfill < 0 || progressfill > 0xFFFF) + if (progressfill < 0 || progressfill > 0xFFFF) { printf("Invalid Color%s", CFG_PRINTF_NEWLINE); return; @@ -79,7 +77,7 @@ void cmd_progress(uint8_t argc, char **argv) } // Draw the progress bar (always use rounded corners for simplicity sake) - drawProgressBar(x, y, w, h, DRAW_ROUNDEDCORNERS_ALL, DRAW_ROUNDEDCORNERS_ALL, border, borderfill, progressborder, progressfill, percent); + progressbarRender(x, y, w, h, percent, progressfill, THEME_DEFAULT); } #endif diff --git a/project/commands/drawing/cmd_rectangle.c b/project/commands/drawing/cmd_rectangle.c index ff27504..05f039d 100644 --- a/project/commands/drawing/cmd_rectangle.c +++ b/project/commands/drawing/cmd_rectangle.c @@ -125,7 +125,7 @@ void cmd_rectangleround(uint8_t argc, char **argv) } else { - drawRectangleRounded(x1, y1, x2, y2, (uint16_t)c, radius, corners); + drawRoundedRectangleFilled(x1, y1, x2, y2, (uint16_t)c, radius, corners); } } diff --git a/project/commands/drawing/cmd_text.c b/project/commands/drawing/cmd_text.c index ad669d0..d25830f 100644 --- a/project/commands/drawing/cmd_text.c +++ b/project/commands/drawing/cmd_text.c @@ -46,13 +46,6 @@ #ifdef CFG_TFTLCD #include "drivers/displays/tft/lcd.h" #include "drivers/displays/tft/drawing.h" - #include "drivers/displays/tft/fonts/dejavusans9.h" - - // Only include this w/UART since there isn't enough space otherwise! - #ifdef CFG_PRINTF_UART - #include "drivers/displays/tft/fonts/dejavusansmono8.h" - #include "drivers/displays/tft/fonts/dejavusansbold9.h" - #endif /**************************************************************************/ /*! @@ -61,7 +54,7 @@ /**************************************************************************/ void cmd_text(uint8_t argc, char **argv) { - int32_t x, y, color; + int32_t x, y, bgcolor, fontcolor; int32_t font; uint8_t i, len; char *data_ptr, data[80]; @@ -69,37 +62,39 @@ void cmd_text(uint8_t argc, char **argv) // Convert supplied parameters getNumber (argv[0], &x); getNumber (argv[1], &y); - getNumber (argv[2], &color); - getNumber (argv[3], &font); + getNumber (argv[2], &bgcolor); + getNumber (argv[3], &fontcolor); + getNumber (argv[4], &font); // Get message contents data_ptr = data; - for (i=0; i