diff options
author | reinelt <> | 2006-07-12 20:47:51 +0000 |
---|---|---|
committer | reinelt <> | 2006-07-12 20:47:51 +0000 |
commit | def7fb22af955b63ca661875d37a608b0b41f8e2 (patch) | |
tree | b5a38eacfbdba691a62a42ed0a8a1545f7560e42 | |
parent | db62448f9c05290e042612897ce650429c9a3b77 (diff) | |
download | lcd4linux-def7fb22af955b63ca661875d37a608b0b41f8e2.tar.gz |
[lcd4linux @ 2006-07-12 20:47:51 by reinelt]
indent
Diffstat (limited to '')
-rw-r--r-- | drv_G15.c | 385 | ||||
-rw-r--r-- | drv_LCDLinux.c | 9 | ||||
-rw-r--r-- | plugin_exec.c | 9 |
3 files changed, 196 insertions, 207 deletions
@@ -1,4 +1,4 @@ -/* $Id: drv_G15.c,v 1.7 2006/07/12 20:45:30 reinelt Exp $ +/* $Id: drv_G15.c,v 1.8 2006/07/12 20:47:51 reinelt Exp $ * * Driver for Logitech G-15 keyboard LCD screen * @@ -24,6 +24,9 @@ * * * $Log: drv_G15.c,v $ + * Revision 1.8 2006/07/12 20:47:51 reinelt + * indent + * * Revision 1.7 2006/07/12 20:45:30 reinelt * G15 and thread patch by Anton * @@ -64,8 +67,8 @@ #include <usb.h> #include <fcntl.h> -#include <linux/input.h> -#include <linux/uinput.h> +#include <linux/input.h> +#include <linux/uinput.h> #include <signal.h> #include "debug.h" @@ -101,7 +104,7 @@ unsigned char l_key_states[5]; static int uinput_fd; static int kb_mutex; static int kb_thread_pid; -static int kb_single_keypress=0; +static int kb_single_keypress = 0; /****************************************/ @@ -111,225 +114,203 @@ static int kb_single_keypress=0; void drv_G15_keyDown(unsigned char scancode) { - struct input_event event; - memset(&event, 0, sizeof(event)); - - event.type = EV_KEY; - event.code = scancode; - event.value = 1; - write (uinput_fd, &event, sizeof(event)); + struct input_event event; + memset(&event, 0, sizeof(event)); + + event.type = EV_KEY; + event.code = scancode; + event.value = 1; + write(uinput_fd, &event, sizeof(event)); } void drv_G15_keyUp(unsigned char scancode) { - struct input_event event; - memset(&event, 0, sizeof(event)); - - event.type = EV_KEY; - event.code = scancode; - event.value = 0; - write (uinput_fd, &event, sizeof(event)); + struct input_event event; + memset(&event, 0, sizeof(event)); + + event.type = EV_KEY; + event.code = scancode; + event.value = 0; + write(uinput_fd, &event, sizeof(event)); } void drv_G15_keyDownUp(unsigned char scancode) { - drv_G15_keyDown(scancode); - drv_G15_keyUp(scancode); - + drv_G15_keyDown(scancode); + drv_G15_keyUp(scancode); + } inline unsigned char drv_G15_evalScanCode(int key) { - // first 12 G keys produce F1 - F12, thats 0x3a + key - if (key < 12) - { - return 0x3a + key; - } - // the other keys produce Key '1' (above letters) + key, thats 0x1e + key - else - { - return 0x1e + key - 12; // sigh, half an hour to find -12 .... - } + // first 12 G keys produce F1 - F12, thats 0x3a + key + if (key < 12) { + return 0x3a + key; + } + // the other keys produce Key '1' (above letters) + key, thats 0x1e + key + else { + return 0x1e + key - 12; // sigh, half an hour to find -12 .... + } } void drv_G15_processKeyEvent(unsigned char *buffer) { - const int g_scancode_offset = 167; - const int m_scancode_offset = 187; - const int l_scancode_offset = 191; - int i; - int is_set; - unsigned char m_key_new_states[4]; - unsigned char l_key_new_states[5]; - unsigned char orig_scancode; + const int g_scancode_offset = 167; + const int m_scancode_offset = 187; + const int l_scancode_offset = 191; + int i; + int is_set; + unsigned char m_key_new_states[4]; + unsigned char l_key_new_states[5]; + unsigned char orig_scancode; // printf("%hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx %hhx \n\n",buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5],buffer[6],buffer[7],buffer[8]); // usleep(100); - if (buffer[0] == 0x01) - { - DEBUG("Checking keys: "); - - - for (i=0;i<18;++i) - { - orig_scancode = drv_G15_evalScanCode(i); - is_set = 0; - - if (buffer[1] == orig_scancode || buffer[2] == orig_scancode || buffer[3] == orig_scancode || - buffer[4] == orig_scancode || buffer[5] == orig_scancode) - is_set = 1; - - if (!is_set && g_key_states[i] != 0) - { - // key was pressed but is no more - if (!kb_single_keypress) - drv_G15_keyUp( g_scancode_offset + i); - g_key_states[i] = 0; - debug("G%d going up",(i+1)); - } - else if (is_set && g_key_states[i] == 0) - { - if (!kb_single_keypress) - drv_G15_keyDown ( g_scancode_offset + i); - else - drv_G15_keyDownUp ( g_scancode_offset + i); - - g_key_states[i] = 1; - debug("G%d going down",(i+1)); - } - } - } - else - { - if (buffer[0] == 0x02) - { - memset(m_key_new_states,0,sizeof(m_key_new_states)); - - if (buffer[6]&0x01) - m_key_new_states[0] = 1; - if (buffer[7]&0x02) - m_key_new_states[1] = 1; - if (buffer[8]&0x04) - m_key_new_states[2] = 1; - if (buffer[7]&0x40) - m_key_new_states[3] = 1; - - for (i=0;i<4;++i) - { - if (!m_key_new_states[i] && m_key_states[i] != 0) - { - // key was pressed but is no more - if (!kb_single_keypress) - drv_G15_keyUp( m_scancode_offset + i); - m_key_states[i] = 0; - debug("M%d going up",(i+1)); - } - else if (m_key_new_states[i] && m_key_states[i] == 0) - { - if (!kb_single_keypress) - drv_G15_keyDown ( m_scancode_offset + i); - else - drv_G15_keyDownUp ( m_scancode_offset + i); - m_key_states[i] = 1; - debug("M%d going down",(i+1)); - } - } - - memset(l_key_new_states,0,sizeof(l_key_new_states)); - if (buffer[8]&0x80) - l_key_new_states[0] = 1; - if (buffer[2]&0x80) - l_key_new_states[1] = 1; - if (buffer[3]&0x80) - l_key_new_states[2] = 1; - if (buffer[4]&0x80) - l_key_new_states[3] = 1; - if (buffer[5]&0x80) - l_key_new_states[4] = 1; - - for (i=0;i<5;++i) - { - if (!l_key_new_states[i] && l_key_states[i] != 0) - { - // key was pressed but is no more - if (!kb_single_keypress) - drv_G15_keyUp( l_scancode_offset + i); - l_key_states[i] = 0; - debug("L%d going up",(i+1)); - } - else if (l_key_new_states[i] && l_key_states[i] == 0) - { - if (!kb_single_keypress) - drv_G15_keyDown ( l_scancode_offset + i); - else - drv_G15_keyDownUp ( l_scancode_offset + i); - l_key_states[i] = 1; - debug("L%d going down",(i+1)); - } - } - - } - } + if (buffer[0] == 0x01) { + DEBUG("Checking keys: "); + + + for (i = 0; i < 18; ++i) { + orig_scancode = drv_G15_evalScanCode(i); + is_set = 0; + + if (buffer[1] == orig_scancode || buffer[2] == orig_scancode || buffer[3] == orig_scancode || + buffer[4] == orig_scancode || buffer[5] == orig_scancode) + is_set = 1; + + if (!is_set && g_key_states[i] != 0) { + // key was pressed but is no more + if (!kb_single_keypress) + drv_G15_keyUp(g_scancode_offset + i); + g_key_states[i] = 0; + debug("G%d going up", (i + 1)); + } else if (is_set && g_key_states[i] == 0) { + if (!kb_single_keypress) + drv_G15_keyDown(g_scancode_offset + i); + else + drv_G15_keyDownUp(g_scancode_offset + i); + + g_key_states[i] = 1; + debug("G%d going down", (i + 1)); + } + } + } else { + if (buffer[0] == 0x02) { + memset(m_key_new_states, 0, sizeof(m_key_new_states)); + + if (buffer[6] & 0x01) + m_key_new_states[0] = 1; + if (buffer[7] & 0x02) + m_key_new_states[1] = 1; + if (buffer[8] & 0x04) + m_key_new_states[2] = 1; + if (buffer[7] & 0x40) + m_key_new_states[3] = 1; + + for (i = 0; i < 4; ++i) { + if (!m_key_new_states[i] && m_key_states[i] != 0) { + // key was pressed but is no more + if (!kb_single_keypress) + drv_G15_keyUp(m_scancode_offset + i); + m_key_states[i] = 0; + debug("M%d going up", (i + 1)); + } else if (m_key_new_states[i] && m_key_states[i] == 0) { + if (!kb_single_keypress) + drv_G15_keyDown(m_scancode_offset + i); + else + drv_G15_keyDownUp(m_scancode_offset + i); + m_key_states[i] = 1; + debug("M%d going down", (i + 1)); + } + } + + memset(l_key_new_states, 0, sizeof(l_key_new_states)); + if (buffer[8] & 0x80) + l_key_new_states[0] = 1; + if (buffer[2] & 0x80) + l_key_new_states[1] = 1; + if (buffer[3] & 0x80) + l_key_new_states[2] = 1; + if (buffer[4] & 0x80) + l_key_new_states[3] = 1; + if (buffer[5] & 0x80) + l_key_new_states[4] = 1; + + for (i = 0; i < 5; ++i) { + if (!l_key_new_states[i] && l_key_states[i] != 0) { + // key was pressed but is no more + if (!kb_single_keypress) + drv_G15_keyUp(l_scancode_offset + i); + l_key_states[i] = 0; + debug("L%d going up", (i + 1)); + } else if (l_key_new_states[i] && l_key_states[i] == 0) { + if (!kb_single_keypress) + drv_G15_keyDown(l_scancode_offset + i); + else + drv_G15_keyDownUp(l_scancode_offset + i); + l_key_states[i] = 1; + debug("L%d going down", (i + 1)); + } + } + + } + } } void drv_G15_closeUIDevice() { - DEBUG("closing device"); - ioctl(uinput_fd, UI_DEV_DESTROY); - close(uinput_fd); + DEBUG("closing device"); + ioctl(uinput_fd, UI_DEV_DESTROY); + close(uinput_fd); } void drv_G15_initKeyHandling(char *device_filename) { - struct uinput_user_dev device; - int i; - DEBUG("Key Handling init") - uinput_fd = open(device_filename, O_RDWR); - - if (uinput_fd < 0) - { - info("Error, could not open the uinput device"); - info("Compile your kernel for uinput, calling it a day now"); - info("mknod uinput c 10 223"); - abort(); - } - memset(&device,0,sizeof(device)); - strncpy(device.name, "G15 Keys", UINPUT_MAX_NAME_SIZE); - device.id.bustype = BUS_USB; - device.id.version = 4; - - ioctl(uinput_fd, UI_SET_EVBIT, EV_KEY); - - for (i=0;i<256;++i) - ioctl(uinput_fd, UI_SET_KEYBIT, i); - - write(uinput_fd, &device, sizeof(device)); - - if (ioctl(uinput_fd, UI_DEV_CREATE)) - { - info("Failed to create input device"); - abort(); - } + struct uinput_user_dev device; + int i; + DEBUG("Key Handling init") + uinput_fd = open(device_filename, O_RDWR); + + if (uinput_fd < 0) { + info("Error, could not open the uinput device"); + info("Compile your kernel for uinput, calling it a day now"); + info("mknod uinput c 10 223"); + abort(); + } + memset(&device, 0, sizeof(device)); + strncpy(device.name, "G15 Keys", UINPUT_MAX_NAME_SIZE); + device.id.bustype = BUS_USB; + device.id.version = 4; + + ioctl(uinput_fd, UI_SET_EVBIT, EV_KEY); + + for (i = 0; i < 256; ++i) + ioctl(uinput_fd, UI_SET_KEYBIT, i); + + write(uinput_fd, &device, sizeof(device)); + + if (ioctl(uinput_fd, UI_DEV_CREATE)) { + info("Failed to create input device"); + abort(); + } // atexit(&closeDevice); - - memset(g_key_states, 0, sizeof(g_key_states)); - memset(m_key_states, 0, sizeof(m_key_states)); - memset(l_key_states, 0, sizeof(l_key_states)); + + memset(g_key_states, 0, sizeof(g_key_states)); + memset(m_key_states, 0, sizeof(m_key_states)); + memset(l_key_states, 0, sizeof(l_key_states)); } static void drv_G15_KBThread(void __attribute__ ((unused)) * notused) { unsigned char buffer[9]; - int ret; - while (1) - { + int ret; + while (1) { mutex_lock(kb_mutex); - ret = usb_bulk_read(g15_lcd, 0x81, (char*)buffer, 9, 10); -// ret = usb_interrupt_read(g15_lcd, 0x81, (char*)buffer, 9, 10); - mutex_unlock(kb_mutex); - if (ret == 9) - { + ret = usb_bulk_read(g15_lcd, 0x81, (char *) buffer, 9, 10); +// ret = usb_interrupt_read(g15_lcd, 0x81, (char*)buffer, 9, 10); + mutex_unlock(kb_mutex); + if (ret == 9) { drv_G15_processKeyEvent(buffer); - } - } + } + } } static int drv_G15_open() @@ -505,17 +486,17 @@ static int drv_G15_start(const char *section) drv_G15_contrast(contrast); } */ - s = cfg_get(section, "Uinput", ""); - if (s!=NULL && *s!='\0' ){ - cfg_number(section, "SingleKeyPress", 0, 0, 1, &kb_single_keypress); + s = cfg_get(section, "Uinput", ""); + if (s != NULL && *s != '\0') { + cfg_number(section, "SingleKeyPress", 0, 0, 1, &kb_single_keypress); drv_G15_initKeyHandling(s); - - DEBUG("creating thread for keyboard"); - kb_mutex=mutex_create(); - kb_thread_pid=thread_create("G15_KBThread", drv_G15_KBThread, NULL); - DEBUG("done"); - } + DEBUG("creating thread for keyboard"); + kb_mutex = mutex_create(); + kb_thread_pid = thread_create("G15_KBThread", drv_G15_KBThread, NULL); + + DEBUG("done"); + } DEBUG("left"); return 0; @@ -547,7 +528,7 @@ int drv_G15_init(const char *section, const int quiet) { int ret; - info("%s: %s", Name, "$Revision: 1.7 $"); + info("%s: %s", Name, "$Revision: 1.8 $"); DEBUG("entered"); @@ -602,8 +583,8 @@ int drv_G15_quit(const int quiet) drv_generic_graphic_quit(); mutex_destroy(kb_mutex); - usleep(10*1000); - kill(kb_thread_pid,SIGKILL); + usleep(10 * 1000); + kill(kb_thread_pid, SIGKILL); drv_G15_closeUIDevice(); DEBUG("closing UInputDev"); diff --git a/drv_LCDLinux.c b/drv_LCDLinux.c index 8fb7c51..63199c2 100644 --- a/drv_LCDLinux.c +++ b/drv_LCDLinux.c @@ -1,4 +1,4 @@ -/* $Id: drv_LCDLinux.c,v 1.13 2006/04/17 08:10:42 reinelt Exp $ +/* $Id: drv_LCDLinux.c,v 1.14 2006/07/12 20:47:51 reinelt Exp $ * * driver for the LCD-Linux HD44780 kernel driver * http://lcd-linux.sourceforge.net @@ -24,6 +24,9 @@ * * * $Log: drv_LCDLinux.c,v $ + * Revision 1.14 2006/07/12 20:47:51 reinelt + * indent + * * Revision 1.13 2006/04/17 08:10:42 reinelt * LCDLinux patch from Mattia; widget_image moved to EXTRA_SOURCE * @@ -206,7 +209,7 @@ static int drv_LL_start(const char *section, const int quiet) return -1; } info("%s: %dx%d display with %d controllers, flags=0x%02x:", - Name, buf.cntr_cols, buf.cntr_rows, buf.num_cntr, buf.flags); + Name, buf.cntr_cols, buf.cntr_rows, buf.num_cntr, buf.flags); info("%s: busy-flag checking %sabled", Name, buf.flags & HD44780_CHECK_BF ? "en" : "dis"); info("%s: bus width %d bits", Name, buf.flags & HD44780_4BITS_BUS ? 4 : 8); info("%s: font size %s", Name, buf.flags & HD44780_5X10_FONT ? "5x10" : "5x8"); @@ -311,7 +314,7 @@ int drv_LL_init(const char *section, const int quiet) int asc255bug; int ret; - info("%s: %s", Name, "$Revision: 1.13 $"); + info("%s: %s", Name, "$Revision: 1.14 $"); /* display preferences */ XRES = 5; /* pixel width of one char */ diff --git a/plugin_exec.c b/plugin_exec.c index ec7806d..2a39b55 100644 --- a/plugin_exec.c +++ b/plugin_exec.c @@ -1,4 +1,4 @@ -/* $Id: plugin_exec.c,v 1.10 2006/07/12 20:45:30 reinelt Exp $ +/* $Id: plugin_exec.c,v 1.11 2006/07/12 20:47:51 reinelt Exp $ * * plugin for external processes * @@ -27,6 +27,9 @@ * * * $Log: plugin_exec.c,v $ + * Revision 1.11 2006/07/12 20:47:51 reinelt + * indent + * * Revision 1.10 2006/07/12 20:45:30 reinelt * G15 and thread patch by Anton * @@ -178,6 +181,8 @@ static void exec_thread(void *data) static void destroy_exec_thread(const int n) { + kill(Thread[n].pid, SIGKILL); + if (Thread[n].mutex != 0) mutex_destroy(Thread[n].mutex); if (Thread[n].cmd) @@ -186,7 +191,7 @@ static void destroy_exec_thread(const int n) free(Thread[n].key); if (Thread[n].ret) shm_destroy(Thread[n].shmid, Thread[n].ret); - kill(Thread[n].pid,SIGKILL); + Thread[n].delay = 0; Thread[n].mutex = 0; Thread[n].pid = 0; |