mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-01-11 19:44:52 +00:00
fix: analog input check uese correct comparison
input selection coming from SIMPL is 1-based, not 0-based. Comparison to input port array length needs to be <= instead of <
This commit is contained in:
@@ -19,7 +19,7 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
/// Abstract base class for display devices that provides common display functionality
|
/// Abstract base class for display devices that provides common display functionality
|
||||||
/// including power control, input switching, and routing capabilities.
|
/// including power control, input switching, and routing capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class DisplayBase : EssentialsDevice, IDisplay, ICurrentSources
|
public abstract class DisplayBase : EssentialsDevice, IDisplay, ICurrentSources, IHasFeedback
|
||||||
{
|
{
|
||||||
private RoutingInputPort _currentInputPort;
|
private RoutingInputPort _currentInputPort;
|
||||||
|
|
||||||
@@ -73,13 +73,11 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
|
|
||||||
var handler = CurrentSourceChange;
|
var handler = CurrentSourceChange;
|
||||||
|
|
||||||
if (handler != null)
|
handler?.Invoke(_CurrentSourceInfo, ChangeType.WillChange);
|
||||||
handler(_CurrentSourceInfo, ChangeType.WillChange);
|
|
||||||
|
|
||||||
_CurrentSourceInfo = value;
|
_CurrentSourceInfo = value;
|
||||||
|
|
||||||
if (handler != null)
|
handler?.Invoke(_CurrentSourceInfo, ChangeType.DidChange);
|
||||||
handler(_CurrentSourceInfo, ChangeType.DidChange);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SourceListItem _CurrentSourceInfo;
|
SourceListItem _CurrentSourceInfo;
|
||||||
@@ -160,6 +158,9 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
IsCoolingDownFeedback = new BoolFeedback("IsCoolingDown", IsCoolingDownFeedbackFunc);
|
IsCoolingDownFeedback = new BoolFeedback("IsCoolingDown", IsCoolingDownFeedbackFunc);
|
||||||
IsWarmingUpFeedback = new BoolFeedback("IsWarmingUp", IsWarmingUpFeedbackFunc);
|
IsWarmingUpFeedback = new BoolFeedback("IsWarmingUp", IsWarmingUpFeedbackFunc);
|
||||||
|
|
||||||
|
Feedbacks.Add(IsCoolingDownFeedback);
|
||||||
|
Feedbacks.Add(IsWarmingUpFeedback);
|
||||||
|
|
||||||
InputPorts = new RoutingPortCollection<RoutingInputPort>();
|
InputPorts = new RoutingPortCollection<RoutingInputPort>();
|
||||||
|
|
||||||
CurrentSources = new Dictionary<eRoutingSignalType, SourceListItem>
|
CurrentSources = new Dictionary<eRoutingSignalType, SourceListItem>
|
||||||
@@ -194,17 +195,8 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
/// Gets the collection of feedback objects for this display device.
|
/// Gets the collection of feedback objects for this display device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual FeedbackCollection<Feedback> Feedbacks
|
public virtual FeedbackCollection<Feedback> Feedbacks { get; private set; } = new FeedbackCollection<Feedback>();
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return new FeedbackCollection<Feedback>
|
|
||||||
{
|
|
||||||
IsCoolingDownFeedback,
|
|
||||||
IsWarmingUpFeedback
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes a switch to the specified input on the display device. Must be implemented by derived classes.
|
/// Executes a switch to the specified input on the display device. Must be implemented by derived classes.
|
||||||
@@ -252,47 +244,35 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
/// <param name="joinMap">The join map configuration for the device.</param>
|
/// <param name="joinMap">The join map configuration for the device.</param>
|
||||||
protected void LinkDisplayToApi(DisplayBase displayDevice, BasicTriList trilist, DisplayControllerJoinMap joinMap)
|
protected void LinkDisplayToApi(DisplayBase displayDevice, BasicTriList trilist, DisplayControllerJoinMap joinMap)
|
||||||
{
|
{
|
||||||
Debug.LogMessage(LogEventLevel.Debug, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
|
this.LogDebug("Linking to Trilist {ipId}", trilist.ID.ToString("X"));
|
||||||
Debug.LogMessage(LogEventLevel.Information, "Linking to Display: {0}", displayDevice.Name);
|
this.LogDebug("Linking to Display: {displayName}", displayDevice.Name);
|
||||||
|
|
||||||
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = displayDevice.Name;
|
trilist.StringInput[joinMap.Name.JoinNumber].StringValue = displayDevice.Name;
|
||||||
|
|
||||||
var commMonitor = displayDevice as ICommunicationMonitor;
|
if (displayDevice is ICommunicationMonitor commMonitor)
|
||||||
if (commMonitor != null)
|
|
||||||
{
|
{
|
||||||
commMonitor.CommunicationMonitor.IsOnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
commMonitor.CommunicationMonitor.IsOnlineFeedback.LinkInputSig(trilist.BooleanInput[joinMap.IsOnline.JoinNumber]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: revisit this as there could be issues with this approach
|
||||||
var inputNumber = 0;
|
var inputNumber = 0;
|
||||||
var inputKeys = new List<string>();
|
var inputKeys = new List<string>();
|
||||||
|
|
||||||
var inputNumberFeedback = new IntFeedback(() => inputNumber);
|
var inputNumberFeedback = new IntFeedback("inputNumber", () => inputNumber);
|
||||||
|
|
||||||
// Two way feedbacks
|
// Add input number feedback to the device feedback collection to keep it around...
|
||||||
var twoWayDisplay = displayDevice as TwoWayDisplayBase;
|
Feedbacks.Add(inputNumberFeedback);
|
||||||
|
|
||||||
if (twoWayDisplay != null)
|
// Two way feedbacks
|
||||||
|
if (displayDevice is TwoWayDisplayBase twoWayDisplay)
|
||||||
{
|
{
|
||||||
trilist.SetBool(joinMap.IsTwoWayDisplay.JoinNumber, true);
|
trilist.SetBool(joinMap.IsTwoWayDisplay.JoinNumber, true);
|
||||||
|
|
||||||
twoWayDisplay.CurrentInputFeedback.OutputChange += (o, a) => Debug.LogMessage(LogEventLevel.Information, "CurrentInputFeedback_OutputChange {0}", a.StringValue);
|
twoWayDisplay.CurrentInputFeedback.OutputChange += (o, a) => this.LogDebug("CurrentInputFeedback_OutputChange {input}", a.StringValue);
|
||||||
|
|
||||||
|
|
||||||
inputNumberFeedback.LinkInputSig(trilist.UShortInput[joinMap.InputSelect.JoinNumber]);
|
inputNumberFeedback.LinkInputSig(trilist.UShortInput[joinMap.InputSelect.JoinNumber]);
|
||||||
}
|
|
||||||
|
|
||||||
// Power Off
|
twoWayDisplay.PowerIsOnFeedback.OutputChange += (o, a) =>
|
||||||
trilist.SetSigTrueAction(joinMap.PowerOff.JoinNumber, () =>
|
|
||||||
{
|
|
||||||
inputNumber = 102;
|
|
||||||
inputNumberFeedback.FireUpdate();
|
|
||||||
displayDevice.PowerOff();
|
|
||||||
});
|
|
||||||
|
|
||||||
var twoWayDisplayDevice = displayDevice as TwoWayDisplayBase;
|
|
||||||
if (twoWayDisplayDevice != null)
|
|
||||||
{
|
|
||||||
twoWayDisplayDevice.PowerIsOnFeedback.OutputChange += (o, a) =>
|
|
||||||
{
|
{
|
||||||
if (!a.BoolValue)
|
if (!a.BoolValue)
|
||||||
{
|
{
|
||||||
@@ -307,10 +287,18 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
twoWayDisplayDevice.PowerIsOnFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PowerOff.JoinNumber]);
|
twoWayDisplay.PowerIsOnFeedback.LinkComplementInputSig(trilist.BooleanInput[joinMap.PowerOff.JoinNumber]);
|
||||||
twoWayDisplayDevice.PowerIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PowerOn.JoinNumber]);
|
twoWayDisplay.PowerIsOnFeedback.LinkInputSig(trilist.BooleanInput[joinMap.PowerOn.JoinNumber]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Power Off
|
||||||
|
trilist.SetSigTrueAction(joinMap.PowerOff.JoinNumber, () =>
|
||||||
|
{
|
||||||
|
inputNumber = 102;
|
||||||
|
inputNumberFeedback.FireUpdate();
|
||||||
|
displayDevice.PowerOff();
|
||||||
|
});
|
||||||
|
|
||||||
// PowerOn
|
// PowerOn
|
||||||
trilist.SetSigTrueAction(joinMap.PowerOn.JoinNumber, () =>
|
trilist.SetSigTrueAction(joinMap.PowerOn.JoinNumber, () =>
|
||||||
{
|
{
|
||||||
@@ -320,44 +308,61 @@ namespace PepperDash.Essentials.Devices.Common.Displays
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < displayDevice.InputPorts.Count; i++)
|
for (int i = 0; i < displayDevice.InputPorts.Count; i++)
|
||||||
{
|
{
|
||||||
if (i < joinMap.InputNamesOffset.JoinSpan)
|
var localindex = i;
|
||||||
|
if (localindex >= joinMap.InputNamesOffset.JoinSpan)
|
||||||
{
|
{
|
||||||
inputKeys.Add(displayDevice.InputPorts[i].Key);
|
this.LogWarning("Device has {inputCount} inputs. The Join Map allows up to {joinSpan} inputs. Discarding inputs {discardStart} - {discardEnd} from bridge.",
|
||||||
var tempKey = inputKeys.ElementAt(i);
|
displayDevice.InputPorts.Count, joinMap.InputNamesOffset.JoinSpan, localindex + 1, displayDevice.InputPorts.Count);
|
||||||
trilist.SetSigTrueAction((ushort)(joinMap.InputSelectOffset.JoinNumber + i),
|
|
||||||
() => displayDevice.ExecuteSwitch(displayDevice.InputPorts[tempKey].Selector));
|
continue;
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, displayDevice, "Setting Input Select Action on Digital Join {0} to Input: {1}",
|
|
||||||
joinMap.InputSelectOffset.JoinNumber + i, displayDevice.InputPorts[tempKey].Key.ToString());
|
|
||||||
trilist.StringInput[(ushort)(joinMap.InputNamesOffset.JoinNumber + i)].StringValue = displayDevice.InputPorts[i].Key.ToString();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Debug.LogMessage(LogEventLevel.Information, displayDevice, "Device has {0} inputs. The Join Map allows up to {1} inputs. Discarding inputs {2} - {3} from bridge.",
|
{
|
||||||
displayDevice.InputPorts.Count, joinMap.InputNamesOffset.JoinSpan, i + 1, displayDevice.InputPorts.Count);
|
inputKeys.Add(displayDevice.InputPorts[localindex].Key);
|
||||||
|
|
||||||
|
var tempKey = inputKeys.ElementAt(localindex);
|
||||||
|
|
||||||
|
trilist.SetSigTrueAction((ushort)(joinMap.InputSelectOffset.JoinNumber + localindex), () => displayDevice.ExecuteSwitch(displayDevice.InputPorts[tempKey].Selector));
|
||||||
|
|
||||||
|
this.LogDebug("Setting Input Select Action on Digital Join {joinNumber} to Input: {input}", joinMap.InputSelectOffset.JoinNumber + localindex, displayDevice.InputPorts[tempKey].Key);
|
||||||
|
|
||||||
|
trilist.SetString((uint)(joinMap.InputNamesOffset.JoinNumber + localindex), displayDevice.InputPorts[localindex].Key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.LogMessage(LogEventLevel.Verbose, displayDevice, "Setting Input Select Action on Analog Join {0}", joinMap.InputSelect);
|
this.LogDebug("Setting Input Select Action on Analog Join {inputSelectJoin}", joinMap.InputSelect);
|
||||||
trilist.SetUShortSigAction(joinMap.InputSelect.JoinNumber, (a) =>
|
|
||||||
|
trilist.SetUShortSigAction(joinMap.InputSelect.JoinNumber, (requestedInput) =>
|
||||||
{
|
{
|
||||||
if (a == 0)
|
if (requestedInput == 0)
|
||||||
{
|
{
|
||||||
displayDevice.PowerOff();
|
displayDevice.PowerOff();
|
||||||
inputNumber = 0;
|
inputNumber = 0;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (a > 0 && a < displayDevice.InputPorts.Count && a != inputNumber)
|
|
||||||
|
// using 1-based indexing for inputs coming from SIMPL, so need to check if the input is <= the count, not <
|
||||||
|
if (requestedInput > 0 && requestedInput <= displayDevice.InputPorts.Count && requestedInput != inputNumber)
|
||||||
{
|
{
|
||||||
displayDevice.ExecuteSwitch(displayDevice.InputPorts.ElementAt(a - 1).Selector);
|
displayDevice.ExecuteSwitch(displayDevice.InputPorts.ElementAt(requestedInput - 1).Selector);
|
||||||
inputNumber = a;
|
|
||||||
|
inputNumber = requestedInput;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else if (a == 102)
|
|
||||||
|
if (requestedInput == 102)
|
||||||
{
|
{
|
||||||
displayDevice.PowerToggle();
|
displayDevice.PowerToggle();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (displayDevice is TwoWayDisplayBase)
|
||||||
|
{
|
||||||
|
inputNumberFeedback?.FireUpdate();
|
||||||
}
|
}
|
||||||
if (twoWayDisplay != null)
|
|
||||||
inputNumberFeedback.FireUpdate();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user