⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util_lcd.c

📁 cc2x30_sw_examples: 适用于SmartRF05EB 支持CC2430、CC2530 提供Light_Switch及perTest例程。
💻 C
字号:
/*******************************************************************************
  Filename:     util_lcd.c

  Description:  Utility library for LCD control

*******************************************************************************/

/*******************************************************************************
* INCLUDES
*/
#include "hal_defs.h"
#include "hal_mcu.h"
#include "hal_board.h"
#include "hal_lcd.h"
#include "hal_joystick.h"
#include "hal_button.h"

#include "util_lcd.h"
#include "hal_rf.h"
#include "string.h"
#include "stdlib.h"

#ifndef LCD_NOT_SUPPORTED

/*******************************************************************************
* LOCAL VARIABLES
*/
// Logo
#if !defined(SRF04EB) && !defined(ASSY_EXP4618_CC2420)
static const char symbol1[8] = {0x03, 0x07, 0x0E, 0x0E, 0x1C, 0x19, 0x1B, 0x1B};
static const char symbol2[8] = {0x1B, 0x1B, 0x19, 0x1C, 0x0E, 0x0E, 0x07, 0x03};
static const char symbol3[8] = {0x18, 0x1E, 0x07, 0x03, 0x18, 0x1C, 0x06, 0x00};
static const char symbol4[8] = {0x00, 0x06, 0x1C, 0x18, 0x03, 0x07, 0x1E, 0x18};
#endif

const char ppBarGraphChar[8][8] = {
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F },
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F },
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F },
    { 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F },
    { 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F },
    { 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F },
    { 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F },
    { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F },
};

/*******************************************************************************
* GLOBAL FUNCTIONS
*/

#ifdef ASSY_EXP4618_CC2420
extern void halLcdWriteLine7Seg(const char *text);
#endif

#ifndef WIN32
/*******************************************************************************
* @fn          utilLcdMenuSelect
*
* @brief       Show a horisontally scrolled text menu on the LCD. Text lines given in
*               an array is shown in line 2 of the LCD, these lines are browsable.
*               The menu is navigated by using the joystick left and right, and press
*               S1 button to select an option. The function then returns the element number
*               in the given menu list that was chosen by the user.
*
* @param       ppMenu - pointer to list of texts to display for menu options
*              nMenuItems - number of menu options
*
* @return      uint8 - index to which of the menu items that was chosen
*/
uint8 utilMenuSelect(const menu_t* pMenu)
{
    uint8 index;
    uint8 updateLCD;
    #ifdef SRF04EB
    char pLcdLine2[30] = "    ";
    #endif

    index= 0;
    updateLCD= TRUE;            // Force update first time

    while (halButtonPushed()!=HAL_BUTTON_1) {
        // Joystick input: Reset = UP, Decr = LEFT, Incr = RIGHT
        if (halJoystickGetDir()==HAL_JOYSTICK_EVT_RIGHT) {
            index++;
            index %= pMenu->nItems;
            updateLCD = TRUE;
        } else if (halJoystickGetDir()==HAL_JOYSTICK_EVT_LEFT) {
            if(index == 0)
               index = pMenu->nItems-1;
            else
              index--;

            updateLCD = TRUE;
        }

        if(updateLCD) {
            // Display the updated value and arrows
            #ifdef SRF04EB
             // Make space for left arrow at left end of display
            strncpy(&(pLcdLine2[1]), (char*)pMenu->pMenuItems[index].szDescr, halLcdGetLineLength()-2);
            halLcdWriteLine(HAL_LCD_LINE_2, pLcdLine2);
            halLcdWriteChar(HAL_LCD_LINE_2, 0, '<');
            halLcdWriteChar(HAL_LCD_LINE_2, halLcdGetLineLength()-1, '>');
            #elif defined(ASSY_EXP4618_CC2420)
            halLcdWriteLine7Seg((char*)pMenu->pMenuItems[index].szDescr);
            #else
            halLcdWriteLine(HAL_LCD_LINE_2, (char*)pMenu->pMenuItems[index].szDescr);
            halLcdWriteChar(HAL_LCD_LINE_3, 0, '<');
            halLcdWriteChar(HAL_LCD_LINE_3, halLcdGetLineLength()-1, '>');
            #endif

            updateLCD = FALSE;
            HAL_DEBOUNCE(halJoystickGetDir()==HAL_JOYSTICK_EVT_CENTER);
        }
    }

    return pMenu->pMenuItems[index].value;
}




