Skip to content

Commit

Permalink
Merge pull request #11 from PepperDash/feature/testing-updates
Browse files Browse the repository at this point in the history
Feature/testing updates
  • Loading branch information
ndorin committed May 20, 2024
2 parents 977d4ec + 2482e48 commit d396d67
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Rs232Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class Rs232Commands

public static readonly byte[] VolumeUp = { 0x8C, 0x00, 0x05, 0x03, 0x00, 0x00 };
public static readonly byte[] VolumeDown = { 0x8C, 0x00, 0x05, 0x03, 0x00, 0x01 };
public static readonly byte[] VolumeDirect = { 0x83, 0x00, 0x05, 0x03, 0x01, 0x00 }; //reset byte[5] to actual volume level
public static readonly byte[] VolumeDirect = { 0x8C, 0x00, 0x05, 0x03, 0x01, 0x00 }; //reset byte[5] to actual volume level

public static readonly byte[] MuteOn = { 0x8C, 0x00, 0x06, 0x03, 0x01, 0x01};
public static readonly byte[] MuteOff = { 0x8C, 0x00, 0x06, 0x03, 0x01, 0x00 };
Expand Down
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 d396d67

Please sign in to comment.