105 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			105 lines
		
	
	
		
			1.8 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"
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | // 作为批检仪使用时读取按键
 | ||
|  | 
 | ||
|  | 
 | ||
|  | typedef struct{ | ||
|  |   int inited; | ||
|  |   int run; | ||
|  | }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,*in2,*in3,*in4; | ||
|  |   int input=0,input_lock=1; | ||
|  |   in1=dev_get("gpioin1"); | ||
|  |   in2=dev_get("gpioin2"); | ||
|  |   in3=dev_get("gpioin3"); | ||
|  |   in4=dev_get("gpioin4"); | ||
|  |   in1->init(in1); | ||
|  |   in2->init(in2); | ||
|  |   in3->init(in3); | ||
|  |   in4->init(in4); | ||
|  | 
 | ||
|  |   while (s->run) | ||
|  |   { | ||
|  |     rt_thread_mdelay(20); | ||
|  |     //input=(in1->state(in1))|(in2->state(in2)<<1)|(in3->state(in3)<<2)|(in4->state(in4)<<3);
 | ||
|  |     input=(in1->state(in1)); | ||
|  |     if(input!=input_lock) | ||
|  |     { | ||
|  |       DBG_LOG("key=%08X",input); | ||
|  |       input_lock=input; | ||
|  |       if((input&1)==0) | ||
|  |       { | ||
|  |         request_check(s); | ||
|  |       } | ||
|  |     } | ||
|  |   } | ||
|  |      | ||
|  | } | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | // 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 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); | ||
|  |   } | ||
|  |   return 0; | ||
|  | } | ||
|  | app_init_export(init_thread) | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 |