summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/kbd_helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/kbd_helper.c')
-rw-r--r--apps/plugins/lib/kbd_helper.c63
1 files changed, 63 insertions, 0 deletions
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}