This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using the joystick on the SmartRF05 board when a peripheral application

Other Parts Discussed in Thread: CC2540

Problem
I have the CC2540 development boards. These are working beautifully with all of the examples. so far. I am trying to create a peripheral application that uses the joystick. I have copied the simpleBLEPeripheral application and it is working perfectly as the simple BLE peripheral application. However the joystick seems to operate strangely. I tried to copy the correct setup and initialization from the simpleBLECentral example since it uses the joystick correctly. I have attached the output in the steps to recreate the problem.

summary:

I have added the register for keys in the init function

I have added a print statement in KEY_CHANGE handler

after a reset I get two KEY change events. The first is the correct joystick movement (left, right, etc.) and the second is a KEY_CHANGE event of 0. at this point all joystick touches are ignored except UP. that causes two KEY_CHANGE events. the first being UP event and the second being a 0. The UP position on the joystick will work forever with two change events but no other KEY_CHANGE events are seen.

In addition when I hit the joystick I am disconnected if I have  BLE connection active.

I am sure there is something simple that I overlooked. Any help would be appreciated. I need to simulate a peripheral application where various buttons/switches are toggled.  I want to keep the connections alive and just respond to the joystick in the peripheral application like the central application does.

********* example output ************

shift: 0 keys: 08   <-- after a reset first hit of joystick LEFT (or any other joystick position) causes two KEY_CHANGE events seen here
shift: 0 keys: 00

after this the only KEY_CHANGE event is joystick UP
this causes two KEY_CHANGE events as shown below
all other hits on joystick do not cause a KEY_CHANGE event

shift: 0 keys: 01
shift: 0 keys: 00



***** KEY Handling ****
static void IC2MBLEPeripheral_HandleKeys( uint8 shift, uint8 keys )
{
  VOID shift;  // Intentionally unreferenced parameter

  printf("shift: %d keys: %02X\n",shift,keys);

    if(keys & HAL_KEY_UP)
    {
    }

    if(keys & HAL_KEY_LEFT)
    {
    }

    if(keys & HAL_KEY_RIGHT)
    {
    }

    if(keys & HAL_KEY_DOWN)
    {
    }

    if(keys & HAL_KEY_CENTER)
    {
    }

}

************** added to init function ******
  // Register for all key events - This app will handle all key events
  RegisterForKeys( IC2MBLEPeripheral_TaskID );

  • I have same problem. Amazingly equal my situation.

    in the disconnect state, it work correctly.

    But when the connect state, problem is occured.

    someone help us would be grateful.

  • Hi Guys,

    I'm not familiar with BLE stack, but I do familiar with smartRF05EB and with cc253x/4x family

    of devices in general. I have one question to you, just out of curiosity, the printf() function, in

    Tymothy's post, have you added it, or it already was there as a part of a BLE sample project?

    My point is, I'm not sure the printf() will work in this case since the output device is LCD, with

    ready API functions (hal_lcd module), moreover, using printf() may result in an unknown, or

    unexplained, behavior.

  • I doesn't use printf() .  Using HAL_LCD API, I plotted joystick's status on LCD.

    here is my code. I can't find my mistake.

    if ( keys & HAL_KEY_UP )
    {
    if ( toggle1 == 1 ){
    toggle1 = 0;
    toggle2 = 0;
    HalLcdWriteStringValue( "STOP 0 ", 0, 10, HAL_LCD_LINE_2 );
    }
    else if ( toggle1 == 0 ){
    toggle1 = 1;
    toggle2 = 0;

    HalLcdWriteStringValue( "SEND 0 :", 1, 10, HAL_LCD_LINE_2 );
    }
    }

    if ( keys & HAL_KEY_LEFT )
    {
    if ( toggle2 == 1 ){
    toggle1 = 0;
    toggle2 = 0;
    HalLcdWriteStringValue( "STOP 1 ", 0, 10, HAL_LCD_LINE_2 );
    }
    else if ( toggle2 == 0 ){
    toggle1 = 0;
    toggle2 = 1;
    HalLcdWriteStringValue( "SEND 1 :", 1, 10, HAL_LCD_LINE_2 );
    }
    }

  • I have resolved my issue. I had the battery service and the joystick enabled at the same time.

    There was a conflict. printf should work also. I have used them but they do take time and will disconnect if there are many printfs or a long printf.