115 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			115 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| 
 | |
| #include "board.h"
 | |
| #include "rtthread.h"
 | |
| #include "debug.h"
 | |
| #include "string.h"
 | |
| #include "dev_flash.h"
 | |
| #include "prot_uc.h"
 | |
| #include "key.h"
 | |
| #include "mystdlib.h"
 | |
| #include "transmit.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("gpioin1");
 | |
|   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)
 | |
|       {
 | |
|         // 主机交互存在且非忙的时候才发送请求
 | |
|         if(s->tran&&(tran_get_busy(s->tran)==0))
 | |
|           request_check(s);
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|     
 | |
| }
 | |
| 
 | |
| // 获取实时按键状态,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 void init_later(void *t)
 | |
| {
 | |
|   void *protu=app_variable("protu",0,0);
 | |
|   if(protu){
 | |
|     protu_codec_set(protu,protu_find_codec("ym_checker"));
 | |
|     connect(t,key_send_signal,0,protu,protu_send_call);
 | |
|     DBG_LOG("key thread created");
 | |
|   }else{
 | |
|     DBG_WARN("can not fond variable \"protu\"");
 | |
|   }
 | |
| }
 | |
| static void init_tran(void *t)
 | |
| {
 | |
|   self_def *s=t;
 | |
|   s->tran=app_variable("tran",0,0);
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| 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);
 | |
|     app_valid_call("protu",init_later,s);
 | |
|     app_valid_call("tran",init_tran,s);
 | |
|   }
 | |
|   return 0;
 | |
| }
 | |
| app_init_export(init_thread)
 | |
| 
 | |
| 
 | |
| 
 | 
