aboutsummaryrefslogtreecommitdiff
path: root/lib/libusb/usb-hid.c
diff options
context:
space:
mode:
authorDinar Valeev <dvaleev@suse.com>2015-07-13 16:23:38 +0200
committerAlexey Kardashevskiy <aik@ozlabs.ru>2015-07-20 21:04:26 +1000
commitc8bd0cdce2bd7c4498d61079553c89747656614d (patch)
tree8cac0f8b4425aa7230a6277a4d1891ca2ea0dc80 /lib/libusb/usb-hid.c
parentf8e7ca8e061a84752ae7729d25f6cbc9c3a3f66b (diff)
downloadSLOF-c8bd0cdce2bd7c4498d61079553c89747656614d.zip
SLOF-c8bd0cdce2bd7c4498d61079553c89747656614d.tar.gz
SLOF-c8bd0cdce2bd7c4498d61079553c89747656614d.tar.bz2
usb-hid: Caps is not always shift
Caps behaves like shift only for latin characters. In case we're typing - for example with caps enabled, SLOF picks _ char from shifted table. Treat caps as shift only for letters. Signed-off-by: Dinar Valeev <dvaleev@suse.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib/libusb/usb-hid.c')
-rw-r--r--lib/libusb/usb-hid.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/libusb/usb-hid.c b/lib/libusb/usb-hid.c
index f0cab8a..9d90006 100644
--- a/lib/libusb/usb-hid.c
+++ b/lib/libusb/usb-hid.c
@@ -28,6 +28,10 @@
#define HID_REQ_SET_IDLE 0x0A
#define HID_REQ_SET_PROTOCOL 0x0B
+//key position for latin letters
+#define KEYP_LATIN_A 4
+#define KEYP_LATIN_Z 29
+
//#define KEY_DEBUG
/* HID SPEC - 7.2.6 Set_Protocol Request */
@@ -83,6 +87,8 @@ uint8_t set_leds;
const uint8_t *key_std = NULL;
const uint8_t *key_std_shift = NULL;
+uint8_t ctrl; /* modifiers */
+
/**
* read character from Keyboard-Buffer
*
@@ -111,6 +117,16 @@ static void write_key(uint8_t key)
}
/**
+ * Checks if keypos is a latin key
+ * @param keypos
+ * @return -
+ */
+static bool is_latin(uint8_t keypos)
+{
+ return keypos >= KEYP_LATIN_A && keypos <= KEYP_LATIN_Z;
+}
+
+/**
* Convert keyboard usage-ID to ANSI-Code
*
* @param Ctrl=Modifier Byte
@@ -120,22 +136,24 @@ static void write_key(uint8_t key)
static void get_char(uint8_t ctrl, uint8_t keypos)
{
uint8_t ch;
+ bool caps = false;
#ifdef KEY_DEBUG
printf("pos %02X\n", keypos);
#endif
if (set_leds & LED_CAPS_LOCK) /* is CAPS Lock set ? */
- ctrl |= MODIFIER_SHIFT; /* simulate shift */
+ caps = true;
- if (ctrl == 0) {
+ /* caps is a shift only for latin chars */
+ if ((!caps && ctrl == 0) || (caps && !is_latin(keypos))) {
ch = key_std[keypos];
if (ch != 0)
write_key(ch);
return;
}
- if (ctrl & MODIFIER_SHIFT) {
+ if ((ctrl & MODIFIER_SHIFT) || caps) {
ch = key_std_shift[keypos];
if (ch != 0)
write_key(ch);
@@ -187,6 +205,12 @@ static void check_key_code(uint8_t *buf)
set_leds ^= LED_CAPS_LOCK;
break;
+ case 0x36: /*Shift pressed*/
+ ctrl |= MODIFIER_SHIFT;
+ break;
+ case 0xb6: /*Shift unpressed*/
+ ctrl &= ~MODIFIER_SHIFT;
+ break;
case 0x3a: /* F1 */
write_key(0x1b);
write_key(0x5b);