diff --git a/espmusicmouse/host_driver/host_driver.py b/espmusicmouse/host_driver/host_driver.py index bffc7b8..a451360 100644 --- a/espmusicmouse/host_driver/host_driver.py +++ b/espmusicmouse/host_driver/host_driver.py @@ -60,10 +60,10 @@ class RfidTokenRead: class RotaryEncoderEvent: def __init__(self, msg_content: bytes): - self.position, self.direction = struct.unpack(" self.volume_max: + volume = self.volume_max + print("volume", volume) + self.media_player.audio_set_volume(volume) + + def set_volume_limits(self, vmin, vmax): + self.volume_min = vmin + self.volume_max = vmax + def change_volume(self, amount=1): vol = self.media_player.audio_get_volume() + amount - print("volume", vol) - if vol > 100: - vol = 100 - if vol < 0: - vol = 0 - self.media_player.audio_set_volume(vol) + self.set_volume(vol) diff --git a/espmusicmouse/src/Messages.h b/espmusicmouse/src/Messages.h index 81ab186..cb966c3 100644 --- a/espmusicmouse/src/Messages.h +++ b/espmusicmouse/src/Messages.h @@ -42,6 +42,7 @@ struct MsgRfidTokenRead struct MsgRotaryEncoder { int32_t position; + int32_t increment; uint8_t direction; }; diff --git a/espmusicmouse/src/main.cpp b/espmusicmouse/src/main.cpp index 897f026..eee29ec 100644 --- a/espmusicmouse/src/main.cpp +++ b/espmusicmouse/src/main.cpp @@ -60,11 +60,20 @@ void setupRotaryEncoder() ESP_ERROR_CHECK(rotary_encoder_set_queue(&info, eventQueueRotaryEncoder)); } +int32_t lastRotaryPosition = 0; +bool lastRotaryPositionValid = false; void handleRotaryEncoder() { rotary_encoder_event_t event = {0}; if (xQueueReceive(eventQueueRotaryEncoder, &event, 0) == pdTRUE) - sendMessageToHost(MsgRotaryEncoder{event.state.position, (uint8_t)(event.state.direction)}); + { + int32_t increment = 0; + if (lastRotaryPositionValid) + increment = lastRotaryPosition - event.state.position; + sendMessageToHost(MsgRotaryEncoder{event.state.position, increment, (uint8_t)(event.state.direction)}); + lastRotaryPositionValid = true; + lastRotaryPosition = event.state.position; + } } // -------------------------------------------------- Buttons ---------------------------------------- @@ -190,12 +199,13 @@ void handleTouchInputs() touch_pad_read(TOUCH_PAD_RIGHT_FOOT, &touchRightFoot); touch_pad_read(TOUCH_PAD_LEFT_EAR, &touchLeftEar); touch_pad_read(TOUCH_PAD_RIGHT_EAR, &touchRightEar); - + //Serial.printf("Feet %d %d, Ears %d, %d\n", touchLeftFoot, touchRightFoot, touchLeftEar, touchRightEar); + //delay(100); bool currentState[4]; currentState[int(TouchButton::LEFT_FOOT)] = touchLeftFoot < 380; currentState[int(TouchButton::RIGHT_FOOT)] = touchRightFoot < 380; currentState[int(TouchButton::LEFT_EAR)] = touchLeftEar < 430; - currentState[int(TouchButton::RIGHT_EAR)] = touchRightEar < 430; + currentState[int(TouchButton::RIGHT_EAR)] = touchRightEar < 400; for (int i = 0; i < 4; ++i) {