A simple IAL analysis (infrared remote control)

xiaoxiao2021-03-06  41

Simple IAL analysis 1. Program description 1. The following program is based on an infrared device file that receives hardware encoding of infrared remote control from the device. 2. Two files need to overwrite two files in libmingiui * / src / IAL /, plus -enable-video-qvfb 3. For simple, modify them directly on the QVFB engine. Source code and code Description /*qvfb.h*/

#ifndef _ial_qvfb_h # define _ial_qvfb_h

#define kb_dev "/ dev / ir" // an outgoing infrared device, when the button is pressed, you can read a integer #define time_keyup 30 // set a button automatically bounce the clock 30MS

Struct qvfbkeydata {unsigned int uncode; // unsigned int modifiers; // Byte Press; // Byte Repeat;}; // Read the structure of infrared data, is actually an unsigned integer

#ifdef __cplusplusextern "c" {#ENDIF / * __CPLUSPLUS * /

Bool initQvfbinput (Input * Input, const char * mdev, const char * mtype); Void Termqvfbinput (void);

#ifdef __cplusplus} #ENDIF / * __CPLUSPLUS * /

#ENDIF / * _IAL_QVFB_H * /

*** File End ********************************************* / * qvfb.c * /

#include #include #include #include #include #include

#include "common.h"

#ifdef _qvfb_ial

#include #include #include #include

#include "minigui.h" #include "misc.h" #include "ial.h" #include "qvfb.h"

extern unsigned int __mg_timer_counter; // minigui a timer comes static int mouse_fd = -1; static int kbd_fd = -1; // static POINT mouse_pt; // static int mouse_buttons; static struct QVFbKeyData kbd_data; static unsigned char kbd_state [ NR_keys]; static unsigned char last = 0; // Save the last next to the scan code static int Time_pre = -1; // below is a hardware code to the scan code Transformation table static int keycode_scancode [0x21] = {Scancode_Cursorblockup, / * 0x00 UP0 UP * / SCANCODE_CURSORBLOCKDOWN, / * 0x01 Down DOWN * / SCANCODE_CURSORBLOCKRIGHT, / * 0x02 Right RIGHT * / SCANCODE_CURSORBLOCKLEFT, / * 0x03 Left LEFT * / 0x003C, / * 0x04 Audio F2 * / SCANCODE_LEFTALT, / * 0x05 MENU * / 0x0040, / * 0x06 Radio Electric / Guang F6 * / Scancode_escape, / * 0x07 exit esc * / 0x003d, / * 0x08 Pause F3 * / 0x003b, / * 0x09 FAV F1 * / 0x0044, / * 0x0a oer f10 * / 0x003f, / * 0x0b TV zoom F5 * / 0x0057, / * 0x0c mute f11 * / 0x0000, / * 0x0d no this button * / 0x0042, / * 0x0E TV / SAT search F8 * / 0x003E, / * 0x0f txt f4 * / scancode_0 , / * 0x10 0 0 * / Scancode_1, / * 0x11 1 1 * / Scancode_2, / * 0x12 2 2 * / scancode_3, / * 0x13 3 3 * / Scancode_4, / * 0x14 4 4 * / Scancode_5, / * 0x15 5 5 * / Scancode_6, / * 0x16 6 6 * / Scancode_7, / * 0x17 7 7 * / Scancode_8, / * 0x18 8 8 * / SCANCODE_9, / * 0x19 9 9 * / SCANCODE_CAPSLOCK, / * 0x1A quality CAPLOCK * / SCANCODE_BACKSPACE, / * 0x1B recall BACKSPACE * / SCANCODE_PAGEUP, / * 0x1C Sat PAGEUP * / SCANCODE_PAGEDOWN, / * 0x1D Skew PAGEDOWN * / 0x0043, / * 0x1e guid f9 * / scancode_enter, / * 0x1f ok enter * / 0x0041 / * 0x40 Info F7 * /};

static unsigned char keycode_to_scancode (unsigned int keycode) {keycode >> = 16; keycode & = 0x0FF; fprintf (stderr, "IAL:! keycode =% d / n", keycode); if (keycode> = 0x20) {keycode = 0x20;} return keycode_scancode [keycode];} / ********************** LOW Level Input Operations *********** ********** // * * Mouse Operations - Event * Mouse function empty, ignore * / static int mouse_update (void) {Return 1;}

Static void mouse_getxy (int * x, int * y) {;}

static int mouse_getbutton (void) {return 0;} static int keyboard_update (void) {struct QVFbKeyData l_kbd_data; int ret; (! (last & 0x80)) if {ret = read (kbd_fd, & l_kbd_data, sizeof (struct QVFbKeyData)); Determine if there is data IF (RET == SIZEOF (Struct QVFBKEYDATA) {kbd_data = l_kbd_data;} else {return 0;} / / button is not poured until other buttons last = keycode_to_scancode (kbd_data.uitode); KBD_State [ Last] = 1; // New button Press Time_pre = __mg_timer_counter; // Start button Bullet Upon Meter FPRINTF (stderr, "il: key down! / n");} else {kbd_state [Last & 0x7f] = 0; time_pre = -1; LAST = 0; fprintf (stderr, "il: key up! / N");} return nr_keys;

Static const char * keyboard_getstate (void) {Return KBD_State;}

/ * NOTE by weiym: Do not ignore the fd_set in, out, and except * / # ifdef _LITE_VERSIONstatic int wait_event (int which, int maxfd, fd_set * in, fd_set * out, fd_set * except, struct timeval * timeout) #elsestatic INT WAIT_EVENT (int WHICH, FD_SET * IN, FD_SET * OUT, FD_SET * EXCEPT, STRUCT TIMEVAL * TIMEOUT "#ENDIF {Int Interval; fd_set rfds; int RetValue = 0; INT FD, E; IF (Time_pre> 0) {Interval = __mg_timer_counter - time_pre; if (Interval> Time_Keyup) {// kbd_state [Last] = 0; Last | = 0x80; // Send button Bullet Data RetValue | = IAL_KEYEVENT; RETURN RETVALUE;}} / if (! in) { IN = & rfds; fd_zero (in);} if (Which & Il_MouseEvent && mouse_fd> = 0) {fd = mouse_fd; fd_set (fd, in); # idf ___version if (fd> maxfd) Maxfd = fd; #ENDIF}

IF (Which & Ial_KeyEvent) {fd = kbd_fd; fd_set (kbd_fd, in); # ifdef _lite_version if (fd> maxfd) Maxfd = fd; #ENDIF}

/ * Fixme: pass the real set size * / # neydef _lite_version E = SELECT (Maxfd 1, IN, OUT, EXCEPT, TIMEOUT); #ELSE E = SELECT (FD_SETSIZE, IN, OUT, EXCEPT, TIMEOUT); #ENDIF

If (e> 0 && time_pre <0) {// button does not generate an event until the button bounces fd = mouse_fd; / * if data is present on the mouse fd, service it: * / if (fd> = 0 && fd_isset (fd, in)) {fd_clr (fd, in); RetValue | = IAL_MOUSEEVENT;}

FD = kbd_fd; / * if data is present on the keyboard fd, service it: * / if (fd> = 0 && fd_isset (fd, in)) {FD_CLR (FD, IN); RetValue | = IAL_KEYEVENT;}} else IF (E <0 || Time_pre> 0) {RETURN-1;}

Return RetValue;}

Bool initQvfbinput (Input * Input, const char * mdev, const char * mtype) {kbd_fd = open (kb_dev, o_rdonly); if (kbd_fd <0) {fprintf (stderr, "al: can not open / dev / cent! / n ");

/ Input-> update_mouse = mouse_update; input-> get_mouse_xy = mouse_getxy; input-> set_mouse_xy = NULL; input-> get_mouse_button = mouse_getbutton; input-> set_mouse_range = NULL; input-> suspend_mouse = NULL; input-> resume_mouse = NULL;

input-> update_keyboard = keyboard_update; input-> get_keyboard_state = keyboard_getstate; input-> suspend_keyboard = NULL; input-> resume_keyboard = NULL; input-> set_leds = NULL;

Input-> WAIT_EVENT = WAIT_EVENT;

Return True;} Void Termqvfbinput (void) {if (kbd_fd> = 0) Close (KBD_FD);

#ENDIF / * _QVFB_IAL * /

*** File End *******************************************

转载请注明原文地址:https://www.9cbs.com/read-56493.html

New Post(0)