Fixed volume up/down; Working on linking display power fb to room on fb

This commit is contained in:
Heath Volmer
2017-08-18 12:20:22 -06:00
parent 394be710a4
commit 25122abed1
16 changed files with 331 additions and 146 deletions

View File

@@ -40,8 +40,8 @@ namespace PepperDash.Essentials.Core
{
if (pollTime > warningTime || pollTime > errorTime)
throw new ArgumentException("pollTime must be less than warning or errorTime");
if (pollTime < 5000)
throw new ArgumentException("pollTime cannot be less than 5000 ms");
//if (pollTime < 5000)
// throw new ArgumentException("pollTime cannot be less than 5000 ms");
Client = client;
PollTime = pollTime;
@@ -63,8 +63,8 @@ namespace PepperDash.Essentials.Core
{
if (pollTime > warningTime || pollTime > errorTime)
throw new ArgumentException("pollTime must be less than warning or errorTime");
if (pollTime < 5000)
throw new ArgumentException("pollTime cannot be less than 5000 ms");
//if (pollTime < 5000)
// throw new ArgumentException("pollTime cannot be less than 5000 ms");
Client = client;
PollTime = pollTime;
@@ -112,7 +112,7 @@ namespace PepperDash.Essentials.Core
StartErrorTimers();
if (Client.IsConnected)
{
Debug.Console(2, Client, "Monitor, Polling");
Debug.Console(2, this, "Polling");
if(PollAction != null)
PollAction.Invoke();
else
@@ -120,7 +120,7 @@ namespace PepperDash.Essentials.Core
}
else
{
Debug.Console(2, Client, "Monitor, Comm not connected");
Debug.Console(2, this, "Comm not connected");
}
}
@@ -132,7 +132,7 @@ namespace PepperDash.Essentials.Core
if (Client.IsConnected)
{
//Client.IsConnected -= OneTimeConnectHandler;
Debug.Console(2, Client, "Monitor, Comm connected");
Debug.Console(2, this, "Comm connected");
Poll();
}
}

View File

@@ -99,6 +99,7 @@
<Reference Include="System.Data" />
</ItemGroup>
<ItemGroup>
<Compile Include="Ramps and Increments\ActionIncrementer.cs" />
<Compile Include="Comm and IR\CommFactory.cs" />
<Compile Include="Comm and IR\CommunicationExtras.cs" />
<Compile Include="Comm and IR\REMOVE ComPortConfig.cs" />
@@ -132,6 +133,7 @@
<Compile Include="Devices\IVolumeAndAudioInterfaces.cs" />
<Compile Include="Display\BasicIrDisplay.cs" />
<Compile Include="Feedbacks\BoolFeedbackOneShot.cs" />
<Compile Include="Ramps and Increments\UshortSigIncrementer.cs" />
<Compile Include="Routing\ICardPortsDevice.cs" />
<Compile Include="InUseTracking\IInUseTracking.cs" />
<Compile Include="InUseTracking\InUseTracking.cs" />

View File

