summaryrefslogtreecommitdiff
path: root/apps/plugins/lib
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2020-07-21 02:33:53 -0400
committerWilliam Wilgus <wilgus.william@gmail.com>2020-07-22 06:48:28 -0400
commitcb94b3ae2ee7a66845895e2c704cdf62ee74ba13 (patch)
tree0b2da61e3d513fdc37d18f075b6c079e85165781 /apps/plugins/lib
parenta5df94beb5cd7fd87828b9532b4a1a4da13ef774 (diff)
downloadrockbox-cb94b3ae2ee7a66845895e2c704cdf62ee74ba13.tar.gz
rockbox-cb94b3ae2ee7a66845895e2c704cdf62ee74ba13.zip
keyboard add ability to specify temporary custom layouts
rb core allows you to load custom keyboard layouts this patch adds the ability to load a keyboard layout in a buffer the custom layout is temporary and does not overwrite the current layout use like so: unsigned short kbd[64]; unsigned short *kbd_p = kbd; if (!kbd_create_layout("ABCD1234\n", kbd, sizeof(kbd))) kbd_p = NULL; rb->kbd_input(buf,sizeof(buf), kbd_p); Change-Id: I7be2bd4a1b4797a147fa70228a9749dc56ac052a
Diffstat (limited to 'apps/plugins/lib')
-rw-r--r--apps/plugins/lib/SOURCES2
-rw-r--r--apps/plugins/lib/kbd_helper.c63
-rw-r--r--apps/plugins/lib/kbd_helper.h27
3 files changed, 92 insertions, 0 deletions
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index 9a7aef51d0..1149f35bac 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -69,6 +69,8 @@ bmp_smooth_scale.c
69pluginlib_albumart.c 69pluginlib_albumart.c
70#endif 70#endif
71 71
72kbd_helper.c
73
72#endif /* HAVE_LCD_BITMAP */ 74#endif /* HAVE_LCD_BITMAP */
73 75
74#ifdef HAVE_TOUCHSCREEN 76#ifdef HAVE_TOUCHSCREEN
diff --git a/apps/plugins/lib/kbd_helper.c b/apps/plugins/lib/kbd_helper.c
new file mode 100644
index 0000000000..00191c3532
--- /dev/null
+++ b/apps/plugins/lib/kbd_helper.c
@@ -0,0 +1,63 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2020 William Wilgus
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "plugin.h"
22#include "kbd_helper.h"
23
24/* USAGE:
25 unsigned short kbd[64];
26 unsigned short *kbd_p = kbd;
27 if (!kbd_create_layout("ABCD1234\n", kbd, sizeof(kbd)))
28 kbd_p = NULL;
29
30 rb->kbd_input(buf,sizeof(buf), kbd_p);
31*/
32
33/* create a custom keyboard layout for kbd_input
34 * success returns size of buffer used
35 * failure returns 0
36*/
37int kbd_create_layout(char *layout, unsigned short *buf, int bufsz)
38{
39 unsigned short *pbuf;
40 const unsigned char *p = layout;
41 int len = 0;
42 pbuf = buf;
43 while (*p && (pbuf - buf + 8) < bufsz)
44 {
45 p = rb->utf8decode(p, &pbuf[len+1]);
46 if (pbuf[len+1] == '\n')
47 {
48 *pbuf = len;
49 pbuf += len+1;
50 len = 0;
51 }
52 else
53 len++;
54 }
55
56 if (len+1 < bufsz)
57 {
58 *pbuf = len;
59 pbuf[len+1] = 0xFEFF; /* mark end of characters */
60 return len + 1;
61 }
62 return 0;
63}
diff --git a/apps/plugins/lib/kbd_helper.h b/apps/plugins/lib/kbd_helper.h
new file mode 100644
index 0000000000..90443cbf3f
--- /dev/null
+++ b/apps/plugins/lib/kbd_helper.h
@@ -0,0 +1,27 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2020 William Wilgus
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef KBD_HELPER_H
22#define KBD_HELPER_H
23
24/* create a custom keyboard layout for kbd_input */
25int kbd_create_layout(char *layout, unsigned short *buf, int bufsz);
26
27#endif /* KBD_HELPER_H */