Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
lcd_base.cpp@0:0099ad246127, 2015-05-12 (annotated)
- Committer:
- casval
- Date:
- Tue May 12 19:13:04 2015 +0000
- Revision:
- 0:0099ad246127
- Child:
- 1:1a3dd94e13cf
LCD libary for the landtiger board with ili9325 Controller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
casval | 0:0099ad246127 | 1 | /* |
casval | 0:0099ad246127 | 2 | * Copyright (C)2010-2012 Henning Karlsen. All right reserved. |
casval | 0:0099ad246127 | 3 | * Copyright (C)2012 Todor Todorov. |
casval | 0:0099ad246127 | 4 | * |
casval | 0:0099ad246127 | 5 | * This library is free software; you can redistribute it and/or |
casval | 0:0099ad246127 | 6 | * modify it under the terms of the GNU Lesser General Public |
casval | 0:0099ad246127 | 7 | * License as published by the Free Software Foundation; either |
casval | 0:0099ad246127 | 8 | * version 2.1 of the License, or (at your option) any later version. |
casval | 0:0099ad246127 | 9 | * |
casval | 0:0099ad246127 | 10 | * This library is distributed in the hope that it will be useful, |
casval | 0:0099ad246127 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
casval | 0:0099ad246127 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
casval | 0:0099ad246127 | 13 | * Lesser General Public License for more details. |
casval | 0:0099ad246127 | 14 | * |
casval | 0:0099ad246127 | 15 | * You should have received a copy of the GNU Lesser General Public |
casval | 0:0099ad246127 | 16 | * License along with this library; if not, write to: |
casval | 0:0099ad246127 | 17 | * |
casval | 0:0099ad246127 | 18 | * Free Software Foundation, Inc. |
casval | 0:0099ad246127 | 19 | * 51 Franklin St, 5th Floor, Boston, MA 02110-1301, USA |
casval | 0:0099ad246127 | 20 | * |
casval | 0:0099ad246127 | 21 | *********************************************************************/ |
casval | 0:0099ad246127 | 22 | #include "lcd_base.h" |
casval | 0:0099ad246127 | 23 | #include "helpers.h" |
casval | 0:0099ad246127 | 24 | |
casval | 0:0099ad246127 | 25 | // Task GUI und Restbus greifen auf den LCD zu, daher müssen die Funktionen durch ein Mutex geschützt werden |
casval | 0:0099ad246127 | 26 | Mutex lcd_mutex; |
casval | 0:0099ad246127 | 27 | |
casval | 0:0099ad246127 | 28 | LCD::LCD( unsigned short width, unsigned short height, PinName CS, PinName RS, PinName DIR, PinName EN, PinName LE, PinName BL, backlight_t blType, float defaultBacklight ) |
casval | 0:0099ad246127 | 29 | : _disp_width( width ), _disp_height( height ), _lcd_pin_cs( CS ), _lcd_pin_rs( RS ), _lcd_pin_dir(DIR), _lcd_pin_en(EN), _lcd_pin_le(LE), _bl_type( blType ) |
casval | 0:0099ad246127 | 30 | { |
casval | 0:0099ad246127 | 31 | SetForeground(); |
casval | 0:0099ad246127 | 32 | SetBackground(); |
casval | 0:0099ad246127 | 33 | _font = &TerminusFont; |
casval | 0:0099ad246127 | 34 | if ( defaultBacklight < 0 ) _bl_pwm_default = 0; |
casval | 0:0099ad246127 | 35 | else if ( defaultBacklight > 1.0 ) _bl_pwm_default = 1.0; |
casval | 0:0099ad246127 | 36 | else _bl_pwm_default = defaultBacklight; |
casval | 0:0099ad246127 | 37 | if ( BL != NC ) |
casval | 0:0099ad246127 | 38 | { |
casval | 0:0099ad246127 | 39 | if ( blType == Constant ) |
casval | 0:0099ad246127 | 40 | { |
casval | 0:0099ad246127 | 41 | _bl_pwm = 0; |
casval | 0:0099ad246127 | 42 | _lcd_pin_bl = new DigitalOut( BL ); |
casval | 0:0099ad246127 | 43 | } |
casval | 0:0099ad246127 | 44 | else |
casval | 0:0099ad246127 | 45 | { |
casval | 0:0099ad246127 | 46 | _lcd_pin_bl = 0; |
casval | 0:0099ad246127 | 47 | _bl_pwm = new PwmOut( BL ); |
casval | 0:0099ad246127 | 48 | _bl_pwm->period_ms( 8.33 ); // 120 Hz |
casval | 0:0099ad246127 | 49 | _bl_pwm_current = _bl_pwm_default; |
casval | 0:0099ad246127 | 50 | // initially off |
casval | 0:0099ad246127 | 51 | *_bl_pwm = 0; |
casval | 0:0099ad246127 | 52 | } |
casval | 0:0099ad246127 | 53 | |
casval | 0:0099ad246127 | 54 | } |
casval | 0:0099ad246127 | 55 | else |
casval | 0:0099ad246127 | 56 | { |
casval | 0:0099ad246127 | 57 | _lcd_pin_bl = 0; |
casval | 0:0099ad246127 | 58 | _bl_pwm = 0; |
casval | 0:0099ad246127 | 59 | } |
casval | 0:0099ad246127 | 60 | } |
casval | 0:0099ad246127 | 61 | |
casval | 0:0099ad246127 | 62 | void LCD::Sleep( void ) |
casval | 0:0099ad246127 | 63 | { |
casval | 0:0099ad246127 | 64 | if ( _lcd_pin_bl != 0 ) |
casval | 0:0099ad246127 | 65 | *_lcd_pin_bl = LOW; |
casval | 0:0099ad246127 | 66 | else if ( _bl_pwm != 0 ) |
casval | 0:0099ad246127 | 67 | *_bl_pwm = 0; |
casval | 0:0099ad246127 | 68 | } |
casval | 0:0099ad246127 | 69 | |
casval | 0:0099ad246127 | 70 | void LCD::WakeUp( void ) |
casval | 0:0099ad246127 | 71 | { |
casval | 0:0099ad246127 | 72 | if ( _lcd_pin_bl != 0 ) |
casval | 0:0099ad246127 | 73 | *_lcd_pin_bl = HIGH; |
casval | 0:0099ad246127 | 74 | else if ( _bl_pwm != 0 ) |
casval | 0:0099ad246127 | 75 | *_bl_pwm = _bl_pwm_current; |
casval | 0:0099ad246127 | 76 | } |
casval | 0:0099ad246127 | 77 | |
casval | 0:0099ad246127 | 78 | inline |
casval | 0:0099ad246127 | 79 | void LCD::SetForeground( unsigned int color ) |
casval | 0:0099ad246127 | 80 | { |
casval | 0:0099ad246127 | 81 | _foreground = color; |
casval | 0:0099ad246127 | 82 | } |
casval | 0:0099ad246127 | 83 | |
casval | 0:0099ad246127 | 84 | inline |
casval | 0:0099ad246127 | 85 | void LCD::SetBackground( unsigned int color ) |
casval | 0:0099ad246127 | 86 | { |
casval | 0:0099ad246127 | 87 | _background = color; |
casval | 0:0099ad246127 | 88 | } |
casval | 0:0099ad246127 | 89 | |
casval | 0:0099ad246127 | 90 | void LCD::SetFont( const font_t *font ) |
casval | 0:0099ad246127 | 91 | { |
casval | 0:0099ad246127 | 92 | _font = font; |
casval | 0:0099ad246127 | 93 | } |
casval | 0:0099ad246127 | 94 | |
casval | 0:0099ad246127 | 95 | inline |
casval | 0:0099ad246127 | 96 | unsigned short LCD::GetWidth( void ) |
casval | 0:0099ad246127 | 97 | { |
casval | 0:0099ad246127 | 98 | if ( _orientation == LANDSCAPE || _orientation == LANDSCAPE_REV ) return _disp_height; |
casval | 0:0099ad246127 | 99 | return _disp_width; |
casval | 0:0099ad246127 | 100 | } |
casval | 0:0099ad246127 | 101 | |
casval | 0:0099ad246127 | 102 | inline |
casval | 0:0099ad246127 | 103 | unsigned short LCD::GetHeight( void ) |
casval | 0:0099ad246127 | 104 | { |
casval | 0:0099ad246127 | 105 | if ( _orientation == LANDSCAPE || _orientation == LANDSCAPE_REV ) return _disp_width; |
casval | 0:0099ad246127 | 106 | return _disp_height; |
casval | 0:0099ad246127 | 107 | } |
casval | 0:0099ad246127 | 108 | |
casval | 0:0099ad246127 | 109 | inline |
casval | 0:0099ad246127 | 110 | uint8_t LCD::GetFontWidth( void ) |
casval | 0:0099ad246127 | 111 | { |
casval | 0:0099ad246127 | 112 | if ( _font != 0 ) return _font->Width; |
casval | 0:0099ad246127 | 113 | return 0; |
casval | 0:0099ad246127 | 114 | } |
casval | 0:0099ad246127 | 115 | |
casval | 0:0099ad246127 | 116 | inline |
casval | 0:0099ad246127 | 117 | uint8_t LCD::GetFontHeight( void ) |
casval | 0:0099ad246127 | 118 | { |
casval | 0:0099ad246127 | 119 | if ( _font != 0 ) return _font->Height; |
casval | 0:0099ad246127 | 120 | return 0; |
casval | 0:0099ad246127 | 121 | } |
casval | 0:0099ad246127 | 122 | |
casval | 0:0099ad246127 | 123 | void LCD::SetBacklightLevel( float level ) |
casval | 0:0099ad246127 | 124 | { |
casval | 0:0099ad246127 | 125 | switch ( _bl_type ) |
casval | 0:0099ad246127 | 126 | { |
casval | 0:0099ad246127 | 127 | case Direct: |
casval | 0:0099ad246127 | 128 | if ( _bl_pwm != 0 ) |
casval | 0:0099ad246127 | 129 | { |
casval | 0:0099ad246127 | 130 | *_bl_pwm = level; |
casval | 0:0099ad246127 | 131 | _bl_pwm_current = level; |
casval | 0:0099ad246127 | 132 | } |
casval | 0:0099ad246127 | 133 | break; |
casval | 0:0099ad246127 | 134 | |
casval | 0:0099ad246127 | 135 | case Indirect: |
casval | 0:0099ad246127 | 136 | break; |
casval | 0:0099ad246127 | 137 | case Constant: |
casval | 0:0099ad246127 | 138 | default: |
casval | 0:0099ad246127 | 139 | break; |
casval | 0:0099ad246127 | 140 | } |
casval | 0:0099ad246127 | 141 | } |
casval | 0:0099ad246127 | 142 | |
casval | 0:0099ad246127 | 143 | void LCD::FillScreen( int color ) |
casval | 0:0099ad246127 | 144 | { |
casval | 0:0099ad246127 | 145 | |
casval | 0:0099ad246127 | 146 | ////////////////////// |
casval | 0:0099ad246127 | 147 | lcd_mutex.lock(); |
casval | 0:0099ad246127 | 148 | ////////////////////// |
casval | 0:0099ad246127 | 149 | unsigned int rgb = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color; |
casval | 0:0099ad246127 | 150 | Activate(); |
casval | 0:0099ad246127 | 151 | ClearXY(); |
casval | 0:0099ad246127 | 152 | for ( int i = 0; i < ( ( _disp_width ) * ( _disp_height ) ); i++ ) |
casval | 0:0099ad246127 | 153 | SetPixelColor( rgb ); |
casval | 0:0099ad246127 | 154 | Deactivate(); |
casval | 0:0099ad246127 | 155 | /////////////////////////////// |
casval | 0:0099ad246127 | 156 | lcd_mutex.unlock(); |
casval | 0:0099ad246127 | 157 | /////////////////////////////// |
casval | 0:0099ad246127 | 158 | } |
casval | 0:0099ad246127 | 159 | |
casval | 0:0099ad246127 | 160 | inline |
casval | 0:0099ad246127 | 161 | void LCD::ClearScreen( void ) |
casval | 0:0099ad246127 | 162 | { |
casval | 0:0099ad246127 | 163 | FillScreen( -1 ); |
casval | 0:0099ad246127 | 164 | } |
casval | 0:0099ad246127 | 165 | |
casval | 0:0099ad246127 | 166 | void LCD::DrawPixel( unsigned short x, unsigned short y, int color ) |
casval | 0:0099ad246127 | 167 | { |
casval | 0:0099ad246127 | 168 | ////////////////////// |
casval | 0:0099ad246127 | 169 | lcd_mutex.lock(); |
casval | 0:0099ad246127 | 170 | ////////////////////// |
casval | 0:0099ad246127 | 171 | Activate(); |
casval | 0:0099ad246127 | 172 | SetXY( x, y, x, y ); |
casval | 0:0099ad246127 | 173 | SetPixelColor( color == -1 ? _background : |
casval | 0:0099ad246127 | 174 | color == -2 ? _foreground : color ); |
casval | 0:0099ad246127 | 175 | Deactivate(); |
casval | 0:0099ad246127 | 176 | ////////////////////// |
casval | 0:0099ad246127 | 177 | lcd_mutex.unlock(); |
casval | 0:0099ad246127 | 178 | ////////////////////// |
casval | 0:0099ad246127 | 179 | } |
casval | 0:0099ad246127 | 180 | |
casval | 0:0099ad246127 | 181 | void LCD::DrawLine( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
casval | 0:0099ad246127 | 182 | { |
casval | 0:0099ad246127 | 183 | |
casval | 0:0099ad246127 | 184 | ////////////////////// |
casval | 0:0099ad246127 | 185 | lcd_mutex.lock(); |
casval | 0:0099ad246127 | 186 | ////////////////////// |
casval | 0:0099ad246127 | 187 | double delta, tx, ty; |
casval | 0:0099ad246127 | 188 | |
casval | 0:0099ad246127 | 189 | if ( ( ( x2 - x1 ) < 0 ) ) |
casval | 0:0099ad246127 | 190 | { |
casval | 0:0099ad246127 | 191 | swap( ushort, x1, x2 ) |
casval | 0:0099ad246127 | 192 | swap( ushort, y1, y2 ) |
casval | 0:0099ad246127 | 193 | } |
casval | 0:0099ad246127 | 194 | if ( ( ( y2 - y1 ) < 0 ) ) |
casval | 0:0099ad246127 | 195 | { |
casval | 0:0099ad246127 | 196 | swap( ushort, x1, x2 ) |
casval | 0:0099ad246127 | 197 | swap( ushort, y1, y2 ) |
casval | 0:0099ad246127 | 198 | } |
casval | 0:0099ad246127 | 199 | |
casval | 0:0099ad246127 | 200 | if ( y1 == y2 ) |
casval | 0:0099ad246127 | 201 | { |
casval | 0:0099ad246127 | 202 | if ( x1 > x2 ) |
casval | 0:0099ad246127 | 203 | swap( ushort, x1, x2 ) |
casval | 0:0099ad246127 | 204 | DrawHLine( x1, y1, x2 - x1, color ); |
casval | 0:0099ad246127 | 205 | } |
casval | 0:0099ad246127 | 206 | else if ( x1 == x2 ) |
casval | 0:0099ad246127 | 207 | { |
casval | 0:0099ad246127 | 208 | if ( y1 > y2 ) |
casval | 0:0099ad246127 | 209 | swap( ushort, y1, y2 ) |
casval | 0:0099ad246127 | 210 | DrawVLine( x1, y1, y2 - y1, color ); |
casval | 0:0099ad246127 | 211 | } |
casval | 0:0099ad246127 | 212 | else |
casval | 0:0099ad246127 | 213 | { |
casval | 0:0099ad246127 | 214 | unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color; |
casval | 0:0099ad246127 | 215 | Activate(); |
casval | 0:0099ad246127 | 216 | if ( abs( x2 - x1 ) > abs( y2 - y1 ) ) |
casval | 0:0099ad246127 | 217 | { |
casval | 0:0099ad246127 | 218 | delta = ( double( y2 - y1 ) / double( x2 - x1 ) ); |
casval | 0:0099ad246127 | 219 | ty = double( y1 ); |
casval | 0:0099ad246127 | 220 | if ( x1 > x2 ) |
casval | 0:0099ad246127 | 221 | { |
casval | 0:0099ad246127 | 222 | for ( int i = x1; i >= x2; i-- ) |
casval | 0:0099ad246127 | 223 | { |
casval | 0:0099ad246127 | 224 | SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) ); |
casval | 0:0099ad246127 | 225 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 226 | ty = ty - delta; |
casval | 0:0099ad246127 | 227 | } |
casval | 0:0099ad246127 | 228 | } |
casval | 0:0099ad246127 | 229 | else |
casval | 0:0099ad246127 | 230 | { |
casval | 0:0099ad246127 | 231 | for ( int i = x1; i <= x2; i++ ) |
casval | 0:0099ad246127 | 232 | { |
casval | 0:0099ad246127 | 233 | SetXY( i, int( ty + 0.5 ), i, int( ty + 0.5 ) ); |
casval | 0:0099ad246127 | 234 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 235 | ty = ty + delta; |
casval | 0:0099ad246127 | 236 | } |
casval | 0:0099ad246127 | 237 | } |
casval | 0:0099ad246127 | 238 | } |
casval | 0:0099ad246127 | 239 | else |
casval | 0:0099ad246127 | 240 | { |
casval | 0:0099ad246127 | 241 | delta = ( float( x2 - x1 ) / float( y2 - y1 ) ); |
casval | 0:0099ad246127 | 242 | tx = float( x1 ); |
casval | 0:0099ad246127 | 243 | if ( y1 > y2 ) |
casval | 0:0099ad246127 | 244 | { |
casval | 0:0099ad246127 | 245 | for ( int i = y2 + 1; i > y1; i-- ) |
casval | 0:0099ad246127 | 246 | { |
casval | 0:0099ad246127 | 247 | SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i ); |
casval | 0:0099ad246127 | 248 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 249 | tx = tx + delta; |
casval | 0:0099ad246127 | 250 | } |
casval | 0:0099ad246127 | 251 | } |
casval | 0:0099ad246127 | 252 | else |
casval | 0:0099ad246127 | 253 | { |
casval | 0:0099ad246127 | 254 | for ( int i = y1; i < y2 + 1; i++ ) |
casval | 0:0099ad246127 | 255 | { |
casval | 0:0099ad246127 | 256 | SetXY( int( tx + 0.5 ), i, int( tx + 0.5 ), i ); |
casval | 0:0099ad246127 | 257 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 258 | tx = tx + delta; |
casval | 0:0099ad246127 | 259 | } |
casval | 0:0099ad246127 | 260 | } |
casval | 0:0099ad246127 | 261 | } |
casval | 0:0099ad246127 | 262 | Deactivate(); |
casval | 0:0099ad246127 | 263 | } |
casval | 0:0099ad246127 | 264 | /////////////////////////////// |
casval | 0:0099ad246127 | 265 | lcd_mutex.unlock(); |
casval | 0:0099ad246127 | 266 | /////////////////////////////// |
casval | 0:0099ad246127 | 267 | } |
casval | 0:0099ad246127 | 268 | |
casval | 0:0099ad246127 | 269 | void LCD::DrawRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
casval | 0:0099ad246127 | 270 | { |
casval | 0:0099ad246127 | 271 | ////////////////////// |
casval | 0:0099ad246127 | 272 | lcd_mutex.lock(); |
casval | 0:0099ad246127 | 273 | ////////////////////// |
casval | 0:0099ad246127 | 274 | |
casval | 0:0099ad246127 | 275 | if ( x1 > x2 ) swap( ushort, x1, x2 ) |
casval | 0:0099ad246127 | 276 | if ( y1 > y2 ) swap( ushort, y1, y2 ) |
casval | 0:0099ad246127 | 277 | |
casval | 0:0099ad246127 | 278 | DrawHLine( x1, y1, x2 - x1, color ); |
casval | 0:0099ad246127 | 279 | DrawHLine( x1, y2, x2 - x1, color ); |
casval | 0:0099ad246127 | 280 | DrawVLine( x1, y1, y2 - y1, color ); |
casval | 0:0099ad246127 | 281 | DrawVLine( x2, y1, y2 - y1, color ); |
casval | 0:0099ad246127 | 282 | |
casval | 0:0099ad246127 | 283 | /////////////////////////////// |
casval | 0:0099ad246127 | 284 | lcd_mutex.unlock(); |
casval | 0:0099ad246127 | 285 | /////////////////////////////// |
casval | 0:0099ad246127 | 286 | } |
casval | 0:0099ad246127 | 287 | |
casval | 0:0099ad246127 | 288 | void LCD::DrawRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
casval | 0:0099ad246127 | 289 | { |
casval | 0:0099ad246127 | 290 | if ( x1 > x2 ) swap( ushort, x1, x2 ) |
casval | 0:0099ad246127 | 291 | if ( y1 > y2 ) swap( ushort, y1, y2 ) |
casval | 0:0099ad246127 | 292 | |
casval | 0:0099ad246127 | 293 | if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 ) |
casval | 0:0099ad246127 | 294 | { |
casval | 0:0099ad246127 | 295 | DrawPixel( x1 + 1, y1 + 1, color ); |
casval | 0:0099ad246127 | 296 | DrawPixel( x2 - 1, y1 + 1, color ); |
casval | 0:0099ad246127 | 297 | DrawPixel( x1 + 1, y2 - 1, color ); |
casval | 0:0099ad246127 | 298 | DrawPixel( x2 - 1, y2 - 1, color ); |
casval | 0:0099ad246127 | 299 | DrawHLine( x1 + 2, y1, x2 - x1 - 4, color ); |
casval | 0:0099ad246127 | 300 | DrawHLine( x1 + 2, y2, x2 - x1 - 4, color ); |
casval | 0:0099ad246127 | 301 | DrawVLine( x1, y1 + 2, y2 - y1 - 4, color ); |
casval | 0:0099ad246127 | 302 | DrawVLine( x2, y1 + 2, y2 - y1 - 4, color ); |
casval | 0:0099ad246127 | 303 | } |
casval | 0:0099ad246127 | 304 | } |
casval | 0:0099ad246127 | 305 | |
casval | 0:0099ad246127 | 306 | void LCD::FillRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
casval | 0:0099ad246127 | 307 | { |
casval | 0:0099ad246127 | 308 | ////////////////////// |
casval | 0:0099ad246127 | 309 | lcd_mutex.lock(); |
casval | 0:0099ad246127 | 310 | ////////////////////// |
casval | 0:0099ad246127 | 311 | |
casval | 0:0099ad246127 | 312 | if ( x1 > x2 ) swap( ushort, x1, x2 ); |
casval | 0:0099ad246127 | 313 | if ( y1 > y2 ) swap( ushort, y1, y2 ); |
casval | 0:0099ad246127 | 314 | |
casval | 0:0099ad246127 | 315 | for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ ) |
casval | 0:0099ad246127 | 316 | { |
casval | 0:0099ad246127 | 317 | DrawHLine( x1, y1 + i, x2 - x1, color ); |
casval | 0:0099ad246127 | 318 | DrawHLine( x1, y2 - i, x2 - x1, color ); |
casval | 0:0099ad246127 | 319 | } |
casval | 0:0099ad246127 | 320 | /////////////////////////////// |
casval | 0:0099ad246127 | 321 | lcd_mutex.unlock(); |
casval | 0:0099ad246127 | 322 | /////////////////////////////// |
casval | 0:0099ad246127 | 323 | } |
casval | 0:0099ad246127 | 324 | |
casval | 0:0099ad246127 | 325 | void LCD::FillRoundRect( unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, int color ) |
casval | 0:0099ad246127 | 326 | { |
casval | 0:0099ad246127 | 327 | if ( x1 > x2 ) swap( ushort, x1, x2 ) |
casval | 0:0099ad246127 | 328 | if ( y1 > y2 ) swap( ushort, y1, y2 ) |
casval | 0:0099ad246127 | 329 | |
casval | 0:0099ad246127 | 330 | if ( ( x2 - x1 ) > 4 && ( y2 - y1 ) > 4 ) |
casval | 0:0099ad246127 | 331 | { |
casval | 0:0099ad246127 | 332 | for ( int i = 0; i < ( ( y2 - y1 ) / 2 ) + 1; i++ ) |
casval | 0:0099ad246127 | 333 | { |
casval | 0:0099ad246127 | 334 | switch ( i ) |
casval | 0:0099ad246127 | 335 | { |
casval | 0:0099ad246127 | 336 | case 0: |
casval | 0:0099ad246127 | 337 | DrawHLine( x1 + 2, y1 + i, x2 - x1 - 4, color ); |
casval | 0:0099ad246127 | 338 | DrawHLine( x1 + 2, y2 - i, x2 - x1 - 4, color ); |
casval | 0:0099ad246127 | 339 | break; |
casval | 0:0099ad246127 | 340 | |
casval | 0:0099ad246127 | 341 | case 1: |
casval | 0:0099ad246127 | 342 | DrawHLine( x1 + 1, y1 + i, x2 - x1 - 2, color ); |
casval | 0:0099ad246127 | 343 | DrawHLine( x1 + 1, y2 - i, x2 - x1 - 2, color ); |
casval | 0:0099ad246127 | 344 | break; |
casval | 0:0099ad246127 | 345 | |
casval | 0:0099ad246127 | 346 | default: |
casval | 0:0099ad246127 | 347 | DrawHLine( x1, y1 + i, x2 - x1, color ); |
casval | 0:0099ad246127 | 348 | DrawHLine( x1, y2 - i, x2 - x1, color ); |
casval | 0:0099ad246127 | 349 | break; |
casval | 0:0099ad246127 | 350 | } |
casval | 0:0099ad246127 | 351 | } |
casval | 0:0099ad246127 | 352 | } |
casval | 0:0099ad246127 | 353 | } |
casval | 0:0099ad246127 | 354 | |
casval | 0:0099ad246127 | 355 | void LCD::DrawCircle( unsigned short x, unsigned short y, unsigned short radius, int color ) |
casval | 0:0099ad246127 | 356 | { |
casval | 0:0099ad246127 | 357 | int f = 1 - radius; |
casval | 0:0099ad246127 | 358 | int ddF_x = 1; |
casval | 0:0099ad246127 | 359 | int ddF_y = -2 * radius; |
casval | 0:0099ad246127 | 360 | int x1 = 0; |
casval | 0:0099ad246127 | 361 | int y1 = radius; |
casval | 0:0099ad246127 | 362 | unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color; |
casval | 0:0099ad246127 | 363 | |
casval | 0:0099ad246127 | 364 | Activate(); |
casval | 0:0099ad246127 | 365 | SetXY( x, y + radius, x, y + radius ); |
casval | 0:0099ad246127 | 366 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 367 | SetXY( x, y - radius, x, y - radius ); |
casval | 0:0099ad246127 | 368 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 369 | SetXY( x + radius, y, x + radius, y ); |
casval | 0:0099ad246127 | 370 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 371 | SetXY( x - radius, y, x - radius, y ); |
casval | 0:0099ad246127 | 372 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 373 | |
casval | 0:0099ad246127 | 374 | while ( x1 < y1 ) |
casval | 0:0099ad246127 | 375 | { |
casval | 0:0099ad246127 | 376 | if ( f >= 0 ) |
casval | 0:0099ad246127 | 377 | { |
casval | 0:0099ad246127 | 378 | y1--; |
casval | 0:0099ad246127 | 379 | ddF_y += 2; |
casval | 0:0099ad246127 | 380 | f += ddF_y; |
casval | 0:0099ad246127 | 381 | } |
casval | 0:0099ad246127 | 382 | x1++; |
casval | 0:0099ad246127 | 383 | ddF_x += 2; |
casval | 0:0099ad246127 | 384 | f += ddF_x; |
casval | 0:0099ad246127 | 385 | SetXY( x + x1, y + y1, x + x1, y + y1 ); |
casval | 0:0099ad246127 | 386 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 387 | SetXY( x - x1, y + y1, x - x1, y + y1 ); |
casval | 0:0099ad246127 | 388 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 389 | SetXY( x + x1, y - y1, x + x1, y - y1 ); |
casval | 0:0099ad246127 | 390 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 391 | SetXY( x - x1, y - y1, x - x1, y - y1 ); |
casval | 0:0099ad246127 | 392 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 393 | SetXY( x + y1, y + x1, x + y1, y + x1 ); |
casval | 0:0099ad246127 | 394 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 395 | SetXY( x - y1, y + x1, x - y1, y + x1 ); |
casval | 0:0099ad246127 | 396 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 397 | SetXY( x + y1, y - x1, x + y1, y - x1 ); |
casval | 0:0099ad246127 | 398 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 399 | SetXY( x - y1, y - x1, x - y1, y - x1 ); |
casval | 0:0099ad246127 | 400 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 401 | } |
casval | 0:0099ad246127 | 402 | Deactivate(); |
casval | 0:0099ad246127 | 403 | } |
casval | 0:0099ad246127 | 404 | |
casval | 0:0099ad246127 | 405 | void LCD::FillCircle( unsigned short x, unsigned short y, unsigned short radius, int color ) |
casval | 0:0099ad246127 | 406 | { |
casval | 0:0099ad246127 | 407 | unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color; |
casval | 0:0099ad246127 | 408 | Activate(); |
casval | 0:0099ad246127 | 409 | for ( int y1 = -radius; y1 <= radius; y1++ ) |
casval | 0:0099ad246127 | 410 | for ( int x1 = -radius; x1 <= radius; x1++ ) |
casval | 0:0099ad246127 | 411 | if ( x1 * x1 + y1 * y1 <= radius * radius ) |
casval | 0:0099ad246127 | 412 | { |
casval | 0:0099ad246127 | 413 | SetXY( x + x1, y + y1, x + x1, y + y1 ); |
casval | 0:0099ad246127 | 414 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 415 | } |
casval | 0:0099ad246127 | 416 | Deactivate(); |
casval | 0:0099ad246127 | 417 | } |
casval | 0:0099ad246127 | 418 | |
casval | 0:0099ad246127 | 419 | void LCD::Print( const char *str, unsigned short x, unsigned short y, int fgColor, int bgColor, unsigned short deg ) |
casval | 0:0099ad246127 | 420 | { |
casval | 0:0099ad246127 | 421 | ////////////////////// |
casval | 0:0099ad246127 | 422 | lcd_mutex.lock(); |
casval | 0:0099ad246127 | 423 | ////////////////////// |
casval | 0:0099ad246127 | 424 | |
casval | 0:0099ad246127 | 425 | int stl, i; |
casval | 0:0099ad246127 | 426 | |
casval | 0:0099ad246127 | 427 | stl = strlen( str ); |
casval | 0:0099ad246127 | 428 | |
casval | 0:0099ad246127 | 429 | if ( x == RIGHT ) |
casval | 0:0099ad246127 | 430 | x = GetWidth() - ( stl * _font->Width ); |
casval | 0:0099ad246127 | 431 | if ( x == CENTER ) |
casval | 0:0099ad246127 | 432 | x = ( GetWidth() - ( stl * _font->Width ) ) / 2; |
casval | 0:0099ad246127 | 433 | |
casval | 0:0099ad246127 | 434 | for ( i = 0; i < stl; i++ ) |
casval | 0:0099ad246127 | 435 | if ( deg == 0 ) |
casval | 0:0099ad246127 | 436 | PrintChar( *str++, x + ( i * ( _font->Width ) ), y, fgColor, bgColor ); |
casval | 0:0099ad246127 | 437 | else |
casval | 0:0099ad246127 | 438 | RotateChar( *str++, x, y, i, fgColor, bgColor, deg ); |
casval | 0:0099ad246127 | 439 | /////////////////////////////// |
casval | 0:0099ad246127 | 440 | lcd_mutex.unlock(); |
casval | 0:0099ad246127 | 441 | /////////////////////////////// |
casval | 0:0099ad246127 | 442 | } |
casval | 0:0099ad246127 | 443 | |
casval | 0:0099ad246127 | 444 | void LCD::DrawBitmap( unsigned short x, unsigned short y, const bitmap_t* img, unsigned char scale ) |
casval | 0:0099ad246127 | 445 | { |
casval | 0:0099ad246127 | 446 | ////////////////////// |
casval | 0:0099ad246127 | 447 | lcd_mutex.lock(); |
casval | 0:0099ad246127 | 448 | ////////////////////// |
casval | 0:0099ad246127 | 449 | |
casval | 0:0099ad246127 | 450 | int tx, ty, tc, tsx, tsy; |
casval | 0:0099ad246127 | 451 | |
casval | 0:0099ad246127 | 452 | Activate(); |
casval | 0:0099ad246127 | 453 | if ( scale == 1 ) |
casval | 0:0099ad246127 | 454 | { |
casval | 0:0099ad246127 | 455 | SetXY( x, y, x + img->Width - 1, y + img->Height - 1 ); |
casval | 0:0099ad246127 | 456 | |
casval | 0:0099ad246127 | 457 | if ( img->Format == RGB16 ) |
casval | 0:0099ad246127 | 458 | { |
casval | 0:0099ad246127 | 459 | const unsigned short *pixel = ( const unsigned short* ) img->PixelData; |
casval | 0:0099ad246127 | 460 | for ( tc = 0; tc < ( img->Width * img->Height ); tc++ ) |
casval | 0:0099ad246127 | 461 | SetPixelColor( *pixel++, img->Format ); |
casval | 0:0099ad246127 | 462 | } |
casval | 0:0099ad246127 | 463 | else if ( img->Format == RGB18 ) |
casval | 0:0099ad246127 | 464 | { |
casval | 0:0099ad246127 | 465 | const unsigned int *pixel = ( const unsigned int* ) img->PixelData; |
casval | 0:0099ad246127 | 466 | for ( tc = 0; tc < ( img->Width * img->Height ); tc++ ) |
casval | 0:0099ad246127 | 467 | SetPixelColor( *pixel++, img->Format ); |
casval | 0:0099ad246127 | 468 | } |
casval | 0:0099ad246127 | 469 | } |
casval | 0:0099ad246127 | 470 | else |
casval | 0:0099ad246127 | 471 | { |
casval | 0:0099ad246127 | 472 | if ( img->Format == RGB16 ) |
casval | 0:0099ad246127 | 473 | { |
casval | 0:0099ad246127 | 474 | const unsigned short *pixel = ( const unsigned short* ) img->PixelData; |
casval | 0:0099ad246127 | 475 | |
casval | 0:0099ad246127 | 476 | for ( ty = 0; ty < img->Height; ty++ ) |
casval | 0:0099ad246127 | 477 | { |
casval | 0:0099ad246127 | 478 | SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale ); |
casval | 0:0099ad246127 | 479 | for ( tsy = 0; tsy < scale; tsy++ ) |
casval | 0:0099ad246127 | 480 | { |
casval | 0:0099ad246127 | 481 | for ( tx = 0; tx < img->Width; tx++ ) |
casval | 0:0099ad246127 | 482 | { |
casval | 0:0099ad246127 | 483 | for ( tsx = 0; tsx < scale; tsx++ ) |
casval | 0:0099ad246127 | 484 | SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format ); |
casval | 0:0099ad246127 | 485 | } |
casval | 0:0099ad246127 | 486 | } |
casval | 0:0099ad246127 | 487 | } |
casval | 0:0099ad246127 | 488 | } |
casval | 0:0099ad246127 | 489 | else if ( img->Format == RGB18 ) |
casval | 0:0099ad246127 | 490 | { |
casval | 0:0099ad246127 | 491 | const unsigned int *pixel = ( const unsigned int* ) img->PixelData; |
casval | 0:0099ad246127 | 492 | |
casval | 0:0099ad246127 | 493 | for ( ty = 0; ty < img->Height; ty++ ) |
casval | 0:0099ad246127 | 494 | { |
casval | 0:0099ad246127 | 495 | SetXY( x, y + ( ty * scale ), x + ( ( img->Width * scale ) - 1 ), y + ( ty * scale ) + scale ); |
casval | 0:0099ad246127 | 496 | for ( tsy = 0; tsy < scale; tsy++ ) |
casval | 0:0099ad246127 | 497 | { |
casval | 0:0099ad246127 | 498 | for ( tx = 0; tx < img->Width; tx++ ) |
casval | 0:0099ad246127 | 499 | { |
casval | 0:0099ad246127 | 500 | for ( tsx = 0; tsx < scale; tsx++ ) |
casval | 0:0099ad246127 | 501 | SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format ); |
casval | 0:0099ad246127 | 502 | } |
casval | 0:0099ad246127 | 503 | } |
casval | 0:0099ad246127 | 504 | } |
casval | 0:0099ad246127 | 505 | } |
casval | 0:0099ad246127 | 506 | } |
casval | 0:0099ad246127 | 507 | Deactivate(); |
casval | 0:0099ad246127 | 508 | /////////////////////////////// |
casval | 0:0099ad246127 | 509 | lcd_mutex.unlock(); |
casval | 0:0099ad246127 | 510 | /////////////////////////////// |
casval | 0:0099ad246127 | 511 | } |
casval | 0:0099ad246127 | 512 | |
casval | 0:0099ad246127 | 513 | void LCD::DrawBitmap( unsigned short x, unsigned short y, const bitmap_t* img, unsigned short deg, unsigned short rox, unsigned short roy ) |
casval | 0:0099ad246127 | 514 | { |
casval | 0:0099ad246127 | 515 | ////////////////////// |
casval | 0:0099ad246127 | 516 | lcd_mutex.lock(); |
casval | 0:0099ad246127 | 517 | ////////////////////// |
casval | 0:0099ad246127 | 518 | |
casval | 0:0099ad246127 | 519 | int tx, ty, newx, newy; |
casval | 0:0099ad246127 | 520 | double radian; |
casval | 0:0099ad246127 | 521 | radian = deg * 0.0175; |
casval | 0:0099ad246127 | 522 | |
casval | 0:0099ad246127 | 523 | if ( deg == 0 ) |
casval | 0:0099ad246127 | 524 | DrawBitmap( x, y, img ); |
casval | 0:0099ad246127 | 525 | else |
casval | 0:0099ad246127 | 526 | { |
casval | 0:0099ad246127 | 527 | Activate(); |
casval | 0:0099ad246127 | 528 | |
casval | 0:0099ad246127 | 529 | if ( img->Format == RGB16 ) |
casval | 0:0099ad246127 | 530 | { |
casval | 0:0099ad246127 | 531 | const unsigned short *pixel = ( const unsigned short* ) img->PixelData; |
casval | 0:0099ad246127 | 532 | |
casval | 0:0099ad246127 | 533 | for ( ty = 0; ty < img->Height; ty++ ) |
casval | 0:0099ad246127 | 534 | for ( tx = 0; tx < img->Width; tx++ ) |
casval | 0:0099ad246127 | 535 | { |
casval | 0:0099ad246127 | 536 | newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) ); |
casval | 0:0099ad246127 | 537 | newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) ); |
casval | 0:0099ad246127 | 538 | |
casval | 0:0099ad246127 | 539 | SetXY( newx, newy, newx, newy ); |
casval | 0:0099ad246127 | 540 | SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format ); |
casval | 0:0099ad246127 | 541 | } |
casval | 0:0099ad246127 | 542 | } |
casval | 0:0099ad246127 | 543 | else if ( img->Format == RGB18 ) |
casval | 0:0099ad246127 | 544 | { |
casval | 0:0099ad246127 | 545 | const unsigned int *pixel = ( const unsigned int* ) img->PixelData; |
casval | 0:0099ad246127 | 546 | |
casval | 0:0099ad246127 | 547 | for ( ty = 0; ty < img->Height; ty++ ) |
casval | 0:0099ad246127 | 548 | for ( tx = 0; tx < img->Width; tx++ ) |
casval | 0:0099ad246127 | 549 | { |
casval | 0:0099ad246127 | 550 | newx = x + rox + ( ( ( tx - rox ) * cos( radian ) ) - ( ( ty - roy ) * sin( radian ) ) ); |
casval | 0:0099ad246127 | 551 | newy = y + roy + ( ( ( ty - roy ) * cos( radian ) ) + ( ( tx - rox ) * sin( radian ) ) ); |
casval | 0:0099ad246127 | 552 | |
casval | 0:0099ad246127 | 553 | SetXY( newx, newy, newx, newy ); |
casval | 0:0099ad246127 | 554 | SetPixelColor( pixel[ ( ty * img->Width ) + tx ], img->Format ); |
casval | 0:0099ad246127 | 555 | } |
casval | 0:0099ad246127 | 556 | } |
casval | 0:0099ad246127 | 557 | Deactivate(); |
casval | 0:0099ad246127 | 558 | } |
casval | 0:0099ad246127 | 559 | ////////////////////// |
casval | 0:0099ad246127 | 560 | lcd_mutex.unlock(); |
casval | 0:0099ad246127 | 561 | ////////////////////// |
casval | 0:0099ad246127 | 562 | } |
casval | 0:0099ad246127 | 563 | |
casval | 0:0099ad246127 | 564 | inline |
casval | 0:0099ad246127 | 565 | void LCD::Activate( void ) |
casval | 0:0099ad246127 | 566 | { |
casval | 0:0099ad246127 | 567 | _lcd_pin_cs = LOW; |
casval | 0:0099ad246127 | 568 | } |
casval | 0:0099ad246127 | 569 | |
casval | 0:0099ad246127 | 570 | inline |
casval | 0:0099ad246127 | 571 | void LCD::Deactivate( void ) |
casval | 0:0099ad246127 | 572 | { |
casval | 0:0099ad246127 | 573 | _lcd_pin_cs = HIGH; |
casval | 0:0099ad246127 | 574 | } |
casval | 0:0099ad246127 | 575 | |
casval | 0:0099ad246127 | 576 | inline |
casval | 0:0099ad246127 | 577 | void LCD::WriteCmdData( unsigned short cmd, unsigned short data ) |
casval | 0:0099ad246127 | 578 | { |
casval | 0:0099ad246127 | 579 | WriteCmd( cmd ); |
casval | 0:0099ad246127 | 580 | WriteData( data ); |
casval | 0:0099ad246127 | 581 | } |
casval | 0:0099ad246127 | 582 | |
casval | 0:0099ad246127 | 583 | inline |
casval | 0:0099ad246127 | 584 | void LCD::ClearXY( void ) |
casval | 0:0099ad246127 | 585 | { |
casval | 0:0099ad246127 | 586 | SetXY( 0, 0, GetWidth() - 1, GetHeight() - 1 ); |
casval | 0:0099ad246127 | 587 | } |
casval | 0:0099ad246127 | 588 | |
casval | 0:0099ad246127 | 589 | void LCD::DrawHLine( unsigned short x, unsigned short y, unsigned short len, int color ) |
casval | 0:0099ad246127 | 590 | { |
casval | 0:0099ad246127 | 591 | unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color; |
casval | 0:0099ad246127 | 592 | |
casval | 0:0099ad246127 | 593 | Activate(); |
casval | 0:0099ad246127 | 594 | SetXY( x, y, x + len, y ); |
casval | 0:0099ad246127 | 595 | for ( int i = 0; i < len + 1; i++ ) |
casval | 0:0099ad246127 | 596 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 597 | Deactivate(); |
casval | 0:0099ad246127 | 598 | } |
casval | 0:0099ad246127 | 599 | |
casval | 0:0099ad246127 | 600 | void LCD::DrawVLine( unsigned short x, unsigned short y, unsigned short len, int color ) |
casval | 0:0099ad246127 | 601 | { |
casval | 0:0099ad246127 | 602 | unsigned int usedColor = color == -1 ? _background : color == -2 ? _foreground : ( unsigned int ) color; |
casval | 0:0099ad246127 | 603 | |
casval | 0:0099ad246127 | 604 | Activate(); |
casval | 0:0099ad246127 | 605 | SetXY( x, y, x, y + len ); |
casval | 0:0099ad246127 | 606 | for ( int i = 0; i < len; i++ ) |
casval | 0:0099ad246127 | 607 | SetPixelColor( usedColor ); |
casval | 0:0099ad246127 | 608 | Deactivate(); |
casval | 0:0099ad246127 | 609 | } |
casval | 0:0099ad246127 | 610 | |
casval | 0:0099ad246127 | 611 | void LCD::PrintChar( char c, unsigned short x, unsigned short y, int fgColor, int bgColor ) |
casval | 0:0099ad246127 | 612 | { |
casval | 0:0099ad246127 | 613 | uint8_t i, ch; |
casval | 0:0099ad246127 | 614 | uint16_t j; |
casval | 0:0099ad246127 | 615 | unsigned int usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned int ) fgColor; |
casval | 0:0099ad246127 | 616 | unsigned int usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned int ) bgColor; |
casval | 0:0099ad246127 | 617 | |
casval | 0:0099ad246127 | 618 | uint16_t totalCharBytes = ( _font->Width * _font->Height ) / 8; |
casval | 0:0099ad246127 | 619 | int16_t position = _font->Position[ c - _font->Offset ]; |
casval | 0:0099ad246127 | 620 | if ( position == -1 ) position = 0; // will print space character |
casval | 0:0099ad246127 | 621 | |
casval | 0:0099ad246127 | 622 | Activate(); |
casval | 0:0099ad246127 | 623 | |
casval | 0:0099ad246127 | 624 | SetXY( x, y, x + _font->Width - 1, y + _font->Height - 1 ); |
casval | 0:0099ad246127 | 625 | |
casval | 0:0099ad246127 | 626 | for ( j = 0; j < totalCharBytes; j++ ) |
casval | 0:0099ad246127 | 627 | { |
casval | 0:0099ad246127 | 628 | ch = _font->Data[ position ]; |
casval | 0:0099ad246127 | 629 | for ( i = 0; i < 8; i++ ) |
casval | 0:0099ad246127 | 630 | { |
casval | 0:0099ad246127 | 631 | if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) SetPixelColor( usedColorFG ); |
casval | 0:0099ad246127 | 632 | else SetPixelColor( usedColorBG ); |
casval | 0:0099ad246127 | 633 | } |
casval | 0:0099ad246127 | 634 | position++; |
casval | 0:0099ad246127 | 635 | } |
casval | 0:0099ad246127 | 636 | Deactivate(); |
casval | 0:0099ad246127 | 637 | } |
casval | 0:0099ad246127 | 638 | |
casval | 0:0099ad246127 | 639 | void LCD::RotateChar( char c, unsigned short x, unsigned short y, int pos, int fgColor, int bgColor, unsigned short deg ) |
casval | 0:0099ad246127 | 640 | { |
casval | 0:0099ad246127 | 641 | uint8_t i, j, ch; |
casval | 0:0099ad246127 | 642 | int newx, newy; |
casval | 0:0099ad246127 | 643 | double radian; |
casval | 0:0099ad246127 | 644 | radian = deg * 0.0175; |
casval | 0:0099ad246127 | 645 | |
casval | 0:0099ad246127 | 646 | unsigned int usedColorFG = fgColor == -1 ? _background : fgColor == -2 ? _foreground : ( unsigned int ) fgColor; |
casval | 0:0099ad246127 | 647 | unsigned int usedColorBG = bgColor == -1 ? _background : bgColor == -2 ? _foreground : ( unsigned int ) bgColor; |
casval | 0:0099ad246127 | 648 | |
casval | 0:0099ad246127 | 649 | int16_t position = _font->Position[ c - _font->Offset ]; |
casval | 0:0099ad246127 | 650 | if ( position == -1 ) position = 0; // will print space character |
casval | 0:0099ad246127 | 651 | |
casval | 0:0099ad246127 | 652 | Activate(); |
casval | 0:0099ad246127 | 653 | |
casval | 0:0099ad246127 | 654 | for ( j = 0; j < _font->Height; j++ ) |
casval | 0:0099ad246127 | 655 | { |
casval | 0:0099ad246127 | 656 | for ( uint16_t zz = 0; zz < ( ( double ) _font->Width / 8 ); zz++ ) |
casval | 0:0099ad246127 | 657 | { |
casval | 0:0099ad246127 | 658 | ch = _font->Data[ position + zz ]; |
casval | 0:0099ad246127 | 659 | for ( i = 0; i < 8; i++ ) |
casval | 0:0099ad246127 | 660 | { |
casval | 0:0099ad246127 | 661 | newx = x + ( ( ( i + ( zz * 8 ) + ( pos * _font->Width ) ) * cos( radian ) ) - ( ( j ) * sin( radian ) ) ); |
casval | 0:0099ad246127 | 662 | newy = y + ( ( ( j ) * cos( radian ) ) + ( ( i + ( zz * 8 ) + ( pos * _font->Width ) ) * sin( radian ) ) ); |
casval | 0:0099ad246127 | 663 | |
casval | 0:0099ad246127 | 664 | SetXY( newx, newy, newx + 1, newy + 1 ); |
casval | 0:0099ad246127 | 665 | |
casval | 0:0099ad246127 | 666 | if ( ( ch & ( 1 << ( 7 - i ) ) ) != 0 ) SetPixelColor( usedColorFG ); |
casval | 0:0099ad246127 | 667 | else SetPixelColor( usedColorBG ); |
casval | 0:0099ad246127 | 668 | } |
casval | 0:0099ad246127 | 669 | } |
casval | 0:0099ad246127 | 670 | position += ( _font->Width / 8 ); |
casval | 0:0099ad246127 | 671 | } |
casval | 0:0099ad246127 | 672 | |
casval | 0:0099ad246127 | 673 | Deactivate(); |
casval | 0:0099ad246127 | 674 | } |
casval | 0:0099ad246127 | 675 |