@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// An incrementer that can use the values of some other object/primitive value to do its thing.
/// It uses an Action to set the value and a Func to get the value from whatever this is
/// attached to.
/// </summary>
public class ActionIncrementer
{
public int ChangeAmount { get; set; }
public int MaxValue { get; set; }
public int MinValue { get; set; }
public uint RepeatDelay { get; set; }
public uint RepeatTime { get; set; }
Action<int> SetAction;
Func<int> GetFunc;
CTimer Timer;
/// <summary>
///
/// </summary>
/// <param name="changeAmount"></param>
/// <param name="minValue"></param>
/// <param name="maxValue"></param>
/// <param name="repeatDelay"></param>
/// <param name="repeatTime"></param>
/// <param name="setAction">Action that will be called when this needs to set the destination value</param>
/// <param name="getFunc">Func that is called to get the current value</param>
public ActionIncrementer(int changeAmount, int minValue, int maxValue, uint repeatDelay, uint repeatTime, Action<int> setAction, Func<int> getFunc)
{
SetAction = setAction;
GetFunc = getFunc;
ChangeAmount = changeAmount;
MaxValue = maxValue;
MinValue = minValue;
RepeatDelay = repeatDelay;
RepeatTime = repeatTime;
}
/// <summary>
/// Starts incrementing cycle
/// </summary>
public void StartUp()
{
if (Timer != null) return;
Go(ChangeAmount);
}
/// <summary>
/// Starts decrementing cycle
/// </summary>
public void StartDown()
{
if (Timer != null) return;
Go(-ChangeAmount);
}
/// <summary>
/// Stops the repeat
/// </summary>
public void Stop()
{
if (Timer != null)
Timer.Stop();
Timer = null;
}
/// <summary>
/// Helper that does the work of setting new level, and starting repeat loop, checking against bounds first.
/// </summary>
/// <param name="change"></param>
void Go(int change)
{
int currentLevel = GetFunc();
// Fire once then pause
int newLevel = currentLevel + change;
bool atLimit = CheckLevel(newLevel, out newLevel);
SetAction(newLevel);
if (atLimit) // Don't go past end
Stop();
else if (Timer == null) // Only enter the timer if it's not already running
Timer = new CTimer(o => { Go(change); }, null, RepeatDelay, RepeatTime);
}
/// <summary>
/// Helper to check a new level against min/max. Returns revised level if new level
/// will go out of bounds
/// </summary>
/// <param name="levelIn">The level to check against bounds</param>
/// <param name="levelOut">Revised level if bounds are exceeded. Min or max</param>
/// <returns>true if new level is at or past bounds</returns>
bool CheckLevel(int levelIn, out int levelOut)
{
bool isAtLimit = false;
if (levelIn > MaxValue)
{
levelOut = MaxValue;
isAtLimit = true;
}
else if (levelIn < MinValue)
{
levelOut = MinValue;
isAtLimit = true;
}
else
levelOut = levelIn;
return isAtLimit;
}
}
}

View File

@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using PepperDash.Core;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Attaches to UShortInputSig and does incremental ramping of the signal
/// </summary>
public class UshortSigIncrementer
{
UShortInputSig TheSig;
public ushort ChangeAmount { get; set; }
public int MaxValue { get; set; }
public int MinValue { get; set; }
public uint RepeatDelay { get; set; }
public uint RepeatTime { get; set; }
bool SignedMode;
CTimer Timer;
public UshortSigIncrementer(UShortInputSig sig, ushort changeAmount, int minValue, int maxValue, uint repeatDelay, uint repeatTime)
{
TheSig = sig;
ChangeAmount = changeAmount;
MaxValue = maxValue;
MinValue = minValue;
if (MinValue < 0 || MaxValue < 0) SignedMode = true;
RepeatDelay = repeatDelay;
RepeatTime = repeatTime;
if (SignedMode && (MinValue < -32768 || MaxValue > 32767))
Debug.Console(1, "UshortSigIncrementer has signed values that exceed range of -32768, 32767");
}
public void StartUp()
{
if (Timer != null) return;
Go(ChangeAmount);
}
public void StartDown()
{
if (Timer != null) return;
Go(-ChangeAmount);
}
void Go(int change)
{
int level;
if (SignedMode) level = TheSig.ShortValue;
else level = TheSig.UShortValue;
// Fire once then pause
int newLevel = level + change;
bool atLimit = CheckLevel(newLevel, out newLevel);
SetValue((ushort)newLevel);
if (atLimit) // Don't go past end
Stop();
else if (Timer == null) // Only enter the timer if it's not already running
Timer = new CTimer(o => { Go(change); }, null, RepeatDelay, RepeatTime);
}
bool CheckLevel(int levelIn, out int levelOut)
{
bool IsAtLimit = false;
if (levelIn > MaxValue)
{
levelOut = MaxValue;
IsAtLimit = true;
}
else if (levelIn < MinValue)
{
levelOut = MinValue;
IsAtLimit = true;
}
else
levelOut = levelIn;
return IsAtLimit;
}
public void Stop()
{
if (Timer != null)
Timer.Stop();
Timer = null;
}
void SetValue(ushort value)
{
//CrestronConsole.PrintLine("Increment level:{0} / {1}", value, (short)value);
TheSig.UShortValue = value;
}
}
}

View File

