-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlayoutmemory.cpp
96 lines (74 loc) · 1.52 KB
/
layoutmemory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "Arduino.h"
#include <EEPROM.h>
#include "layoutmemory.h"
#define MAX_KEYB_LAYOUT_ID 1
/*! \brief Only init variables
*/
KeyLayout::KeyLayout()
{
uiCurrentKeyboardLayout = 0xFF;
}
/*! \brief Init function, not to be called from constructor.
Restores settings from eeprom.
*/
void KeyLayout::Init(void)
{
Restore();
}
/*! \brief Print current selected layout namew.
*/
void KeyLayout::Print(void)
{
Serial.print("Keyboard Layout is: ");
switch (uiCurrentKeyboardLayout)
{
case 0:
Serial.println("US");
break;
case 1:
Serial.println("DE");
break;
default:
Serial.println(uiCurrentKeyboardLayout, HEX);
break;
}
}
/*! \brief Stores current active layout to eeprom.
*/
void KeyLayout::Store(void)
{
EEPROM.write(0, uiCurrentKeyboardLayout);
}
/*! \brief Restores active layout from eeprom.
*/
void KeyLayout::Restore(void)
{
Set(EEPROM.read(0));
}
/*! \brief Select new layout.
Switch to the next layout and back to 0 if the MAX_KEYB_LAYOUT_ID is reached.
*/
void KeyLayout::Toggle(void)
{
Set(uiCurrentKeyboardLayout + 1);
}
/*! \brief Set the active layout direct..
Sets the active layout and thecks the range.
*/
void KeyLayout::Set(uint8_t uiLayoutID)
{
if (uiLayoutID > MAX_KEYB_LAYOUT_ID)
uiLayoutID = 0;
if (uiCurrentKeyboardLayout != uiLayoutID)
{
uiCurrentKeyboardLayout = uiLayoutID;
Store();
Print();
}
}
/*! \brief Returns the current active layout.
*/
uint8_t KeyLayout::Get(void)
{
return uiCurrentKeyboardLayout;
}