Ejemplo n.º 1
0
/*****************************************************************************
 * @fn        printHeader
 *
 * @brief     Prints the header of the menu system on the top page/line on the
 *            LCD. This includes title and navigation item numbers in right 
 *            corner. Also prints an underline.
 *
 * input parameters
 *
 * @param     pMenu   - The menu struct which is going to be displayed
 */
static void printHeader(const menu_t *pMenu)
{
  /* displaying navigation data in the top
   * each of them returns the amount of pixels they occupie
   */
   
  uint8 occupied = printNavNumbers(pMenu);   /* numbers in top right corner */

  /* determining prefered title depending on where in the menu the user is */
  char *prefTitle;
  if(pMenu->pTextHeader)
  {
    prefTitle = pMenu->pTextHeader;
  }
  else if(pMenu->pParentMenu)
  {
    menu_t *pTopMenu = menuTop(pMenu);
    int8 nCurrentItem = pTopMenu->nCurrentItem;
    prefTitle=pTopMenu->pItems[nCurrentItem].pTextDescription;
  }
  else
  {
    prefTitle = "Main Menu";
  }

  /* calculating maximal width for menu title and the threshold to when the
   * title is too big to be centered and must be skeewed. Both are specified
   * in number of characters, not pixels.
   */
  uint8 maxWidth = (LCD_COLS-occupied)/LCD_CHAR_WIDTH-1;
  uint8 skewThreshold = (LCD_COLS-2*occupied)/LCD_CHAR_WIDTH-2;
  
  /* truncates title as necessary */
  char title[22];
  uint8 prefTitleLen = lcdGetStringLength(prefTitle);
  uint8 width = ( prefTitleLen<maxWidth ? prefTitleLen : maxWidth );
  for(uint8 i=0;i<width;i++)
  {
    title[i]=prefTitle[i];
  }
  title[width] = '\0';

  /* writes title */
  if(width<=skewThreshold)
  { 
    /* title's not too big to be centered */
    lcdBufferPrintStringAligned(0, title,eLcdAlignCenter,eLcdPage0);
    //lcdBufferPrintStringCentered(0,title,0);
  }
  else
  {
    /* title's too big to be centered. Skew title */
    int8 pos = LCD_COLS-occupied-LCD_CHAR_WIDTH-width*LCD_CHAR_WIDTH;
    lcdBufferPrintString(0,title,pos,eLcdPage0);
  }

  /* header underline */
  lcdBufferSetHLine(0,0,LCD_COLS-1,7);

}
Ejemplo n.º 2
0
/**************************************************************************************************
 * @fn      HalLcdWriteStringAligned
 *
 * @brief   Write a string to the LCD with the specified alignment
 *
 * @param   str       - pointer to the string that will be displayed
 *          alignment - the alignment to give to the string.  Use the enumerated values:
 *                      \li \b eLcdAlignLeft
 *                      \li \b eLcdAlignCenter
 *                      \li \b LCD_ALIGN_RIGHT
 *          line      - line number to display
 *
 * @return  None
 **************************************************************************************************/