@@ -69,93 +69,4 @@ namespace PepperDash.Essentials.Core
sig.CreateRamp(level, time / 10);
}
}
/// <summary>
/// Attaches to UShortInputSig and does incremental ramping of the signal
/// </summary>
public class UshortSigIncrementer
{
UShortInputSig TheSig;
public ushort ChangeAmount { get; set; }
public int MaxValue { get; set; }
public int MinValue { get; set; }
public uint RepeatDelay { get; set; }
public uint RepeatTime { get; set; }
bool SignedMode;
CTimer Timer;
public UshortSigIncrementer(UShortInputSig sig, ushort changeAmount, int minValue, int maxValue, uint repeatDelay, uint repeatTime)
{
TheSig = sig;
ChangeAmount = changeAmount;
MaxValue = maxValue;
MinValue = minValue;
if (MinValue < 0 || MaxValue < 0) SignedMode = true;
RepeatDelay = repeatDelay;
RepeatTime = repeatTime;
if (SignedMode && (MinValue < -32768 || MaxValue > 32767))
Debug.Console(1, "UshortSigIncrementer has signed values that exceed range of -32768, 32767");
}
public void StartUp()
{
if (Timer != null) return;
Go(ChangeAmount);
}
public void StartDown()
{
if (Timer != null) return;
Go(-ChangeAmount);
}
void Go(int change)
{
int level;
if (SignedMode) level = TheSig.ShortValue;
else level = TheSig.UShortValue;
// Fire once then pause
int newLevel = level + change;
bool atLimit = CheckLevel(newLevel, out newLevel);
SetValue((ushort)newLevel);
if (atLimit) // Don't go past end
Stop();
else if (Timer == null) // Only enter the timer if it's not already running
Timer = new CTimer(o => { Go(change); }, null, RepeatDelay, RepeatTime);
}
bool CheckLevel(int levelIn, out int levelOut)
{
bool IsAtLimit = false;
if (levelIn > MaxValue)
{
levelOut = MaxValue;
IsAtLimit = true;
}
else if (levelIn < MinValue)
{
levelOut = MinValue;
IsAtLimit = true;
}
else
levelOut = levelIn;
return IsAtLimit;
}
public void Stop()
{
if (Timer != null)
Timer.Stop();
Timer = null;
}
void SetValue(ushort value)
{
//CrestronConsole.PrintLine("Increment level:{0} / {1}", value, (short)value);
TheSig.UShortValue = value;
}
}
}

View File

