M4_Eyes: add sound to user_hid.cpp (enable voice changer in config)
#include <Arduino.h>
#include "Adafruit_TinyUSB.h"
#include "globals.h"
+extern volatile uint16_t voiceLastReading; // In pdmvoice.cpp
#define UP_BUTTON_KEYCODE_TO_SEND HID_KEY_U
#define A_BUTTON_KEYCODE_TO_SEND HID_KEY_A
#define DOWN_BUTTON_KEYCODE_TO_SEND HID_KEY_D
#define SHAKE_KEYCODE_TO_SEND HID_KEY_SPACE
+// Sound reaction REQUIRES '"voice" : true' in config.eye,
+// even if not using sound output...we're using it to steal
+// access to the mic here.
+#define SOUND_KEYCODE_TO_SEND HID_KEY_SPACE
+#define SOUND_THRESHOLD 1000
// HID report descriptor using TinyUSB's template
// Single Report (no ID) descriptor
@@ -61,6 +67,14 @@ void user_loop(void) {
keycode[3] = SHAKE_KEYCODE_TO_SEND;
}
+ if(voiceLastReading) { // usu. non-zero if voice changer enabled
+ int level = abs((int32_t)voiceLastReading - 32768);
+ if(level > SOUND_THRESHOLD) {
+ Serial.println("Sound");
+ keycode[4] = SOUND_KEYCODE_TO_SEND;
+ }
+ }
+
bool anypressed = false;
for (int k=0; k<sizeof(keycode); k++) {
if (keycode[k] != 0) {