/*******************************************************************************
* @fn          utilPrintLogo
*
* @brief       Prints splash screen and logo
*
* @param       szAppName - String with name of application. Length of string must be
               no longer than (LCD_LINE_LENGTH - 5)
*
* @return      none
*/
void utilPrintLogo(char* szAppName)
{
    char lcdLine1[] = "   CCxxxx ( )";
    char lcdLine2[30]="   ";                    // Support up to 30 characters LCD line length
    uint8 lcdLineLength = halLcdGetLineLength();

    strncpy(&lcdLine1[5],utilChipIdToStr(halRfGetChipId()),4);
    lcdLine1[11] = (char)halRfGetChipVer() + '0';

    if( (strlen(szAppName)+strlen(lcdLine2)) <= lcdLineLength ) {
        strcat(lcdLine2, szAppName);
    }
    #ifdef SRF04EB
    halLcdWriteLine(HAL_LCD_LINE_1, lcdLine1);
    halLcdWriteLine(HAL_LCD_LINE_2, lcdLine2);

    #elif defined(ASSY_EXP4618_CC2420)
    halLcdWriteLine7Seg(lcdLine1+3);            // Only the chip name

    #else   // SRF05EB
    halLcdCreateSpecChar(0, symbol1);
    halLcdCreateSpecChar(1, symbol2);
    halLcdCreateSpecChar(2, symbol3);
    halLcdCreateSpecChar(3, symbol4);
    halLcdWriteLine(HAL_LCD_LINE_1, lcdLine1);
    halLcdWriteLine(HAL_LCD_LINE_2, lcdLine2);
    halLcdWriteLine(HAL_LCD_LINE_3, "   TI LPW");
    halLcdWriteSpecChar(HAL_LCD_LINE_1, 0, 0);
    halLcdWriteSpecChar(HAL_LCD_LINE_2, 0, 1);
    halLcdWriteSpecChar(HAL_LCD_LINE_1, 1, 2);
    halLcdWriteSpecChar(HAL_LCD_LINE_2, 1, 3);
    #endif
}

#endif

/*******************************************************************************
* @fn          utilPrintText
*
* @brief       Prints a text string across all lines of the display. Newlines
*              cause continuation on the next line.
*
* @param       pTxt - text to display
*
* @param       n - number of characters to print
*
* @return      0
*/
uint8 utilPrintText(uint8* pTxt, uint8 n)
{
    uint8 li[3];
    uint8  i, iLine, nChars, nLines;

    // Display properties
    nLines= halLcdGetNumLines();
    nChars= nLines*halLcdGetLineLength();

    // Split string on newlines
    i= 0;
    iLine= 0;
    li[0]= 0;
    li[1]= 0xff;
    li[2]= 0xff;

    while(i<n && i<nChars && iLine<nLines) {
        if (pTxt[i]=='\n') {
            iLine++;
            li[iLine]= i+1;
            pTxt[i]= '\0';
        }
        i++;
    }

    // Display
	for (iLine=0; iLine<nLines; iLine++) {
		if (li[iLine]!=0xFF)
			halLcdWriteLine(HAL_LCD_LINE_1+iLine, (char const*)pTxt + li[iLine] );
	}

    return 0;
}

/*******************************************************************************
* @fn         utilLoadBarGraph
*
* @brief      Load bar graph symbols on LCD. This function must be called before
*             utilLcdBarGraph can be used.
*
* @param      none
*
* @return     none
*/
void utilLoadBarGraph(void)
{
	uint8 n;

    // Load the bar graph characters
    for (n = 0; n < 8; n++) {
        halLcdCreateSpecChar(n, ppBarGraphChar[n]);
    }
}

/*******************************************************************************
* @fn         utilDisplayBarGraph
*
* @brief      Display bar graph on LCD
*
* @param      uint8 line - line number
*             uint8 col - column number
*             uint8 min - minimum value
*             uint8 value - value to display
*
* @return     int8 - sampled RSSI value
*/
void utilDisplayBarGraph(uint8 line, uint8 col, uint8 min, uint8 value)
{
    if (value <= min) {
        halLcdWriteChar(line, col, ' ');
    } else if (value >= min + 8) {
        halLcdWriteSpecChar(line, col, 7);
    } else {
        halLcdWriteSpecChar(line, col, value - min - 1);
    }
}

#endif

/*------------------------------------------------------------------------------
										  0ooo                                     
								ooo0	 (	 )                                     
								(	)	  ) /                                      
								 \ (	 (_/                                       
								  \_)		 Modify By:cuiqingwei [gary]                  
------------------------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -