kpd_api.c
来自「是一个手机功能的模拟程序」· C语言 代码 · 共 457 行 · 第 1/2 页
C
457 行
}
}
}
return ret;
}
/**
* function: kpd_change_mode
*/
T_RV_RET kpd_change_mode( T_KPD_SUBSCRIBER subscriber,
T_KPD_VIRTUAL_KEY_TABLE* notified_keys_p,
T_KPD_MODE new_mode)
{
T_RV_RET ret = RV_INVALID_PARAMETER;
T_RVF_MB_STATUS mb_status;
T_KPD_CHANGE_MODE_MSG* msg_change_mode_p;
T_SUBSCRIBER_ID subscriber_id;
UINT8 i;
/* Check if subscriber id is correct */
if ( kpd_subscriber_id_used(subscriber, &subscriber_id) == TRUE)
{
if ( (notified_keys_p != 0)
&& (notified_keys_p->nb_notified_keys > 0)
&& (notified_keys_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) )
{
/* Reserve memory for message */
mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_CHANGE_MODE_MSG), (void **) &msg_change_mode_p);
if (mb_status != RVF_RED) /* Memory allocation success */
{
/* Fill the message */
msg_change_mode_p->hdr.msg_id = KPD_CHANGE_MODE_MSG;
msg_change_mode_p->subscriber_id = subscriber_id;
msg_change_mode_p->new_mode = new_mode;
msg_change_mode_p->notified_keys.nb_notified_keys = notified_keys_p->nb_notified_keys;
for (i = 0; i < notified_keys_p->nb_notified_keys; i++)
msg_change_mode_p->notified_keys.notified_keys[i] = notified_keys_p->notified_keys[i];
/* Send message to the keypad task */
rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_change_mode_p);
ret = RV_OK;
}
else
{
KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR);
ret = RV_MEMORY_ERR;
}
}
}
return ret;
}
/**
* function: kpd_own_keypad
*/
T_RV_RET kpd_own_keypad( T_KPD_SUBSCRIBER subscriber,
BOOL is_keypad_owner,
T_KPD_VIRTUAL_KEY_TABLE* keys_owner_p)
{
T_RV_RET ret = RV_INVALID_PARAMETER;
T_RVF_MB_STATUS mb_status;
T_KPD_OWN_KEYPAD_MSG* msg_own_keypad_p;
T_SUBSCRIBER_ID subscriber_id;
UINT8 i;
/* Check if subscriber id is correct */
if ( kpd_subscriber_id_used(subscriber, &subscriber_id) == TRUE)
{
/* If subscriber want to be the owner of the keypad, list of keys is checked
else, subscriber want to release the keypad, check list of key is useless */
if (is_keypad_owner == TRUE)
{
if ( (keys_owner_p != 0)
&& (keys_owner_p->nb_notified_keys > 0)
&& (keys_owner_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS) )
ret = RV_OK;
}
else
ret = RV_OK;
if (ret == RV_OK)
{
/* Reserve memory for message */
mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_OWN_KEYPAD_MSG), (void **) &msg_own_keypad_p);
if (mb_status != RVF_RED) /* Memory allocation success */
{
/* Fill the message */
msg_own_keypad_p->hdr.msg_id = KPD_OWN_KEYPAD_MSG;
msg_own_keypad_p->subscriber_id = subscriber_id;
msg_own_keypad_p->is_keypad_owner = is_keypad_owner;
msg_own_keypad_p->keys_owner.nb_notified_keys = keys_owner_p->nb_notified_keys;
for (i = 0; i < keys_owner_p->nb_notified_keys; i++)
msg_own_keypad_p->keys_owner.notified_keys[i] = keys_owner_p->notified_keys[i];
/* Send message to the keypad task */
rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_own_keypad_p);
}
else
{
KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR);
ret = RV_MEMORY_ERR;
}
}
}
return ret;
}
/**
* function: kpd_set_key_config
*/
T_RV_RET kpd_set_key_config(T_KPD_SUBSCRIBER subscriber,
T_KPD_VIRTUAL_KEY_TABLE* reference_keys_p,
T_KPD_VIRTUAL_KEY_TABLE* new_keys_p)
{
#ifdef KPD_MODE_CONFIG
T_RVF_MB_STATUS mb_status;
T_KPD_SET_CONFIG_MODE_MSG* msg_set_config_mode_p;
T_RV_RET ret = RV_INVALID_PARAMETER;
T_SUBSCRIBER_ID subscriber_id;
UINT8 i;
INT8 position;
/* Check if subscriber id is correct */
if ( kpd_subscriber_id_used(subscriber, &subscriber_id) == TRUE)
{
if ( (reference_keys_p != 0)
&& (reference_keys_p->nb_notified_keys > 0)
&& (reference_keys_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS)
&& (new_keys_p != 0)
&& (new_keys_p->nb_notified_keys > 0)
&& (new_keys_p->nb_notified_keys <= KPD_NB_PHYSICAL_KEYS)
&& (reference_keys_p->nb_notified_keys == new_keys_p->nb_notified_keys) )
{
/* Check if all keys of reference_keys_p are defined in default mode */
for (i = 0; i < reference_keys_p->nb_notified_keys; i++)
{
ret = kpd_retrieve_virtual_key_position(reference_keys_p->notified_keys[i],
KPD_DEFAULT_MODE,&position);
if (ret == RV_INVALID_PARAMETER)
return ret;
}
if (ret == RV_OK)
{
/* Reserve memory for message */
mb_status = rvf_get_buf (kpd_env_ctrl_blk->prim_id, sizeof(T_KPD_SET_CONFIG_MODE_MSG), (void **) &msg_set_config_mode_p);
if (mb_status != RVF_RED) /* Memory allocation success */
{
/* Fill the message */
msg_set_config_mode_p->hdr.msg_id = KPD_SET_CONFIG_MODE_MSG;
msg_set_config_mode_p->subscriber_id = subscriber_id;
msg_set_config_mode_p->reference_keys.nb_notified_keys = reference_keys_p->nb_notified_keys;
for (i = 0; i < reference_keys_p->nb_notified_keys; i++)
msg_set_config_mode_p->reference_keys.notified_keys[i] = reference_keys_p->notified_keys[i];
msg_set_config_mode_p->new_keys.nb_notified_keys = new_keys_p->nb_notified_keys;
for (i = 0; i < new_keys_p->nb_notified_keys; i++)
msg_set_config_mode_p->new_keys.notified_keys[i] = new_keys_p->notified_keys[i];
/* Send message to the keypad task */
rvf_send_msg(kpd_env_ctrl_blk->addr_id, msg_set_config_mode_p);
}
else
{
KPD_SEND_TRACE("KPD: Memory allocation error", RV_TRACE_LEVEL_ERROR);
ret = RV_MEMORY_ERR;
}
}
}
}
return ret;
#else
return RV_NOT_SUPPORTED;
#endif
}
/**
* function: kpd_get_available_keys
*/
T_RV_RET kpd_get_available_keys( T_KPD_VIRTUAL_KEY_TABLE* available_keys_p)
{
kpd_get_default_keys(available_keys_p);
return RV_OK;
}
/**
* function: kpd_get_ascii_key_code
*/
T_RV_RET kpd_get_ascii_key_code( T_KPD_VIRTUAL_KEY_ID key,
T_KPD_MODE mode,
char** ascii_code_pp)
{
INT8 position;
/* Check if mode is authorized */
if ( (mode != KPD_DEFAULT_MODE) && (mode != KPD_ALPHANUMERIC_MODE) )
return RV_INVALID_PARAMETER;
/* Check if key exist in the defined mode */
kpd_retrieve_virtual_key_position(key, mode, &position);
if (position == KPD_POS_NOT_AVAILABLE)
return RV_INVALID_PARAMETER;
/* Retrieve ASCII key value */
kpd_get_ascii_key_value(position, mode, ascii_code_pp);
return RV_OK;
}
/**
* function: KP_Init
*/
void KP_Init( void(pressed(T_KPD_VIRTUAL_KEY_ID)), void(released(void)) )
{
Kp.pressed = pressed;
Kp.released = released;
}
/*@}*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?