From f9f12448077ed9ad0b9f1d303ce3479aa759ecfe Mon Sep 17 00:00:00 2001 From: Martin Bauer Date: Wed, 15 Dec 2021 19:21:16 +0100 Subject: [PATCH] mouse leds test --- espmusicmouse/.gitignore | 3 +- espmusicmouse/src/main.cpp | 96 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/espmusicmouse/.gitignore b/espmusicmouse/.gitignore index 69107a2..240be72 100644 --- a/espmusicmouse/.gitignore +++ b/espmusicmouse/.gitignore @@ -2,4 +2,5 @@ .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json .vscode/launch.json -.vscode/ipch \ No newline at end of file +.vscode/ipch +venv \ No newline at end of file diff --git a/espmusicmouse/src/main.cpp b/espmusicmouse/src/main.cpp index cb6b196..a35528a 100644 --- a/espmusicmouse/src/main.cpp +++ b/espmusicmouse/src/main.cpp @@ -11,6 +11,8 @@ #include "effects/AlexaSwipe.h" #include "effects/RandomTwoColorInterpolation.h" +#include "driver/touch_pad.h" + #include "Messages.h" #include "TaskLed.h" @@ -56,6 +58,27 @@ void setupRotaryEncoder() ESP_ERROR_CHECK(rotary_encoder_set_queue(&info, eventQueueRotaryEncoder)); } +// -------------------------------------------------- Buttons ---------------------------------------- + +constexpr int BUTTON1_PIN = 25; +constexpr int BUTTON2_PIN = 14; +constexpr int ROTARY_PRESS_PIN = 13; +constexpr int BUTTON1_LED_PIN = 33; +constexpr int BUTTON2_LED_PIN = 12; + +void setupButtons() +{ + pinMode(BUTTON1_PIN, INPUT_PULLUP); + pinMode(BUTTON2_PIN, INPUT_PULLUP); + pinMode(ROTARY_PRESS_PIN, INPUT_PULLUP); + + pinMode(BUTTON1_LED_PIN, OUTPUT); + pinMode(BUTTON2_LED_PIN, OUTPUT); + + digitalWrite(BUTTON1_LED_PIN, 1); + digitalWrite(BUTTON2_LED_PIN, 1); +} + // -------------------------------------------------- Led circle ---------------------------------------- LedStripRGBW<51> ledStripCircle; Esp32DriverRGBW ledDriverCircle; @@ -68,17 +91,90 @@ void setupLedCircle() ledTaskCircle.startEffect(EffectStaticConfig{ColorRGBW{0, 0, 0, 0}}); } +// -------------------------------------------------- Touch Buttons ---------------------------------------- +constexpr auto TOUCH_PAD_RIGHT_EAR = TOUCH_PAD_NUM0; +constexpr auto TOUCH_PAD_LEFT_EAR = TOUCH_PAD_NUM9; +constexpr auto TOUCH_PAD_RIGHT_FOOT = TOUCH_PAD_NUM2; +constexpr auto TOUCH_PAD_LEFT_FOOT = TOUCH_PAD_NUM3; + +void setupTouchButtons() +{ + touch_pad_init(); + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_1V); + for (auto pad : {TOUCH_PAD_RIGHT_EAR, TOUCH_PAD_LEFT_EAR, TOUCH_PAD_RIGHT_FOOT, TOUCH_PAD_LEFT_FOOT}) + touch_pad_config(pad, 0); + + touch_pad_filter_start(2); +} + //------------------------------------------------------------------------------------------------------- +LedStripRGBW<12 + 16 + 17> ledStripMouse; +Esp32DriverRGBW ledDriverMouse; + void setup() { Serial.begin(115200); setupRfidReader(); setupRotaryEncoder(); setupLedCircle(); + setupButtons(); + setupTouchButtons(); + + ledDriverMouse.begin(16, 1); +} + +void handleTouchInputs() +{ } void loop() { handleIncomingMessagesFromHost(&ledTaskCircle); + + int btn1 = !digitalRead(BUTTON1_PIN); + int btn2 = !digitalRead(BUTTON2_PIN); + int rotaryBtn = !digitalRead(ROTARY_PRESS_PIN); + + uint16_t touchLeftEar = 1, touchRightEar = 1, touchLeftFoot = 1, touchRightFoot = 1; + + touch_pad_read(TOUCH_PAD_LEFT_FOOT, &touchLeftFoot); + touch_pad_read(TOUCH_PAD_RIGHT_FOOT, &touchRightFoot); + touch_pad_read(TOUCH_PAD_LEFT_EAR, &touchLeftEar); // 430 + touch_pad_read(TOUCH_PAD_RIGHT_EAR, &touchRightEar); // 430 + + //Serial.printf("%d, %d, %d | re %d, le %d, rf %d, lf %d\n", btn1, btn2, rotaryBtn, touchRightEar, touchLeftEar, touchRightFoot, touchLeftFoot); + + for (int i = 0; i < ledStripMouse.numLeds(); ++i) + ledStripMouse.set(i, 0, 0, 30, 0); + + bool rightFootPressed = touchRightFoot < 380; + bool leftFootPressed = touchLeftFoot < 380; + bool leftEarPressed = touchLeftEar < 430; + bool rightEarPressed = touchRightEar < 430; + + if (btn1 || rightFootPressed) + { + for (int i = 0; i < 6; ++i) + ledStripMouse.set(i, 180, 0, 255, 0); + } + + if (btn2 || leftFootPressed) + { + for (int i = 6; i < 12; ++i) + ledStripMouse.set(i, 180, 0, 255, 0); + } + + if (leftEarPressed) + for (int i = 12; i < 12 + 16; ++i) + ledStripMouse.set(i, 28, 241, 234, 0); + + if (rightEarPressed) + for (int i = 12 + 16; i < ledStripMouse.numLeds(); ++i) + ledStripMouse.set(i, 28, 241, 234, 0); + + ledDriverMouse.writeSync(ledStripMouse.rawData(), ledStripMouse.numLeds()); + delay(50); + + //delay(150); } \ No newline at end of file