📄 console_remote_control.cpp
字号:
}
/**
*******************************************************************************
* PollKeyboardThread is the entry point for the thread which polls the keyboard.
* If the keyboard is pressed the thread will try to convert the keycode into a
* remote control button code and will call the remote callback.
*
*******************************************************************************/
static void PollKeyboardThread ( void )
{
KeyboardKeycodeType keycode;
RC_KEY remoteControlButton;
while ( pollKeyboardThreadExitRequest == FALSE )
{
if ( Keyboard_IsKeyAvailable() == TRUE )
{
keycode = Keyboard_GetKey();
if ( keycode == '?' )
{
RemoteControlHelp();
}
else
if ( ConvertKeycodeToRemoteCode( keycode, &remoteControlButton ) == TRUE )
{
if ( remoteCallback != NULL )
{
DbgPrint(("RemoteControl: sending button %s\n",RemoteControlButtonName(remoteControlButton)));
remoteCallback(remoteCallbackContext,remoteControlButton,FALSE);
}
}
}
OS_TaskDelay(OS_WAIT_1S/10);
}
OS_TaskExit();
}
/**
*******************************************************************************
* RemoteControlHelp outputs a help banner using debug print
*
*******************************************************************************/
void RemoteControlHelp ( void )
{
DbgPrint((" REMOTE CONTROL HELP \n"));
DbgPrint(("------------------------------------------\n"));
DbgPrint(("X = power P = play \n"));
DbgPrint(("Q = quit S = stop \n"));
DbgPrint(("M = menu U = pause \n"));
DbgPrint(("R = return < = skip back \n"));
DbgPrint(("T = title > = skip fwd \n"));
DbgPrint(("V = setup <enter> = select \n"));
DbgPrint(("D = display arrows = arrows \n"));
DbgPrint(("E = eject 0..9 = 0..9 \n"));
DbgPrint(("------------------------------------------\n"));
}
/**
*******************************************************************************
* Remote_Initialize initializes the keyboard interface and creates the thread
* used to poll the keyboard.
*
* @return RC_SUCCESS if successful, RC_FAILURE otherwise
*******************************************************************************/
RC_STATUS Remote_Initialize(void)
{
Keyboard_Open();
pollKeyboardThreadHandle = OS_TaskSpawn("poll_keyboard_thread", OS_TASK_LOW_PRIORITY, POLL_KEYBOARD_THREAD_STACK_SIZE, (OS_FUNCPTR)PollKeyboardThread);
if ( pollKeyboardThreadHandle == (ERR_CODE)OS_FAILURE )
{
DbgPrint(("Remote_Initialize: unable to create keyboard polling thread\n"));
return ( RC_FAILURE );
}
RemoteControlHelp();
remoteInitialized = TRUE;
return ( RC_SUCCESS );
}
/**
*******************************************************************************
* Remote_Uninitialize releases the keyboard interface terminates the thread
* used to poll the keyboard.
*
* @return RC_SUCCESS if successful, RC_FAILURE otherwise
*******************************************************************************/
RC_STATUS Remote_Uninitialize(void)
{
OS_STATUS osStatus;
remoteInitialized = FALSE;
pollKeyboardThreadExitRequest = TRUE;
osStatus = OS_TaskJoin(pollKeyboardThreadHandle);
if ( osStatus != OS_OK )
{
return ( RC_FAILURE );
}
OS_TaskDelete(pollKeyboardThreadHandle);
Keyboard_Close();
return ( RC_SUCCESS );
}
/**
*******************************************************************************
* Remote_IsInitialized checks if remote has been initialized
*
* @return TRUE if remote module has been initialized, FASLE otherwise
*******************************************************************************/
BOOLEAN Remote_IsInitialized(void)
{
return ( remoteInitialized );
}
/**
*******************************************************************************
* Remote_Write not implemented
*
* @return always returns RC_FAILURE
*******************************************************************************/
RC_STATUS Remote_Write(ULONG KeyCode, PVOID pvParam)
{
return ( RC_FAILURE );
}
/**
*******************************************************************************
* Remote_RegisterCallback registers a callback to be used to send remote control
* button presses. This module can only support 1 callback.
*
* @param newCallback RC_CALLBACK routine
* @param pvContext pointer to a void that is passed when callback is made
*
* @return RC_SUCCESS if successful, RC_FAILURE otherwise
*******************************************************************************/
RC_STATUS Remote_RegisterCallback(RC_CALLBACK newCallback, PVOID pvContext)
{
remoteCallback = newCallback;
remoteCallbackContext = pvContext;
return ( RC_SUCCESS );
}
/**
*******************************************************************************
* Remote_RemoveCallback unregisters a callback used to send remote control
* button presses. This module can only support 1 callback.
*
* @param callback RC_CALLBACK routine to be unregistered
*
* @return RC_SUCCESS if successful, RC_FAILURE if callback has not been registered
*******************************************************************************/
RC_STATUS Remote_RemoveCallback(RC_CALLBACK callback)
{
if ( remoteCallback != callback )
{
return ( RC_FAILURE);
}
remoteCallback = NULL;
remoteCallbackContext = NULL;
return ( RC_SUCCESS );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -