Graphics Drawing Interface EZLCD4 display using serial

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gdiezl4.cpp Source File

gdiezl4.cpp

00001 /*****************************************************************************
00002 //   $Workfile: $
00003 //    Function: graphics drive - EZLCD04 implementation
00004 //      Author: Bill Basser
00005 //   $JustDate: $
00006 //   $Revision: $
00007 //
00008 //    This document contains proprietary data and information of
00009 //  Cyber Integration LLC.  It is the exclusive property of
00010 //  Cyber Integration, LLC and will not be disclosed in any form to
00011 //  any party without prior written permission of Cyber Integration, LLC.
00012 //  This document may not be reproduced or further used without the
00013 //  prior written permission of Cyber Integration, LLC.
00014 //
00015 //  Copyright (C) 2011 Cyber Integration, LLC. All Rights Reserved
00016 //
00017 //  $History: $
00018  *
00019  *****************************************************************************/
00020 
00021 // local includes
00022 #include "gdiezl4.h"
00023 
00024 // define the MSB/LSB extraction utilities
00025 #define    MSB(w)    (( w >> 8 ) & 0xFF )
00026 #define    LSB(w)    ( w & 0xFF )
00027 
00028 /******************************************************************************
00029 //    Function Name: GdiEzL4( tTx, tRx )
00030 //      Description: construction
00031 //            Entry: tTx = transmit pin
00032 //                   tRx = receive pin    
00033 //             Exit: none
00034 // Globals modified: none
00035 //  Locals modified: none
00036 //  Locals modified: none
00037 ******************************************************************************/
00038 GdiEzL4::GdiEzL4( PinName pinTx, PinName pinRx ) : m_serDisp( pinTx, pinRx )
00039 {
00040     // create the interface
00041     m_serDisp.baud( 115200 );
00042     m_serDisp.attach( this, &GdiEzL4::LocalCallback );
00043     
00044     // initialize
00045     m_serDisp.putc( EZ_BTP );
00046     m_serDisp.putc( ON );
00047 
00048     // turn the backlight on/clear screen to white
00049     BacklightCtl( ON );
00050     ClearScreen( RGB( 255, 255, 255 ));
00051 }
00052 
00053 /******************************************************************************
00054 //    Function Name: GdiEzL4( )
00055 //      Description: destruction
00056 //            Entry: none
00057 //             Exit: none
00058 // Globals modified: none
00059 //  Locals modified: none
00060 //  Locals modified: none
00061 ******************************************************************************/
00062 GdiEzL4::~GdiEzL4( void )
00063 {
00064 }
00065 
00066 /******************************************************************************
00067 //    Function Name: GdiBacklightCtl( bOffOn )
00068 //      Description: turn backlight off/on
00069 //            Entry: bOffOn
00070 //             Exit: none
00071 // Globals modified: none
00072 //  Locals modified: anBuffer, nBufLen
00073 ******************************************************************************/
00074 void GdiEzL4::BacklightCtl( BOOL bOffOn )
00075 {
00076     // set the correct state of the backlight
00077     m_serDisp.putc(( bOffOn ) ? EZ_LON : EZ_LOF );
00078 }
00079 
00080 /******************************************************************************
00081 //    Function Name: GdiClearScreen( wColor )
00082 //      Description: clear the screen to the color
00083 //            Entry: wColor = background color
00084 //             Exit: none
00085 // Globals modified: none
00086 //  Locals modified: anBuffer, nBufLen
00087 ******************************************************************************/
00088 void GdiEzL4::ClearScreen( U16 wColor )
00089 {
00090     // clear the screen
00091     m_serDisp.putc( EZ_FGC );
00092     m_serDisp.putc( LSB( wColor ));
00093     m_serDisp.putc( MSB( wColor ));
00094     m_serDisp.putc( EZ_CLS );
00095 }
00096 
00097 /******************************************************************************
00098 //    Function Name: GdiDrawRect( U16 wColor, U16 wSx, U8 nSy, U16 wWidth, U8 nHeight, BOOL bFill )
00099 //      Description: draw a rectangle
00100 //            Entry: wColor = rectangle color
00101 //                   wSx = starting X
00102 //                   nSy = starting Y
00103 //                   wWidth = width of box
00104 //                   nHeight = height of box
00105 //                   bFill = fill color
00106 //             Exit: none
00107 // Globals modified: none
00108 //  Locals modified: anBuffer, nBufLen
00109 ******************************************************************************/
00110 void GdiEzL4::DrawRect( U16 wColor, U16 wSx, U8 nSy, U16 wWidth, U8 nHeight, BOOL bFill )
00111 {
00112     U16 wEx = wSx + wWidth - 1;
00113     U8 nEy = nSy + nHeight - 1;
00114 
00115     // draw a rectangle
00116     m_serDisp.putc( EZ_FGC );
00117     m_serDisp.putc( LSB( wColor ));
00118     m_serDisp.putc( MSB( wColor ));
00119     m_serDisp.putc( EZ_SXY );
00120     m_serDisp.putc( MSB( wSx ));
00121     m_serDisp.putc( LSB( wSx ));
00122     m_serDisp.putc( nSy );
00123     m_serDisp.putc( ( bFill ) ? EZ_BXF : EZ_BOX );
00124     m_serDisp.putc( MSB( wEx ));
00125     m_serDisp.putc( LSB( wEx ));
00126     m_serDisp.putc( nEy );
00127 }
00128 
00129 /******************************************************************************
00130 //    Function Name: GdiDrawLine( wColor, wSx, nSy, wEx, nEy )
00131 //      Description: draw line
00132 //            Entry: wColor = color
00133 //                   wSx = starting X
00134 //                   nSy = starting Y
00135 //                   wEx = ending X
00136 //                   nEy = ending Y
00137 //             Exit: none
00138 // Globals modified: none
00139 //  Locals modified: anBuffer, nBufLen
00140 ******************************************************************************/
00141 void GdiEzL4::DrawLine( U16 wColor, U16 wSx, U8 nSy, U16 wEx, U8 nEy )
00142 {
00143     // set the color/set starting x/y
00144     m_serDisp.putc( EZ_FGC );
00145     m_serDisp.putc( LSB( wColor ));
00146     m_serDisp.putc( MSB( wColor ));
00147     m_serDisp.putc( EZ_SXY );
00148     m_serDisp.putc( MSB( wSx ));
00149     m_serDisp.putc( LSB( wSx ));
00150     m_serDisp.putc( nSy );
00151 
00152     // determine type of line
00153     if ( wSx == wEx )
00154     {
00155         // vertical line
00156         m_serDisp.putc( EZ_VLN );
00157         m_serDisp.putc( nEy );
00158     }
00159     else if ( nSy == nEy )
00160     {
00161         // horizontal line
00162         m_serDisp.putc( EZ_HLN );
00163         m_serDisp.putc( MSB( wEx ));
00164         m_serDisp.putc( LSB( wEx ));
00165     }
00166     else
00167     {
00168         // diagonal line
00169         m_serDisp.putc( EZ_LIN );
00170         m_serDisp.putc( MSB( wEx ));
00171         m_serDisp.putc( LSB( wEx ));
00172         m_serDisp.putc( nEy );
00173     }
00174 }
00175 
00176 
00177 /******************************************************************************
00178 //    Function Name: GdiDrawIcon( wSx, nSy, nIcon )
00179 //      Description: draw an icon
00180 //            Entry: wSx = starting X
00181 //                   nSy = starting Y
00182 //                   nIcon = icon number
00183 //             Exit: none
00184 // Globals modified: none
00185 //  Locals modified: anBuffer, nBufLen
00186 ******************************************************************************/
00187 void GdiEzL4::DrawIcon( U16 wSx, U8 nSy, U8 nIcon )
00188 {
00189     // draw a icon
00190     m_serDisp.putc( EZ_SXY );
00191     m_serDisp.putc( MSB( wSx ));
00192     m_serDisp.putc( LSB( wSx ));
00193     m_serDisp.putc( nSy );
00194     m_serDisp.putc( EZ_ICF );
00195     m_serDisp.putc( nIcon );
00196 }
00197 
00198 /******************************************************************************
00199 //    Function Name: GdiDrawChar( wColor, nFont, wSx, nSy, bBackground, nDir, cChar )
00200 //      Description: draw a character with the designated font, color
00201 //            Entry: wColor = color
00202 //                   nFont = font number
00203 //                   wSx = starting X
00204 //                   nSy = starting Y
00205 //                   bBackground = true if drawn on background
00206 //                   nDir = text direction
00207 //                   cChar = color
00208 //             Exit: none
00209 // Globals modified: none
00210 //  Locals modified: anBuffer, nBufLen
00211 ******************************************************************************/
00212 void GdiEzL4::DrawChar( U16 wColor, U8 nFont, U16 wSx, U8 nSy, BOOL bBackground, GDITXTDIR eDir, C8 cChar )
00213 {
00214     // set the color/set xy/set font/draw character
00215     m_serDisp.putc( EZ_FGC );
00216     m_serDisp.putc( LSB( wColor ));
00217     m_serDisp.putc( MSB( wColor ));
00218     m_serDisp.putc( EZ_SXY );
00219     m_serDisp.putc( MSB( wSx ));
00220     m_serDisp.putc( LSB( wSx ));
00221     m_serDisp.putc( nSy );
00222     m_serDisp.putc( EZ_FNT );
00223     m_serDisp.putc( nFont );
00224     m_serDisp.putc( EZ_TXN + ( U8 )eDir );
00225     m_serDisp.putc(( bBackground ) ? EZ_CHB : EZ_CHR );
00226     m_serDisp.putc( cChar );
00227 }
00228 
00229 /******************************************************************************
00230 //    Function Name: GdiDrawString( wFgcClr, wBgcClr, nFont, wSx, nSy, bBackground, eDir, szMsg )
00231 //      Description: draw a string with the desinated font, color
00232 //            Entry: wFgClr = foreground color
00233 //                   wBgClr = background color
00234 //                   nFont = font number
00235 //                   wSx = starting X
00236 //                   nSy = starting Y
00237 //                   bBackground = true if drawn on background
00238 //                   eDir = text direction
00239 //                   szMsg -> pointer to zero delimited string
00240 //             Exit: none
00241 // Globals modified: none
00242 //  Locals modified: anBuffer, nBufLen
00243 ******************************************************************************/
00244 void GdiEzL4::DrawString( U16 wFgClr, U16 wBgClr, U8 nFont, U16 wSx, U8 nSy, BOOL bBackground, GDITXTDIR eDir, PC8 pszMsg )
00245 {
00246     // if backgound
00247     if ( bBackground )
00248     {
00249         // set the background color
00250         m_serDisp.putc( EZ_BGC );
00251         m_serDisp.putc( LSB( wBgClr ));
00252         m_serDisp.putc( MSB( wBgClr ));
00253     }
00254 
00255     // set color/set sx/set font/send command
00256     m_serDisp.putc( EZ_FGC );
00257     m_serDisp.putc( LSB( wFgClr ));
00258     m_serDisp.putc( MSB( wFgClr ));
00259     m_serDisp.putc( EZ_SXY );
00260     m_serDisp.putc( MSB( wSx ));
00261     m_serDisp.putc( LSB( wSx ));
00262     m_serDisp.putc( nSy );
00263     m_serDisp.putc( EZ_FNT );
00264     m_serDisp.putc( nFont );
00265     m_serDisp.putc( EZ_TXN + ( U8 )eDir );
00266     m_serDisp.putc(( bBackground ) ? EZ_STB : EZ_STR );
00267 
00268     // copy the string till buffer size
00269     U8    nChar = 0;
00270     while (( nChar = *( pszMsg++ )) != '\0' )
00271         m_serDisp.putc( nChar );
00272 
00273     // stuff the delimiter
00274     m_serDisp.putc( nChar );
00275 }
00276 
00277 /*****************************************************************************
00278 //    Function Name: GdiDrawButton( nIndex, ptBtnDef )
00279 //      Description: draws a button
00280 //            Entry: nIndex = button index
00281 //                   ptBtnDef -> button definition structure
00282 //             Exit: none
00283 // Globals modified: none
00284 //  Locals modified: none
00285 ******************************************************************************/
00286 void GdiEzL4::DrawButton( U8 nBtnIdx, GDIBTNDEF* ptBtnDef )
00287 {
00288     // draw a button
00289     m_serDisp.putc( EZ_BTD );
00290     m_serDisp.putc( nBtnIdx );
00291     m_serDisp.putc( ptBtnDef->eInitalState );
00292     m_serDisp.putc( ptBtnDef->nUpIcon );
00293     m_serDisp.putc( ptBtnDef->nDnIcon );
00294     m_serDisp.putc( ptBtnDef->nDsIcon );
00295     m_serDisp.putc( MSB( ptBtnDef->wUpLfX ));
00296     m_serDisp.putc( LSB( ptBtnDef->wUpLfX ));
00297     m_serDisp.putc( ptBtnDef->nUpLfY );
00298     m_serDisp.putc( ptBtnDef->nTouchWidth );
00299     m_serDisp.putc( ptBtnDef->nTouchHeight );
00300 }
00301 
00302 /*****************************************************************************
00303 //    Function Name: GdiRemoveAllButton( )
00304 //      Description: remove all button
00305 //            Entry: none
00306 //             Exit: none
00307 // Globals modified: none
00308 //  Locals modified: none
00309 ******************************************************************************/
00310 void GdiEzL4::RemoveAllButtons( void )
00311 {
00312     // send the remove all buttons command
00313     m_serDisp.putc( EZ_BDL );
00314 }
00315 
00316 void GdiEzL4::PingDisplay( void )
00317 {
00318     // send a ping
00319     m_serDisp.putc( EZ_PNG );
00320 }
00321 
00322 void GdiEzL4::LocalCallback( void )
00323 {
00324     U8    nChar;
00325     
00326     // call the callback
00327     nChar = m_serDisp.getc( );
00328     m_pvFuncCallBack.call( nChar );
00329 }