* [PATCH v2] Caps in not always shift
@ 2015-07-08 16:47 Dinar valeev
2015-07-09 6:00 ` Thomas Huth
2015-07-10 6:42 ` Paul Mackerras
0 siblings, 2 replies; 5+ messages in thread
From: Dinar valeev @ 2015-07-08 16:47 UTC (permalink / raw)
To: linuxppc-dev, aik, nikunj, thuth; +Cc: Dinar Valeev
From: Dinar Valeev <dvaleev@suse.com>
Caps behaves like shift only for latin characters.
In case we're typing - for example with caps enabled, SLOF picks _ char
from shifted table.
Threat caps as shift only for letters.
Signed-off-by: Dinar Valeev <dvaleev@suse.com>
---
lib/libusb/usb-hid.c | 32 +++++++++++++++++++++++++++++---
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/lib/libusb/usb-hid.c b/lib/libusb/usb-hid.c
index f0cab8a..18210ae 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,18 @@ static void write_key(uint8_t key)
}
/**
+ * Checks if keypos is a latin key
+ * @param keypos
+ * @return -
+ */
+void check_latin(uint8_t keypos)
+ if (keypos > KEYP_LATIN_A || keypos < KEYP_LATIN_Z) {
+ return true;
+ } else {
+ return false;
+ }
+
+/**
* Convert keyboard usage-ID to ANSI-Code
*
* @param Ctrl=Modifier Byte
@@ -120,22 +138,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 && !check_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 +207,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);
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] Caps in not always shift
2015-07-08 16:47 [PATCH v2] Caps in not always shift Dinar valeev
@ 2015-07-09 6:00 ` Thomas Huth
2015-07-09 12:59 ` Segher Boessenkool
2015-07-10 6:42 ` Paul Mackerras
1 sibling, 1 reply; 5+ messages in thread
From: Thomas Huth @ 2015-07-09 6:00 UTC (permalink / raw)
To: Dinar valeev; +Cc: linuxppc-dev, aik, nikunj, Dinar Valeev, slof
Hi!
Please CC to slof@lists.ozlabs.org now that we've finally got a SLOF
mailing list :-) !
On Wed, 8 Jul 2015 18:47:44 +0200
Dinar valeev <k0da@opensuse.org> wrote:
...
> /**
> + * Checks if keypos is a latin key
> + * @param keypos
> + * @return -
> + */
> +void check_latin(uint8_t keypos)
> + if (keypos > KEYP_LATIN_A || keypos < KEYP_LATIN_Z) {
> + return true;
> + } else {
> + return false;
> + }
> +
That does not look like valid C to me ... "void" return type and
returning true or false ... and what about the outermost curly braces?
Anyway, you could even write this much more simple without if-statement
instead:
bool check_latin(uint8_t keypos)
{
return keypos > KEYP_LATIN_A || keypos < KEYP_LATIN_Z;
}
Thomas
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] Caps in not always shift
2015-07-09 6:00 ` Thomas Huth
@ 2015-07-09 12:59 ` Segher Boessenkool
0 siblings, 0 replies; 5+ messages in thread
From: Segher Boessenkool @ 2015-07-09 12:59 UTC (permalink / raw)
To: Thomas Huth; +Cc: Dinar valeev, aik, linuxppc-dev, slof, Dinar Valeev, nikunj
On Thu, Jul 09, 2015 at 08:00:48AM +0200, Thomas Huth wrote:
> > /**
> > + * Checks if keypos is a latin key
> > + * @param keypos
> > + * @return -
> > + */
> > +void check_latin(uint8_t keypos)
> > + if (keypos > KEYP_LATIN_A || keypos < KEYP_LATIN_Z) {
> > + return true;
> > + } else {
> > + return false;
> > + }
> > +
>
> That does not look like valid C to me ... "void" return type and
> returning true or false ...
Valid C90, not valid C99 or C11. Any sane compiler will warn in any
case :-)
> and what about the outermost curly braces?
Yeah, this doesn't compile at all.
> Anyway, you could even write this much more simple without if-statement
> instead:
>
> bool check_latin(uint8_t keypos)
> {
> return keypos > KEYP_LATIN_A || keypos < KEYP_LATIN_Z;
> }
It's a pretty bad name, "check" doesn't give an indication of what the
polarity of the return value is.
I would expect something more like
bool is_latin(uint8_t keypos)
{
return keypos >= KEYP_LATIN_A && keypos <= KEYP_LATIN_Z;
}
or
bool is_not_latin(uint8_t keypos)
{
return keypos < KEYP_LATIN_A || keypos > KEYP_LATIN_Z;
}
The proposed code would always return true?
Segher
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] Caps in not always shift
2015-07-08 16:47 [PATCH v2] Caps in not always shift Dinar valeev
2015-07-09 6:00 ` Thomas Huth
@ 2015-07-10 6:42 ` Paul Mackerras
2015-07-13 10:11 ` Dinar Valeev
1 sibling, 1 reply; 5+ messages in thread
From: Paul Mackerras @ 2015-07-10 6:42 UTC (permalink / raw)
To: Dinar valeev; +Cc: linuxppc-dev, aik, nikunj, thuth, Dinar Valeev
On Wed, Jul 08, 2015 at 06:47:44PM +0200, Dinar valeev wrote:
> From: Dinar Valeev <dvaleev@suse.com>
>
> Caps behaves like shift only for latin characters.
> In case we're typing - for example with caps enabled, SLOF picks _ char
> from shifted table.
>
> Threat caps as shift only for letters.
"Treat" not "Threat".
And I suggest you make the subject "Caps is ..." rather than
"Caps in ...".
Paul.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] Caps in not always shift
2015-07-10 6:42 ` Paul Mackerras
@ 2015-07-13 10:11 ` Dinar Valeev
0 siblings, 0 replies; 5+ messages in thread
From: Dinar Valeev @ 2015-07-13 10:11 UTC (permalink / raw)
To: Paul Mackerras
Cc: linuxppc-dev, aik, Nikunj A Dadhania, Thomas Huth, Dinar Valeev
On Fri, Jul 10, 2015 at 8:42 AM, Paul Mackerras <paulus@samba.org> wrote:
> On Wed, Jul 08, 2015 at 06:47:44PM +0200, Dinar valeev wrote:
>> From: Dinar Valeev <dvaleev@suse.com>
>>
>> Caps behaves like shift only for latin characters.
>> In case we're typing - for example with caps enabled, SLOF picks _ char
>> from shifted table.
>>
>> Threat caps as shift only for letters.
>
> "Treat" not "Threat".
>
> And I suggest you make the subject "Caps is ..." rather than
> "Caps in ...".
>
> Paul.
Thanks, I've sent v3
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-07-13 10:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-08 16:47 [PATCH v2] Caps in not always shift Dinar valeev
2015-07-09 6:00 ` Thomas Huth
2015-07-09 12:59 ` Segher Boessenkool
2015-07-10 6:42 ` Paul Mackerras
2015-07-13 10:11 ` Dinar Valeev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).