You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.5 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2022. All rights reserved.
* Description: main
* Author: App-Dev Group
* Create: 2012-01-01
*/
#include <thread>
#include "tinyxml2.h"
#include "IrUser.h"
using namespace std;
using namespace android;
static std::unique_ptr<IrUser> g_irUser = std::make_unique<IrUser>();
namespace {
const int WINDOW = 258;
void IrSampleThread()
{
unsigned long long key = 0LL;
unsigned int linuxKeycode = 0;
unsigned int readTimeout = 200; // ms
unsigned int num = 0;
bool threadStopFlag = false;
bool isMouseEventKey = false;
char name[64]; // 64 is name array init size
uapi_key_status status = UAPI_KEY_STATUS_DOWN;
static bool u32MouseMode = false;
static int yCoordinate = 360; // half of 720
g_irUser->InitCoordinate(yCoordinate);
while (!threadStopFlag) {
int ret = g_irUser->options->androidIrInterface->IR_GetValueWithProtocol(status, key, name, sizeof(name),
readTimeout);
if (ret != 0) {
if (!g_irUser->options->debugIrEnable) {
continue;
}
g_irUser->IrAutomatedTest(num, key, status);
}
isMouseEventKey = false;
bool isBrowserMouseMode = false;
g_irUser->SetBrowserMouseMode(isBrowserMouseMode);
if (!g_irUser->SetLinuxKeycode(linuxKeycode, key)) {
continue;
}
// shield PIP(WINDOW) key
if (linuxKeycode == WINDOW) {
isMouseEventKey = true;
XLOGD("you have pressed PIP key\n ,yCoordinate is %d ", yCoordinate);
if (status == UAPI_KEY_STATUS_UP) {
u32MouseMode = !u32MouseMode;
}
}
printf("IR got value linux_key:%u; status:%d.;", linuxKeycode, status);
if (isBrowserMouseMode || u32MouseMode) {
XLOGD("We are entering into MOUSE MODE! \ny_coodinate is %d", yCoordinate);
g_irUser->SetMoveStep(isBrowserMouseMode, status);
g_irUser->LinuxKeycodeLogic(linuxKeycode, status, isMouseEventKey, yCoordinate);
} else {
g_irUser->RotateKey(linuxKeycode);
}
g_irUser->ReportKey(isMouseEventKey, status, linuxKeycode);
}
return;
}
void ThreadProcess()
{
thread irThread(IrSampleThread);
irThread.join();
g_irUser->options->androidIrInterface->IR_DeInit();
printf("Ir sample thread exit! Bye!\n");
}
}
int main(int argc, char *argv[])
{
if (argv == nullptr ||
g_irUser->options->ProcessOptions(argc, argv) == TD_SUCCESS ||
g_irUser->androidVinputInterface->VinputInit() == -1) {
exit(-1);
}
g_irUser->keyParsInterface->GetKeycode(g_irUser->keyArray, g_irUser->keyArryNum);
g_irUser->SetPowerKey();
if (g_irUser->options->CheckParams() < 0) {
g_irUser->options->Usage(*argv[0]);
exit(-1);
}
// open
printf("IR_Init-ing...");
if (g_irUser->options->androidIrInterface->IR_Init() != 0) {
perror("Fail to open ir dev!");
exit(-1);
}
if (g_irUser->options->CheckParamsSet() == TD_FAILURE) {
g_irUser->options->androidIrInterface->IR_DeInit();
exit(-1);
}
ThreadProcess();
return 0;
}