Skip to content

Commit

Permalink
feat: volume control works
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-welker committed May 17, 2024
1 parent 9ade2a6 commit 2482e48
Showing 1 changed file with 73 additions and 18 deletions.
91 changes: 73 additions & 18 deletions src/SonyBraviaDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,32 @@ public void SetVolume(ushort level)
_pollTimer.Reset(1000, pollTime);
}

private void SetVolume(int level, bool resetPoll = false)
{
Debug.Console(2, this, "Input level: {0}", level);

var volumeCommand = Rs232Commands.VolumeDirect;

volumeCommand[5] = (byte)level;

if (_comsIsRs232)
{
var command = volumeCommand.WithChecksum();
_lastCommand = command;
_coms.SendBytes(command);

if (resetPoll)
{
_pollTimer.Reset(1000, pollTime);
}

return;
}

CommandQueue.Enqueue(SimpleIpCommands.GetControlCommand(_coms, "VOLM", level));
_pollTimer.Reset(1000, pollTime);
}

public void VolumeUp(bool pressRelease)
{
if (!pressRelease)
Expand All @@ -1133,10 +1159,6 @@ public void VolumeUp(bool pressRelease)
_volumeTimer = null;
}

var command = Rs232Commands.VolumeQuery.WithChecksum();
_lastCommand = command;
_coms.SendBytes(command);

_pollTimer.Reset(1000, pollTime);
return;
}
Expand All @@ -1148,10 +1170,28 @@ public void VolumeUp(bool pressRelease)
_volumeCounter = 0;

_volumeTimer = new CTimer(o => {
var command = _volumeCounter % 2 == 0 ? Rs232Commands.VolumeUp.WithChecksum() : Rs232Commands.VolumeQuery.WithChecksum();
_lastCommand = command;
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, _volumeCounter % 2 == 0 ? "Sending Volume Up command {command}" : "Sending Volume Query command {command}", this, ComTextHelper.GetEscapedText(command));
_coms.SendBytes(command);
this.LogVerbose("rawVolume: {raw:X2} maxVolume: {max:X2}", _rawVolume, maxVolumeLevel);
if (_rawVolume > maxVolumeLevel) return;
int increment = 1;
if (_volumeCounter > 4)
{
increment = 2;
}
if (_volumeCounter > 16)
{
increment = 4;
}
_rawVolume += increment;
SetVolume(_rawVolume);
VolumeLevelFeedback.FireUpdate();
_volumeCounter += 1;
}, null, 0, 500);

Expand All @@ -1168,11 +1208,7 @@ public void VolumeDown(bool pressRelease)
_volumeTimer.Stop();
_volumeTimer.Dispose();
_volumeTimer = null;
}

var command = Rs232Commands.VolumeQuery.WithChecksum();
_lastCommand = command;
_coms.SendBytes(command);
}

_pollTimer.Reset(1000, pollTime);
return;
Expand All @@ -1183,13 +1219,32 @@ public void VolumeDown(bool pressRelease)
_pollTimer.Stop();

_volumeCounter = 0;

_volumeTimer = new CTimer(o => {
var command = _volumeCounter % 2 == 0 ? Rs232Commands.VolumeDown.WithChecksum() : Rs232Commands.VolumeQuery.WithChecksum();
_lastCommand = command;
Debug.LogMessage(Serilog.Events.LogEventLevel.Information, _volumeCounter % 2 == 0 ? "Sending Volume Down command {command}" : "Sending Volume Query command {command}", this, ComTextHelper.GetEscapedText(command));
_coms.SendBytes(command);
this.LogVerbose("rawVolume: {raw:X2} maxVolume: {max:X2}", _rawVolume, maxVolumeLevel);
if (_rawVolume <= 0) return;
int increment = 1;
if(_volumeCounter > 4)
{
increment = 2;
}
if(_volumeCounter > 16)
{
increment = 4;
}
_rawVolume -= increment;
SetVolume(_rawVolume);
VolumeLevelFeedback.FireUpdate();
_volumeCounter += 1;
}, null, 0, 500);

return;
Expand Down

0 comments on commit 2482e48

Please sign in to comment.