-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudio_control.ino
More file actions
111 lines (99 loc) · 2.4 KB
/
audio_control.ino
File metadata and controls
111 lines (99 loc) · 2.4 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Audio control
*/
void setupAudioControl() {
// None
}
void volumeDown(ESPRotary& volume_knob) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Volume Down");
bleKeyboard.write(KEY_MEDIA_VOLUME_DOWN);
setFrequencyLED(GREEN);
}
}
void volumeUp(ESPRotary& volume_knob) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Volume Up");
bleKeyboard.write(KEY_MEDIA_VOLUME_UP);
setFrequencyLED(RED);
}
}
void volumeClick(Button2& volume_button) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Mute");
bleKeyboard.write(KEY_MEDIA_MUTE);
if (muted) {
frequency_led.setPixelColor(0, frequency_led.Color(0, 0, 0));
} else {
frequency_led.setPixelColor(0, frequency_led.Color(0, 0, 255));
muted = true;
}
frequency_led.show();
}
}
/**
* Long press handler for volume button
* Currently only logs the event
*/
void volumeLongClick(Button2& volume_button) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Long press!");
}
}
/**
* Previous track button handler
*/
void button1Click(Button2& button_1) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Button 1 pressed");
bleKeyboard.write(KEY_MEDIA_PREVIOUS_TRACK);
setFrequencyLED(YELLOW);
}
}
/**
* Play/Pause button handler
*/
void button2Click(Button2& button_2) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Button 2 pressed");
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);
setFrequencyLED(PURPLE);
}
}
/**
* Next track button handler
*/
void button3Click(Button2& button_3) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Button 3 pressed");
bleKeyboard.write(KEY_MEDIA_NEXT_TRACK);
setFrequencyLED(CHARTREUSE);
}
}
/**
* Custom function button handler
*/
void button4Click(Button2& button_4) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Button 4 pressed");
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);
setFrequencyLED(CYAN);
}
}
/**
* Sleep button handler
* Triggers deep sleep mode after sending play/pause command
*/
void button5Click(Button2& button_5) {
if(bleKeyboard.isConnected()) {
DEBUG_PRINTLN("Button 5 pressed");
DEBUG_PRINTLN("Going to sleep");
bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);
setFrequencyLED(YELLOW);
// Add a small delay before sleep to ensure commands are sent
delay(100);
frequency_led.setPixelColor(0, OFF);
frequency_led.show();
esp_deep_sleep_start();
}
}