Moving commands into byte representations. Working on Volume

This commit is contained in:
Heath Volmer
2017-08-10 15:29:53 -06:00
parent 6d21950180
commit efd5b59bda
12 changed files with 124 additions and 94 deletions

View File

@@ -69,7 +69,7 @@
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="PepperDash_Core, Version=1.0.0.16459, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="PepperDash_Core, Version=1.0.0.16459, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\PepperDash.Core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath> <HintPath>..\..\..\pepperdash-simplsharp-core\Pepperdash Core\CLZ Builds\PepperDash_Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="SimplSharpCustomAttributesInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL"> <Reference Include="SimplSharpCustomAttributesInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>

View File

@@ -57,9 +57,9 @@
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="PepperDash_Core, Version=1.0.0.15153, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="PepperDash_Core, Version=1.0.0.15153, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\PepperDash.Core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath> <HintPath>..\..\..\pepperdash-simplsharp-core\Pepperdash Core\CLZ Builds\PepperDash_Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="PepperDash_Essentials_Core, Version=1.0.0.14500, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="PepperDash_Essentials_Core, Version=1.0.0.24289, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Essentials Core\PepperDashEssentialsBase\bin\PepperDash_Essentials_Core.dll</HintPath> <HintPath>..\..\Essentials Core\PepperDashEssentialsBase\bin\PepperDash_Essentials_Core.dll</HintPath>
</Reference> </Reference>

View File

@@ -48,7 +48,8 @@ namespace PepperDash.Essentials.Devices.Displays
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(0, "Displays factory: Exception creating device type {0}, key {1}: {2}", dc.Type, dc.Key, e.Message); Debug.Console(0, "Displays factory: Exception creating device type {0}, key {1}: \nCONFIG JSON: {2} \nERROR: {3}\n\n",
dc.Type, dc.Key, JsonConvert.SerializeObject(dc), e);
return null; return null;
} }

View File

