getting started with EssentialsTechRoom

This commit is contained in:
Andrew Welker
2020-12-01 16:20:59 -07:00
parent f283f82bbc
commit 008a052045
4 changed files with 291 additions and 163 deletions

View File

@@ -22,30 +22,25 @@ namespace PepperDash.Essentials.Room.Config
public static Device GetRoomObject(DeviceConfig roomConfig) public static Device GetRoomObject(DeviceConfig roomConfig)
{ {
var typeName = roomConfig.Type.ToLower(); var typeName = roomConfig.Type.ToLower();
if (typeName == "huddle") if (typeName == "huddle")
{ {
var huddle = new EssentialsHuddleSpaceRoom(roomConfig); return new EssentialsHuddleSpaceRoom(roomConfig);
return huddle;
} }
else if (typeName == "huddlevtc1") if (typeName == "huddlevtc1")
{ {
var rm = new EssentialsHuddleVtc1Room(roomConfig); return new EssentialsHuddleVtc1Room(roomConfig);
return rm;
} }
else if (typeName == "ddvc01Bridge") if (typeName == "ddvc01Bridge")
{ {
return new Device(roomConfig.Key, roomConfig.Name); // placeholder device that does nothing. return new Device(roomConfig.Key, roomConfig.Name); // placeholder device that does nothing.
} }
else if (typeName == "dualdisplay") if (typeName == "dualdisplay")
{ {
var rm = new EssentialsDualDisplayRoom(roomConfig); return new EssentialsDualDisplayRoom(roomConfig);
return rm;
} }
return null; return typeName != "techRoom" ? null : new EssentialsTechRoom(roomConfig);
} }
/// <summary> /// <summary>

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
namespace PepperDash.Essentials.Room.Config
{
public class EssentialsTechRoomConfig
{
public List<string> Displays;
public List<string> Tuners;
public string ScheduleProviderKey;
public string UserPin;
public string TechPin;
public string PresetsFileName;
public EssentialsTechRoomConfig()
{
Displays = new List<string>();
Tuners = new List<string>();
}
}
}

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Presets;
using PepperDash.Essentials.Devices.Common;
using PepperDash.Essentials.Room.Config;
namespace PepperDash.Essentials
{
public class EssentialsTechRoom:EssentialsRoomBase
{
private Dictionary<string, IRSetTopBoxBase> _tuners;
private Dictionary<string, TwoWayDisplayBase> _displays;
private DevicePresetsModel _tunerPresets;
private readonly EssentialsTechRoomConfig _config;
public EssentialsTechRoom(DeviceConfig config) : base(config)
{
_config = config.Properties.ToObject<EssentialsTechRoomConfig>();
_tunerPresets = new DevicePresetsModel(String.Format("{0}-presets", config.Key), _config.PresetsFileName);
_tuners = GetDevices<IRSetTopBoxBase>(_config.Tuners);
_displays = GetDevices<TwoWayDisplayBase>(_config.Displays);
}
private Dictionary<string, T> GetDevices<T>(ICollection<string> config) where T:IKeyed
{
try
{
var returnValue = DeviceManager.AllDevices.OfType<T>()
.Where(d => config.Contains(d.Key))
.ToDictionary(d => d.Key, d => d);
return returnValue;
}
catch
{
Debug.Console(0, this, Debug.ErrorLogLevel.Error, "Error getting devices. Check Essentials Configuration");
return null;
}
}
#region Overrides of EssentialsRoomBase
protected override Func<bool> IsWarmingFeedbackFunc
{
get { throw new NotImplementedException(); }
}
protected override Func<bool> IsCoolingFeedbackFunc
{
get { throw new NotImplementedException(); }
}
protected override Func<bool> OnFeedbackFunc
{
get { throw new NotImplementedException(); }
}
protected override void EndShutdown()
{
throw new NotImplementedException();
}
public override void SetDefaultLevels()
{
throw new NotImplementedException();
}
public override void PowerOnToDefaultOrLastSource()
{
throw new NotImplementedException();
}
public override bool RunDefaultPresentRoute()
{
throw new NotImplementedException();
}
public override void RoomVacatedForTimeoutPeriod(object o)
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@@ -1,13 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO; using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PepperDash.Core; using PepperDash.Core;
//using SSMono.IO; //using SSMono.IO;
@@ -19,43 +15,25 @@ namespace PepperDash.Essentials.Core.Presets
/// </summary> /// </summary>
public class DevicePresetsModel : Device public class DevicePresetsModel : Device
{ {
public event EventHandler PresetsLoaded; private readonly bool _initSuccess;
public int PulseTime { get; set; }
public int DigitSpacingMS { get; set; }
public bool PresetsAreLoaded { get; private set; }
public List<PresetChannel> PresetsList { get { return _PresetsList.ToList(); } }
List<PresetChannel> _PresetsList;
public int Count { get { return PresetsList != null ? PresetsList.Count : 0; } }
public bool UseLocalImageStorage { get; set; }
public string ImagesLocalHostPrefix { get; set; }
public string ImagesPathPrefix { get; set; }
public string ListPathPrefix { get; set; }
/// <summary> /// <summary>
/// The methods on the STB device to call when dialing /// The methods on the STB device to call when dialing
/// </summary> /// </summary>
Dictionary<char, Action<bool>> DialFunctions; private Dictionary<char, Action<bool>> _dialFunctions;
Action<bool> EnterFunction;
bool DialIsRunning; private bool _dialIsRunning;
string FilePath; private Action<bool> _enterFunction;
bool InitSuccess; private string _filePath;
//SSMono.IO.FileSystemWatcher ListWatcher;
public DevicePresetsModel(string key, ISetTopBoxNumericKeypad setTopBox, string fileName) public DevicePresetsModel(string key, ISetTopBoxNumericKeypad setTopBox, string fileName)
: base(key) : this(key, fileName)
{ {
PulseTime = 150;
DigitSpacingMS = 150;
try try
{ {
// 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)
{ {
{'1', setTopBox.Digit1}, {'1', setTopBox.Digit1},
{'2', setTopBox.Digit2}, {'2', setTopBox.Digit2},
@@ -73,11 +51,17 @@ namespace PepperDash.Essentials.Core.Presets
catch catch
{ {
Debug.Console(0, "DevicePresets '{0}', not attached to INumericKeypad device. Ignoring", key); Debug.Console(0, "DevicePresets '{0}', not attached to INumericKeypad device. Ignoring", key);
DialFunctions = null; _dialFunctions = null;
return; return;
} }
EnterFunction = setTopBox.KeypadEnter; _enterFunction = setTopBox.KeypadEnter;
}
public DevicePresetsModel(string key, string fileName) : base(key)
{
PulseTime = 150;
DigitSpacingMs = 150;
UseLocalImageStorage = true; UseLocalImageStorage = true;
@@ -88,17 +72,30 @@ namespace PepperDash.Essentials.Core.Presets
SetFileName(fileName); SetFileName(fileName);
//ListWatcher = new FileSystemWatcher(@"\HTML\presets\lists"); _initSuccess = true;
//ListWatcher.NotifyFilter = NotifyFilters.LastWrite;
//ListWatcher.EnableRaisingEvents = true;
//ListWatcher.Changed += ListWatcher_Changed;
InitSuccess = true;
} }
public int PulseTime { get; set; }
public int DigitSpacingMs { get; set; }
public bool PresetsAreLoaded { get; private set; }
public List<PresetChannel> PresetsList { get; private set; }
public int Count
{
get { return PresetsList != null ? PresetsList.Count : 0; }
}
public bool UseLocalImageStorage { get; set; }
public string ImagesLocalHostPrefix { get; set; }
public string ImagesPathPrefix { get; set; }
public string ListPathPrefix { get; set; }
public event EventHandler PresetsLoaded;
public void SetFileName(string path) public void SetFileName(string path)
{ {
FilePath = ListPathPrefix + path; _filePath = ListPathPrefix + path;
LoadChannels(); LoadChannels();
} }
@@ -107,72 +104,94 @@ namespace PepperDash.Essentials.Core.Presets
PresetsAreLoaded = false; PresetsAreLoaded = false;
try try
{ {
var pl = JsonConvert.DeserializeObject<PresetsList>(Crestron.SimplSharp.CrestronIO.File.ReadToEnd(FilePath, Encoding.ASCII)); var pl = JsonConvert.DeserializeObject<PresetsList>(File.ReadToEnd(_filePath, Encoding.ASCII));
Name = pl.Name; Name = pl.Name;
_PresetsList = pl.Channels; PresetsList = pl.Channels;
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Console(2, this, "LoadChannels: Error reading presets file. These presets will be empty:\r '{0}'\r Error:{1}", FilePath, e.Message); Debug.Console(2, this,
"LoadChannels: Error reading presets file. These presets will be empty:\r '{0}'\r Error:{1}",
_filePath, e.Message);
// Just save a default empty list // Just save a default empty list
_PresetsList = new List<PresetChannel>(); PresetsList = new List<PresetChannel>();
} }
PresetsAreLoaded = true; PresetsAreLoaded = true;
var handler = PresetsLoaded; var handler = PresetsLoaded;
if (handler != null) if (handler != null)
{
handler(this, EventArgs.Empty); handler(this, EventArgs.Empty);
} }
}
public void Dial(int presetNum) public void Dial(int presetNum)
{ {
if (presetNum <= _PresetsList.Count) if (presetNum <= PresetsList.Count)
Dial(_PresetsList[presetNum - 1].Channel); {
Dial(PresetsList[presetNum - 1].Channel);
}
} }
public void Dial(string chanNum) public void Dial(string chanNum)
{ {
if (DialIsRunning || !InitSuccess) return; if (_dialIsRunning || !_initSuccess)
if (DialFunctions == null) {
return;
}
if (_dialFunctions == null)
{ {
Debug.Console(1, "DevicePresets '{0}', not attached to keypad device. Ignoring channel", Key); Debug.Console(1, "DevicePresets '{0}', not attached to keypad device. Ignoring channel", Key);
return; return;
} }
DialIsRunning = true; _dialIsRunning = true;
CrestronInvoke.BeginInvoke(o => CrestronInvoke.BeginInvoke(o =>
{ {
foreach (var c in chanNum.ToCharArray()) foreach (var c in chanNum.ToCharArray())
{ {
if (DialFunctions.ContainsKey(c)) if (_dialFunctions.ContainsKey(c))
Pulse(DialFunctions[c]); {
CrestronEnvironment.Sleep(DigitSpacingMS); Pulse(_dialFunctions[c]);
}
CrestronEnvironment.Sleep(DigitSpacingMs);
} }
if (EnterFunction != null) if (_enterFunction != null)
Pulse(EnterFunction); {
DialIsRunning = false; Pulse(_enterFunction);
}
_dialIsRunning = false;
}); });
} }
void Pulse(Action<bool> act) public void Dial(string chanNum, ISetTopBoxNumericKeypad setTopBox)
{
_dialFunctions = new Dictionary<char, Action<bool>>(10)
{
{'1', setTopBox.Digit1},
{'2', setTopBox.Digit2},
{'3', setTopBox.Digit3},
{'4', setTopBox.Digit4},
{'5', setTopBox.Digit5},
{'6', setTopBox.Digit6},
{'7', setTopBox.Digit7},
{'8', setTopBox.Digit8},
{'9', setTopBox.Digit9},
{'0', setTopBox.Digit0},
{'-', setTopBox.Dash}
};
_enterFunction = setTopBox.KeypadEnter;
Dial(chanNum);
}
private void Pulse(Action<bool> act)
{ {
act(true); act(true);
CrestronEnvironment.Sleep(PulseTime); CrestronEnvironment.Sleep(PulseTime);
act(false); act(false);
} }
/// <summary>
/// Event handler for filesystem watcher. When directory changes, this is called
/// </summary>
//void ListWatcher_Changed(object sender, FileSystemEventArgs e)
//{
// Debug.Console(1, this, "folder modified: {0}", e.FullPath);
// if (e.FullPath.Equals(FilePath, StringComparison.OrdinalIgnoreCase))
// {
// Debug.Console(1, this, "File changed: {0}", e.ChangeType);
// LoadChannels();
// }
//}
} }
} }