Added logic to send presets to far end

This commit is contained in:
Andrew Welker
2020-12-08 16:24:22 -07:00
parent 56cf54a644
commit b09c151738
2 changed files with 30 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
using Crestron.SimplSharpPro.DeviceSupport; using Crestron.SimplSharpPro.DeviceSupport;
using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.SmartObjects; using PepperDash.Essentials.Core.SmartObjects;
@@ -8,7 +8,7 @@ namespace PepperDash.Essentials.Core
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public interface INumericKeypad public interface INumericKeypad:IKeyed
{ {
void Digit0(bool pressRelease); void Digit0(bool pressRelease);
void Digit1(bool pressRelease); void Digit1(bool pressRelease);

View File

@@ -7,6 +7,7 @@ using Newtonsoft.Json;
using PepperDash.Core; using PepperDash.Core;
//using SSMono.IO; //using SSMono.IO;
using PepperDash.Core.WebApi.Presets;
namespace PepperDash.Essentials.Core.Presets namespace PepperDash.Essentials.Core.Presets
{ {
@@ -15,9 +16,13 @@ namespace PepperDash.Essentials.Core.Presets
/// </summary> /// </summary>
public class DevicePresetsModel : Device public class DevicePresetsModel : Device
{ {
private CCriticalSection _fileOps = new CCriticalSection(); public delegate void PresetChangedCallback(ISetTopBoxNumericKeypad device, string channel);
private readonly CCriticalSection _fileOps = new CCriticalSection();
private readonly bool _initSuccess; private readonly bool _initSuccess;
private ISetTopBoxNumericKeypad _setTopBox;
/// <summary> /// <summary>
/// The methods on the STB device to call when dialing /// The methods on the STB device to call when dialing
/// </summary> /// </summary>
@@ -32,6 +37,8 @@ namespace PepperDash.Essentials.Core.Presets
{ {
try try
{ {
_setTopBox = setTopBox;
// Grab the digit functions from the device // Grab the digit functions from the device
// If any fail, the whole thing fails peacefully // If any fail, the whole thing fails peacefully
_dialFunctions = new Dictionary<char, Action<bool>>(10) _dialFunctions = new Dictionary<char, Action<bool>>(10)
@@ -76,6 +83,8 @@ namespace PepperDash.Essentials.Core.Presets
_initSuccess = true; _initSuccess = true;
} }
public event PresetChangedCallback PresetChanged;
public int PulseTime { get; set; } public int PulseTime { get; set; }
public int DigitSpacingMs { get; set; } public int DigitSpacingMs { get; set; }
public bool PresetsAreLoaded { get; private set; } public bool PresetsAreLoaded { get; private set; }
@@ -172,6 +181,10 @@ namespace PepperDash.Essentials.Core.Presets
} }
_dialIsRunning = false; _dialIsRunning = false;
}); });
if (_setTopBox == null) return;
OnPresetChanged(_setTopBox, chanNum);
} }
public void Dial(int presetNum, ISetTopBoxNumericKeypad setTopBox) public void Dial(int presetNum, ISetTopBoxNumericKeypad setTopBox)
@@ -201,9 +214,23 @@ namespace PepperDash.Essentials.Core.Presets
_enterFunction = setTopBox.KeypadEnter; _enterFunction = setTopBox.KeypadEnter;
OnPresetChanged(setTopBox, chanNum);
Dial(chanNum); Dial(chanNum);
} }
private void OnPresetChanged(ISetTopBoxNumericKeypad setTopBox, string channel)
{
var handler = PresetChanged;
if (handler == null)
{
return;
}
handler(setTopBox, channel);
}
public void UpdatePreset(int index, PresetChannel preset) public void UpdatePreset(int index, PresetChannel preset)
{ {
if (index >= PresetsList.Count) if (index >= PresetsList.Count)