From 66cd39c0138b0d92b9030fd30b7b96c3b236a953 Mon Sep 17 00:00:00 2001 From: Andrew Welker Date: Wed, 16 Dec 2020 16:21:10 -0700 Subject: [PATCH] changed event names and added saved event --- .../Room/Types/EssentialsTechRoom.cs | 4 +-- .../Presets/DevicePresets.cs | 28 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/PepperDashEssentials/Room/Types/EssentialsTechRoom.cs b/PepperDashEssentials/Room/Types/EssentialsTechRoom.cs index acd44710..535cab22 100644 --- a/PepperDashEssentials/Room/Types/EssentialsTechRoom.cs +++ b/PepperDashEssentials/Room/Types/EssentialsTechRoom.cs @@ -36,7 +36,7 @@ namespace PepperDash.Essentials _tunerPresets.SetFileName(_config.PresetsFileName); - _tunerPresets.PresetChanged += TunerPresetsOnPresetChanged; + _tunerPresets.PresetRecalled += TunerPresetsOnPresetRecalled; _tuners = GetDevices(_config.Tuners); _displays = GetDevices(_config.Displays); @@ -78,7 +78,7 @@ namespace PepperDash.Essentials #endregion - private void TunerPresetsOnPresetChanged(ISetTopBoxNumericKeypad device, string channel) + private void TunerPresetsOnPresetRecalled(ISetTopBoxNumericKeypad device, string channel) { if (!_currentPresets.ContainsKey(device.Key)) { diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Presets/DevicePresets.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Presets/DevicePresets.cs index 6fb228a4..d2724d77 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Presets/DevicePresets.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Presets/DevicePresets.cs @@ -16,12 +16,14 @@ namespace PepperDash.Essentials.Core.Presets /// public class DevicePresetsModel : Device { - public delegate void PresetChangedCallback(ISetTopBoxNumericKeypad device, string channel); + public delegate void PresetRecalledCallback(ISetTopBoxNumericKeypad device, string channel); + + public delegate void PresetsSavedCallback(List presets); private readonly CCriticalSection _fileOps = new CCriticalSection(); private readonly bool _initSuccess; - private ISetTopBoxNumericKeypad _setTopBox; + private readonly ISetTopBoxNumericKeypad _setTopBox; /// /// The methods on the STB device to call when dialing @@ -83,7 +85,8 @@ namespace PepperDash.Essentials.Core.Presets _initSuccess = true; } - public event PresetChangedCallback PresetChanged; + public event PresetRecalledCallback PresetRecalled; + public event PresetsSavedCallback PresetsSaved; public int PulseTime { get; set; } public int DigitSpacingMs { get; set; } @@ -188,7 +191,7 @@ namespace PepperDash.Essentials.Core.Presets if (_setTopBox == null) return; - OnPresetChanged(_setTopBox, chanNum); + OnPresetRecalled(_setTopBox, chanNum); } public void Dial(int presetNum, ISetTopBoxNumericKeypad setTopBox) @@ -218,14 +221,14 @@ namespace PepperDash.Essentials.Core.Presets _enterFunction = setTopBox.KeypadEnter; - OnPresetChanged(setTopBox, chanNum); + OnPresetRecalled(setTopBox, chanNum); Dial(chanNum); } - private void OnPresetChanged(ISetTopBoxNumericKeypad setTopBox, string channel) + private void OnPresetRecalled(ISetTopBoxNumericKeypad setTopBox, string channel) { - var handler = PresetChanged; + var handler = PresetRecalled; if (handler == null) { @@ -265,6 +268,8 @@ namespace PepperDash.Essentials.Core.Presets { file.Write(json, Encoding.UTF8); } + + } finally { @@ -273,6 +278,15 @@ namespace PepperDash.Essentials.Core.Presets } + private void OnPresetsSaved() + { + var handler = PresetsSaved; + + if (handler == null) return; + + handler(PresetsList); + } + private void Pulse(Action act) { act(true);