@@ -24,11 +24,13 @@ namespace PepperDash.Essentials.Devices.Displays
bool _PowerIsOn;
bool _IsWarmingUp;
bool _IsCoolingDown;
ushort _VolumeLevel;
ushort _VolumeLevelForSig;
int _LastVolumeSent;
bool _IsMuted;
RoutingInputPort _CurrentInputPort;
byte[] IncomingBuffer = new byte[]{};
//CTimer StatusTimer;
ActionIncrementer VolumeIncrementer;
bool VolumeIsRamping;
protected override Func<bool> PowerIsOnFeedbackFunc { get { return () => _PowerIsOn; } }
protected override Func<bool> IsCoolingDownFeedbackFunc { get { return () => _IsCoolingDown; } }
@@ -85,9 +87,13 @@ namespace PepperDash.Essentials.Devices.Displays
void Init()
{
WarmupTime = 10000;
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 30000, 120000, 300000, StatusGet);
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 2000, 120000, 300000, StatusGet);
DeviceManager.AddDevice(CommunicationMonitor);
VolumeIncrementer = new ActionIncrementer(655, 0, 65535, 800, 80,
v => SetVolume((ushort)v),
() => _LastVolumeSent);
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.HdmiIn1, eRoutingSignalType.AudioVideo,
eRoutingPortConnectionType.Hdmi, new Action(InputHdmi1), this), 0x21);
@@ -112,7 +118,7 @@ namespace PepperDash.Essentials.Devices.Displays
AddRoutingInputPort(new RoutingInputPort(RoutingPortNames.RgbIn2, eRoutingSignalType.Video,
eRoutingPortConnectionType.Rgb, new Action(new Action(InputRgb2)), this), 0x1E);
VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevel; });
VolumeLevelFeedback = new IntFeedback(() => { return _VolumeLevelForSig; });
MuteFeedback = new BoolFeedback(() => _IsMuted);
StatusGet();
@@ -238,7 +244,6 @@ namespace PepperDash.Essentials.Devices.Displays
_PowerIsOn = newVal;
PowerIsOnFeedback.FireUpdate();
}
}
/// <summary>
@@ -246,11 +251,13 @@ namespace PepperDash.Essentials.Devices.Displays
/// </summary>
/// <param name="b"></param>
void UpdateVolumeFB(byte b)
{
{
var newVol = (ushort)Scale((double)b, 0, 100, 0, 65535);
if (newVol != _VolumeLevel)
if (!VolumeIsRamping)
_LastVolumeSent = newVol;
if (newVol != _VolumeLevelForSig)
{
_VolumeLevel = newVol;
_VolumeLevelForSig = newVol;
VolumeLevelFeedback.FireUpdate();
}
}
@@ -450,8 +457,10 @@ namespace PepperDash.Essentials.Devices.Displays
/// <param name="level"></param>
public void SetVolume(ushort level)
{
var volByte = Convert.ToByte(Scale(level, 0, 65535, 0, 100)); // The inputs to Scale ensures it won't overflow
SendBytes(new byte[] { 0xAA, 0x12, 0x00, 0x01, volByte, 0x00 });
_LastVolumeSent = level;
var scaled = (int)Scale(level, 0, 65535, 0, 100);
// The inputs to Scale ensure that byte won't overflow
SendBytes(new byte[] { 0xAA, 0x12, 0x00, 0x01, Convert.ToByte(scaled), 0x00 });
}
/// <summary>
@@ -534,7 +543,16 @@ namespace PepperDash.Essentials.Devices.Displays
/// <param name="pressRelease"></param>
public void VolumeDown(bool pressRelease)
{
throw new NotImplementedException();
if (pressRelease)
{
VolumeIncrementer.StartDown();
VolumeIsRamping = true;
}
else
{
VolumeIsRamping = false;
VolumeIncrementer.Stop();
}
}
/// <summary>
@@ -543,9 +561,21 @@ namespace PepperDash.Essentials.Devices.Displays
/// <param name="pressRelease"></param>
public void VolumeUp(bool pressRelease)
{
throw new NotImplementedException();
}
if (pressRelease)
{
VolumeIncrementer.StartUp();
VolumeIsRamping = true;
}
else
{
VolumeIsRamping = false;
VolumeIncrementer.Stop();
}
}
/// <summary>
///
/// </summary>
public void VolumeGet()
{
SendBytes(new byte[] { 0xAA, 0x12, 0x00, 0x00, 0x00 });

View File

@@ -14,6 +14,23 @@ namespace PepperDash.Essentials
public event EventHandler<VolumeDeviceChangeEventArgs> CurrentVolumeDeviceChange;
public event SourceInfoChangeHandler CurrentSingleSourceChange;
protected override Func<bool> OnFeedbackFunc
{
get
{
return () =>
{
var disp = DefaultDisplay as DisplayBase;
var val = CurrentSourceInfo != null
&& CurrentSourceInfo.Type == eSourceListItemType.Route
&& disp != null
&& disp.PowerIsOnFeedback.BoolValue;
Debug.Console(2, this, "************** ROOM POWER {0}", val);
return val;
};
}
}
public EssentialsRoomPropertiesConfig Config { get; private set; }
public IRoutingSinkWithSwitching DefaultDisplay { get; private set; }
@@ -91,11 +108,6 @@ namespace PepperDash.Essentials
public string CurrentSourceInfoKey { get; private set; }
/// <summary>
///
/// </summary>
public BoolFeedback OnFeedback { get; private set; }
/// <summary>
///
/// </summary>
@@ -115,13 +127,19 @@ namespace PepperDash.Essentials
CurrentVolumeControls = DefaultVolumeControls;
var disp = DefaultDisplay as DisplayBase;
OnFeedback = new BoolFeedback(() =>
{
return CurrentSourceInfo != null
&& CurrentSourceInfo.Type == eSourceListItemType.Route
&& disp != null
&& disp.PowerIsOnFeedback.BoolValue;
});
if (disp != null)
{
disp.PowerIsOnFeedback.OutputChange += (o, a) =>
{
if (disp.PowerIsOnFeedback.BoolValue != OnFeedback.BoolValue)
{
if (!disp.PowerIsOnFeedback.BoolValue)
CurrentSourceInfo = null;
OnFeedback.FireUpdate();
}
};
}
SourceListKey = "default";
EnablePowerOnToLastSource = true;
}

