diff --git a/software/main/src/main.cpp b/software/main/src/main.cpp index 30720a4..719b592 100644 --- a/software/main/src/main.cpp +++ b/software/main/src/main.cpp @@ -12,6 +12,7 @@ #include "avrcp.h" #include "a2dp.h" #include "twai.h" +#include "volume.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -48,4 +49,5 @@ extern "C" void app_main() { /* can::init(); */ twai::init(); + volume_controller::init(); } diff --git a/software/main/src/twai.cpp b/software/main/src/twai.cpp index e1eb541..aa8fe0f 100644 --- a/software/main/src/twai.cpp +++ b/software/main/src/twai.cpp @@ -60,7 +60,6 @@ void twai::change_volume(bool up) { buttons.volume_down = true; } - twai_message_t message; memset(&message, 0, sizeof(message)); @@ -71,6 +70,22 @@ void twai::change_volume(bool up) { message.data[2] = ((uint8_t*)&buttons)[2]; + for (int i = 0; i < message.data_length_code; i++) { + ESP_LOGI(TWAI_TAG, "%i: 0x%X", i, message.data[i]); + } + + if (twai_transmit(&message, pdMS_TO_TICKS(1000)) == ESP_OK) { + ESP_LOGI(TWAI_TAG, "Message queued for transmission"); + } else { + ESP_LOGI(TWAI_TAG, "Failed tp queue message for transmission"); + } + + vTaskDelay(pdMS_TO_TICKS(30)); + + buttons.volume_up = false; + buttons.volume_down = false; + message.data[0] = ((uint8_t*)&buttons)[0]; + for (int i = 0; i < message.data_length_code; i++) { ESP_LOGI(TWAI_TAG, "%i: 0x%X", i, message.data[i]); } diff --git a/software/main/src/volume.cpp b/software/main/src/volume.cpp index 945b9aa..c21a6a1 100644 --- a/software/main/src/volume.cpp +++ b/software/main/src/volume.cpp @@ -17,7 +17,7 @@ static uint8_t remote_volume; // 0-30 static uint8_t radio_volume; -static bool synced = false; +static bool synced = true; static _lock_t lock; void volume_controller::set_from_radio(int v) { @@ -79,7 +79,7 @@ static void correct_volume(void*) { } } - vTaskDelay(pdMS_TO_TICKS(100)); + vTaskDelay(pdMS_TO_TICKS(30)); } }