📄 hw_recog_fs.c
字号:
//HW_recog.c
#include "os_api.h"
#include "HW_recog_FS.h"
#include "HW_Core.h"
#include "user_tasks_id.h"
#include "mmi_theme.h"
#include "mmi_signal.h"
#ifdef _SMMI_UNIT_TEST_
#define LOCAL
#else
#define LOCAL static
#endif
#define HW_TRACE SCI_TRACE_LOW
#define HWRECOG_STACK_SIZE 0x400
#define HWRECOG_QUEUE_NUM 20
uint32 HWrecog_stack_addr[HWRECOG_STACK_SIZE >> 2];
uint32 HWrecog_queue_addr[HWRECOG_QUEUE_NUM * SCI_QUEUE_ITEM_SIZE];
#ifdef WIN32
LOCAL uint8 g_tp_buffer[TP_SIZE * 2] = {0};
#else
LOCAL uint16 g_tp_buffer[TP_SIZE * 2] = {0};
#endif
LOCAL uint8 g_Hw_Buf[DATASIZE]; //allocate 12K bytes memory
LOCAL uint8 *g_dic_data;
#ifdef WIN32
typedef int (__stdcall*RECOG_PROC)(uint16*pStrokInfo, uint16*pCandidates, int dMaxCandiNumber, int dRecognizeType);
#else
typedef int (*RECOG_PROC)(uint16*pStrokInfo, uint16*pCandidates, int dMaxCandiNumber, int dRecognizeType);
#endif
RECOG_PROC recog_proc;
LOCAL void thread_HWrecog_entry(uint32 argc, void *argv);
LOCAL void HWRecog_Startup(HWRECOG_SIGNAL_T *sig_ptr);
LOCAL void SendSignalToIME(uint16 *candi_data_ptr, uint8 cur_candi_num);
uint32 HWRecog_task_init(void)
{
uint32 result = 0;
result = SCI_CreateStaticThread(HW_RECOG, "HW_recog", thread_HWrecog_entry, 0, 0,
HWrecog_stack_addr, HWRECOG_STACK_SIZE,
SCI_PRIORITY_IDLE, SCI_PREEMPT,
"Q_HW_recog", HWrecog_queue_addr, HWRECOG_QUEUE_NUM,
SCI_AUTO_START);
return result;
}
#ifdef WIN32
// WIN32 version:
// get recognize proc from "hw.dll"
#include "windows.h"
static void* GetProcAddressFromDll(char *pDllName, char *pProcName)
{
HMODULE hRecogDll;
hRecogDll = LoadLibrary(pDllName);
SCI_ASSERT(NULL != hRecogDll);
return GetProcAddress(hRecogDll, pProcName);
}
#endif
LOCAL void thread_HWrecog_entry(uint32 argc, void *argv)
{
HWRECOG_SIGNAL_T *sig_ptr;
uint32 run_time = 0;
#ifndef WIN32
g_dic_data = (uint8*)MMITHEME_GetHwIMEDicdara();
HWSetDictionary( (uint32)g_Hw_Buf, (uint32)g_dic_data );
#endif
#ifdef WIN32
recog_proc = GetProcAddressFromDll("hw.dll", "HWRecognize"); // ! copy hw.dll to simulator dir
SCI_ASSERT(NULL != recog_proc);
#else
recog_proc = HWRecognize;
#endif
while (1)
{
sig_ptr = (HWRECOG_SIGNAL_T *)SCI_GetSignal(HW_RECOG);
//HW_TRACE("thread_HWrecog_entry: Received signal: 0x%04x!", sig_ptr->SignalCode);
//run_time = SCI_GetTickCount();
if(NULL != sig_ptr)
{
HWRecog_Startup(sig_ptr);
}
SCI_FREE(sig_ptr);
//run_time = SCI_GetTickCount() - run_time;
//HW_TRACE("HW_RECOG: task run_time = %dms", run_time);
}
}
LOCAL void HWRecog_Startup(HWRECOG_SIGNAL_T *sig_ptr)
{
static uint16 s_candi_data[HW_CANDI_MAX_NUM] = {0};
uint16 *tp_buffer_ptr = g_tp_buffer;
int max_candi_num = sig_ptr->max_candi_num;
int recog_type = sig_ptr->recog_type;
uint8 cur_candi_num = 0;
uint32 recog_time;
SCI_ASSERT(NULL != sig_ptr);
SCI_ASSERT(NULL != sig_ptr->tp_buffer_ptr);
//HW_TRACE("HW_RECOG: sig_ptr->max_candi_num = %d", sig_ptr->max_candi_num);
HW_TRACE("HW_RECOG: sig_ptr->tp_buffer_ptr = %x", sig_ptr->tp_buffer_ptr);
HW_TRACE("HW_RECOG: recog_type = %x", recog_type);
SCI_MEMCPY(tp_buffer_ptr, sig_ptr->tp_buffer_ptr, sizeof(g_tp_buffer));
SCI_MEMSET(sig_ptr->tp_buffer_ptr, 0, sizeof(g_tp_buffer));
//HW_TRACE("HWRecog_Startup: start TickCount = %d", SCI_GetTickCount());
recog_time = SCI_GetTickCount();
cur_candi_num = recog_proc(tp_buffer_ptr,
s_candi_data,
max_candi_num,
recog_type);
recog_time = SCI_GetTickCount() - recog_time;
HW_TRACE("HWRecog_Startup: recognise total time = %d", recog_time);
HW_TRACE("HWRecog_Startup: cur_candi_num = 0x%x", cur_candi_num);
//HW_TRACE("HWRecog_Startup: s_candi_data[0] = 0x%x", s_candi_data[0]);
//HW_TRACE("HWRecog_Startup: s_candi_data[1] = 0x%x", s_candi_data[1]);
//HW_TRACE("HWRecog_Startup: s_candi_data[2] = 0x%x", s_candi_data[2]);
//HW_TRACE("HWRecog_Startup: s_candi_data[3] = 0x%x", s_candi_data[3]);
//HW_TRACE("HWRecog_Startup: s_candi_data[4] = 0x%x", s_candi_data[4]);
//HW_TRACE("HWRecog_Startup: s_candi_data[5] = 0x%x", s_candi_data[5]);
//HW_TRACE("HWRecog_Startup: s_candi_data[6] = 0x%x", s_candi_data[6]);
//HW_TRACE("HWRecog_Startup: s_candi_data[7] = 0x%x", s_candi_data[7]);
SendSignalToIME(s_candi_data, cur_candi_num);
}
LOCAL void SendSignalToIME(uint16 *candi_data_ptr, uint8 cur_candi_num)
{
uint32 result = 0;
HWCANDI_SIGNAL_T *candi_sig;
SCI_ASSERT(NULL != candi_data_ptr);
MMI_CREATE_SIGNAL(
candi_sig,
0,
sizeof(HWCANDI_SIGNAL_T),
HW_RECOG);
candi_sig->candi_buffer_ptr = candi_data_ptr;
candi_sig->cur_candi_num = cur_candi_num;
HW_TRACE("HWRecog: SendSignalToIME()");
result = SCI_SendSignal((xSignalHeader)candi_sig, P_APP);
if(SCI_SUCCESS != result)
{
SCI_TRACE_LOW("SendSignalToIME: result = %d", result);
SCI_ASSERT(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -