Taranis Q X7 optimized wizard (#5198)
[opentx.git] / radio / src / keys.h
blobc50c52857265da698b6d06a2e38ee6a9599891da
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _KEYS_H_
22 #define _KEYS_H_
24 #define EVT_KEY_MASK(e) ((e) & 0x1f)
26 #if defined(PCBHORUS)
27 #define _MSK_KEY_BREAK 0x0200
28 #define _MSK_KEY_REPT 0x0400
29 #define _MSK_KEY_FIRST 0x0600
30 #define _MSK_KEY_LONG 0x0800
31 #define _MSK_KEY_FLAGS 0x0e00
32 #define EVT_ENTRY 0x1000
33 #define EVT_ENTRY_UP 0x2000
34 #else
35 #define _MSK_KEY_BREAK 0x20
36 #define _MSK_KEY_REPT 0x40
37 #define _MSK_KEY_FIRST 0x60
38 #define _MSK_KEY_LONG 0x80
39 #define _MSK_KEY_FLAGS 0xe0
40 #define EVT_ENTRY 0xbf
41 #define EVT_ENTRY_UP 0xbe
42 #endif
44 // normal order of events is: FIRST, LONG, REPEAT, REPEAT, ..., BREAK
45 #define EVT_KEY_FIRST(key) ((key)|_MSK_KEY_FIRST) // fired when key is pressed
46 #define EVT_KEY_LONG(key) ((key)|_MSK_KEY_LONG) // fired when key is held pressed for a while
47 #define EVT_KEY_REPT(key) ((key)|_MSK_KEY_REPT) // fired when key is held pressed long enough, fires multiple times with increasing speed
48 #define EVT_KEY_BREAK(key) ((key)|_MSK_KEY_BREAK) // fired when key is released (short or long), but only if the event was not killed
50 #define IS_KEY_FIRST(evt) (((evt) & _MSK_KEY_FLAGS) == _MSK_KEY_FIRST)
51 #define IS_KEY_LONG(evt) (((evt) & _MSK_KEY_FLAGS) == _MSK_KEY_LONG)
52 #define IS_KEY_REPT(evt) (((evt) & _MSK_KEY_FLAGS) == _MSK_KEY_REPT)
53 #define IS_KEY_BREAK(evt) (((evt) & _MSK_KEY_FLAGS) == _MSK_KEY_BREAK)
55 #if (defined(PCBHORUS) || defined(PCBFLAMENCO) || defined(PCBTARANIS)) && defined(ROTARY_ENCODER_NAVIGATION)
56 typedef uint16_t event_t;
57 #define EVT_ROTARY_BREAK EVT_KEY_BREAK(KEY_ENTER)
58 #define EVT_ROTARY_LONG EVT_KEY_LONG(KEY_ENTER)
59 #define EVT_ROTARY_LEFT 0xDF00
60 #define EVT_ROTARY_RIGHT 0xDE00
61 #define IS_NEXT_EVENT(event) (event==EVT_ROTARY_RIGHT)
62 #define IS_PREVIOUS_EVENT(event) (event==EVT_ROTARY_LEFT)
63 #elif defined(ROTARY_ENCODER_NAVIGATION)
64 typedef uint8_t event_t;
65 #define EVT_ROTARY_BREAK 0xcf
66 #define EVT_ROTARY_LONG 0xce
67 #define EVT_ROTARY_LEFT 0xdf
68 #define EVT_ROTARY_RIGHT 0xde
69 #define IS_NEXT_EVENT(event) (event==EVT_ROTARY_RIGHT || event==EVT_KEY_FIRST(KEY_DOWN) || event==EVT_KEY_REPT(KEY_DOWN))
70 #define IS_PREVIOUS_EVENT(event) (event==EVT_ROTARY_LEFT || event==EVT_KEY_FIRST(KEY_UP) || event==EVT_KEY_REPT(KEY_UP))
71 #else
72 typedef uint8_t event_t;
73 #define IS_NEXT_EVENT(event) (event==EVT_KEY_FIRST(KEY_DOWN) || event==EVT_KEY_REPT(KEY_DOWN))
74 #define IS_PREVIOUS_EVENT(event) (event==EVT_KEY_FIRST(KEY_UP) || event==EVT_KEY_REPT(KEY_UP))
75 #endif
77 #if defined(COLORLCD)
78 #define EVT_REFRESH 0xDD00
79 #endif
81 class Key
83 private:
84 uint8_t m_vals;
85 uint8_t m_cnt;
86 uint8_t m_state;
87 public:
88 void input(bool val);
89 bool state() const { return m_vals > 0; }
90 void pauseEvents();
91 void killEvents();
92 uint8_t key() const;
95 extern Key keys[NUM_KEYS];
96 extern event_t s_evt;
98 #define putEvent(evt) s_evt = evt
100 void pauseEvents(event_t event);
101 void killEvents(event_t event);
103 #if defined(CPUARM)
104 bool clearKeyEvents();
105 event_t getEvent(bool trim=false);
106 #else
107 void clearKeyEvents();
108 event_t getEvent();
109 #endif
111 uint8_t keyDown();
113 #endif // _KEYS_H_