96 lines
1.5 KiB
C
96 lines
1.5 KiB
C
|
|
#include "board.h"
|
|
#include "rtthread.h"
|
|
#include "debug.h"
|
|
#include "string.h"
|
|
#include "dev_flash.h"
|
|
#include "commend.h"
|
|
#include "key.h"
|
|
#include "mystdlib.h"
|
|
|
|
|
|
|
|
// 作为批检仪使用时读取按键
|
|
|
|
|
|
typedef struct{
|
|
int inited;
|
|
int run;
|
|
int input;
|
|
int input_lock;
|
|
void *tran;
|
|
}self_def;
|
|
|
|
|
|
static self_def g_self;
|
|
|
|
static void request_check(void *p);
|
|
|
|
static void key_thread(void *arg)
|
|
{
|
|
self_def *s=arg;
|
|
gpioin_def *in1;
|
|
in1=dev_get("key");
|
|
in1->init(in1);
|
|
s->input=0;
|
|
s->input_lock=1;
|
|
|
|
while (s->run)
|
|
{
|
|
rt_thread_mdelay(20);
|
|
s->input=(in1->state(in1));
|
|
if(s->input!=s->input_lock)
|
|
{
|
|
DBG_LOG("key=%08X",s->input);
|
|
s->input_lock=s->input;
|
|
if((s->input&1)==0)
|
|
{
|
|
// 发送按键按下消息
|
|
cmd_print("key pressed");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// 获取实时按键状态,1按下
|
|
int key_pressed(void)
|
|
{
|
|
self_def *s=&g_self;
|
|
return !s->input;
|
|
}
|
|
|
|
|
|
// cmd=0x37
|
|
static void request_check(void *p)
|
|
{
|
|
const sys_param_def *par=sys_param();
|
|
array_def *d=arr_creat();
|
|
emit key_send_signal(p,0x37,arr_temp(d));
|
|
//DBG_LOG("tcp liver:%s",str_temp(arr_string(d)));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int init_thread(void)
|
|
{
|
|
if(strcmp(sys_param()->device_type,"checker")==0)
|
|
{
|
|
self_def *s=&g_self;
|
|
s->inited=1;
|
|
s->run=1;
|
|
rt_thread_t rt_t=rt_thread_create("key_t",key_thread,s,1024,15,20);
|
|
rt_thread_startup(rt_t);
|
|
DBG_LOG("key thread created.");
|
|
}
|
|
return 0;
|
|
}
|
|
app_init_export(init_thread)
|
|
|
|
|
|
|