Beispiel #1
0
void rfSendData(void)
{
  uint8 pTxData[20] ={'l','i','y','a','n','f','e','n','g','v','5','8','7','a','b',0};
    uint8 ret;
    uint8 recvCnt=0;
    uint8 ch=0;
    // Keep Receiver off when not needed to save power
    basicRfReceiveOff();
    
    // Main loop
    while (TRUE) {
      recvCnt=0;
      
       ret = basicRfSendPacket(0xffff, pTxData, sizeof pTxData); //广播地址      
       if (ret == SUCCESS) {
          printf("send msg ok\r\n");
          hal_led_on(1);
          halMcuWaitMs(100);
          hal_led_off(1);
          halMcuWaitMs(900); 
       } else {
          printf("send msg error\r\n");
          hal_led_on(1);
          halMcuWaitMs(1000);
          hal_led_off(1);
       }
       
    }
}
Beispiel #2
0
void playVGuitar() {
	
	unsigned char usrExit[] = {0};
	char keyNote = 0;
	unsigned int xCoord = 0;
	unsigned int yCoord = 0;
	unsigned char sendBuf[3] = {0};
	
	while(1) {
		if (RF_gets_nblk(usrExit) != 0) {
			if (strncmp (usrExit, "STOP", 4) == 0) {
				break;
			}
		}
		else {
			getTsXY(&xCoord, &yCoord);
			keyNote = guitar_key_match(xCoord, yCoord);
			halMcuWaitMs(20);
			if (keyNote) {
				//send the note over rf and serial
				sendBuf[0] = 0;					//Channel
				sendBuf[1] = keyNote;		//Note
				sendBuf[2] = 0x7f; 			//Attack Velocity //TODO: use pressure
				halMcuWaitMs(50);
				RF_Send(sendBuf, 3);
			}
		}
	}//while(1)
}
Beispiel #3
0
void rfSendData(void)
{
    uint8 pTxData[20];
    uint8 ret;
    // Keep Receiver off when not needed to save power
    basicRfReceiveOff();
    //sprintf(pTxData,"distince:%u CM.", uWaveDistance());
    printf("goto while...\r\n");
    // Main loop
    while (TRUE) {
       printf("in while...\r\n");
       dht11_update(pTxData);
       printf("get data ok...\r\n");
       ret = basicRfSendPacket(RECV_ADDR, pTxData, sizeof pTxData);       
       if (ret == SUCCESS) {
          printf("send msg ok!!!\r\n");
          hal_led_on(1);
          halMcuWaitMs(100);
          hal_led_off(1);
          halMcuWaitMs(900); 
       } else {
          printf("send msg error!!!\r\n");
          hal_led_on(1);
          halMcuWaitMs(1000);
          hal_led_off(1);
       }
       
    }
}
void clear_screen(void)
{
	printf_pc_code((__code char*)"\033c");			//Reset Terminal
	halMcuWaitMs(200);

	printf_pc_code((__code char*)"\033[2J");			//Clear Screen
	halMcuWaitMs(200);
}
/***********************************************************************************
* @fn      setYDrive
*
* @brief   Drive Y+drive High and Y-drive Low, Configure ADC Pins
*
* @param   none
*
* @return  none
*/
void setYDrive(void)
{
	clearDrives();
	MCU_IO_OUTPUT(0,YP_C,1);
	MCU_IO_OUTPUT(0,YN_C,0);
	halMcuWaitMs(1);                                 // Delay to allow settling
}
void get_audio_termination(void)
{
	char mybuf[4];
	char user_data=0;

	while(audio_loop == TRUE)
	{
		print_audio_termination_screen();
		user_data = expect_value(2);

		if( user_data != 0)
		{	//Goes here if data is valid;
			bzero(mybuf,4);
			//sprintf(mybuf,"%d",user_data); //TODO
			if(user_data == 1)
			{
				printf_pc_code((__code char*)"\n\n\rPC will be used as Audio Termination.\n\r");
				audio_termination = PC;
			}
			else
			{
				printf_pc_code((__code char*)"VS1053 will be used as Audio Termination.\n\r");
				audio_termination = VS1053;
			}
			break;	//break out of while loop
		}
		else
		{
			printf_pc_code((__code char*)"INVALID DATA\n\r");
			halMcuWaitMs(1000);
			clear_screen();
		}
	}
}
Beispiel #7
0
/******************************************************************************
* @fn  halButtonPushed
*
* @brief
*      This function detects if 'S1' is being pushed. The function
*      implements software debounce. Return true only if previuosly called
*      with button not pushed. Return true only once each time the button
*      is pressed.
*
* Parameters:
*
* @param  void
*
* @return uint8
*          HAL_BUTTON_1:    Button is being pushed
*          HAL_BUTTON_NONE: Button is not being pushed
*
******************************************************************************/
uint8 halButtonPushed(void)
{
    uint8 i;
    uint8 value;
    static uint8 prevValue;

    if (value = HAL_BUTTON_1_PUSHED()){
        for(i = 0; i < 10; i++) {
            if(!HAL_BUTTON_1_PUSHED()){
                value = HAL_BUTTON_NONE;
                break;
            }
        }
    }

    if (value){
        if (!prevValue){
            value = prevValue = HAL_BUTTON_1;
            halMcuWaitMs(50);
        }
        else {
            value = HAL_BUTTON_NONE;
        }
    }
    else{
        prevValue = HAL_BUTTON_NONE;
    }

    return value;
}
/***********************************************************************************
* @fn      setTouchDrives
*
* @brief   Set Y+drive to input with pull-up, X-drive to output low
*
* @param   none
*
* @return  none
*/
void setTouchDrives(void)
{
	clearDrives();
	MCU_IO_OUTPUT(0,YP_C,1);
	MCU_IO_INPUT(0,YP_C,MCU_IO_PULLUP);
	MCU_IO_OUTPUT(0,XN_C,0);
	halMcuWaitMs(1);                                 // Wait for pin to settle
}
Beispiel #9
0
void midiReset() {

  	//MIDI_RESET = 1;
	MCU_IO_OUTPUT(1,1,1);
	//delay_millisec(100);
	halMcuWaitMs(100);

  	MCU_IO_OUTPUT(1,1,0);
	//MIDI_RESET = 0;
	//delay_millisec(100);
	halMcuWaitMs(100);
	
	//MIDI_RESET = 1;
	MCU_IO_OUTPUT(1,1,1);
	//delay_millisec(100);
	halMcuWaitMs(200);
}
/***********************************************************************************
* @fn          halAssertHandler
*
* @brief       Logic to handle an assert.
*
* @param       none
*
* @return      none
***********************************************************************************
*/
void halAssertHandler(void)
{
    // execute code that handles asserts 
    // blink all leds
    while(TRUE){
        halLedToggle(1);
        halMcuWaitMs(50);
    }
}
Beispiel #11
0
//----------------------------------------------------------------
// @fn      M200_Init
//----------------------------------------------------------------
void M200_Init(void)
{
    HAL_I2C_SCL_DIR_OUT();
    HAL_I2C_SDA_DIR_OUT();

    SHT_ConnectReset();
    SHT_Start();
    SHT_WriteByte(0x1E);
    halMcuWaitMs(200);
}
void get_playback_option(void)
{
	char mybuf[4];
	char user_data=0;

	while(playback_loop == TRUE)
	{
		print_playback_screen();
		user_data = expect_value(4);

		if( user_data != 0)
		{	//Goes here if data is valid;
			bzero(mybuf,4);
			//sprintf(mybuf,"%d",user_data); //TODO

							switch(user_data)
						{
						case 1:
						{
							playback=0;
							break;
						}

						case 2:
						{
							playback=1;
							break;
						}

						case 3:
						{
							playback=2;
							break;
						}

						case 4:
						{
							playback=3;
							break;
						}
						default:
							break;
						}

			break;	//break out of while loop
		}
		else
		{
			printf_pc_code((__code char*)"INVALID DATA\n\r");
			halMcuWaitMs(1000);
			clear_screen();
		}
	}
}
Beispiel #13
0
//--------------------------------------------
// Reset the SHT M200 sensor moudule connect
//--------------------------------------------
void SHT_ConnectReset(void)
{
    uint8 i;

    HAL_I2C_SDA_SET();
    HAL_I2C_SCL_CLR();
    halMcuWaitUs(20);
    for (i = 0; i < 9; i++)
    {
        HAL_I2C_SCL_SET();
        halMcuWaitUs(5);
        HAL_I2C_SCL_CLR();
        halMcuWaitUs(5);
    }
	halMcuWaitMs(100);
}
void get_record_option(void)
{
	char mybuf[4];
	char user_data=0;

	while(record_loop == TRUE)
	{
		print_record_screen();
		user_data = expect_value(3);

		if( user_data != 0)
		{																	//Goes here if data is valid;
			bzero(mybuf,4);
			if(user_data == 1)
			{
				record_notes = TRUE;
			}
			else if(user_data == 2)
			{
				record_notes = FALSE;
			}
			else
			{
				play_recorded_notes = TRUE;

				rv_loop = FALSE;
				wrv_loop= FALSE;
				guitar_loop=FALSE;
				piano_loop = FALSE;
				audio_loop=FALSE;
				record_loop=FALSE;
				track_loop=FALSE;
				playback_loop=TRUE;

			}

			break;	//break out of while loop
		}
		else
		{
			printf_pc_code((__code char*)"INVALID DATA\n\r");
			halMcuWaitMs(1000);
			clear_screen();
		}
	}
}
Beispiel #15
0
/******************************************************************************
* @fn          waitForAck
*
* @brief       Wait for acknowledge
*
* @param       timeout in milliseconds
*
* @return      TRUE if the ACK has been received
*/
static uint8 waitForAck(uint8 timeout)
{
    uint8 f;

    while (!fAckRdy && timeout>0) {
        halMcuWaitMs(1);
        timeout--;
    }
    if (fAckRdy) {
        f= TRUE;
        fAckRdy= FALSE;
    } else {
        f= FALSE;
    }

    return f;
}
Beispiel #16
0
 /***********************************************************************************
 * @fn          halLcdInit
 *
 * @brief       Initalise LCD
 *
 * @param       none
 *
 * @return      none
 */