void HalLcdWriteStringAligned( char *str, uint8 alignment, uint8 line)
{
#if (HAL_LCD == TRUE)
  if ( line <= HAL_LCD_LINE_8)
  {
    // Write aligned string to buffer.
    lcdBufferPrintStringAligned( BSP_DEFAULT_BUFFER, str, (tLcdAlign) alignment, (tLcdPage) (line - 1));
  
    // Write to LCD.
    lcdSendBuffer(BSP_DEFAULT_BUFFER);
  }
#endif // (HAL_LCD == TRUE)
}
Ejemplo n.º 3
0
/**************************************************************************//**
* @brief    Main function of example.
******************************************************************************/
void main(void)
{
    uint8_t ui8KeyBm = 0;
    uint_fast16_t ui16Cnt = 0;
    uint8_t ui8Byte = APP_TX_BYTE;

    //
    // Initialize clocks and board I/O
    //
    bspInit(BSP_SYS_CLK_SPD);

    //
    // Set LED1 to indicate life
    //
    bspLedSet(BSP_LED_1);

    //
    // Initialize key driver
    //
    bspKeyInit(BSP_KEY_MODE_ISR);
    bspKeyIntEnable(BSP_KEY_SELECT|BSP_KEY_UP);

    //
    // Initialize UART to USB MCU
    //
    bspUartBufInit(pui8TxBuf, sizeof(pui8TxBuf), pui8RxBuf, sizeof(pui8RxBuf));

    //
    // Application must register the UART interrupt handler
    //
    UARTIntRegister(BSP_UART_BASE, &appUartIsr);

    //
    // Open UART connection
    //
    if(bspUartOpen(eBaudRate115200) != BSP_UART_SUCCESS)
    {
        //
        // Failed to initialize UART handler
        //
        bspAssert();
    }

    //
    // Initialize SPI interface to LCD, configure LCD, and display information.
    //
    bspSpiInit(BSP_SPI_CLK_SPD);
    lcdInit();
    lcdBufferPrintStringAligned(0, "UART example", eLcdAlignCenter, eLcdPage0);
    lcdBufferInvertPage(0, 0,127, eLcdPage0);
    lcdBufferPrintString(0, "Baud rate   :", 6, eLcdPage2);
    lcdBufferPrintIntAligned(0, bspUartBaudRateGet(), eLcdAlignRight, eLcdPage2);
    lcdBufferPrintString(0, "Format      :", 6, eLcdPage3);
    lcdBufferPrintStringAligned(0, "8-N-1", eLcdAlignRight, eLcdPage3);
    lcdBufferPrintString(0, "Flow control:", 6, eLcdPage4);
    lcdBufferPrintStringAligned(0, "No", eLcdAlignRight, eLcdPage4);
    lcdBufferPrintStringAligned(0, "Transmit: UP key", eLcdAlignRight, eLcdPage6);
    lcdBufferPrintStringAligned(0, "SELECT to toggle mode", eLcdAlignCenter, eLcdPage7);
    lcdBufferInvertPage(0, 0,127, eLcdPage7);
    lcdSendBuffer(0);

    //
    // Enable global interrupts
    //
    IntMasterEnable();

    while(1)
    {
        ui8KeyBm = bspKeyPushed(BSP_KEY_ALL);

        if(BSP_KEY_SELECT & ui8KeyBm)
        {
            //
            // Change mode
            //
            bRepeaterMode ^= 1;
            bspLedToggle(BSP_LED_3);

            //
            // Update LCD for the new mode
            //
            lcdBufferClearPart(0, 0,127, eLcdPage6, eLcdPage6);
            if(bRepeaterMode)
            {
                lcdBufferPrintStringAligned(0, "Repeater mode",
                                            eLcdAlignCenter, eLcdPage6);
            }
            else
            {
                lcdBufferPrintStringAligned(0, "Transmit: UP key",
                                            eLcdAlignCenter, eLcdPage6);
            }
            lcdSendBufferPart(0, 0,127, eLcdPage6, eLcdPage6);
        }

        //
        // Read data from UART RX buffer to application buffer
        //
        ui16Cnt = bspUartDataGet(pui8AppBuf, bspUartRxCharsAvail());

        if(bRepeaterMode)
        {
            //
            // Repeater mode
            //

            if(ui16Cnt)
            {
                //
                // Send data from application buffer to UART TX buffer
                //
                bspUartDataPut(pui8AppBuf, ui16Cnt);
            }
        }
        else
        {
            //
            // Transmit mode
            //

            if(BSP_KEY_UP & ui8KeyBm)
            {
                //
                // Transmit a single character
                //
                bspUartDataPut(&ui8Byte, 1);
            }
        }
    }
}
Ejemplo n.º 4
0
/***************************************************************************//**
 *   @brief      Updates LCD buffer and sends buffer to LCD module
 *
 *  		   	  +-----------------------------------------+
 *                |_____________  SIGFOX DEMO_______________|
 *                | UL:	  XX    XX    XX    XX    XX    XX  |
 *                |       XX    XX    XX    XX    XX    XX  |
 *                |                                         |
 *                | DL:	  XX    XX    XX    XX    XX    XX  |
 *                |       XX    XX                          |
 *                |_________________________________________|
 *                |			 (c) Texas Instruments			|
 *                +-----------------------------------------+
 *
 *******************************************************************************/
static void
updateLCD(void)
{
	char ulmsg[36] = {0};
	char dlmsg[24] = {0};

	char ulmsg1[18] = {0};
	char ulmsg2[18] = {0};
	char dlmsg1[18] = {0};
	char dlmsg2[6] = {0};

	dataToString((unsigned char*) message, ulmsg, 24);
	dataToString((unsigned char*) ReceivedPayload, dlmsg, 16);

	// Format the converted string to display on LCD
	unsigned char n;
	unsigned char m = 0;
	for(n=0;n<12;n++)
	{
		if(m % 3 == 0)
		{
			ulmsg1[m] = ' ';
			ulmsg2[m] = ' ';
			dlmsg1[m] = ' ';
			if(n<4)
			{
				dlmsg2[m] = ' ';
			}
			m++;
		}
			ulmsg1[m] = ulmsg[n];
			ulmsg2[m] = ulmsg[12+n];
			dlmsg1[m] = dlmsg[n];
			if(n<4)
			{
				dlmsg2[m] = dlmsg[12+n];
			}
			m++;
	}

    // Clear LCD
    lcdBufferClear(0);
    lcdSendBuffer(0);

    // Load status buffer
    lcdBufferPrintStringAligned(0, "Sigfox Demo", eLcdAlignCenter, eLcdPage0);
    lcdBufferSetHLine(0, 0, LCD_COLS-1, 7);
    lcdBufferInvertPage(0, 0, LCD_COLS, eLcdPage0);
    lcdSendBufferPart(0, 0, 127, eLcdPage0,eLcdPage0);

    lcdBufferClearPart(0, 0, 127, eLcdPage1, eLcdPage6);

    lcdBufferPrintString(0, "UL:", 0, eLcdPage1);
    lcdBufferPrintString(0, ulmsg1, 20, eLcdPage1);
    lcdSendBufferPart(0, 0, 127, eLcdPage1,eLcdPage1);

    lcdBufferPrintString(0, ulmsg2, 20, eLcdPage2);
    lcdSendBufferPart(0, 20, 127, eLcdPage2,eLcdPage2);

    lcdBufferClearPart(0, 0, 127, eLcdPage3, eLcdPage6);
    lcdBufferPrintString(0, "DL:", 0, eLcdPage4);
    lcdBufferPrintString(0, dlmsg1, 20, eLcdPage4);
    lcdSendBufferPart(0, 0, 127, eLcdPage4,eLcdPage4);

    lcdBufferPrintString(0, dlmsg2, 20, eLcdPage5);
    lcdSendBufferPart(0, 20, 55, eLcdPage5,eLcdPage5);

    lcdBufferPrintString(0, "(c) Texas Instruments" , 0, eLcdPage7);
    lcdBufferSetHLine(0, 0, LCD_COLS-1, 55);
    lcdBufferInvertPage(0, 0, LCD_COLS, eLcdPage7);

    // Send the buffer to the LCD screen
    lcdSendBufferPart(0, 0, 127, eLcdPage7, eLcdPage7);
}