Numworks Epsilon  1.4.1
Graphing Calculator Operating System
keyboard.h
Go to the documentation of this file.
1 #ifndef ION_KEYBOARD_H
2 #define ION_KEYBOARD_H
3 
4 extern "C" {
5 #include <stdint.h>
6 #include <assert.h>
7 }
8 
9 namespace Ion {
10 namespace Keyboard {
11 
12 enum class Key : uint8_t {
13  A1=0, A2=1, A3=2, A4=3, A5=4, A6=5,
14  B1=6, B2=7, /* B3=8, B4=9, B5=10, B6=11, */
15  C1=12, C2=13, C3=14, C4=15, C5=16, C6=17,
16  D1=18, D2=19, D3=20, D4=21, D5=22, D6=23,
17  E1=24, E2=25, E3=26, E4=27, E5=28, E6=29,
18  F1=30, F2=31, F3=32, F4=33, F5=34, // F6=35,
19  G1=36, G2=37, G3=38, G4=39, G5=40, // G6=41,
20  H1=42, H2=43, H3=44, H4=45, H5=46, // H6=47,
21  I1=48, I2=49, I3=50, I4=51, I5=52, // I6=53,
22 };
23 
24 constexpr Key ValidKeys[] = {
31 };
32 
33 constexpr int NumberOfKeys = 54;
34 constexpr int NumberOfValidKeys = 46;
35 
36 class State {
37 public:
38  constexpr State(uint64_t s = 0) :
39  m_bitField(s)
40  {}
41  /* "Shift behavior is undefined if the right operand is negative, or greater
42  * than or equal to the length in bits of the promoted left operand" according
43  * to C++ spec but k is always in [0:52]. */
44  explicit constexpr State(Key k) :
45  m_bitField((uint64_t)1 << (uint8_t)k)
46  {}
47  inline bool keyDown(Key k) const {
48  assert((uint8_t)k < 64);
49  return (m_bitField>>(uint8_t)k) & 1;
50  }
51  operator uint64_t() const { return m_bitField; }
52 private:
53  uint64_t m_bitField;
54 };
55 
56 State scan();
57 
58 static_assert(sizeof(State)*8>NumberOfKeys, "Ion::Keyboard::State cannot hold a keyboard snapshot");
59 
60 
61 }
62 }
63 
64 #endif
#define assert(e)
Definition: assert.h:9
constexpr State(Key k)
Definition: keyboard.h:44
unsigned char uint8_t
Definition: stdint.h:4
constexpr int NumberOfKeys
Definition: keyboard.h:33
constexpr int NumberOfValidKeys
Definition: keyboard.h:34
unsigned long long uint64_t
Definition: stdint.h:7
bool keyDown(Key k) const
Definition: keyboard.h:47
State scan()
Definition: keyboard.cpp:50
constexpr State(uint64_t s=0)
Definition: keyboard.h:38
void Keyboard(const char *input)
Definition: keyboard.cpp:9
Definition: backlight.h:6
constexpr Key ValidKeys[]
Definition: keyboard.h:24