View File

@@ -16,6 +16,14 @@ namespace PepperDash.Essentials
public event SourceInfoChangeHandler CurrentDisplay1SourceChange;
public event SourceInfoChangeHandler CurrentDisplay2SourceChange;
protected override Func<bool> OnFeedbackFunc { get {
return () => (CurrentSingleSourceInfo != null
&& CurrentSingleSourceInfo.Type != eSourceListItemType.Off)
|| (Display1SourceInfo != null
&& Display1SourceInfo.Type != eSourceListItemType.Off)
|| (Display2SourceInfo != null
&& Display2SourceInfo.Type != eSourceListItemType.Off); } }
public EssentialsPresentationRoomPropertiesConfig Config { get; private set; }
public Dictionary<uint, IRoutingSinkNoSwitching> Displays { get; private set; }
@@ -141,16 +149,10 @@ namespace PepperDash.Essentials
}
SourceListItem _Display2SourceInfo;
/// <summary>
///
/// </summary>
public BoolFeedback OnFeedback { get; private set; }
/// <summary>
/// If an audio dialer is available for this room
/// </summary>
public bool HasAudioDialer { get { return false; } }
/// <summary>
///
/// </summary>
@@ -173,15 +175,7 @@ namespace PepperDash.Essentials
//else if (defaultAudio is IHasVolumeDevice)
// DefaultVolumeControls = (defaultAudio as IHasVolumeDevice).VolumeDevice;
OnFeedback = new BoolFeedback(() =>
{ return (CurrentSingleSourceInfo != null
&& CurrentSingleSourceInfo.Type != eSourceListItemType.Off)
|| (Display1SourceInfo != null
&& Display1SourceInfo.Type != eSourceListItemType.Off)
|| (Display2SourceInfo != null
&& Display2SourceInfo.Type != eSourceListItemType.Off);
});
SourceListKey = "default";
EnablePowerOnToLastSource = true;
}

View File

@@ -20,11 +20,23 @@ namespace PepperDash.Essentials
/// <summary>
///
/// </summary>
public class EssentialsRoomBase : Device
public abstract class EssentialsRoomBase : Device
{
/// <summary>
///
/// </summary>
public BoolFeedback OnFeedback { get; private set; }
public BoolFeedback IsWarmingFeedback { get; private set; }
public BoolFeedback IsCoolingFeedback { get; private set; }
public BoolFeedback ShutdownPendingFeedback { get; private set; }
protected abstract Func<bool> OnFeedbackFunc { get; }
public EssentialsRoomBase(string key, string name) : base(key, name)
{
OnFeedback = new BoolFeedback(OnFeedbackFunc);
}
}
}

View File

@@ -147,13 +147,7 @@ namespace PepperDash.Essentials
: base(parent.TriList)
{
Config = config;
Parent = parent;
//SelectASourceVisibleFeedback = new BoolFeedback(() =>
// CurrentRoom != null && !CurrentRoom.OnFeedback.BoolValue && this.IsVisible);
//SourcesDynamicList = new SmartObjectDynamicList(
// TriList.SmartObjects[UISmartObjectJoin.SourceList], true, 3200);
Parent = parent;
SourcesSrl = new SubpageReferenceList(TriList, 3200, 3, 3, 3);
ActivityFooterSrl = new SubpageReferenceList(TriList, 15022, 3, 3, 3);
@@ -242,12 +236,16 @@ namespace PepperDash.Essentials
base.Show();
}
/// <summary>
/// Handler for room on/off feedback
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void OnFeedback_OutputChange(object sender, EventArgs e)
{
if (CurrentRoom.OnFeedback.BoolValue)
{
TriList.BooleanInput[UIBoolJoin.VolumeSingleMute1Visible].BoolValue = true;
//TriList.BooleanInput[UIBoolJoin.StagingPageVisible].BoolValue = true;
}
else
{