Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/testing updates #11

Merged
merged 2 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading