changed event names and added saved event

This commit is contained in:
Andrew Welker
2020-12-16 16:21:10 -07:00
parent 91eec8c258
commit 66cd39c013
2 changed files with 23 additions and 9 deletions

View File

@@ -36,7 +36,7 @@ namespace PepperDash.Essentials
_tunerPresets.SetFileName(_config.PresetsFileName); _tunerPresets.SetFileName(_config.PresetsFileName);
_tunerPresets.PresetChanged += TunerPresetsOnPresetChanged; _tunerPresets.PresetRecalled += TunerPresetsOnPresetRecalled;
_tuners = GetDevices<IRSetTopBoxBase>(_config.Tuners); _tuners = GetDevices<IRSetTopBoxBase>(_config.Tuners);
_displays = GetDevices<TwoWayDisplayBase>(_config.Displays); _displays = GetDevices<TwoWayDisplayBase>(_config.Displays);
@@ -78,7 +78,7 @@ namespace PepperDash.Essentials
#endregion #endregion
private void TunerPresetsOnPresetChanged(ISetTopBoxNumericKeypad device, string channel) private void TunerPresetsOnPresetRecalled(ISetTopBoxNumericKeypad device, string channel)
{ {
if (!_currentPresets.ContainsKey(device.Key)) if (!_currentPresets.ContainsKey(device.Key))
{ {

View File

@@ -16,12 +16,14 @@ namespace PepperDash.Essentials.Core.Presets
/// </summary> /// </summary>
public class DevicePresetsModel : Device 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<PresetChannel> presets);
private readonly CCriticalSection _fileOps = new CCriticalSection(); private readonly CCriticalSection _fileOps = new CCriticalSection();
private readonly bool _initSuccess; private readonly bool _initSuccess;
private ISetTopBoxNumericKeypad _setTopBox; private readonly ISetTopBoxNumericKeypad _setTopBox;
/// <summary> /// <summary>
/// The methods on the STB device to call when dialing /// The methods on the STB device to call when dialing
@@ -83,7 +85,8 @@ namespace PepperDash.Essentials.Core.Presets
_initSuccess = true; _initSuccess = true;
} }
public event PresetChangedCallback PresetChanged; public event PresetRecalledCallback PresetRecalled;
public event PresetsSavedCallback PresetsSaved;
public int PulseTime { get; set; } public int PulseTime { get; set; }
public int DigitSpacingMs { get; set; } public int DigitSpacingMs { get; set; }
@@ -188,7 +191,7 @@ namespace PepperDash.Essentials.Core.Presets
if (_setTopBox == null) return; if (_setTopBox == null) return;
OnPresetChanged(_setTopBox, chanNum); OnPresetRecalled(_setTopBox, chanNum);
} }
public void Dial(int presetNum, ISetTopBoxNumericKeypad setTopBox) public void Dial(int presetNum, ISetTopBoxNumericKeypad setTopBox)
@@ -218,14 +221,14 @@ namespace PepperDash.Essentials.Core.Presets
_enterFunction = setTopBox.KeypadEnter; _enterFunction = setTopBox.KeypadEnter;
OnPresetChanged(setTopBox, chanNum); OnPresetRecalled(setTopBox, chanNum);
Dial(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) if (handler == null)
{ {
@@ -265,6 +268,8 @@ namespace PepperDash.Essentials.Core.Presets
{ {
file.Write(json, Encoding.UTF8); file.Write(json, Encoding.UTF8);
} }
} }
finally 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<bool> act) private void Pulse(Action<bool> act)
{ {
act(true); act(true);