Skip to content

Commit b3bafd7

Browse files
M4_Eyes: add sound to user_hid.cpp (enable voice changer in config)
1 parent 082cdb2 commit b3bafd7

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

M4_Eyes/user_hid.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
#include <Arduino.h>
44
#include "Adafruit_TinyUSB.h"
55
#include "globals.h"
6+
extern volatile uint16_t voiceLastReading; // In pdmvoice.cpp
67

78
#define UP_BUTTON_KEYCODE_TO_SEND HID_KEY_U
89
#define A_BUTTON_KEYCODE_TO_SEND HID_KEY_A
910
#define DOWN_BUTTON_KEYCODE_TO_SEND HID_KEY_D
1011
#define SHAKE_KEYCODE_TO_SEND HID_KEY_SPACE
12+
// Sound reaction REQUIRES '"voice" : true' in config.eye,
13+
// even if not using sound output...we're using it to steal
14+
// access to the mic here.
15+
#define SOUND_KEYCODE_TO_SEND HID_KEY_SPACE
16+
#define SOUND_THRESHOLD 1000
1117

1218
// HID report descriptor using TinyUSB's template
1319
// Single Report (no ID) descriptor
@@ -61,6 +67,14 @@ void user_loop(void) {
6167
keycode[3] = SHAKE_KEYCODE_TO_SEND;
6268
}
6369

70+
if(voiceLastReading) { // usu. non-zero if voice changer enabled
71+
int level = abs((int32_t)voiceLastReading - 32768);
72+
if(level > SOUND_THRESHOLD) {
73+
Serial.println("Sound");
74+
keycode[4] = SOUND_KEYCODE_TO_SEND;
75+
}
76+
}
77+
6478
bool anypressed = false;
6579
for (int k=0; k<sizeof(keycode); k++) {
6680
if (keycode[k] != 0) {

0 commit comments

Comments
 (0)