From 6550ce376a8c5c20ff5d069d1977370d2de3a3c3 Mon Sep 17 00:00:00 2001 From: Ruben Henares Date: Sat, 5 Sep 2020 21:25:27 -0700 Subject: [PATCH 1/5] Bringing back old master volume edit screen --- Embedded/MaxMix/Display.ino | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Embedded/MaxMix/Display.ino b/Embedded/MaxMix/Display.ino index 781463cd..44a5f1ee 100644 --- a/Embedded/MaxMix/Display.ino +++ b/Embedded/MaxMix/Display.ino @@ -147,6 +147,24 @@ void DrawSelectionVolumeBar(Adafruit_SSD1306* display, uint8_t volume, bool isMu display->drawLine(x0, y0, x0, y1, WHITE); } +void DrawSelectionItemVolume(Adafruit_SSD1306* display, uint8_t volume) +{ + uint8_t x0; + + if( volume < 10) + x0 = DISPLAY_AREA_CENTER_MARGIN_SIDE + DISPLAY_AREA_CENTER_WIDTH - DISPLAY_CHAR_WIDTH_X2; + else if(volume < 100) + x0 = DISPLAY_AREA_CENTER_MARGIN_SIDE + DISPLAY_AREA_CENTER_WIDTH - DISPLAY_CHAR_WIDTH_X2 * 2 - DISPLAY_CHAR_SPACING_X2 * 2; + else if(volume == 100) + x0 = DISPLAY_AREA_CENTER_MARGIN_SIDE + DISPLAY_AREA_CENTER_WIDTH - DISPLAY_CHAR_WIDTH_X2 * 3 - DISPLAY_CHAR_SPACING_X2 * 3; + + display->setTextSize(2); + display->setTextColor(WHITE); + display->setCursor(x0, 0); + + display->print(volume); +} + //--------------------------------------------------------- // Draws the output mode screen //--------------------------------------------------------- @@ -167,15 +185,12 @@ void DisplayOutputSelectScreen(Adafruit_SSD1306* display, char* name, uint8_t vo void DisplayOutputEditScreen(Adafruit_SSD1306* display, char* name, uint8_t volume, bool isMuted, uint8_t modeIndex, uint8_t modeCount) { display->clearDisplay(); - + DrawDotGroup(display, modeIndex, modeCount); - DrawItemName(display, name, 1, DISPLAY_CHAR_WIDTH_X1, DISPLAY_CHAR_HEIGHT_X1, DISPLAY_CHAR_SPACING_X1, DISPLAY_AREA_CENTER_MARGIN_SIDE, 0, GetTimerDisplayA, ResetTimerDisplayA, DISPLAY_SCROLL_SPEED_X1); - // Clear sides - display->fillRect(0, 0, DISPLAY_AREA_CENTER_MARGIN_SIDE, DISPLAY_CHAR_HEIGHT_X1, BLACK); - display->fillRect(DISPLAY_WIDTH - DISPLAY_AREA_CENTER_MARGIN_SIDE, 0, DISPLAY_AREA_CENTER_MARGIN_SIDE, DISPLAY_CHAR_HEIGHT_X1, BLACK); + DrawItemName(display, "VOL", 2, DISPLAY_CHAR_WIDTH_X2, DISPLAY_CHAR_HEIGHT_X2, DISPLAY_CHAR_SPACING_X2, DISPLAY_AREA_CENTER_MARGIN_SIDE, 0, GetTimerDisplayA, ResetTimerDisplayA, DISPLAY_SCROLL_SPEED_X2); + DrawSelectionItemVolume(display, volume); + DrawSelectionVolumeBar(display, volume, isMuted); - DrawEditVolumeBar(display, volume, isMuted); - DrawEditVolume(display, volume); display->display(); } From 5522b38a5da289de23840c8f6a564e94744266f8 Mon Sep 17 00:00:00 2001 From: Ruben Henares Date: Sat, 5 Sep 2020 21:52:27 -0700 Subject: [PATCH 2/5] Adding default endpoint switch from device --- Desktop/Application/MaxMix/MaxMix.csproj | 1 + .../Services/Audio/AudioSessionService.cs | 5 ++ .../Services/Audio/IAudioSessionService.cs | 1 + .../Message/MessageSetDefaultEndpoint.cs | 59 +++++++++++++++++++ .../MaxMix/ViewModels/MainViewModel.cs | 8 ++- Embedded/MaxMix/Commands.ino | 28 ++++++++- Embedded/MaxMix/Config.h | 3 +- Embedded/MaxMix/MaxMix.ino | 3 + 8 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 Desktop/Application/MaxMix/Services/Communication/Message/MessageSetDefaultEndpoint.cs diff --git a/Desktop/Application/MaxMix/MaxMix.csproj b/Desktop/Application/MaxMix/MaxMix.csproj index 52d25770..6be9cbb3 100644 --- a/Desktop/Application/MaxMix/MaxMix.csproj +++ b/Desktop/Application/MaxMix/MaxMix.csproj @@ -135,6 +135,7 @@ + diff --git a/Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs b/Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs index 1b7cf814..0a045538 100644 --- a/Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs +++ b/Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs @@ -101,6 +101,11 @@ public void SetItemVolume(int id, int volume, bool isMuted) // TODO: Raise error } } + + public void SetDefaultEndpoint(int id) + { + + } #endregion #region Private Methods diff --git a/Desktop/Application/MaxMix/Services/Audio/IAudioSessionService.cs b/Desktop/Application/MaxMix/Services/Audio/IAudioSessionService.cs index 785376f4..1c1174f6 100644 --- a/Desktop/Application/MaxMix/Services/Audio/IAudioSessionService.cs +++ b/Desktop/Application/MaxMix/Services/Audio/IAudioSessionService.cs @@ -7,6 +7,7 @@ internal interface IAudioSessionService void Start(); void Stop(); void SetItemVolume(int id, int volume, bool isMuted); + void SetDefaultEndpoint(int id); event DefaultAudioDeviceChangedDelegate DefaultDeviceChanged; event AudioDeviceCreatedDelegate DeviceCreated; diff --git a/Desktop/Application/MaxMix/Services/Communication/Message/MessageSetDefaultEndpoint.cs b/Desktop/Application/MaxMix/Services/Communication/Message/MessageSetDefaultEndpoint.cs new file mode 100644 index 00000000..86443c71 --- /dev/null +++ b/Desktop/Application/MaxMix/Services/Communication/Message/MessageSetDefaultEndpoint.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MaxMix.Services.Communication +{ + internal class MessageSetDefaultEndpoint : IMessage + { + #region Constructor + public MessageSetDefaultEndpoint() { } + public MessageSetDefaultEndpoint(int id) + { + _id = id; + } + #endregion + + #region Consts + #endregion + + #region Fields + private int _id; + #endregion + + #region Properties + public int Id { get => _id; } + #endregion + + #region Private Methods + #endregion + + #region Public Methods + + /* + * --------------------------------------- + * CHUNK TYPE SIZE (BYTES) + * --------------------------------------- + * ID INT32 4 + * --------------------------------------- + * 4 + */ + + public byte[] GetBytes() + { + var result = new List(); + result.AddRange(BitConverter.GetBytes(Id)); + return result.ToArray(); + } + + public bool SetBytes(byte[] bytes) + { + var idBytes = bytes.Take(4).Reverse().ToArray(); + _id = BitConverter.ToInt32(idBytes, 0); + return true; + } + #endregion + } +} \ No newline at end of file diff --git a/Desktop/Application/MaxMix/ViewModels/MainViewModel.cs b/Desktop/Application/MaxMix/ViewModels/MainViewModel.cs index 38a1aa34..9fb1c227 100644 --- a/Desktop/Application/MaxMix/ViewModels/MainViewModel.cs +++ b/Desktop/Application/MaxMix/ViewModels/MainViewModel.cs @@ -33,7 +33,8 @@ public MainViewModel() _serializationService.RegisterType(2); _serializationService.RegisterType(3); _serializationService.RegisterType(4); - _serializationService.RegisterType(5); + _serializationService.RegisterType(5); + _serializationService.RegisterType(6); _settingsViewModel = new SettingsViewModel(); _settingsViewModel.PropertyChanged += OnSettingsChanged; @@ -237,6 +238,11 @@ private void OnMessageReceived(object sender, IMessage message) var message_ = message as MessageUpdateVolumeSession; _audioSessionService.SetItemVolume(message_.Id, message_.Volume, message_.IsMuted); } + else if (message.GetType() == typeof(MessageSetDefaultEndpoint)) + { + var message_ = message as MessageSetDefaultEndpoint; + _audioSessionService.SetDefaultEndpoint(message_.Id); + } } private void OnCommunicationError(object sender, string e) diff --git a/Embedded/MaxMix/Commands.ino b/Embedded/MaxMix/Commands.ino index 67d00239..ef78e935 100644 --- a/Embedded/MaxMix/Commands.ino +++ b/Embedded/MaxMix/Commands.ino @@ -42,6 +42,23 @@ void SendItemVolumeCommand(Item* item, uint8_t* rawBuffer, uint8_t* packageBuffe Serial.write(packageBuffer, encodeSize); } +//--------------------------------------------------------- +//--------------------------------------------------------- +void SendSetDefaultEndpointCommand(Item* item, uint8_t* rawBuffer, uint8_t* packageBuffer) +{ + rawBuffer[0] = packageRevision++; + rawBuffer[1] = MSG_COMMAND_SET_DEFAULT_ENDPOINT; + + rawBuffer[2] = (uint8_t)(item->id >> 24) & 0xFF; + rawBuffer[3] = (uint8_t)(item->id >> 16) & 0xFF; + rawBuffer[4] = (uint8_t)(item->id >> 8) & 0xFF; + rawBuffer[5] = (uint8_t)item->id & 0xFF; + + uint8_t encodeSize = EncodePackage(rawBuffer, 8, packageBuffer); + Serial.write(packageBuffer, encodeSize); +} + + //--------------------------------------------------------- //--------------------------------------------------------- void AddItemCommand(uint8_t* packageBuffer, Item* itemsBuffer, uint8_t* itemCount) @@ -75,8 +92,15 @@ void RemoveItemCommand(uint8_t* packageBuffer, Item* itemsBuffer, uint8_t* itemC //--------------------------------------------------------- void UpdateItemVolumeCommand(uint8_t* packageBuffer, Item* itemsBuffer, uint8_t index) { - itemsBuffer[index].volume = packageBuffer[6]; - itemsBuffer[index].isMuted = packageBuffer[7]; + itemsBuffer[index].volume = packageBuffer[6]; + itemsBuffer[index].isMuted = packageBuffer[7]; +} + +//--------------------------------------------------------- +//--------------------------------------------------------- +void SetDefaultEndpointCommand(uint8_t* packageBuffer, Item* itemsBuffer, uint8_t index) +{ + } //--------------------------------------------------------- diff --git a/Embedded/MaxMix/Config.h b/Embedded/MaxMix/Config.h index ebe631c8..b45415a6 100644 --- a/Embedded/MaxMix/Config.h +++ b/Embedded/MaxMix/Config.h @@ -71,7 +71,8 @@ static const uint8_t MSG_COMMAND_ACKNOWLEDGMENT = 1; static const uint8_t MSG_COMMAND_ADD = 2; static const uint8_t MSG_COMMAND_REMOVE = 3; static const uint8_t MSG_COMMAND_UPDATE_VOLUME = 4; -static const uint8_t MSG_COMMAND_SETTINGS = 5; +static const uint8_t MSG_COMMAND_SET_DEFAULT_ENDPOINT = 5; +static const uint8_t MSG_COMMAND_SETTINGS = 6; static const uint8_t MSG_PACKET_DELIMITER = 0; diff --git a/Embedded/MaxMix/MaxMix.ino b/Embedded/MaxMix/MaxMix.ino index 8d6b347d..8883dede 100644 --- a/Embedded/MaxMix/MaxMix.ino +++ b/Embedded/MaxMix/MaxMix.ino @@ -526,6 +526,9 @@ bool ProcessEncoderButton() if(mode == MODE_OUTPUT) { + if(stateOutput == STATE_OUTPUT_NAVIGATE) + SendSetDefaultEndpointCommand(&devices[itemIndexOutput], sendBuffer, encodeBuffer); + stateOutput = CycleState(stateOutput, STATE_OUTPUT_COUNT); TimerDisplayReset(); } From 5aa49bc7308025e0b5624a7bbf5ab46829eacdbe Mon Sep 17 00:00:00 2001 From: Ruben Henares Date: Sat, 5 Sep 2020 22:27:27 -0700 Subject: [PATCH 3/5] Adding default endpoint switch from app to device --- .../MaxMix/ViewModels/MainViewModel.cs | 2 ++ Embedded/MaxMix/Commands.ino | 7 ------- Embedded/MaxMix/Display.ino | 5 ++++- Embedded/MaxMix/MaxMix.ino | 19 ++++++++++++++++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Desktop/Application/MaxMix/ViewModels/MainViewModel.cs b/Desktop/Application/MaxMix/ViewModels/MainViewModel.cs index 9fb1c227..c510d7ae 100644 --- a/Desktop/Application/MaxMix/ViewModels/MainViewModel.cs +++ b/Desktop/Application/MaxMix/ViewModels/MainViewModel.cs @@ -181,6 +181,8 @@ private void RaiseExitRequested() #region EventHandlers private void OnDefaultDeviceChanged(object sender, int id) { + var message = new MessageSetDefaultEndpoint(id); + _communicationService.Send(message); } private void OnDeviceCreated(object sender, int id, string displayName, int volume, bool isMuted) diff --git a/Embedded/MaxMix/Commands.ino b/Embedded/MaxMix/Commands.ino index ef78e935..1de3d9c5 100644 --- a/Embedded/MaxMix/Commands.ino +++ b/Embedded/MaxMix/Commands.ino @@ -96,13 +96,6 @@ void UpdateItemVolumeCommand(uint8_t* packageBuffer, Item* itemsBuffer, uint8_t itemsBuffer[index].isMuted = packageBuffer[7]; } -//--------------------------------------------------------- -//--------------------------------------------------------- -void SetDefaultEndpointCommand(uint8_t* packageBuffer, Item* itemsBuffer, uint8_t index) -{ - -} - //--------------------------------------------------------- //--------------------------------------------------------- void UpdateSettingsCommand(uint8_t* packageBuffer, Settings* settings) diff --git a/Embedded/MaxMix/Display.ino b/Embedded/MaxMix/Display.ino index 44a5f1ee..f455a57e 100644 --- a/Embedded/MaxMix/Display.ino +++ b/Embedded/MaxMix/Display.ino @@ -168,7 +168,7 @@ void DrawSelectionItemVolume(Adafruit_SSD1306* display, uint8_t volume) //--------------------------------------------------------- // Draws the output mode screen //--------------------------------------------------------- -void DisplayOutputSelectScreen(Adafruit_SSD1306* display, char* name, uint8_t volume, bool isMuted, uint8_t leftArrow, uint8_t rightArrow, uint8_t modeIndex, uint8_t modeCount) +void DisplayOutputSelectScreen(Adafruit_SSD1306* display, char* name, uint8_t volume, bool isMuted, bool isDefaultEndpoint, uint8_t leftArrow, uint8_t rightArrow, uint8_t modeIndex, uint8_t modeCount) { display->clearDisplay(); @@ -179,6 +179,9 @@ void DisplayOutputSelectScreen(Adafruit_SSD1306* display, char* name, uint8_t vo DrawSelectionArrows(display, leftArrow, rightArrow); DrawSelectionVolumeBar(display, volume, isMuted); + if(isDefaultEndpoint) + DrawSelectionChannelName(display, "O"); + display->display(); } diff --git a/Embedded/MaxMix/MaxMix.ino b/Embedded/MaxMix/MaxMix.ino index 8883dede..577b8d6f 100644 --- a/Embedded/MaxMix/MaxMix.ino +++ b/Embedded/MaxMix/MaxMix.ino @@ -82,6 +82,8 @@ int8_t itemIndexApp = 0; int8_t itemIndexGameA = 0; int8_t itemIndexGameB = 0; +uint32_t defaultEndpointId; + // Settings struct Settings settings; @@ -389,6 +391,19 @@ bool ProcessPackage() return false; } } + else if(command == MSG_COMMAND_SET_DEFAULT_ENDPOINT) + { + uint32_t id = GetIdFromPackage(decodeBuffer); + int8_t index = FindItem(id, devices, deviceCount); + if(index == -1) + return false; + + itemIndexOutput = index; + defaultEndpointId = id; + + if(mode == MODE_OUTPUT) + return true; + } else if(command == MSG_COMMAND_SETTINGS) { UpdateSettingsCommand(decodeBuffer, &settings); @@ -655,7 +670,9 @@ void UpdateDisplay() { uint8_t scrollLeft = CanScrollLeft(itemIndexOutput, deviceCount, settings.continuousScroll); uint8_t scrollRight = CanScrollRight(itemIndexOutput, deviceCount, settings.continuousScroll); - DisplayOutputSelectScreen(display, devices[itemIndexOutput].name, devices[itemIndexOutput].volume, devices[itemIndexOutput].isMuted, scrollLeft, scrollRight, mode, MODE_COUNT); + uint8_t isDefaultEndpoint = devices[itemIndexOutput].id == defaultEndpointId; + + DisplayOutputSelectScreen(display, devices[itemIndexOutput].name, devices[itemIndexOutput].volume, devices[itemIndexOutput].isMuted, isDefaultEndpoint, scrollLeft, scrollRight, mode, MODE_COUNT); } else if(stateOutput == STATE_OUTPUT_EDIT) DisplayOutputEditScreen(display, devices[itemIndexOutput].name, devices[itemIndexOutput].volume, devices[itemIndexOutput].isMuted, mode, MODE_COUNT); From b1e6960ac9f8307671d500abd171d380ea7fe915 Mon Sep 17 00:00:00 2001 From: Ruben Henares Date: Sat, 5 Sep 2020 22:40:33 -0700 Subject: [PATCH 4/5] Making edit state default for output mode --- Embedded/MaxMix/MaxMix.ino | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/Embedded/MaxMix/MaxMix.ino b/Embedded/MaxMix/MaxMix.ino index 577b8d6f..da45bdca 100644 --- a/Embedded/MaxMix/MaxMix.ino +++ b/Embedded/MaxMix/MaxMix.ino @@ -66,7 +66,7 @@ uint8_t encodeBuffer[SEND_BUFFER_SIZE]; // State uint8_t mode = MODE_OUTPUT; -uint8_t stateOutput = STATE_OUTPUT_NAVIGATE; +uint8_t stateOutput = STATE_OUTPUT_EDIT; uint8_t stateApplication = STATE_APPLICATION_NAVIGATE; uint8_t stateGame = STATE_GAME_SELECT_A; uint8_t stateDisplay = STATE_DISPLAY_AWAKE; @@ -223,7 +223,7 @@ void ClearSend() void ResetState() { mode = MODE_OUTPUT; - stateOutput = STATE_OUTPUT_NAVIGATE; + stateOutput = STATE_OUTPUT_EDIT; stateApplication = STATE_APPLICATION_NAVIGATE; stateGame = STATE_GAME_SELECT_A; stateDisplay = STATE_DISPLAY_AWAKE; @@ -268,15 +268,6 @@ bool ProcessPackage() } else UpdateItemCommand(decodeBuffer, devices, index); - - if(settings.displayNewItem) - { - itemIndexOutput = index; - if(mode == MODE_OUTPUT) - stateOutput = STATE_OUTPUT_NAVIGATE; - - return true; - } } else { From 8b0993180b6bdb744e7095cde1f193a989191ea0 Mon Sep 17 00:00:00 2001 From: Ruben Henares Date: Sun, 6 Sep 2020 11:09:41 -0700 Subject: [PATCH 5/5] Hooking up set default endpoint method --- .../Application/MaxMix/Services/Audio/AudioSessionService.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs b/Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs index 0a045538..c3a4fa1f 100644 --- a/Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs +++ b/Desktop/Application/MaxMix/Services/Audio/AudioSessionService.cs @@ -104,6 +104,10 @@ public void SetItemVolume(int id, int volume, bool isMuted) public void SetDefaultEndpoint(int id) { + if (_devices.TryGetValue(id, out var device)) + { + AudioExtensions.SetDefaultEndpoint(device.Device.DeviceID, Role.Multimedia); + } } #endregion