summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/action.c85
-rw-r--r--apps/action.h1
-rw-r--r--apps/core_keymap.c9
3 files changed, 54 insertions, 41 deletions
diff --git a/apps/action.c b/apps/action.c
index 3a4cc2ff64..9ef10936f2 100644
--- a/apps/action.c
+++ b/apps/action.c
@@ -70,7 +70,6 @@ static action_last_t action_last =
70 .wait_for_release = false, 70 .wait_for_release = false,
71 71
72#ifndef DISABLE_ACTION_REMAP 72#ifndef DISABLE_ACTION_REMAP
73 .check_remap = false,
74 .core_keymap = NULL, 73 .core_keymap = NULL,
75#endif 74#endif
76 75
@@ -590,12 +589,8 @@ static inline int get_next_context(const struct button_mapping *items, int i)
590*/ 589*/
591static inline void action_code_lookup(action_last_t *last, action_cur_t *cur) 590static inline void action_code_lookup(action_last_t *last, action_cur_t *cur)
592{ 591{
593 int action = ACTION_NONE; 592 int action, i;
594 int context = cur->context; 593 int context = cur->context;
595 int i = 0;
596#ifndef DISABLE_ACTION_REMAP
597 last->check_remap = (last->core_keymap != NULL);
598#endif
599 cur->is_prebutton = false; 594 cur->is_prebutton = false;
600 595
601#ifdef HAVE_LOCKED_ACTIONS 596#ifdef HAVE_LOCKED_ACTIONS
@@ -605,49 +600,55 @@ static inline void action_code_lookup(action_last_t *last, action_cur_t *cur)
605 context |= CONTEXT_LOCKED; 600 context |= CONTEXT_LOCKED;
606#endif 601#endif
607 602
608 for(;;)
609 {
610 /* logf("context = %x",context); */
611#if (BUTTON_REMOTE != 0)
612 if ((cur->button & BUTTON_REMOTE) != 0)
613 {
614 context |= CONTEXT_REMOTE;
615 }
616#endif
617
618 if ((context & CONTEXT_PLUGIN) && cur->get_context_map)
619 {
620 cur->items = cur->get_context_map(context);
621 }
622#ifndef DISABLE_ACTION_REMAP 603#ifndef DISABLE_ACTION_REMAP
623 else if(last->check_remap) /* attempt to look up the button in user supplied remap */ 604 bool check_remap = (last->core_keymap != NULL);
605 /* attempt to look up the button in user supplied remap */
606 if(check_remap && (context & CONTEXT_PLUGIN) == 0)
624 { 607 {
608#if 0 /*Disable the REMOTE context for remap for now (BUTTON_REMOTE != 0)*/
609 if ((cur->button & BUTTON_REMOTE) != 0)
610 {
611 context |= CONTEXT_REMOTE;
612 }
613#endif
625 cur->items = last->core_keymap; 614 cur->items = last->core_keymap;
626 i = 0; 615 i = 0;
627 action = ACTION_UNKNOWN; 616 action = ACTION_UNKNOWN;
628 /* check the lut at the beginning for the desired context */ 617 /* check the lut at the beginning for the desired context */
629 while (cur->items[i].action_code != (int) CONTEXT_STOPSEARCHING) 618 while (cur->items[i].button_code != BUTTON_NONE)
630 { 619 {
631 if (cur->items[i].action_code == CORE_CONTEXT_REMAP(context)) 620 if (cur->items[i].action_code == CORE_CONTEXT_REMAP(context))
632 { 621 {
633 i = cur->items[i].button_code; 622 i = cur->items[i].button_code;
634 action = action_code_worker(last, cur, &i); 623 action = action_code_worker(last, cur, &i);
635 break; 624 if (action != ACTION_UNKNOWN)
625 {
626 cur->action = action;
627 return;
628 }
636 } 629 }
637 i++; 630 i++;
638 } 631 }
632 }
633#endif
639 634
640 if (action != ACTION_UNKNOWN) 635 i = 0;
641 break; 636 action = ACTION_NONE;
642 else 637 /* attempt to look up the button in the in-built keymaps */
643 { 638 for(;;)
644 /* Not found -- fall through to inbuilt keymaps */ 639 {
645 i = 0; 640 /* logf("context = %x",context); */
646 last->check_remap = false; 641#if (BUTTON_REMOTE != 0)
647 cur->items = get_context_mapping(context); 642 if ((cur->button & BUTTON_REMOTE) != 0)
648 } 643 {
644 context |= CONTEXT_REMOTE;
649 } 645 }
650#endif 646#endif
647
648 if ((context & CONTEXT_PLUGIN) && cur->get_context_map)
649 {
650 cur->items = cur->get_context_map(context);
651 }
651 else 652 else
652 { 653 {
653 cur->items = get_context_mapping(context); 654 cur->items = get_context_mapping(context);
@@ -1199,17 +1200,21 @@ int action_set_keymap(struct button_mapping* core_keymap, int count)
1199 if (count > 0 && core_keymap != NULL) /* saf-tey checks :) */ 1200 if (count > 0 && core_keymap != NULL) /* saf-tey checks :) */
1200 { 1201 {
1201 int i = 0; 1202 int i = 0;
1202 if (core_keymap[count - 1].action_code != (int) CONTEXT_STOPSEARCHING || 1203 struct button_mapping* entry = &core_keymap[count - 1];
1203 core_keymap[count - 1].button_code != BUTTON_NONE) /* check for sentinel at end*/ 1204 if (entry->action_code != (int) CONTEXT_STOPSEARCHING ||
1205 entry->button_code != BUTTON_NONE) /* check for sentinel at end*/
1206 {
1204 count = -1; 1207 count = -1;
1208 }
1205 1209
1206 /* check the lut at the beginning for invalid offsets */ 1210 while (count > 0 && /* check the lut at the beginning for invalid offsets */
1207 while (count > 0 && core_keymap[i].action_code != (int) CONTEXT_STOPSEARCHING) 1211 (entry = &core_keymap[i])->action_code != (int) CONTEXT_STOPSEARCHING)
1208 { 1212 {
1209 if ((core_keymap[i].action_code & CONTEXT_REMAPPED) == CONTEXT_REMAPPED) 1213
1214 if ((entry->action_code & CONTEXT_REMAPPED) == CONTEXT_REMAPPED)
1210 { 1215 {
1211 int firstbtn = core_keymap[i].button_code; 1216 int firstbtn = entry->button_code;
1212 int endpos = firstbtn + core_keymap[i].pre_button_code; 1217 int endpos = firstbtn + entry->pre_button_code;
1213 if (firstbtn > count || firstbtn < i || endpos > count) 1218 if (firstbtn > count || firstbtn < i || endpos > count)
1214 { 1219 {
1215 /* offset out of bounds */ 1220 /* offset out of bounds */
@@ -1217,7 +1222,7 @@ int action_set_keymap(struct button_mapping* core_keymap, int count)
1217 break; 1222 break;
1218 } 1223 }
1219 1224
1220 if (core_keymap[endpos].action_code != (int) CONTEXT_STOPSEARCHING) 1225 if (core_keymap[endpos].button_code != BUTTON_NONE)
1221 { 1226 {
1222 /* stop sentinel is not at end of action lut*/ 1227 /* stop sentinel is not at end of action lut*/
1223 count = -3; 1228 count = -3;
diff --git a/apps/action.h b/apps/action.h
index 7fadc015c8..35f08a3dbd 100644
--- a/apps/action.h
+++ b/apps/action.h
@@ -419,7 +419,6 @@ typedef struct
419 bool wait_for_release; 419 bool wait_for_release;
420 420
421#ifndef DISABLE_ACTION_REMAP 421#ifndef DISABLE_ACTION_REMAP
422 bool check_remap;
423 struct button_mapping* core_keymap; 422 struct button_mapping* core_keymap;
424#endif 423#endif
425 424
diff --git a/apps/core_keymap.c b/apps/core_keymap.c
index 131c48f45d..dbe7ae0072 100644
--- a/apps/core_keymap.c
+++ b/apps/core_keymap.c
@@ -23,6 +23,9 @@
23#include "core_alloc.h" 23#include "core_alloc.h"
24#include "core_keymap.h" 24#include "core_keymap.h"
25 25
26/*#define LOGF_ENABLE*/
27#include "logf.h"
28
26#if !defined(__PCTOOL__) || defined(CHECKWPS) 29#if !defined(__PCTOOL__) || defined(CHECKWPS)
27static int keymap_handle = -1; 30static int keymap_handle = -1;
28 31
@@ -76,6 +79,7 @@ int core_load_key_remap(const char *filename)
76 if (core_alloc_keymap(fsize) <= 0) 79 if (core_alloc_keymap(fsize) <= 0)
77 { 80 {
78 count = -30; 81 count = -30;
82 logf("core_keymap: %d Failed to allocate buffer", count);
79 break; 83 break;
80 } 84 }
81 buf = core_get_data(keymap_handle); 85 buf = core_get_data(keymap_handle);
@@ -84,7 +88,10 @@ int core_load_key_remap(const char *filename)
84 count = action_set_keymap((struct button_mapping *) buf, count); 88 count = action_set_keymap((struct button_mapping *) buf, count);
85 } 89 }
86 else 90 else
91 {
87 count = -40; 92 count = -40;
93 logf("core_keymap: %d Failed to read", count);
94 }
88 break; 95 break;
89 } 96 }
90 close(fd); 97 close(fd);
@@ -108,6 +115,7 @@ int open_key_remap(const char *filename, int *fd, size_t *fsize)
108 if (count * sizeof(struct button_mapping) != *fsize) 115 if (count * sizeof(struct button_mapping) != *fsize)
109 { 116 {
110 count = -10; 117 count = -10;
118 logf("core_keymap: %d Size mismatch", count);
111 break; 119 break;
112 } 120 }
113 121
@@ -125,6 +133,7 @@ int open_key_remap(const char *filename, int *fd, size_t *fsize)
125 else /* Header mismatch */ 133 else /* Header mismatch */
126 { 134 {
127 count = -20; 135 count = -20;
136 logf("core_keymap: %d Header mismatch", count);
128 break; 137 break;
129 } 138 }
130 } 139 }