/******************************************************************************* * @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); }
/***************************************************************************** * @fn menuWriteBuffer * * @brief Writes the provided pMenu to the LCD Buffer * * input parameters * * @param pMenu - The menu to be shown on the display */ void menuWriteBuffer(const menu_t *pMenu) { /* Print the header on the first line/page on the LCD if not reserved */ if(!(pMenu->reservedAreas & 1)) { lcdBufferClearPage(0,eLcdPage0); printHeader(pMenu); } /* Which screen and which item is the current on */ int8 nCurrentItem = pMenu->nCurrentItem; int8 screen = pMenu->nScreen; /* Finding first item on screen */ uint8 itemsPerScreen = determineItemsPerScreen(pMenu); uint8 nItem = screen*itemsPerScreen; menuItem_t *pItem = &(pMenu->pItems[nItem]); /* Iterating through items, printing one by one */ tLcdPage page=(tLcdPage)getNextPage(pMenu,0); /* finds first page */ while(nItem<pMenu->nMenuItems && page) { /* write the current item */ lcdBufferClearPage(0,page); printItem(pMenu,nItem,page,0); /* Invert region around item if the item is selected */ if(pItem==&(pMenu->pItems[nCurrentItem])) { lcdBufferSetHLine(0,0,LCD_COLS-1,page*LCD_PAGE_ROWS-1); lcdBufferInvertPage(0,0,LCD_COLS-1,page); } else { if(pMenu->reservedAreas & (1<<(page-1))) { /* if the previous page is reserved, and this page isn't marked, * make sure horizontal line doesn't stick. */ lcdBufferClearHLine(0,0,LCD_COLS-1,page*LCD_PAGE_ROWS-1); } } /* NOTE: if the page over this (marked) item is reserved, the item will * still use 9 pixels of height for the invertion area so that it "steals" * 1 px of height from the reserved page. */ /* If this is a dummy item, invert the region around it if the * master item is selected */ if(pItem->flags & M_EXTEND){ int8 masterNumber = nItem - 1; while(pMenu->pItems[masterNumber].flags & M_EXTEND) { masterNumber--; } if(masterNumber==nCurrentItem) { lcdBufferInvert(0,0,page*LCD_PAGE_ROWS,LCD_COLS-1,(page+1)*LCD_PAGE_ROWS-1); } } /* Iterate */ page = (tLcdPage)getNextPage(pMenu,page); nItem++; pItem = &(pMenu->pItems[nItem]); } /* clearing unused pages that's not reserved */ while(page) { lcdBufferClearPage(0,page); if(pMenu->reservedAreas & (1<<(page-1))) { /* if the previous page is reserved, and this page is empty, * make sure horizontal line doesn't stick. */ lcdBufferClearHLine(0,0,LCD_COLS-1,page*LCD_PAGE_ROWS-1); } page = (tLcdPage)getNextPage(pMenu,page); } }
/***************************************************************************//** * @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(); } } }