/************************* (C) COPYRIGHT 2007 RAISONANCE ********************** * File Name : Str8Line.c * Author : Dale Wheat * Date First Issued : * Description : Optimized straight line drawing functions for the LCD * Revision : *******************************************************************************/ /* Includes ------------------------------------------------------------------*/ #include "circle_api.h" /* Private defines -----------------------------------------------------------*/ #define NEEDEDVERSION "V 1.6" // Put here the minimal CircleOS version needed by your application #define ST7637_RAMWR 0x2C // from "lcd.h" /* Private variables ---------------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ enum MENU_code MsgVersion(void); /* Public variables ----------------------------------------------------------*/ const char Application_Name[8+1] = {"Str8Line"}; // max 8 characters for application name // LCD graphics functions /******************************************************************************* * * DRAW_HLine * *******************************************************************************/ /** * Draw a horizontal line on the LCD screen. * * @param[in] x0 The x-coordinate of the first line endpoint. * @param[in] y The y-coordinate of the line. * @param[in] x1 The x-coordinate of the second line endpoint. * @param[in] color The line color. * * @warning The (0,0) point is in the lower left corner. * **/ void DRAW_HLine ( u8 x0, u8 y, u8 x1, u16 color ) { u8 dx, i; if ( x0 > x1 ) { // swap x0, x1 so that x0 < x1 dx = x1; x1 = x0; x0 = dx; } dx = ( x1 - x0 ) + 1; // length of line // Select the area for LCD output. LCD_SetRect_For_Cmd( x0, y, dx, 1 ); // Select LCD output mode. LCD_SendLCDCmd( ST7637_RAMWR ); for ( i = 0; i < dx; i++ ) { LCD_SendLCDData ( color & 0xff ); // lower byte LCD_SendLCDData ( color >> 8 ); // upper byte } } /******************************************************************************* * * DRAW_VLine * *******************************************************************************/ /** * Draw a vertical line on the LCD screen. * * @param[in] x The x-coordinate of the line. * @param[in] y0 The y-coordinate of the first line endpoint. * @param[in] y1 The y-coordinate of the second line endpoint. * @param[in] color The line color. * * @warning The (0,0) point in in the lower left corner. * **/ void DRAW_VLine ( u8 x, u8 y0, u8 y1, u16 color ) { u8 dy, i; if ( y0 > y1 ) { // swap y0, y1 so that y0 < y1 dy = y1; y1 = y0; y0 = dy; } dy = ( y1 - y0 ) + 1; // length of line // Select the area for LCD output. LCD_SetRect_For_Cmd ( x, y0, 1, dy ); // Select LCD output mode. LCD_SendLCDCmd ( ST7637_RAMWR ); for ( i = 0; i < dy; i++ ) { LCD_SendLCDData ( color & 0xff ); // lower byte LCD_SendLCDData ( color >> 8 ); // upper byte } } /******************************************************************************* * * DRAW_Pixel * *******************************************************************************/ /** * Draw a single pixel on the LCD screen. * * @param[in] x The x-coordinate of the pixel. * @param[in] y The y-coordinate of the pixel. * @param[in] color The pixel color. * * @warning The (0,0) point in in the lower left corner. * **/ void DRAW_Pixel ( u8 x, u8 y, u16 color ) { // Select the area for LCD output. LCD_SetRect_For_Cmd ( x, y, 1, 1 ); // Select LCD output mode. LCD_SendLCDCmd ( ST7637_RAMWR ); LCD_SendLCDData ( color & 0xff ); // lower byte LCD_SendLCDData ( color >> 8 ); // upper byte } /******************************************************************************* * * DRAW_Rectangle * *******************************************************************************/ /** * Draw an unfilled rectangle on the LCD screen. * * @param[in] x0 The x-coordinate of the first corner. * @param[in] y0 The y-coordinate of the first corner. * @param[in] x1 The x-coordinate of the second corner. * @param[in] y1 The y-coordinate of the second corner. * @param[in] color The rectangle border color. * * @warning The (0,0) point is in the lower left corner. * **/ void DRAW_Rectangle ( u8 x0, u8 y0, u8 x1, u8 y1, u16 color ) { DRAW_HLine ( x0, y0, x1, color ); // bottom DRAW_VLine ( x1, y0, y1, color ); // right DRAW_HLine ( x1, y1, x0, color ); // top DRAW_VLine ( x0, y1, y0, color ); // bottom } /******************************************************************************* * * DRAW_RectangleFilled * *******************************************************************************/ /** * Draw a filled rectangle on the LCD screen. * * @param[in] x0 The x-coordinate of the first corner. * @param[in] y0 The y-coordinate of the first corner. * @param[in] x1 The x-coordinate of the second corner. * @param[in] y1 The y-coordinate of the second corner. * @param[in] color The rectangle color. * * @warning The (0,0) point is in the lower left corner. * **/ void DRAW_RectangleFilled ( u8 x0, u8 y0, u8 x1, u8 y1, u16 color ) { u8 dx, dy, i, j; // check for more optimized cases first if ( x0 == x1 ) { if ( y0 == y1 ) { DRAW_Pixel ( x0, y0, color ); // a single pixel } else { DRAW_VLine ( x0, y0, y1, color ); // a vertical line of single pixel width } } else { if ( y0 == y1 ) { DRAW_HLine ( x0, y0, x1, color ); // a horizontal line of single pixel width } else { if ( x0 > x1 ) { // swap x0, x1 so that x0 < x1 dx = x1; x1 = x0; x0 = dx; } dx = ( x1 - x0 ) + 1; // width of rectangle if ( y0 > y1 ) { // swap y0, y1 so that y0 < y1 dy = y1; y1 = y0; y0 = dy; } dy = ( y1 - y0 ) + 1; // height of rectangle // Select the area for LCD output. LCD_SetRect_For_Cmd ( x0, y0, dx, dy ); // Select LCD output mode. LCD_SendLCDCmd ( ST7637_RAMWR ); for ( i = 0; i < dx; i++ ) { for ( j = 0; j < dy; j++ ) { LCD_SendLCDData ( color & 0xff ); // lower byte LCD_SendLCDData ( color >> 8 ); // upper byte } } } } } /******************************************************************************* * * DRAW_DisplayStringCenter * *******************************************************************************/ /** * Draw a text string centered on the LCD screen. * * @param[in] y The y-coordinate of the bottom edge of the text. * @param[in] s A pointer to the string. * * @warning The (0,0) point is in the lower left corner. * **/ void DRAW_DisplayStringCenter ( u8 y, char *s ) { u8 x; x = ( SCREEN_WIDTH - ( strlen ( s ) * DRAW_GetCharMagniCoeff () * CHAR_WIDTH )) / 2; DRAW_DisplayString ( x, y, s, strlen ( s ) ); } /******************************************************************************* * Function Name : Application_Ini * Description : Initialization function of Circle_App. This function will * be called only once by CircleOS. * Input : None * Return : MENU_CONTINUE_COMMAND *******************************************************************************/ enum MENU_code Application_Ini ( void ) { u8 i; if(strcmp(UTIL_GetVersion(), NEEDEDVERSION) < 0) { return MsgVersion(); } // TODO: Write your application initialization function here. // draw some horizontal lines across the LCD for ( i = 0; i < 128; i++ ) DRAW_HLine ( 0, i, 127, RGB_BLACK ); for ( i = 0; i < 128; i++ ) DRAW_HLine ( 0, i, 127, RGB_WHITE ); // draw some vertical lines across the LCD for ( i = 0; i < 128; i++ ) DRAW_VLine ( i, 0, 127, RGB_BLACK ); for ( i = 0; i < 128; i++ ) DRAW_VLine ( i, 0, 127, RGB_WHITE ); // draw some individual pixels DRAW_Pixel ( 64, 64, RGB_BLACK ); // draw various rectangles DRAW_Rectangle ( 1, 1, 62, 62, RGB_RED ); DRAW_Rectangle ( 66, 1, 126, 62, RGB_YELLOW ); DRAW_Rectangle ( 1, 66, 62, 126, RGB_GREEN ); DRAW_Rectangle ( 66, 66, 126, 126, RGB_BLUE ); // draw some 'special case' rectangles DRAW_Rectangle ( 1, 64, 62, 64, RGB_BLACK ); // a horizontal line DRAW_Rectangle ( 64, 66, 64, 126, RGB_BLACK ); // a vertical line DRAW_Rectangle ( 64, 64, 64, 64, RGB_WHITE ); // a single pixel return MENU_CONTINUE_COMMAND; } /******************************************************************************* * Function Name : Application_Handler * Description : Management of the Circle_App. * * Input : None * Return : MENU_CONTINUE *******************************************************************************/ enum MENU_code Application_Handler ( void ) { // TODO: Write your application handling here. // This routine will get called repeatedly by CircleOS, until we // return MENU_LEAVE // exit the application once the button is pressed if ( BUTTON_GetState () == BUTTON_PUSHED ) { BUTTON_WaitForRelease (); BUTTON_SetMode ( BUTTON_ONOFF_FORMAIN ); return MENU_Quit (); } return MENU_CONTINUE; // Returning MENU_LEAVE will quit to CircleOS } /******************************************************************************* * Function Name : MsgVersion * Description : Display the current CircleOS version and the version needed * exit to main menu after 4 secondes * * Input : None * Return : MENU_CONTINUE *******************************************************************************/ enum MENU_code MsgVersion(void) { int hh,mm,ss,ss2; DRAW_DisplayString(5,60,"CircleOS",17); DRAW_DisplayString(80,60,UTIL_GetVersion(),3); DRAW_DisplayString(5,34,NEEDEDVERSION,3); DRAW_DisplayString(40,34," required",12); RTC_GetTime(&hh,&mm,&ss); ss = ss + 4; // 4 secondes ss = ss%60; do { RTC_GetTime(&hh,&mm,&ss2); }while (ss2 != ss); // do while < 4 secondes return MENU_REFRESH; }