[vc_row][vc_column width=”1/1″][vc_column_text]Previous post told us how to install the infrared drivers, and now we read the key value which sending by infrared remote controller to control a LED switch, we need to know how to get the Key value first.[/vc_column_text][vc_tour][vc_tab title=”Preparations:” tab_id=”1387849273-1-6″][vc_column_text]
1.See IR keypad belongs event equipment: Enter the command $ cat / proc / bus / input / devices can view the current input subsystem all of the following event equipment, we find the event equipment ir keypad belongs:
2.Visit the ir-keypad driver registered in input subsystem event event file that reads “/ dev/input/event3″. Is defined in / usr / include / linux / input.h, this document defines the coding structure event event, API, and the standard keys and so on. We just need to read the data in the event event structure can get pressed key code, here’s the next event event structure:
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
}
type ( type of event ) :
EV_KEY: key events , such as the keyboard keys ( which key is pressed ) , left- right mouse button ( under non- strike ) , etc. ;
EV_REL: relative coordinates , mainly refers to moving the mouse event ( relative displacement ) ;
EV_ABS: absolute coordinates , the main means to move the touch screen events , it seems that the mouse can be used in the above , that can not get through to the absolute coordinates of the mouse ( the mouse is a relative displacement of the device ) .
code ( event code ) :
Type the code if the event is EV_KEY, the code is the code for the device keyboard . Code 0 to 127 for the planting key code on the keyboard , 0 × 110 ~ 0 × 116 as the mouse button code, 0 × 110 (BTN_ LEFT) as the left mouse button , 0 × 111 (BTN_RIGHT) is right , 0 × 112 (BTN_ MIDDLE) for the middle mouse button. See other code Meaning / usr / include / linux / input.h file, which will define the appropriate macros to represent different keys. Type the code if the event is EV_REL, code value indicates the type of track. As indicated mouse X -axis direction REL_X ( code 0 × 00), indicating the mouse Y -axis direction REL_Y, indicating the direction of the middle mouse wheel REL_WHEEL.
value ( the value of the event ) :
Type the code if the event is EV_KEY, when the button is pressed a value of 1 , when the release is 0 ; type code if the event is EV_ REL, value of positive values and negative values represent the values of the two different directions . For example : If the code is REL_X, value is 10 words , it means that the mouse coordinates relative to the last , to the x -axis to move 10 pixels to the right.[/vc_column_text][/vc_tab][vc_tab title=”Sample Code:” tab_id=”1387849273-2-7″][vc_column_text]#include <core.h>
#include <stdio.h>
#include <linux/input.h>
#include <unistd.h>
#include <stdlib.h>
int led = 13;
int fd;
struct input_event ir_kb;
void setup()
{
pinMode(led,OUTPUT);
digitalWrite(led,LOW);
fd = open(“/dev/input/event3″,O_RDWR);
if(fd<0)
{
printf(“open keyboard error !\n”);
exit(0);
}
}
void loop()
{
read(fd,&ir_kb,sizeof(ir_kb));
if(ir_kb.value)
{
if( (ir_kb.code==KEY_1)&&(digitalRead(led)==LOW) )
{
digitalWrite(led,HIGH);
printf(“ LED ON\n”);
}
if( (ir_kb.code==KEY_2)&&(digitalRead(led)==HIGH) )
{
digitalWrite(led,LOW);
printf(“ LED_OFF\n”);
}
}
}[/vc_column_text][/vc_tab][vc_tab title=”Test Run:” tab_id=”1387850729546-2-0″][vc_column_text]
Open arduino (as related to root privileges, we need to enter in the terminal $ sudo arduino open arduino IDE), enter the code:
In pcDuino – the D13 after another LED (D13–> positive, GND -> negative; here I use a highlight LED, power is more than an ordinary LED, and pcDuino IO high as 3.3V, so no need to add restrictions resistor can be used), and then run the code.
Routines were inside the switch LED button ‘1 ‘, ‘2’, press the remote button ‘1 ‘, open LED:
Press the remote control button ‘2 ‘, open LED:
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.