From f7bb9e21672566308ab837c370f27c10c154e6fc Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Fri, 2 Apr 2021 21:34:29 -0400 Subject: Add custom action mapping to core results of an idea I discussed in IRC changed the way the lookup in the remap file works.. entries consist of 3 int [action, button, prebtn] context look up table is at the beginning action_code contains the (context | CONTEXT_REMAPPED) button_code contains the index of the first remapped action for the matched context [0] CORE_CONTEXT_REMAP(ctx1) offset1=(3), count=(1) [1] CORE_CONTEXT_REMAP(ctx2, offset2=(5), count=(1) [2] sentinel, 0, 0 [3] act0, btn, 0 [4] sentinel 0, 0 [5] act1, btn, 0 [6] sentinel, 0, 0 Note: last entry of each group is always the sentinel [CONTEXT_STOPSEARCHING, BUTTON_NONE, BUTTON_NONE] contexts must match exactly -- re-mapped contexts run before the built in w/ fall through contexts ie. you can't remap std_context and expect it to match std_context actions from the WPS context. -- Done -- Code for reading core remap entries -- Done -- import of core remap entires from disk -- Done -- plugin to set new key mapping (the hard part) The plugin is started and FULLY functional you can add actions and contexts you can change context, action, button, prebtn delete keymap files load keymapfiles save user keymaps test keymaps before applying them loading keymaps to core still requires restart ----------------------------------------------------------------------------------------------- Change-Id: Ib8b88c5ae91af4d540e1829de5db32669cd68203 --- apps/core_keymap.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 apps/core_keymap.c (limited to 'apps/core_keymap.c') diff --git a/apps/core_keymap.c b/apps/core_keymap.c new file mode 100644 index 0000000000..0a7241a9e0 --- /dev/null +++ b/apps/core_keymap.c @@ -0,0 +1,106 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2020 by William Wilgus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "action.h" +#include "core_alloc.h" +#include "core_keymap.h" + +#if !defined(__PCTOOL__) || defined(CHECKWPS) +int core_load_key_remap(const char *filename) +{ + static int keymap_handle = -1; + char *buf; + int fd = -1; + int count = 0; + size_t fsize = 0; + if (keymap_handle > 0) /* free old buffer */ + { + action_set_keymap(NULL, -1); + keymap_handle = core_free(keymap_handle); + } + if (filename != NULL) + count = open_key_remap(filename, &fd, &fsize); + while (count > 0) + { + + keymap_handle = core_alloc_ex("key remap", fsize, &buflib_ops_locked); + if (keymap_handle <= 0) + { + count = -30; + break; + } + buf = core_get_data(keymap_handle); + if (read(fd, buf, fsize) == (ssize_t) fsize) + { + count = action_set_keymap((struct button_mapping *) buf, count); + } + else + count = -40; + break; + } + close(fd); + return count; +} + +int open_key_remap(const char *filename, int *fd, size_t *fsize) +{ + int count = 0; + + while (filename && fd && fsize) + { + *fsize = 0; + *fd = open(filename, O_RDONLY); + if (*fd) + { + *fsize = filesize(*fd); + + count = *fsize / sizeof(struct button_mapping); + + if (count * sizeof(struct button_mapping) != *fsize) + { + count = -10; + break; + } + + if (count > 1) + { + struct button_mapping header = {0}; + read(*fd, &header, sizeof(struct button_mapping)); + if (KEYREMAP_VERSION == header.action_code && + KEYREMAP_HEADERID == header.button_code && + header.pre_button_code == count) + { + count--; + *fsize -= sizeof(struct button_mapping); + } + else /* Header mismatch */ + { + count = -20; + break; + } + } + } + break; + } + return count; +} + +#endif /* !defined(__PCTOOL__) */ -- cgit v1.2.3