-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
57 lines (44 loc) · 1.44 KB
/
main.ts
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
/*
TTP229 block
*/
//% weight=8 color=#FFD700 block="TTP229"
namespace ttp229
{
//% blockId=ttp229_GetKeyCode
//% block="touch_keyboard|SDOPIN %SDO|SCLPIN %SCL"
export function GetKeyCode(SDO: DigitalPin, SCL: DigitalPin): string
{
let DATA = 0;
pins.digitalWritePin(SDO, 1);
control.waitMicros(93);
pins.digitalWritePin(SDO, 0);
control.waitMicros(10);
for (let i = 0; i < 16; i++)
{
pins.digitalWritePin(SCL, 1);
pins.digitalWritePin(SCL, 0);
DATA |= pins.digitalReadPin(SDO) << i;
}
control.waitMicros(2 * 1000);
switch (DATA&0xFFFF)
{
case 0xFFFE: return "1";
case 0xFFFD: return "2";
case 0xFFFB: return "3";
case 0xFFEF: return "4";
case 0xFFDF: return "5";
case 0xFFBF: return "6";
case 0xFEFF: return "7";
case 0xFDFF: return "8";
case 0xFBFF: return "9";
case 0xDFFF: return "0";
case 0xFFF7: return "A";
case 0xFF7F: return "B";
case 0xF7FF: return "C";
case 0x7FFF: return "D";
case 0xEFFF: return "*";
case 0xBFFF: return "#";
default: return " ";
}
}
}