void halLcdInit(void)
{
    // Initialize I/O
    LCD_CTRL_INIT_PORTS();

    // Perform the initialization sequence
    FUNCTION_SET(CGRAM | COM_FORWARD | THREE_LINE);
    halLcdSetContrast(15);
    SET_POWER_SAVE_MODE(OSC_OFF | POWER_SAVE_ON);
    SET_POWER_CTRL(VOLTAGE_DIVIDER_ON | CONVERTER_AND_REG_ON);
    SET_BIAS_CTRL(BIAS_1_5);
    halMcuWaitMs(21); // 21 ms

    // Clear the display
    halLcdClear();
    halLcdClearAllSpecChars();
    SET_DISPLAY_CTRL(DISPLAY_CTRL_ON | DISPLAY_CTRL_BLINK_OFF | DISPLAY_CTRL_CURSOR_OFF);
}
void get_real_virtual(void)
{
	char mybuf[4];
	char user_data=0;

	while(rv_loop == TRUE)
	{
		print_rv_screen();
		user_data = expect_value(2);

		if( user_data != 0)
		{																//Goes here if data is valid;
			bzero(mybuf,4);

			switch(user_data)
			{
				case 1:
				{
					//printf_pc_code((__code char*)"\n\rReal Instruments Selected***\n\r");
					real_virtual = REAL_INSTRUMENT;
					break;
				}

				case 2:
				{
					//printf_pc_code((__code char*)"\n\r***Virtual Instruments Selected***\n\r");
					real_virtual = VIRTUAL_INSTRUMENT;
					break;
				}

				default:
					break;
			}

			break;	//break out of while loop
		}
		else
		{
			printf_pc_code((__code char*)"INVALID DATA\n\r");
			halMcuWaitMs(1000);
			clear_screen();
		}
	}
}
Beispiel #18
0
/***********************************************************************************
* @fn      halUartBufferedWrite
*
* @brief   Write data buffered to UART. Data is written into a buffer, and the
*          buffer is emptied by UART TX interrupt ISR
*
* @param   uint8* buf - buffer with data to write
*          uint16 length - number of bytes to write
*
* @return  number of bytes written
*/
uint16 halUartBufferedWrite(const uint8* buf, uint16 length)
{
    uint16 n;
    
    n= 0;
    while ( n < length ) {
        uint8 i;
        
        i= bufPut(&rbTxBuf,buf+n,length-n);
        if (i==0) {
            halMcuWaitMs(5);
            i+= bufPut(&rbTxBuf,buf+n,length-n);
            if (i==0)       // Assuming that there is no connection; give up
                break;
        }
        n+= i;
    }
    
    return n; // (bufPut(&rbTxBuf,buf,length));
}
Beispiel #19
0
/************************************************************************************
* @fn  halJoystickPushed
*
* @brief
*      This function detects if the joystick is being pushed. The function
*      implements software debounce. Return true only if previuosly called
*      with joystick not pushed. Return true only once each time the joystick
*      is pressed.
*
* Parameters:
*
* @param  void
*
* @return uint8
*          1: Button is being pushed
*          0: Button is not being pushed
*
******************************************************************************/
uint8 halJoystickPushed(void)
{
  uint8 value, active;
  uint8 i;
  static uint8 prevValue = 0;
  uint16 adcValue;

  // Criterion for button pushed:
  // 3 times joystick active and in center position
  value = 1;
  for (i=0; i<3; i++) {
    active = MCU_IO_GET(HAL_BOARD_IO_JOY_MOVE_PORT, HAL_BOARD_IO_JOY_MOVE_PIN);
    adcValue = adcSampleSingle(ADC_REF_AVDD, ADC_9_BIT, \
        HAL_BOARD_IO_JOYSTICK_ADC_CH);
    // Only use 7 out of the 9 bits
    adcValue = (adcValue & 0x7FC0) >> 8;
    if (! active || adcValue < 0x54) {
      // Joystick not active or not in center position
      value = 0;
      break;
    }
    halMcuWaitUs(3);
  }

  if (value){
    if (!prevValue){
      value = prevValue = 1;
      halMcuWaitMs(100);

    }
    else {
      value = 0;
    }
  }
  else{
    prevValue = 0;
  }

  return value;
}
Beispiel #20
0
//----------------------------------------------------------------
// @fn    M200_GetValue
//----------------------------------------------------------------
void M200_GetValue(void)
{
    uint8 count_1, err = 0;
    uint16 count_2;
    
    while (TRUE)
    {
        SHT_Start();
        err += SHT_WriteByte(0x05); //  Converter H
        if (err > 0)
        {
            break;
        }
        //55ms
        HAL_I2C_SDA_DIR_IN();
        for (count_1 = 0; count_1 < 190; count_1++)
        {
            halMcuWaitMs(1);
            if (HAL_I2C_SDA_VAL() == 0)
            {
                HAL_I2C_SDA_DIR_OUT();
                M200_Humi = SHT_ReadByte(1);
                if (M200_Humi > 0x3F)
                {
                    M200_Humi = 0x3F;
                }
                M200_Humi = (M200_Humi << 8) + (uint16)SHT_ReadByte(1);
                SHT_ReadByte(0);
                break;
            }
        }
        HAL_I2C_SDA_SET();
        HAL_I2C_SDA_DIR_OUT();
        
        halMcuWaitMs(10);
        SHT_Start();
        err += SHT_WriteByte(0x03); // Converter T
        if (err > 0)
        {
            break;
        }
        //210ms
        HAL_I2C_SDA_DIR_IN();
        for (count_2 = 0; count_2 < 600; count_2++)
        {
            halMcuWaitMs(1);
            if (HAL_I2C_SDA_VAL() == 0)
            {
                HAL_I2C_SDA_DIR_OUT();
                M200_Temp = SHT_ReadByte(1);
                if (M200_Temp > 0x3F)
                {
                    M200_Temp = 0x3F;
                }
                M200_Temp = (M200_Temp << 8) + (uint16)SHT_ReadByte(1);
                SHT_ReadByte(0);
                break;
            }
        }
        HAL_I2C_SDA_SET();
        HAL_I2C_SDA_DIR_OUT();       
        break;
    } 
    if (err > 0)
    {
        SHT_ConnectReset();
    }
}
Beispiel #21
0
/***********************************************************************************
* @fn          main
*/
void main(void)
{
  // Initalise board peripherals
  halBoardInit();
  
  
  basicRfSetUp();
  
  // Initalise hal_rf
  if(halRfInit()==FAILED)
  {
    HAL_ASSERT(FALSE);
  }
  
  // Indicate that device is powered
  halLedSet(1);
  halMcuWaitMs(350);
  
  configureUSART0forUART_ALT1();
  uartStartRxForIsr();
  
  while(!start); //waiting for 'a' key from PC 
  //respond to PC -- going to try to start up WRS 
  
  pTxData[0] = INIT_COMM_CMD;
  basicRfReceiveOff();
  if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
  {
    state=1;
  }
  basicRfReceiveOn();
  //wait for ACK from WRS
  
  pTxData[0] = INIT_COEF_CMD;
  basicRfReceiveOff();
  if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
  {
    basicRfReceiveOn();
    
    state=2;//continuous?
    
    //WAIT FOR COEFFICIENTS FROM WRS
    while(!basicRfPacketIsReady());//wait to receive acknowledgement
    
    if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
    {
      if(pRxData[0] == 'C') 
      {  
        //Pass to PC
        for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        {
          U0CSR &= ~0x02; //SET U0TX_BYTE to 0
          U0DBUF = pRxData[uartTxIndex];      
          while (!(U0CSR&0x02));
        }
        // while(!ACK);//waiting for acknowledgement
      }    
    }
  }
  
  //finished sending coefficients to PC 
  
  basicRfReceiveOn();
  
  while(TRUE)
  {
    //Receive package from WRS
    if(basicRfPacketIsReady())
    { 
      
      if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) {
        getRSSI = basicRfGetRssi();
        pRxData[104]=getRSSI;
        if((pRxData[0] == 'P')||(pRxData[0] == 'A'))
        {          
          //SEND DATA TO PC 
          for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
          {
            U0CSR &= ~0x02; //SET U0TX_BYTE to 0
            U0DBUF = pRxData[uartTxIndex];      
            while (!(U0CSR&0x02));
          }
        }
      }
      
    }
    
    //Receive CMD from PC 
    if(changePWMflag)//have this be set in interrupt 
    {
      //basicRfReceiveOff();
      
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send PWM info to WRS
      {
        
        changePWMflag=0;
      }
      //basicRfReceiveOn();
        
        //        while(changePWMflag)//Keep receiving until PWM acknowledge is sent
        //        {
        //          while(!basicRfPacketIsReady());//waiting for acknowledgement -- important here i think
        //          
        //          if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
        //          {
        //            if(pRxData[0] == 'Z')
        //            {
        //              //receive current duty cycle and send back to PC 
        //              for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        //              {
        //                U0CSR &= ~0x02; //SET U0TX_BYTE to 0
        //                U0DBUF = pRxData[uartTxIndex];      
        //                while (!(U0CSR&0x02));
        //              }
        //              changePWMflag = 0;
        //            }
        //            //else send pressure?
        //          }
        //        }
        //      }
      
    }
  }//END OF MAIN WHILE LOOP
}
Beispiel #22
0
/***********************************************************************************
* @fn          main
*/
void main(void)
{
  // Initalise board peripherals
  halBoardInit();
  
  basicRfSetUp();
  
  // Initalise hal_rf
  if(halRfInit()==FAILED)
  {
    HAL_ASSERT(FALSE);
  }
  
  // Indicate that device is powered
  halLedSet(1);
  halMcuWaitMs(350);
  
  configureUSART0forUART_ALT1();
  uartStartRxForIsr();
  
  
  while(TRUE)
  {
    //----------------------
    // INITIALIZE
    //----------------------
    if(initFlag)
    {
      while(!start); //waiting for 'a' key from PC 
      //respond to PC -- going to try to start up WRS 
      start=0;
      pTxData[0] = INIT_COMM_CMD;
      basicRfReceiveOff();
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
      {
        state=1;
      }
      basicRfReceiveOn();
      //wait for ACK from WRS
      
      pTxData[0] = INIT_COEF_CMD;
      basicRfReceiveOff();
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)
      {
        basicRfReceiveOn();
        
        //WAIT FOR COEFFICIENTS FROM WRS
        while(!basicRfPacketIsReady());//wait to receive acknowledgement
        
        if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, NULL)>0) 
        {
          if(pRxData[0] == 'C') 
          {  
            //Pass to PC
            for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
            {
              U0CSR &= ~0x02; //SET U0TX_BYTE to 0
              U0DBUF = pRxData[uartTxIndex];      
              while (!(U0CSR&0x02));
            }
          }    
        }
      }
      
      //finished sending coefficients to PC 
      
      basicRfReceiveOn();
      initFlag=0;
    }
    
    
    
    if(turnOnMotorFlag){
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS
      {
        turnOnMotorFlag=0;
      }
    }
    
    if(sendInitFlag){
      if(basicRfSendPacket(ROBOT_ADDR, pTxData, APP_PAYLOAD_LENGTH)==SUCCESS)//send command to WRS
      {
        initFlag=1;
        sendInitFlag=0;
        //Pass to PC
        for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
        {
          pRxData[0] == 'R';
          U0CSR &= ~0x02; //SET U0TX_BYTE to 0
          U0DBUF = pRxData[uartTxIndex];      
          while (!(U0CSR&0x02));
        }
      }
    }
    //Receive package from WRS
    if(basicRfPacketIsReady())
    { 
      
      if(basicRfReceive(pRxData, APP_PAYLOAD_LENGTH, myRSSI)>0) {
        getRSSI = basicRfGetRssi();
        pRxData[104]=getRSSI;
        if(pRxData[0] == 'D')//||(pRxData[0] == 'I'))
        {          
          //SEND DATA TO PC 
          for (unsigned int uartTxIndex = 0; uartTxIndex<105; uartTxIndex++)
          {
            U0CSR &= ~0x02; //SET U0TX_BYTE to 0
            U0DBUF = pRxData[uartTxIndex];      
            while (!(U0CSR&0x02));
          }
        }
      }
      
    }    
  }
}
/***********************************************************************************
* @fn          main
*
* @brief
*
* @param
*
*
* @return      none
*/
void main (void)
{
    int8 minRssi, maxRssi, rssiOffset;
    int16 barValue;
    int16 txtValue;
    uint8 barHeight, n;

    appShowText=FALSE;
    barHeight=  3;
    txtChannel= 0;

    // Initalise board peripherals
    halBoardInit();

    // Initalise hal_rf
    if(halRfInit()==FAILED) {
      HAL_ASSERT(FALSE);
    }
    // Indicate that device is powered
    halLedSet(1);

    // Print Logo and splash screen on LCD
    utilPrintLogo("Spectrum Anl");
    halMcuWaitMs(3000);

    // Calculate RSSI offset and range (must be done after setting gain mode)
    halRfSetGain(HAL_RF_GAIN_HIGH);

    rssiOffset= halRfGetRssiOffset();
    minRssi=    MIN_RSSI_DBM + rssiOffset;
    maxRssi=    MAX_RSSI_DBM + rssiOffset;

    // Config IO interrupt
    appConfigIO();

    // Set chip in RX scan mode
    halSetRxScanMode();

    // Load bar graph symbols to LCD
    utilLoadBarGraph();

    while(1) {
    	uint8 sample;
    	
        // For each RSSI sample record
        for (sample = 0; sample < SAMPLE_COUNT; sample++) {
        	uint8 channel;
            // Sample channel 11-26
            for(channel = 0; channel < CHANNELS; channel++ ) {
                ppRssi[channel][sample] = halSampleED(channel+CHANNEL_11, SAMPLE_TIME);
            }

            // Update the display with the latest graph values
            for(channel = 0; channel < CHANNELS; channel++ ) {
			
                barValue = -128;
                for (n = 0; n < SAMPLE_COUNT; n++) {
                    barValue = MAX((int8) barValue, ppRssi[channel][n]);
                }
                barValue -= minRssi;

                // Saturate
                if (barValue < 0)
                    barValue = 0;
                if (barValue > ((int16) maxRssi - (int16) minRssi))
                    barValue = (int16) maxRssi - (int16) minRssi;
                // Scale
                barValue *= (barHeight == 2) ? (8 + 1 + 8) : (8 + 1 + 8 + 1 + 8);
                barValue /= maxRssi - minRssi;

                // Display the bar
                for (n = 0; n < barHeight; n++) {
                    utilDisplayBarGraph(n + 1, channel, (barHeight - 1 - n) * 9, barValue);
                }
            }
        }

        // Show RSSI in text form on display
        if(appShowText) {
            txtValue = -128;
            barHeight=2;
            // find peak value
            for (n = 0; n < SAMPLE_COUNT; n++) {
                txtValue = MAX((int8) txtValue, ppRssi[txtChannel][n]);
            }
            txtValue -= rssiOffset;
            utilLcdDisplayValue(3, (char*)channelText[txtChannel], txtValue, " dBm");
        }
        else
            barHeight=3;
    }
}
void select_within_real_virtual(void)
{

	char mybuf[4];
	char user_data=0;


	if(real_virtual == REAL_INSTRUMENT)
	{
		while(wrv_loop == TRUE)
		{
			print_sel_real_screen();
			user_data = expect_value(2);

				if( user_data != 0)
				{
					bzero(mybuf,4);
					//sprintf(mybuf,"%d",user_data);  //TODO
					////printf_pc_code((__code char*)"User pressed");
					////printf_pc_code((__code char*)"%s",mybuf);

					switch(user_data)
					{
						case 1:
						{
							printf_pc_code((__code char*)"\n\r***Drum is the selected Instrument***\n\r");
							drum_piano_guitar_rv = DRUM_REAL_INSTRUMENT;
							drum_piano_guitar = DRUM;
							break;
						}

						case 2:
						{
							printf_pc_code((__code char*)"***\n\rPiano is the selected Instrument***\n\r");
							drum_piano_guitar_rv = PIANO_REAL_INSTRUMENT;
							drum_piano_guitar = PIANO;
							break;
						}

						default:
							break;
					}

					break;
				}
				else
				{
					printf_pc_code((__code char*)"INVALID DATA\n\r");
					halMcuWaitMs(1000);
					clear_screen();
				}
		}
	}
	else if(real_virtual == VIRTUAL_INSTRUMENT) 	//Virtual Instrument
	{
		while(wrv_loop == TRUE)
		{
			print_sel_virtual_screen();
			user_data = expect_value(3);

				if( user_data != 0)
				{
					bzero(mybuf,4);
					//sprintf(mybuf,"%d",user_data);  //TODO
					////printf_pc_code((__code char*)"User pressed");
					////printf_pc_code((__code char*)"%s",mybuf);

					switch(user_data)
					{
						case 1:
						{
							printf_pc_code((__code char*)"\n\r***Drum is the selected Virtual Instrument***\n\r");
							drum_piano_guitar_rv = DRUM_VIRTUAL_INSTRUMENT;
							drum_piano_guitar = DRUM;
							break;
						}

						case 2:
						{
							printf_pc_code((__code char*)"\n\r***Piano is the selected Virtual Instrument***\n\r");
							drum_piano_guitar_rv = PIANO_VIRTUAL_INSTRUMENT;
							drum_piano_guitar = PIANO;
							break;
						}

						case 3:
						{
							printf_pc_code((__code char*)"\n\r***Guitar is the selected Virtual Instrument***\n\r");
							drum_piano_guitar_rv = GUITAR_VIRTUAL_INSTRUMENT;
							drum_piano_guitar = GUITAR;
							break;
						}

						default:
							break;
					}


					break;
				}
				else
				{
					printf_pc_code((__code char*)"INVALID DATA\n\r");
					halMcuWaitMs(1000);
					clear_screen();
				}

		}
	}

}
void select_piano_type(void)
{

	char mybuf[4];
	char user_data=0;

	while(piano_loop == TRUE)
			{
				print_sel_piano_types();
				user_data = expect_value(6);

					if( user_data != 0)
					{
						bzero(mybuf,4);
						//sprintf(mybuf,"%d",user_data);
						////printf_pc_code((__code char*)"User pressed");
						////printf_pc_code((__code char*)"%s",mybuf);

						switch(user_data)
						{
							case 1:
							{
								//printf_pc_code((__code char*)"\n\r***Acoustic Grand Piano is the selected Instrument***\n\n\r");
								piano_type = ACOUSTIC_GRAND_PIANO;
								break;
							}
							case 2:
							{
								//printf_pc_code((__code char*)"\n\r***Bright Acoustic Piano is the selected Instrument***\n\r");
								piano_type = BRIGHT_ACOUSTIC_PIANO;
								break;
							}
							case 3:
							{
								//printf_pc_code((__code char*)"\n\r***Electric Grand Piano is the selected Instrument***\n\n\r");
								piano_type = ELECTRIC_GRAND_PIANO;
								break;
							}
							case 4:
							{
								//printf_pc_code((__code char*)"\n\r***Honky Tonky Piano is the selected Instrument***\n\n\r");
								piano_type = HONKY_TONKY_PIANO;
								break;
							}
							case 5:
							{
								//printf_pc_code((__code char*)"\n\r***Electric Piano 1 is the selected Instrument***\n\n\r");
								piano_type = ELECTRIC_PIANO_1;
								break;
							}
							case 6:
							{
								//printf_pc_code((__code char*)"\n\r***Electric Piano 2 is the selected Instrument***\n\n\r");
								piano_type = ELECTRIC_PIANO_2;
								break;
							}

							default:
								break;
						}

						break;
					}
					else
					{
						printf_pc_code((__code char*)"INVALID DATA\n\r");
						halMcuWaitMs(1000);
						clear_screen();
					}
			}
}
void select_guitar_type(void)
{

	char mybuf[4];
	char user_data=0;

	while(guitar_loop == TRUE)
			{
				print_sel_guitar_types();
				user_data = expect_value(8);

					if( user_data != 0)
					{
						bzero(mybuf,4);
						//sprintf(mybuf,"%d",user_data);
						////printf_pc_code((__code char*)"User pressed");
						////printf_pc_code((__code char*)"%s",mybuf);

						switch(user_data)
						{
							case 1:
							{
								//printf_pc_code((__code char*)"\n\r***Acoustic Guitar (Nylon) is the selected Instrument***\n\n\r");
								piano_type = ACOUSTIC_GUITAR_NYLON;
								break;
							}

							case 2:
							{
								//printf_pc_code((__code char*)"\n\r***Acoustic Guitar (Steel) is the selected Instrument***\n\n\r");
								piano_type = ACOUSTIC_GUITAR_STEEL;
								break;
							}


							case 3:
							{
								//printf_pc_code((__code char*)"\n\r***Electric Guitar (Jazz) is the selected Instrument***\n\n\r");
								piano_type = ELECTRIC_GUITAR_JAZZ;
								break;
							}



							case 4:
							{
								//printf_pc_code((__code char*)"\n\r***Electric Guitar (Clean) is the selected Instrument***\n\n\r");
								piano_type = ELECTRIC_GUITAR_CLEAN;
								break;
							}


							case 5:
							{
								//printf_pc_code((__code char*)"\n\r***Electric Guitar (Muted) is the selected Instrument***\n\n\r");
								piano_type = ELECTRIC_GUITAR_MUTED;
								break;
							}


							case 6:
							{
								//printf_pc_code((__code char*)"\n\r***Overdriven Guitar is the selected Instrument***\n\n\r");
								piano_type = OVERDRIVEN_GUITAR;
								break;
							}


							case 7:
							{
								//printf_pc_code((__code char*)"\n\r***Distortion Guitar is the selected Instrument***\n\n\r");
								piano_type = DISTORTION_GUITAR;
								break;
							}


							case 8:
							{
								//printf_pc_code((__code char*)"\n\r***Guitar Harmonics is the selected Instrument***\n\n\r");
								piano_type = GUITAR_HARMONICS;
								break;
							}

							default:
								break;
						}

						break;
					}
					else
					{
						printf_pc_code((__code char*)"INVALID DATA\n\r");
						halMcuWaitMs(1000);
						clear_screen();
					}
			}
}