/***************************************************************************** * @fn printNavNumbers * * @brief writes the navigation numbers in the top right corner that tells * the user which item is selected and how many items the menu has * got in total (i.e. 4/15). Used as an auxillary function for * displayMenu to improve readability of code. Its writing to the * LCD buffer. * * input parameters * * @param pMenu - The menu to be shown on the display * * output parameters * * @result Returns the number of pixels the navigation numbers occupies on * the right end of the line. */ static uint8 printNavNumbers(const menu_t *pMenu) { if(pMenu->pTextMenuItems) { uint8 nCurrentItem = pMenu->nCurrentItem; char *totalNr = pMenu->pTextMenuItems; char *currentNr = pMenu->pItems[nCurrentItem].pTextNumber; uint8 margin = MENU_MARGIN-(LCD_CHAR_WIDTH-LCD_FONT_WIDTH); uint8 totalNrLen = lcdGetStringLength(totalNr); uint8 currentNrLen = lcdGetStringLength(currentNr); uint8 totalNrPos = LCD_COLS-margin-totalNrLen*LCD_CHAR_WIDTH; uint8 slashPos = totalNrPos-LCD_CHAR_WIDTH; uint8 currentNrPos = slashPos-currentNrLen*LCD_CHAR_WIDTH; lcdBufferPrintString(0,totalNr,totalNrPos,eLcdPage0); lcdBufferPrintString(0,(char*)"/",slashPos,eLcdPage0); lcdBufferPrintString(0,currentNr,currentNrPos,eLcdPage0); /* returns the maximal amount of occupied pixels on the right * uses totalNrLen twice instead of currentNrLen to keep constant * within one menu. */ return margin + 2*totalNrLen*LCD_CHAR_WIDTH + LCD_CHAR_WIDTH + 1; } return 0; /* If there's no "total number of items" text, don't write */ }
/******************************************************************************* * @fn printWelcomeMessage * * @brief Function displaying a welkome message at start-up * * * @param none * * @return none */ static void printWelcomeMessage(void) { lcdBufferClear(0); lcdBufferPrintString(0, "Inf. Pkt. Length Mode", 0, eLcdPage0); lcdBufferSetHLine(0, 0, LCD_COLS - 1, eLcdPage7); lcdBufferPrintString(0, "Waiting to receive", 0, eLcdPage2); lcdBufferPrintString(0, "packets", 0, eLcdPage3); lcdBufferPrintString(0, "Packet RX", 0, eLcdPage7); lcdBufferSetHLine(0, 0, LCD_COLS - 1, 55); lcdBufferInvertPage(0, 0, LCD_COLS, eLcdPage7); lcdSendBuffer(0); }
/******************************************************************************* * @fn updateLcd * * @brief updates LCD buffer and sends buffer to LCD module * * @param none * * @return none */ static void updateLcd(void) { // Update LDC buffer and send to screen. lcdBufferClear(0); lcdBufferPrintString(0, "EasyLink Test", 0, eLcdPage0); lcdBufferSetHLine(0, 0, LCD_COLS-1, 7); lcdBufferPrintString(0, "Received ok:", 0, eLcdPage3); lcdBufferPrintInt(0, packetCounter, 70, eLcdPage4); lcdBufferPrintString(0, "Packet RX ", 0, eLcdPage7); lcdBufferSetHLine(0, 0, LCD_COLS-1, 55); lcdBufferInvertPage(0, 0, LCD_COLS, eLcdPage7); lcdSendBuffer(0); }
/******************************************************************************* * @fn updateLcd * * @brief Updates the LCS every time a packet has been received * with CRC OK * * @param none * * @return none */ static void updateLcd(void) { lcdBufferClear(0); lcdBufferPrintString(0, "Inf. Pkt. Length Mode", 0, eLcdPage0); lcdBufferSetHLine(0, 0, LCD_COLS - 1, eLcdPage7); lcdBufferPrintString(0, "Received packets:", 0, eLcdPage3); lcdBufferPrintInt(0, (int32)(++packetCounter), 102, eLcdPage3); lcdBufferPrintString(0, "RSSI:", 0, eLcdPage5); lcdBufferPrintInt(0, rssi, 40, eLcdPage5); lcdBufferPrintString(0, "Packet RX", 0, eLcdPage7); lcdBufferSetHLine(0, 0, LCD_COLS - 1, 55); lcdBufferInvertPage(0, 0, LCD_COLS, eLcdPage7); lcdSendBuffer(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); }
/***************************************************************************//** * @brief Loads initial LCD buffer and sends buffer to LCD module *******************************************************************************/ static void welcomeLCD(void) { // Clear LCD buffer lcdBufferClear(0); // TI logo lcdSendBuffer(pLcdTiLogo); // Project Text lcdBufferPrintString(0, "TI/Sigfox", 63, eLcdPage2); lcdBufferPrintString(0, "Demo", 63, eLcdPage3); lcdBufferPrintString(0, "SDK", 63, eLcdPage5); lcdSendBufferPart(0, 63, 127, eLcdPage2, eLcdPage6); }
void createMenu( Menu *menu ) { int i; currentMenu = menu; lcdState.menuHover = 0; lcdState.page = eLcdPage0; lcdBufferClear( 0 ); lcdBufferPrintString( 0, currentMenu->header, 0, lcdState.page++ ); for( i = 0; i < currentMenu->menuCount; ++i ) { lcdBufferPrintString( 0, currentMenu->menu[i], 0, lcdState.page++ ); } lcdBufferInvertPage( 0, 0, 127, eLcdPage1 ); lcdSendBuffer( 0 ); }
/************************************************************************************************** * @fn halLcdWriteLine * * @brief Write one line on display. It is required to place a * NULL terminator \0 at the end of the string * * @param uint8 line - display line * char *pText - text buffer to write * * @return none **************************************************************************************************/ void HalLcd_HW_WriteLine(char str[], uint8 line) { /* Initialize with spaces to clear the line on the LCD. */ uint8 buf[] = " "; uint32 len = ((strlen(str) > HAL_LCD_MAX_CHARS) ? HAL_LCD_MAX_CHARS : strlen(str)); /* Copy string characters but not the NULL to keep spaces */ (void)memcpy(buf, str, len); /* Copy into the default buffer */ lcdBufferPrintString((char *)HAL_LCD_DEF_BUF, (char const *)buf, 0, (tLcdPage)line); /* Flush the default buffer to the LCD */ lcdSendBuffer(HAL_LCD_DEF_BUF); }
/************************************************************************************************** * @fn halLcdWriteLine * * @brief Write one line on display. It is required to place a * NULL terminator \0 at the end of the string * * @param uint8 line - display line * char *pText - text buffer to write * * @return none **************************************************************************************************/ void HalLcd_HW_WriteLine(char str[], uint8 line) { // Initialize with spaces to clear the line on the LCD. uint8 buf[] = " "; uint32 len = ((strlen(str) > HAL_LCD_MAX_CHARS) ? HAL_LCD_MAX_CHARS : strlen(str)); //Copy string characters but not the NULL to keep spaces (void)memcpy(buf, str, len); // Copy into the default buffer lcdBufferPrintString(BSP_DEFAULT_BUFFER, (char const *)buf, 1, (tLcdPage)line); // Flush the default buffer to the LCD lcdSendBuffer(BSP_DEFAULT_BUFFER); }
/**************************************************************************//** * @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); } } } }
/***************************************************************************** * @fn printItem * * @brief Prints a given menuItem on the specified line/page in the buffer. * Used as an auxillary function for displayMenu to improve * readability of code. An item consists of three fields to be * printed in the following order: * * +----------+-------------------------+------------+ * | Item nr | Item description | Item value | * +----------+-------------------------+------------+ * * The whole block can be left aligned (default), right aligned * (M_RIGHT), centered (M_CENTER) or it can be splitted such * that item nr and item description is left aligned and item value * is right aligned (M_SPLIT). The description and value can also * swap places with M_SWAP. If nrSize is 0 the nr field will use * only the necessary space. In other words: if some numbers are * one digit and some ar two digits they will not be aligned. * The nrSize input allows for a specified size at i.e. two digits. * * input parameters * * @param pItem - The item to print on the display * @param page - Which page to print the item on * @param selected - Whether or not this item is the selected one * @param nrSize - The size of the number field (in pixels). */ static void printItem(const menu_t *pMenu, uint8 nItem, tLcdPage page, uint8 nrSize) { /* Finding current item and wether or not it is selected (with an arrow) */ menuItem_t *pItem = &(pMenu->pItems[nItem]); int8 selected = (nItem==pMenu->nSelectedItem); /* Setting empty fields to a dummystring '\0' */ char dummyString = '\0'; char *pTextNumber = &dummyString; char *pTextDescription = &dummyString; void *pValue = &dummyString; /* Finding textfields for non-empty fields */ if(pItem->pTextNumber) pTextNumber = pItem->pTextNumber; if(pItem->pTextDescription) pTextDescription = pItem->pTextDescription; if(pItem->pValue) pValue = pItem->pValue; /* Implicit typecasting of pValue to pointers of other applicable datatypes. * This is needed some places */ float *pValueFloat; pValueFloat = pValue; /* fix: using int32 casting gives sign errors */ int *pValueInt = (int*) pValue; /* Masking out flags to make comparing easier */ uint16 alignFlags = pItem->flags & (M_ALIGN_0 | M_ALIGN_1); uint16 pValueFlags = pItem->flags & (M_PVALUE_0 | M_PVALUE_1 | M_PVALUE_2); if(pValue==&dummyString) { /* If no value is presented, pValue points to the dummystring. * Continue working with it as if it's a string regardless of what's * actually in the flag. */ pValueFlags = M_STRING; } /* Calculate the size (in pixels) that number and description needs */ if(nrSize==0) { /* nrSize is not fixed. Determine it. */ nrSize = lcdGetStringLength(pTextNumber)*LCD_CHAR_WIDTH; } uint8 descSize = lcdGetStringLength(pTextDescription)*LCD_CHAR_WIDTH; uint8 selSize = (pMenu->nSelectedItem!=-1)*LCD_CHAR_WIDTH; /* Calculate the size (in pixels) that value needs */ uint8 valSize; uint8 valDecimals; switch(pValueFlags) { case M_FLOAT1: valSize = lcdGetFloatLength(*pValueFloat,1)*LCD_CHAR_WIDTH; break; case M_FLOAT2: valSize = lcdGetFloatLength(*pValueFloat,2)*LCD_CHAR_WIDTH; break; case M_FLOAT3: valSize = lcdGetFloatLength(*pValueFloat,3)*LCD_CHAR_WIDTH; break; case M_FLOAT4: valSize = lcdGetFloatLength(*pValueFloat,4)*LCD_CHAR_WIDTH; break; case M_FLOAT5: valSize = lcdGetFloatLength(*pValueFloat,5)*LCD_CHAR_WIDTH; break; case M_FLOATA: valDecimals = determineDecimals(*pValueFloat); valSize = lcdGetFloatLength(*pValueFloat,valDecimals)*LCD_CHAR_WIDTH; break; case M_STRING: valSize = lcdGetStringLength(pValue)*LCD_CHAR_WIDTH; break; default: /* integer */ valSize = lcdGetIntLength(*pValueInt)*LCD_CHAR_WIDTH; break; } /* The number of margins/spaces between fields and the total size of the line */ int8 numOfMargins = -1; if(nrSize) numOfMargins++; if(descSize) numOfMargins++; if(valSize) numOfMargins++; int16 totalSize = nrSize+descSize+valSize+numOfMargins*LCD_CHAR_WIDTH; if(numOfMargins==-1) numOfMargins=0; /* Calculates position for the number field */ int16 nrPos, descPos, valPos, selPos; switch(alignFlags) { case M_RIGHT: nrPos = (LCD_COLS - MENU_MARGIN - totalSize); break; case M_CENTER: nrPos = (LCD_COLS - MENU_MARGIN - totalSize)/2; break; default: /* note: number is left aligned for both left and splitted alignment */ nrPos = MENU_MARGIN; break; } /* Calculates position for the selected item mark */ selPos = nrPos+nrSize; if(pItem->flags & M_SWAP) /* description and value swaps place */ { /* Calculates position for the value field (after nr field) */ valPos = nrPos + nrSize; if(nrSize||selSize) valPos += LCD_CHAR_WIDTH; /* add a space if item nr is present */ /* Calculates position for the description field */ if(alignFlags==M_SPLIT) { /* Splitted alignment: description is right aligned */ descPos = LCD_COLS - MENU_MARGIN - descSize; } else { /* Normal alignment (left/center/right): description is placed after value */ descPos = valPos + valSize; if(valSize) descPos += LCD_CHAR_WIDTH; /* add a space i descr. is present */ } } else /* Normal constellation of fields */ { /* Calculates position for the description field (after nr field) */ descPos = nrPos + nrSize; if(nrSize||selSize) descPos += LCD_CHAR_WIDTH; /* add a space if item nr is present */ /* Calculates position for the value field */ if(alignFlags==M_SPLIT) { /* Splitted alignment: value is right aligned */ valPos = LCD_COLS - MENU_MARGIN - valSize; } else { /* Normal alignment (left/center/right): value is placed after description */ valPos = descPos + descSize; if(descSize) valPos += LCD_CHAR_WIDTH; /* add a space i descr. is present */ } } /* Print number and description */ lcdBufferPrintString(0,pTextNumber,nrPos,page); lcdBufferPrintString(0,pTextDescription,descPos,page); /* Print selection mark if selected */ if(selected) { lcdBufferPrintString(0,"~",selPos,page); } /* write value to buffer */ switch(pValueFlags) { case M_STRING: lcdBufferPrintString(0,pValue,valPos,page); break; case M_FLOAT1: lcdBufferPrintFloat(0,*pValueFloat,1,valPos,page); break; case M_FLOAT2: lcdBufferPrintFloat(0,*pValueFloat,2,valPos,page); break; case M_FLOAT3: lcdBufferPrintFloat(0,*pValueFloat,3,valPos,page); break; case M_FLOAT4: lcdBufferPrintFloat(0,*pValueFloat,4,valPos,page); break; case M_FLOAT5: lcdBufferPrintFloat(0,*pValueFloat,5,valPos,page); break; case M_FLOATA: lcdBufferPrintFloat(0,*pValueFloat,valDecimals,valPos,page); break; default: lcdBufferPrintInt(0,*pValueInt,valPos,page); break; } }
/****************************************************************************** * @fn main * * @brief Main handles all applications attached to the menu system * * input parameters * * output parameters * *@return */ void main( void ) { // Init clocks and I/O bspInit(BSP_SYS_CLK_16MHZ); // Init leds bspLedInit(); // Init Buttons bspKeyInit(BSP_KEY_MODE_POLL); // Initialize SPI interface to LCD (shared with SPI flash) bspIoSpiInit(BSP_FLASH_LCD_SPI, BSP_FLASH_LCD_SPI_SPD); /* Init Buttons */ bspKeyInit(BSP_KEY_MODE_ISR); bspKeyIntEnable(BSP_KEY_ALL); /* Init LCD and issue a welcome */ lcdInit(); lcdClear(); // Instantiate tranceiver RF spi interface to SCLK ~ 4 MHz */ //input clockDivider - SMCLK/clockDivider gives SCLK frequency trxRfSpiInterfaceInit(0x10); /* Welcome Screen Part */ lcdSendBuffer(trxebWelcomeScreen); lcdBufferPrintString(lcdDefaultBuffer,"TEXAS",60,eLcdPage6); lcdBufferPrintString(lcdDefaultBuffer,"INSTRUMENTS",60,eLcdPage7); lcdSendBufferPart(lcdDefaultBuffer, 60,127,eLcdPage6, eLcdPage7); /* MCU will stay in sleep until button is pressed */ __low_power_mode_3(); bspKeyPushed(BSP_KEY_ALL); //Clear screen lcdBufferClear(0); /* Menu Driver */ menu_t *pCurrentMenu = &mainMenu; uint8 menuButtonsPressed; menuDisplay(pCurrentMenu); __low_power_mode_3(); while(1) { menuButtonsPressed = bspKeyPushed(BSP_KEY_ALL); switch(menuButtonsPressed) { case BSP_KEY_LEFT: pCurrentMenu = menuBack(pCurrentMenu); break; case BSP_KEY_RIGHT: pCurrentMenu = menuEnter(pCurrentMenu); break; case BSP_KEY_DOWN: menuDown(pCurrentMenu); break; case BSP_KEY_UP: menuUp(pCurrentMenu); break; default: break; } menuDisplay(pCurrentMenu); /* Enter low power mode while menu driver waits on user input */ __low_power_mode_3(); } }
/***************************************************************************//** * @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); }
/****************************************************************************** * @fn cc120x_masterStartApp * * @brief * * input parameters * * @param pDummy - pointer to pointer to void. Not used * * output parameters * * @return SNIFF_RETURN_SUCCESS */ uint8 cc120x_masterStartApp(void) { static uint8 marcState; // Set first packet number pkt = 1; // Set up GPIO pins. For debug cc112xSpiWriteReg(CC120X_IOCFG3,&cc120x_gpioConfigMaster[0],4); //Display while configuring radios* lcdBufferClear(0); lcdBufferPrintString(0," RX Sniff Test ",0,eLcdPage0); lcdBufferSetHLine(0,0,LCD_COLS-1,eLcdPage7); lcdBufferPrintString(0," Radio in TX ",0,eLcdPage2); lcdBufferPrintString(0," ",0,eLcdPage3); lcdBufferPrintString(0," Press right button ",0,eLcdPage4); lcdBufferPrintString(0," to send packet ",0,eLcdPage5); lcdBufferPrintString(0," 1 Abort Master Mode ",0,eLcdPage7); lcdBufferSetHLine(0,0,LCD_COLS-1,55); lcdBufferInvertPage(0,0,LCD_COLS,eLcdPage7); lcdSendBuffer(0); // Calibrate radio trxSpiCmdStrobe(CC120X_SCAL); // Wait for calibration to be done (radio back in IDLE state) do { cc120xSpiReadReg(CC120X_MARCSTATE, &marcState, 1); } while (marcState != 0x41); // Put MCU to sleep __low_power_mode_3(); while(1) { if(buttonPressed = bspKeyPushed(BSP_KEY_ALL)) { if(buttonPressed == BSP_KEY_LEFT) { // Left button pressed. Abort function // Put radio in powerdown to save power trxSpiCmdStrobe(CC120X_SPWD); //Insert Carrier Sense threshold warning in Sniff Test Menu drawInfo(); return SNIFF_RETURN_FAILURE; } else if (buttonPressed == BSP_KEY_RIGHT) { //Right button pressed, send packet lcdBufferClear(0); // build packet comArray[0] = PKTLEN; // length field comArray[1] = 0x00; // address field comArray[2] = pkt>>24; // payload comArray[3] = pkt>>16; comArray[4] = pkt>>8; comArray[5] = pkt; // Update LCD lcdBufferPrintString(0," RX Sniff Test ",0,eLcdPage0); lcdBufferSetHLine(0,0,LCD_COLS-1,eLcdPage7); lcdBufferPrintString(0,"Sent Pkt number:",0,eLcdPage3); lcdBufferPrintInt(0,pkt,70,eLcdPage4); lcdBufferPrintString(0," 1 Abort Master Mode ",0,eLcdPage7); lcdBufferSetHLine(0,0,LCD_COLS-1,55); lcdBufferInvertPage(0,0,LCD_COLS,eLcdPage7); lcdSendBuffer(0); // Update packet counter pkt++; // Strobe IDLE and fill TX FIFO trxSpiCmdStrobe(CC120X_SIDLE); // wait for radio to enter IDLE state while((trxSpiCmdStrobe(CC112X_SNOP)& 0xF0) != 0x00); cc112xSpiWriteTxFifo(comArray,PKTLEN+1); // Send packet trxSpiCmdStrobe(CC120X_STX); // Wait for radio to finish sending packet while((trxSpiCmdStrobe(CC120X_SNOP)& 0xF0) != 0x00); // Put radio in powerdown to save power trxSpiCmdStrobe(CC120X_SPWD); //Put MCU to sleep __low_power_mode_3(); } } }