@@ -26,37 +26,15 @@ namespace PepperDash.Essentials.Devices.Displays
public string Ack { get; private set; } public string Ack { get; private set; }
public string Nak { get; private set; } public string Nak { get; private set; }
// Power Commands
public string PowerGetCmd { get; private set; }
public string PowerOnCmd { get; private set; }
public string PowerOffCmd { get; private set; }
// Input Commands
public string InputGetCmd { get; private set; }
public string Dp1Cmd { get; private set; }
public string Hdmi1Cmd { get; private set; }
public string Hdmi2Cmd { get; private set; }
public string Hdmi3Cmd { get; private set; }
public string Dvi1Cmd { get; private set; }
public string Video1Cmd { get; private set; }
public string Rgb1Cmd { get; private set; }
public string Rgb2Cmd { get; private set; }
// Volume Commands // Volume Commands
public string MuteGetCmd { get; private set; } //public string MuteGetCmd { get; private set; }
public string MuteOnCmd { get; private set; } //public string MuteOnCmd { get; private set; }
public string MuteOffCmd { get; private set; } //public string MuteOffCmd { get; private set; }
public string VolumeGetCmd { get; private set; } //public string VolumeGetCmd { get; private set; }
/// <summary> /// <summary>
/// To be appended with the requested volume level. Does not include checksum calculation /// To be appended with the requested volume level. Does not include checksum calculation
@@ -90,6 +68,7 @@ namespace PepperDash.Essentials.Devices.Displays
checksum = checksum - 0x100; checksum = checksum - 0x100;
var checksumByte = Convert.ToByte(checksum); var checksumByte = Convert.ToByte(checksum);
Debug.Console(2, "Append checksum: command={0}, checksum={1}", ComTextHelper.GetEscapedText(command), checksumByte);
string result = string.Format("{0}{1}", command, (char)checksumByte); string result = string.Format("{0}{1}", command, (char)checksumByte);
@@ -118,7 +97,7 @@ namespace PepperDash.Essentials.Devices.Displays
{ {
Communication = comm; Communication = comm;
Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived); Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
ID = id == null ? (byte)0x01 : Convert.ToByte(id); // If id is null, set default value of 0x01, otherwise assign value passed in constructor ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
Init(); Init();
} }
@@ -133,7 +112,7 @@ namespace PepperDash.Essentials.Devices.Displays
{ {
Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000); Communication = new GenericTcpIpClient(key + "-tcp", hostname, port, 5000);
Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived); Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
ID = id == null ? (byte)0x01 : Convert.ToByte(id); // If id is null, set default value of 0x01, otherwise assign value passed in constructor ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
Init(); Init();
} }
@@ -146,7 +125,7 @@ namespace PepperDash.Essentials.Devices.Displays
{ {
Communication = new ComPortController(key + "-com", port, spec); Communication = new ComPortController(key + "-com", port, spec);
Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived); Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
ID = id == null ? (byte)0x01 : Convert.ToByte(id); // If id is null, set default value of 0x01, otherwise assign value passed in constructor ID = id == null ? (byte)0x01 : Convert.ToByte(id, 16); // If id is null, set default value of 0x01, otherwise assign value passed in constructor
Init(); Init();
} }
@@ -168,63 +147,43 @@ namespace PepperDash.Essentials.Devices.Displays
Nak = AppendChecksum(string.Format("\xAA\xFF{0}\x03N", ID)); Nak = AppendChecksum(string.Format("\xAA\xFF{0}\x03N", ID));
//Power Commands
PowerGetCmd = AppendChecksum(string.Format("\x11{0}\x00", ID));
PowerOnCmd = AppendChecksum(string.Format("\x11{0}\x01\x01", ID));
PowerOffCmd = AppendChecksum(string.Format("\x11{0}\x01\x00", ID));
//Input Commands
InputGetCmd = AppendChecksum(string.Format("\x14{0}\x00", ID));
string cmdPrefix = string.Format("\x14{0}\x01", ID); string cmdPrefix = string.Format("\x14{0}\x01", ID);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.AudioVideo, AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this), cmdPrefix, 0x21); eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this), cmdPrefix, 0x21);
Hdmi1Cmd = string.Format("{0}{1}", cmdPrefix, 0x21);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.AudioVideo, AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn2, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this), cmdPrefix, 0x23); eRoutingPortConnectionType.Hdmi, new Action(InputHdmi2), this), cmdPrefix, 0x23);
Hdmi2Cmd = string.Format("{0}{1}", cmdPrefix, 0x23);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo, AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn3, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this), cmdPrefix, 0x32); eRoutingPortConnectionType.Hdmi, new Action(InputHdmi3), this), cmdPrefix, 0x32);
Hdmi3Cmd = string.Format("{0}{1}", cmdPrefix, 0x32);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.AudioVideo, AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DisplayPortIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this), cmdPrefix, 0x25); eRoutingPortConnectionType.DisplayPort, new Action(InputDisplayPort1), this), cmdPrefix, 0x25);
Dp1Cmd = string.Format("{0}{1}", cmdPrefix, 0x25);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.AudioVideo, AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.DviIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this), cmdPrefix, 0x18); eRoutingPortConnectionType.Dvi, new Action(InputDvi1), this), cmdPrefix, 0x18);
Dvi1Cmd = string.Format("{0}{1}", cmdPrefix, 0x18);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.AudioVideo, AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.CompositeIn, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Composite, new Action(InputVideo1), this), cmdPrefix, 0x08); eRoutingPortConnectionType.Composite, new Action(InputVideo1), this), cmdPrefix, 0x08);
Video1Cmd = string.Format("{0}{1}", cmdPrefix, 0x08);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn1, eRoutingSignalType.Video, AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn1, eRoutingSignalType.Video,
eRoutingPortConnectionType.Vga, new Action(InputRgb1), this), cmdPrefix, 0x14); eRoutingPortConnectionType.Vga, new Action(InputRgb1), this), cmdPrefix, 0x14);
Rgb1Cmd = string.Format("{0}{1}", cmdPrefix, 0x14);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn2, eRoutingSignalType.Video, AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn2, eRoutingSignalType.Video,
eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb2)), this), cmdPrefix, 0x1E); eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb2)), this), cmdPrefix, 0x1E);
Rgb2Cmd = string.Format("{0}{1}", cmdPrefix, 0x1E);
// Mute Commands // Mute Commands
MuteGetCmd = AppendChecksum(string.Format("\x13{0}\x00", ID)); //MuteGetCmd = AppendChecksum(string.Format("\x13{0}\x00", ID));
MuteOnCmd = AppendChecksum(string.Format("\x13{0}\x01\x01", ID)); //MuteOnCmd = AppendChecksum(string.Format("\x13{0}\x01\x01", ID));
MuteOffCmd = AppendChecksum(string.Format("\x13{0}\x01\x00", ID)); //MuteOffCmd = AppendChecksum(string.Format("\x13{0}\x01\x00", ID));
// Volume Commands // Volume Commands
VolumeGetCmd = AppendChecksum(string.Format("\x12{0}\x00", ID)); //VolumeGetCmd = AppendChecksum(string.Format("\x12{0}\x00", ID));
VolumeLevelPartialCmd = string.Format("\x12{0}\x01", ID); VolumeLevelPartialCmd = string.Format("\x12{0}\x01", ID);
@@ -233,13 +192,15 @@ namespace PepperDash.Essentials.Devices.Displays
// Query initial device status // Query initial device status
Send(PowerGetCmd); //Send(PowerGetCmd);
PowerGet();
Send(InputGetCmd); InputGet();
//Send(InputGetCmd);
Send(VolumeGetCmd); VolumeGet();
Send(MuteGetCmd); MuteGet();
} }
~SamsungMDC() ~SamsungMDC()
@@ -392,10 +353,30 @@ namespace PepperDash.Essentials.Devices.Displays
Communication.SendText(cmd); Communication.SendText(cmd);
} }
void SendBytes(byte[] b)
{
b[2] = ID;
// append checksum by adding all bytes, except last which should be 00
int checksum = 0;
for (var i = 1; i < b.Length - 1; i++) // add 2nd through 2nd-to-last bytes
{
checksum += b[i];
}
checksum = checksum & 0x000000FF; // mask off MSBs
b[b.Length - 1] = (byte)checksum;
if(Debug.Level == 2) // This check is here to prevent following string format from building unnecessarily on level 0 or 1
Debug.Console(2, this, "Sending:{0}", ComTextHelper.GetEscapedText(b));
Communication.SendBytes(b);
}
public override void PowerOn()
public override void PowerOn()
{ {
Send(PowerOnCmd); //Send(PowerOnCmd);
SendBytes(new byte[] { 0xAA, 0x11, 0x00, 0x01, 0x01, 0x00 });
if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown) if (!PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
{ {
_IsWarmingUp = true; _IsWarmingUp = true;
@@ -417,7 +398,8 @@ namespace PepperDash.Essentials.Devices.Displays
// remove this check. // remove this check.
if (PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown) if (PowerIsOnFeedback.BoolValue && !_IsWarmingUp && !_IsCoolingDown)
{ {
Send(PowerOffCmd); //Send(PowerOffCmd);
SendBytes(new byte[] { 0xAA, 0x11, 0x00, 0x01, 0x00, 0x00 });
_IsCoolingDown = true; _IsCoolingDown = true;
_PowerIsOn = false; _PowerIsOn = false;
PowerIsOnFeedback.FireUpdate(); PowerIsOnFeedback.FireUpdate();
@@ -440,44 +422,59 @@ namespace PepperDash.Essentials.Devices.Displays
PowerOn(); PowerOn();
} }
public void PowerGet()
{
SendBytes(new byte[] { 0xAA, 0x11, 0x00, 0x00, 0x00 });
}
public void InputHdmi1() public void InputHdmi1()
{ {
Send(Hdmi1Cmd); SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x21, 0x00 });
} }
public void InputHdmi2() public void InputHdmi2()
{ {
Send(Hdmi2Cmd); SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x23, 0x00 });
} }
public void InputHdmi3() public void InputHdmi3()
{ {
Send(Hdmi3Cmd); SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x32, 0x00 });
} }
public void InputHdmi4()
{
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x34, 0x00 });
}
public void InputDisplayPort1() public void InputDisplayPort1()
{ {
Send(Dp1Cmd); SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x25, 0x00 });
} }
public void InputDvi1() public void InputDvi1()
{ {
Send(Dvi1Cmd); SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x18, 0x00 });
} }
public void InputVideo1() public void InputVideo1()
{ {
Send(Video1Cmd); SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x08, 0x00 });
} }
public void InputRgb1() public void InputRgb1()
{ {
Send(Rgb1Cmd); SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x14, 0x00 });
} }
public void InputRgb2() public void InputRgb2()
{ {
Send(Rgb2Cmd); SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x01, 0x1E, 0x00 });
}
public void InputGet()
{
SendBytes(new byte[] { 0xAA, 0x14, 0x00, 0x00, 0x00 });
} }
public override void ExecuteSwitch(object selector) public override void ExecuteSwitch(object selector)
@@ -499,6 +496,8 @@ namespace PepperDash.Essentials.Devices.Displays
var levelString = string.Format("{0}{1}", VolumeLevelPartialCmd, Convert.ToByte(scaledLevel)); var levelString = string.Format("{0}{1}", VolumeLevelPartialCmd, Convert.ToByte(scaledLevel));
Debug.Console(2, this, "Volume:{0}", ComTextHelper.GetEscapedText(levelString)); Debug.Console(2, this, "Volume:{0}", ComTextHelper.GetEscapedText(levelString));
var volByte = BitConverter.GetBytes(scaledLevel) FIX THIS HERE!!!!!!!!!!!
Send(levelString); Send(levelString);
_VolumeLevel = level; _VolumeLevel = level;
VolumeLevelFeedback.FireUpdate(); VolumeLevelFeedback.FireUpdate();
@@ -530,37 +529,58 @@ namespace PepperDash.Essentials.Devices.Displays
public BoolFeedback MuteFeedback { get; private set; } public BoolFeedback MuteFeedback { get; private set; }
/// <summary>
///
/// </summary>
public void MuteOff() public void MuteOff()
{ {
Send(MuteOffCmd); SendBytes(new byte[] { 0xAA, 0x13, 0x00, 0x01, 0x00, 0x00 });
} }
/// <summary>
///
/// </summary>
public void MuteOn() public void MuteOn()
{ {
Send(MuteOnCmd); SendBytes(new byte[] { 0xAA, 0x13, 0x00, 0x01, 0x01, 0x00 });
} }
void IBasicVolumeWithFeedback.SetVolume(ushort level) /// <summary>
{ ///
SetVolume(level); /// </summary>
} public void MuteGet()
{
SendBytes(new byte[] { 0xAA, 0x13, 0x00, 0x00, 0x00 });
}
///// <summary>
/////
///// </summary>
///// <param name="level"></param>
//void SetVolume(ushort level)
//{
// SetVolume(level);
//}
#endregion #endregion
#region IBasicVolumeControls Members #region IBasicVolumeControls Members
/// <summary>
///
/// </summary>
public void MuteToggle() public void MuteToggle()
{ {
if (_IsMuted) if (_IsMuted)
{ MuteOff();
Send(MuteOffCmd);
}
else else
{ MuteOn();
Send(MuteOnCmd);
}
} }
/// <summary>
///
/// </summary>
/// <param name="pressRelease"></param>
public void VolumeDown(bool pressRelease) public void VolumeDown(bool pressRelease)
{ {
//throw new NotImplementedException(); //throw new NotImplementedException();
@@ -568,12 +588,21 @@ namespace PepperDash.Essentials.Devices.Displays
SetVolume(_VolumeLevel++); SetVolume(_VolumeLevel++);
} }
/// <summary>
/// /
/// </summary>
/// <param name="pressRelease"></param>
public void VolumeUp(bool pressRelease) public void VolumeUp(bool pressRelease)
{ {
//throw new NotImplementedException(); //throw new NotImplementedException();
SetVolume(_VolumeLevel--); SetVolume(_VolumeLevel--);
} }
public void VolumeGet()
{
SendBytes(new byte[] { 0xAA, 0x12, 0x00, 0x00, 0x00 });
}
#endregion #endregion
} }
} }

View File

@@ -57,9 +57,9 @@
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="PepperDash_Core, Version=1.0.6284.20368, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="PepperDash_Core, Version=1.0.6284.20368, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\PepperDash.Core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath> <HintPath>..\..\..\pepperdash-simplsharp-core\Pepperdash Core\CLZ Builds\PepperDash_Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="PepperDash_Essentials_Core, Version=1.0.0.14500, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="PepperDash_Essentials_Core, Version=1.0.0.24289, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Essentials Core\PepperDashEssentialsBase\bin\PepperDash_Essentials_Core.dll</HintPath> <HintPath>..\..\Essentials Core\PepperDashEssentialsBase\bin\PepperDash_Essentials_Core.dll</HintPath>
</Reference> </Reference>

View File

@@ -81,7 +81,7 @@
</Reference> </Reference>
<Reference Include="PepperDash_Core, Version=1.0.0.18868, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="PepperDash_Core, Version=1.0.0.18868, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\PepperDash.Core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll</HintPath> <HintPath>..\..\..\pepperdash-simplsharp-core\Pepperdash Core\CLZ Builds\PepperDash_Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="PepperDash_Essentials_Core, Version=1.0.0.12925, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="PepperDash_Essentials_Core, Version=1.0.0.12925, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>