Numworks Epsilon  1.4.1
Graphing Calculator Operating System
events.cpp
Go to the documentation of this file.
1 #include <ion.h>
2 
3 namespace Ion {
4 namespace Events {
5 
6 static constexpr char s_textAtIndex[] = { 'A', 0, 'B', 0, 'C', 0,'D', 0};
7 
8 class EventInfo {
9 public:
10  static constexpr EventInfo Undefined() { return EventInfo(0); }
11  static constexpr EventInfo Textless() { return EventInfo(1); }
12  static constexpr EventInfo Text(int index) { return EventInfo(index << 2 & 3); }
13  bool isUndefined() const { return (m_data == 0); }
14  const char * text() const;
15 private:
16  constexpr EventInfo(uint8_t data) : m_data(data) {}
17  uint8_t m_data;
18 };
19 
20 const char * EventInfo::text() const {
21  if (m_data <= 1) {
22  return nullptr;
23  }
24  return s_textAtIndex + (m_data >> 2);
25 }
26 
27 static constexpr EventInfo s_infoForEvent[] = {
29 };
30 
31 
32 Event::Event(Keyboard::Key key, bool shift, bool alpha) {
33  // We're mapping a key, shift and alpha to an event
34  // This can be a bit more complicated than it seems since we want to fall back:
35  // for example, alpha-up is just plain up.
36  // Fallback order :
37  // alpha-X -> X
38  // shift-X -> X
39  // shift-alpha-X -> alpha-X -> X
40 
41  m_data = 255;// Undefined. FIXME
42 
43  int noFallbackOffsets[] = {0};
44  int alphaFallbackOffsets[] = {2*k_eventPageSize, 0};
45  int shiftFallbackOffsets[] = {k_eventPageSize, 0};
46  int shiftAlphaFallbackOffsets[] = {3*k_eventPageSize, 2*k_eventPageSize, 0};
47 
48  int * fallbackOffsets[] = {noFallbackOffsets, shiftFallbackOffsets, alphaFallbackOffsets, shiftAlphaFallbackOffsets};
49 
50  int * fallbackOffset = fallbackOffsets[shift+2*alpha];
51  int i=0;
52  int offset = 0;
53  do {
54  offset = fallbackOffset[i++];
55  m_data = offset + (int)key;
56  } while (offset > 0 && s_infoForEvent[m_data].isUndefined());
57 
58  //TODO assert(m_data != 255); //FIXME: Undefined
59 }
60 
61 const char * Event::text() const {
62  EventInfo info = s_infoForEvent[m_data];
63  return info.text();
64 }
65 
66 }
67 }
68 
69 #if 0
70 class Event {
71  Event(); // Constructor, by the hardware
72 
73 private:
74  uint8_t m_data;
75 };
76 
77 
78 ActionInfo Event::Action::info() {
79  return s_actionInfo[(int)this];
80 }
81 
82 Event::Event(Key key, bool shift, bool alpha) {
83  // We're mapping a key, shift and alpha to an action
84  // This can be a bit more complicated than it seems since we want to fall back:
85  // for example, alpha-up is just plain up.
86  // Fallback order :
87  // alpha-X -> X
88  // shift-X -> X
89  // shift-alpha-X -> alpha-X -> X
90 
91  int noFallbackOffsets[] = {0};
92  int alphaFallbackOffsets[] = {2*k_actionPageSize, 0};
93  int shiftFallbackOffsets[] = {k_actionPageSize, 0};
94  int shiftAlphaFallbackOffsets[] = {3*k_actionPageSize, 2*k_actionPageSize, 0};
95 
96  int * fallbackOffsets[] = {noFallbackOffsets, shiftFallbackOffsets, alphaFallbackOffsets, shiftAlphaFallbackOffsets};
97 
98  int * fallbackOffset = fallbackOffsets[shift+2*alpha];
99  Action action = Action::Undefined;
100  int action = A
101  int i=0;
102  int offset = 0;
103  do {
104  offset = fallbackOffset[i++];
105  action = offset + (int)key;
106  } while (offset > 0 && action.info().isUndefined());
107 
108  assert(!action.info().isUndefined());
109  return action;
110 }
111 #endif
#define assert(e)
Definition: assert.h:9
def data
Definition: i18n.py:176
static constexpr EventInfo Undefined()
Definition: events.cpp:10
unsigned char uint8_t
Definition: stdint.h:4
static constexpr EventInfo Text(int index)
Definition: events.cpp:12
const char * text() const
Definition: events.cpp:61
constexpr Event()
Definition: events.h:17
const char * text() const
Definition: events.cpp:20
static constexpr EventInfo Textless()
Definition: events.cpp:11
Definition: backlight.h:6
bool isUndefined() const
Definition: events.cpp:13