I have a "button" task that receives button down and button receive events. I want to distinguish between short and long button presses. This works the first time; the second call to os_evt_wait_and correctly detects a timeout while waiting for the button release event. However, the second time around, no timeout is detected because the button release event fires right away. while(1) { // Clear any previous events. os_evt_clr( BUTTON_DOWN_EVENT, gButtonTaskID ); os_evt_clr( BUTTON_RELEASE_EVENT, gButtonTaskID ); os_evt_wait_and( BUTTON_DOWN_EVENT, INFINITE_WAIT ); result = os_evt_wait_and(BUTTON_RELEASE_EVENT, 5000 ); //LEDSetup( 0, 0, LED_COLOR_OFF, LED_HOST_COMM_MODE ); // Stop the bluetooth setup task if running. if( gBluetoothSetupTaskID != 0 ) { os_tsk_delete( gBluetoothSetupTaskID ); gBluetoothSetupTaskID = 0; printf( "bluetooth task stopped\n" ); } switch( result) { case OS_R_EVT: // Button was released within 5 sec. printf( "Short button press\n" ); break; case OS_R_TMO: // Button pressed longer than 5 seconds. break; default: break; } } // end of while loop
I apologize for the poor problem description. Let's try that again: I have a "button" task that receives button down and button release events. I want to distinguish between short and long button presses. Short button presses always work. Long button pressed are detected by a timeout while waiting for the button release event. A long button press is detected correctly the first time, but not subsequently. For some reason, the second time around, no timeout is detected because the button release event fires right away even though the button hasn't been released.