-
Notifications
You must be signed in to change notification settings - Fork 0
/
Clavier.h
80 lines (66 loc) · 1.97 KB
/
Clavier.h
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
// Gestion de clavier
// LIB MD_UISwitch
#include <MD_UISwitch.h>
const uint8_t ANALOG_SWITCH_PIN = A0; // switches connected to this pin
#define btnRIGHT 5
#define btnUP 4
#define btnDOWN 3
#define btnLEFT 2
#define btnSELECT 1
#define btnNONE 0
// These key values work for most LCD shields
MD_UISwitch_Analog::uiAnalogKeys_t kt[] =
{
{ 10, 10, btnRIGHT }, // Right
{ 100, 15, btnUP }, // Up
{ 255, 15, btnDOWN }, // Down
{ 410, 15, btnLEFT }, // Left
{ 640, 15, btnSELECT }, // Select
};
/*
// These key values work for most LCD shields
MD_UISwitch_Analog::uiAnalogKeys_t kt[] =
{
{ 10, 10, 'R' }, // Right
{ 100, 15, 'U' }, // Up
{ 255, 15, 'D' }, // Down
{ 410, 15, 'L' }, // Left
{ 640, 15, 'S' }, // Select
};
*/
MD_UISwitch_Analog S(ANALOG_SWITCH_PIN, kt, ARRAY_SIZE(kt));
void SetupClavier(void)
{
S.begin();
//S.enableDoublePress(false);
S.enableLongPress(true);
S.enableRepeat(true);
//S.enableRepeat(false);
S.enableRepeatResult(false);
}
void TestClavier(void)
{
MD_UISwitch::keyResult_t k = S.read();
switch(k)
{
case MD_UISwitch::KEY_NULL: /* Serial.print("KEY_NULL"); */ break;
case MD_UISwitch::KEY_UP: Serial.print("\nKEY_UP "); break;
case MD_UISwitch::KEY_DOWN: Serial.print("\nKEY_DOWN "); break;
case MD_UISwitch::KEY_PRESS: Serial.print("\nKEY_PRESS "); break;
case MD_UISwitch::KEY_DPRESS: Serial.print("\nKEY_DOUBLE "); break;
case MD_UISwitch::KEY_LONGPRESS: Serial.print("\nKEY_LONG "); break;
case MD_UISwitch::KEY_RPTPRESS: Serial.print("\nKEY_REPEAT "); break;
default: Serial.print("\nKEY_UNKNWN "); break;
}
if (k != MD_UISwitch::KEY_NULL)
{
if (S.getKey() >= ' ')
{
Serial.print((char)S.getKey());
Serial.print(" ");
}
Serial.print("[0x");
Serial.print(S.getKey(), HEX);
Serial.print("]");
}
}