-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiotool_attiny85trinket_util.h
More file actions
77 lines (69 loc) · 2.86 KB
/
iotool_attiny85trinket_util.h
File metadata and controls
77 lines (69 loc) · 2.86 KB
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
// iotool_attiny85trinket_util.h
//
// Utility for library TrinketHidCombo.h as replacement
// for DigiKeyboard and DigiMouse.
//
// https://github.com/iotool/IOTool_ATtiny85Digispark_LowLevel
// https://github.com/adafruit/Adafruit-Trinket-USB/tree/master/TrinketHidCombo
//
// TrinketHidCombo.begin(); // starts the USB driver
// TrinketHidCombo.poll(); // must be called at least once every 10ms
// TrinketHidCombo.isConnected(); // checks if USB is connected, 0 if not connected
// TrinketHidCombo.mouseMove(signed char x, signed char y, uint8_t buttonMask);
// TrinketHidCombo.print(char*); // print string
// TrinketHidCombo.println(char*); // print string with line feed
// TrinketHidCombo.pressKey(uint8_t modifiers, uint8_t keycode1[, keycode2..keycode5]);
// TrinketHidCombo.pressMultimediaKey(); // MMKEY_VOL_UP, MMKEY_VOL_DOWN
// TrinketHidCombo.pressSystemCtrlKey(); // SYSCTRLKEY_SLEEP
//
// TrinketUtil_delay(uint16_t millis); // keep usb connection during pause
// TrinketUtil_releaseKey(); // end keystroke after pressKey
// TrinketUtil_capsLockOff(); // disable capslock before print
// TrinketUtil_capsLockRestore(); // restore capslock after print
//
// 2020-09-25 RoHa v1.0 delay, releaseKey
#ifndef IOTOOL_ATTINY85TRINKET_UTIL_H_
#define IOTOOL_ATTINY85TRINKET_UTIL_H_
#define KEYCODE_CAPSLOCK 0x39 // 57
#define KEYCODE_SCROLLLOCK 0x47 // 71
#define KEYCODE_NUMLOCK 0x53 // 83
void TrinketUtil_delay(uint16_t ms) {
// poll() must be called at least once every 10ms to keep up
// the communication between microcontroller and computer via USB.
while (ms>10) {
TrinketHidCombo.poll();
ms-=10;
delay(10);
}
TrinketHidCombo.poll();
delay(ms);
}
void TrinketUtil_releaseKey() {
// Unlike DigiKeyboard, it is necessary to release the keys.
// Without releasing, the keys are permanently pressed.
TrinketHidCombo.pressKey(0,0);
TrinketHidCombo.poll();
}
static uint8_t gTrinketUtilRestoreCase;
void TrinketUtil_capsLockOff() {
// With active CAPSLOCK there are errors with numbers and special characters.
// CAPSLOCK is deactivated before PRINT if necessary.
gTrinketUtilRestoreCase = 0;
if ((TrinketHidCombo.getLEDstate() & KB_LED_CAPS) == KB_LED_CAPS) {
gTrinketUtilRestoreCase = 1;
TrinketHidCombo.pressKey(0,KEYCODE_CAPSLOCK);
TrinketUtil_releaseKey();
}
}
void TrinketUtil_capsLockRestore() {
// If CAPSLOCK was temporarily deactivated, it will be reactivated after the PRINT.
// CAPSLOCK must not be changed on the computer during PRINT output.
if (gTrinketUtilRestoreCase == 1) {
if ((TrinketHidCombo.getLEDstate() & KB_LED_CAPS) != KB_LED_CAPS) {
gTrinketUtilRestoreCase = 1;
TrinketHidCombo.pressKey(0,KEYCODE_CAPSLOCK);
TrinketUtil_releaseKey();
}
}
}
#endif // IOTOOL_ATTINY85TRINKET_UTIL_H_