同步操作将从 OpenHarmony/drivers_peripheral 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
This repository mainly defines and implements the following types of Hardware Driver Interfaces (HDIs) of the input module, allowing upper-layer input services to perform operations for the input devices:
Figure 1 HDI architecture of the input module
The source code directory structure is as follows:
/drivers/peripheral/input
├── hal # HAL code
│ └── include # HAL header files
│ └── src # HAL code implementation
├── interfaces # Driver capability APIs provided for upper-layer services
│ └── include # APIs exposed externally
├── test # Test code
│ └── unittest # Unit test code
The input driver provides input services with driver capability APIs that can be directly called. The APIs involve the Input Manager module, Input Reporter module, and Input Controller module. For example, you can call the APIs to enable or disable an input device, register a listener callback, query the device information, and control the power status.
Table 1 describes major HDI APIs provided by the input module.
Table 1 Major HDI APIs of the input module
The core function of this repository is to provide HDIs for upper-layer input system services to implement input driver capabilities.
The following sample code describes how to use the input HDIs:
#include "input_manager.h"
#define DEV_INDEX 1
IInputInterface *g_inputInterface;
InputReportEventCb g_callback;
/* Define the callback for data reporting. */
static void ReportEventPkgCallback(const EventPackage **pkgs, uint32_t count)
{
if (pkgs == NULL || count > MAX_PKG_NUM) {
return;
}
for (uint32_t i = 0; i < count; i++) {
HDF_LOGI("%s: pkgs[%d] = 0x%x, 0x%x, %d", __func__, i, pkgs[i]->type, pkgs[i]->code, pkgs[i]->value);
}
}
int InputServiceSample(void)
{
uint32_t devType = INIT_DEFAULT_VALUE;
/* Get interfaces of input driver capabilities. */
int ret = GetInputInterface(&g_inputInterface);
if (ret != INPUT_SUCCESS) {
HDF_LOGE("%s: get input interfaces failed, ret = %d", __func__, ret);
return ret;
}
INPUT_CHECK_NULL_POINTER(g_inputInterface, INPUT_NULL_PTR);
INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputManager, INPUT_NULL_PTR);
/* Open a specified input device file. */
ret = g_inputInterface->iInputManager->OpenInputDevice(DEV_INDEX);
if (ret) {
HDF_LOGE("%s: open input device failed, ret = %d", __func__, ret);
return ret;
}
INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputController, INPUT_NULL_PTR);
/* Get the type of the input device. */
ret = g_inputInterface->iInputController->GetDeviceType(DEV_INDEX, &devType);
if (ret) {
HDF_LOGE("%s: get device type failed, ret: %d", __FUNCTION__, ret);
return ret;
}
HDF_LOGI("%s: device1's type is %u\n", __FUNCTION__, devType);
/* Register the data reporting callback for a specified input device. */
g_callback.ReportEventPkgCallback = ReportEventPkgCallback;
INPUT_CHECK_NULL_POINTER(g_inputInterface->iInputReporter, INPUT_NULL_PTR);
ret = g_inputInterface->iInputReporter->RegisterReportCallback(DEV_INDEX, &g_callback);
if (ret) {
HDF_LOGE("%s: register callback failed, ret: %d", __FUNCTION__, ret);
return ret;
}
HDF_LOGI("%s: wait 10s for testing, pls touch the panel now", __FUNCTION__);
OsalMSleep(KEEP_ALIVE_TIME_MS);
/* Unregister the callback of the specified input device. */
ret = g_inputInterface->iInputReporter->UnregisterReportCallback(DEV_INDEX);
if (ret) {
HDF_LOGE("%s: unregister callback failed, ret: %d", __FUNCTION__, ret);
return ret;
}
/* Close a specified input device file. */
ret = g_inputInterface->iInputManager->CloseInputDevice(DEV_INDEX);
if (ret) {
HDF_LOGE("%s: close device failed, ret: %d", __FUNCTION__, ret);
return ret;
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。