/*******************************************************************************
*   @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);
}
예제 #2
0
void refreshScreen( void ) {
    RetVal retVal;
    
    TimerIntClear( GPTIMER0_BASE, GPTIMER_TIMA_TIMEOUT );
    
    if( !currentMenu ) {
        return;
    }
    
    if( currentMenu->menuCount > 0 ) {
        lcdBufferClearPage( 0, lcdState.page );
        
        ( *currentMenu->hoverFunction[lcdState.menuHover] )( &retVal );
        switch( retVal.retType ) {
        case RET_TYPE_INT: 
            lcdBufferPrintInt( 0, retVal.intRet, 0, lcdState.page );
            break;
        case RET_TYPE_FLOAT:
            lcdBufferPrintFloat( 0, retVal.floatRet, 2, 0, lcdState.page );
            break;
        }
    }
    
    lcdSendBufferPart( 0, 0, 127, lcdState.page, lcdState.page );
}
/*******************************************************************************
*   @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);
}
예제 #4
0
/*****************************************************************************
 * @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          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(); 
      }
    }
  }