From a3561bc89b3077c6464357acceda21389311e20d Mon Sep 17 00:00:00 2001 From: jdevito Date: Sat, 7 Oct 2023 19:16:03 -0500 Subject: [PATCH] feat(wip): updates GenericIrController and IrOutputPortController to implement bridge map --- .../Devices/GenericIRController.cs | 76 ++++++++++++++++--- .../Devices/IrOutputPortController.cs | 9 +-- 2 files changed, 69 insertions(+), 16 deletions(-) diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs index 959b334b..b7a25d47 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/GenericIRController.cs @@ -19,15 +19,11 @@ namespace PepperDash.Essentials.Core.Devices private readonly IrOutputPortController _port; - public string[] IrCommands {get { return _port.IrFileCommands; }} - - public Dictionary BridgeJoins; + public string[] IrCommands {get { return _port.IrFileCommands; }} public GenericIrController(string key, string name, IrOutputPortController irPort) : base(key, name) { _port = irPort; - if(_port.UseBridgeJoinMap) BridgeJoins = new Dictionary(); - if (_port == null) { Debug.Console(0, this, Debug.ErrorLogLevel.Error, "IR Port is null, device will not function"); @@ -78,17 +74,75 @@ namespace PepperDash.Essentials.Core.Devices { Debug.Console(0, this, "Using new IR bridge join map"); - var joins = BridgeJoins.Where((kv) => _port.IrFileCommands.Any(cmd => cmd == kv.Key)).ToDictionary(kv => kv.Key, kv=> kv.Value); - foreach (var join in joins) - { - Debug.Console(0, this, "_useBridgeJoinMap: {0}: {1}", join.Key, join.Value); - } - //joinMap.Joins = joins.Select(kv => kv.Value.SetJoinOffset(joinStart)).ToString(); + var bridgeJoins = joinMap.Joins.Where((kv) => _port.IrFileCommands.Any(cmd => cmd == kv.Key)).ToDictionary(kv => kv.Key); + if (bridgeJoins == null) + { + Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Failed to link new IR bridge join map"); + return; + } + foreach (var bridgeJoin in bridgeJoins) + { + Debug.Console(0, this, @"bridgeJoin: Key-'{0}' +Value.Key-'{1}' +Value.JoinNumber-'{2}' +Value.Metadata.Description-'{3}'", + bridgeJoin.Key, + bridgeJoin.Value.Key, + bridgeJoin.Value.Value.JoinNumber, + bridgeJoin.Value.Value.Metadata.Description); + + var joinNumber = bridgeJoin.Value.Value.JoinNumber; + var joinCmd = bridgeJoin.Key; + + trilist.SetBoolSigAction(joinNumber, (b) => Press(joinCmd, b)); + } + + //foreach (var irFileCommand in _port.IrFileCommands) + //{ + // var cmd = irFileCommand; + // JoinDataComplete joinDataComplete; + // if (joinMap.Joins.TryGetValue(cmd, out joinDataComplete)) + // { + // Debug.Console(0, this, "joinDataComplete: attributeName-'{0}', joinNumber-'{1}', joinSpan-'{2}', metadata.description-'{3}'", + // joinDataComplete.AttributeName, joinDataComplete.JoinNumber, joinDataComplete.JoinSpan, joinDataComplete.Metadata.Description); + + // trilist.SetBoolSigAction(joinDataComplete.JoinNumber, (b) => Press(cmd, b)); + // } + // else + // { + // Debug.Console(0, this, "GenericIrController join map does not contain support for IR command '{0}', verify IR file.", cmd); + // } + + + + + // //if (joinMap.Joins.ContainsKey(cmd)) + // //{ + // // Debug.Console(0, this, "joinData: key-'{0}', joinNumber-'{1}', joinSpan-'{2}', description-'{3}'", + // // joinData.Key, joinData.Value.JoinNumber, joinData.Value.JoinSpan, joinData.Value.Metadata.Description); + // //} + + // //Debug.Console(0, this, "_port.IrFileCommand: {0}", irFileCommand); + // //var joinData = joinMap.Joins.FirstOrDefault(j => j.Key == cmd); + + // //if (joinData.Value == null) continue; + + // //joinData.Value.SetJoinOffset(joinStart); + + // //Debug.Console(0, this, "joinData: key-'{0}', joinNumber-'{1}', joinSpan-'{2}', description-'{3}'", + // // joinData.Key, joinData.Value.JoinNumber, joinData.Value.JoinSpan, joinData.Value.Metadata.Description); + + // //joinMap.Joins.Add(joinData.Key, joinData.Value); + + // //trilist.SetBoolSigAction(joinData.Value.JoinNumber, (b) => Press(joinData.Key, b)); + //} } else { Debug.Console(0, this, "Using legacy IR join mapping based on available IR commands"); + joinMap.Joins.Clear(); + for (uint i = 0; i < _port.IrFileCommands.Length; i++) { var cmd = _port.IrFileCommands[i]; diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs index 5ce7a779..a20f06aa 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Devices/IrOutputPortController.cs @@ -55,24 +55,23 @@ namespace PepperDash.Essentials.Core : base(key) { DriverLoaded = new BoolFeedback(() => DriverIsLoaded); + UseBridgeJoinMap = config.Properties["control"].Value("useBridgeJoinMap"); AddPostActivationAction(() => { - IrPort = postActivationFunc(config); + IrPort = postActivationFunc(config); if (IrPort == null) { Debug.Console(0, this, "WARNING No valid IR Port assigned to controller. IR will not function"); return; } - - UseBridgeJoinMap = config.Properties["control"]["useBridgeJoinMap"].Value(); var filePath = Global.FilePathPrefix + "ir" + Global.DirectorySeparator + config.Properties["control"]["irFile"].Value(); Debug.Console(1, "*************Attempting to load IR file: {0}***************", filePath); LoadDriver(filePath); - - PrintAvailableCommands(); + + if(!UseBridgeJoinMap) PrintAvailableCommands(); }); }