Removes essentials-framework as a submodule and brings the files back into the main repo

This commit is contained in:
Neil Dorin
2019-07-09 17:21:53 -06:00
parent 2cd68d40dc
commit 48c6bb78bc
362 changed files with 54624 additions and 5 deletions

View File

@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.Lighting;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.CrestronIO;
namespace PepperDash.Essentials.Devices.Common.Environment.Lighting
{
public class Din8sw8Controller : Device, ISwitchedOutputCollection
{
// Need to figure out some sort of interface to make these switched outputs behave like processor relays so they can be used interchangably
public Din8Sw8 SwitchModule { get; private set; }
/// <summary>
/// Collection of generic switched outputs
/// </summary>
public Dictionary<uint, ISwitchedOutput> SwitchedOutputs { get; private set; }
public Din8sw8Controller(string key, uint cresnetId)
: base(key)
{
SwitchedOutputs = new Dictionary<uint, ISwitchedOutput>();
SwitchModule = new Din8Sw8(cresnetId, Global.ControlSystem);
if (SwitchModule.Register() != eDeviceRegistrationUnRegistrationResponse.Success)
{
Debug.Console(2, this, "Error registering Din8sw8. Reason: {0}", SwitchModule.RegistrationFailureReason);
}
PopulateDictionary();
}
public override bool CustomActivate()
{
return base.CustomActivate();
}
/// <summary>
/// Populates the generic collection with the loads from the Crestron collection
/// </summary>
void PopulateDictionary()
{
foreach (var item in SwitchModule.SwitchedLoads)
{
SwitchedOutputs.Add(item.Number, new Din8sw8Output(item));
}
}
}
/// <summary>
/// Wrapper class to
/// </summary>
public class Din8sw8Output : ISwitchedOutput
{
SwitchedLoadWithOverrideParameter SwitchedOutput;
public BoolFeedback OutputIsOnFeedback { get; protected set; }
public Din8sw8Output(SwitchedLoadWithOverrideParameter switchedOutput)
{
SwitchedOutput = switchedOutput;
OutputIsOnFeedback = new BoolFeedback(new Func<bool>(() => SwitchedOutput.IsOn));
}
public void On()
{
SwitchedOutput.FullOn();
}
public void Off()
{
SwitchedOutput.FullOff();
}
}
}

View File

@@ -0,0 +1,256 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Lighting;
namespace PepperDash.Essentials.Devices.Common.Environment.Lutron
{
public class LutronQuantumArea : LightingBase, ILightingMasterRaiseLower, ICommunicationMonitor
{
public IBasicCommunication Communication { get; private set; }
public CommunicationGather PortGather { get; private set; }
public StatusMonitorBase CommunicationMonitor { get; private set; }
CTimer SubscribeAfterLogin;
public string IntegrationId;
string Username;
string Password;
const string Delimiter = "\x0d\x0a";
const string Set = "#";
const string Get = "?";
public LutronQuantumArea(string key, string name, IBasicCommunication comm, LutronQuantumPropertiesConfig props)
: base(key, name)
{
Communication = comm;
IntegrationId = props.IntegrationId;
if (props.Control.Method != eControlMethod.Com)
{
Username = props.Control.TcpSshProperties.Username;
Password = props.Control.TcpSshProperties.Password;
}
LightingScenes = props.Scenes;
var socket = comm as ISocketStatus;
if (socket != null)
{
// IP Control
socket.ConnectionChange += new EventHandler<GenericSocketStatusChageEventArgs>(socket_ConnectionChange);
}
else
{
// RS-232 Control
}
Communication.TextReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(Communication_TextReceived);
PortGather = new CommunicationGather(Communication, Delimiter);
PortGather.LineReceived += new EventHandler<GenericCommMethodReceiveTextArgs>(PortGather_LineReceived);
if (props.CommunicationMonitorProperties != null)
{
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, props.CommunicationMonitorProperties);
}
else
{
CommunicationMonitor = new GenericCommunicationMonitor(this, Communication, 120000, 120000, 300000, "?ETHERNET,0\x0d\x0a");
}
}
public override bool CustomActivate()
{
Communication.Connect();
CommunicationMonitor.StatusChange += (o, a) => { Debug.Console(2, this, "Communication monitor state: {0}", CommunicationMonitor.Status); };
CommunicationMonitor.Start();
return true;
}
void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e)
{
Debug.Console(2, this, "Socket Status Change: {0}", e.Client.ClientStatus.ToString());
if (e.Client.IsConnected)
{
// Tasks on connect
}
}
/// <summary>
/// Checks for responses that do not contain the delimiter
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
void Communication_TextReceived(object sender, GenericCommMethodReceiveTextArgs args)
{
Debug.Console(2, this, "Text Received: '{0}'", args.Text);
if (args.Text.Contains("login:"))
{
// Login
SendLine(Username);
}
else if (args.Text.Contains("password:"))
{
// Login
SendLine(Password);
SubscribeAfterLogin = new CTimer(x => SubscribeToFeedback(), null, 5000);
}
else if (args.Text.Contains("Access Granted"))
{
if (SubscribeAfterLogin != null)
{
SubscribeAfterLogin.Stop();
}
SubscribeToFeedback();
}
}
/// <summary>
/// Handles all responses that contain the delimiter
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
void PortGather_LineReceived(object sender, GenericCommMethodReceiveTextArgs args)
{
Debug.Console(2, this, "Line Received: '{0}'", args.Text);
try
{
if (args.Text.Contains("~AREA"))
{
var response = args.Text.Split(',');
var integrationId = response[1];
if (integrationId != IntegrationId)
{
Debug.Console(2, this, "Response is not for correct Integration ID");
return;
}
else
{
var action = Int32.Parse(response[2]);
switch (action)
{
case (int)eAction.Scene:
{
var scene = response[3];
CurrentLightingScene = LightingScenes.FirstOrDefault(s => s.ID.Equals(scene));
OnLightingSceneChange();
break;
}
default:
break;
}
}
}
}
catch (Exception e)
{
Debug.Console(2, this, "Error parsing response:\n{0}", e);
}
}
/// <summary>
/// Subscribes to feedback
/// </summary>
public void SubscribeToFeedback()
{
Debug.Console(1, "Sending Monitoring Subscriptions");
SendLine("#MONITORING,6,1");
SendLine("#MONITORING,8,1");
SendLine("#MONITORING,5,2");
}
/// <summary>
/// Recalls the specified scene
/// </summary>
/// <param name="scene"></param>
///
public override void SelectScene(LightingScene scene)
{
Debug.Console(1, this, "Selecting Scene: '{0}'", scene.Name);
SendLine(string.Format("{0}AREA,{1},{2},{3}", Set, IntegrationId, (int)eAction.Scene, scene.ID));
}
/// <summary>
/// Begins raising the lights in the area
/// </summary>
public void MasterRaise()
{
SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Raise));
}
/// <summary>
/// Begins lowering the lights in the area
/// </summary>
public void MasterLower()
{
SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Lower));
}
/// <summary>
/// Stops the current raise/lower action
/// </summary>
public void MasterRaiseLowerStop()
{
SendLine(string.Format("{0}AREA,{1},{2}", Set, IntegrationId, (int)eAction.Stop));
}
/// <summary>
/// Appends the delimiter and sends the string
/// </summary>
/// <param name="s"></param>
public void SendLine(string s)
{
Debug.Console(2, this, "TX: '{0}'", s);
Communication.SendText(s + Delimiter);
}
}
public enum eAction : int
{
SetLevel = 1,
Raise = 2,
Lower = 3,
Stop = 4,
Scene = 6,
DaylightMode = 7,
OccupancyState = 8,
OccupancyMode = 9,
OccupiedLevelOrScene = 12,
UnoccupiedLevelOrScene = 13,
HyperionShaddowSensorOverrideState = 26,
HyperionBrightnessSensorOverrideStatue = 27
}
public class LutronQuantumPropertiesConfig
{
public CommunicationMonitorConfig CommunicationMonitorProperties { get; set; }
public ControlPropertiesConfig Control { get; set; }
public string IntegrationId { get; set; }
public List<LightingScene> Scenes { get; set; }
// Moved to use existing properties in Control object
// public string Username { get; set; }
// public string Password { get; set; }
}
}

View File

@@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.CrestronIO;
using PepperDash.Essentials.Core.Shades;
namespace PepperDash.Essentials.Devices.Common.Environment.Somfy
{
/// <summary>
/// Controls a single shade using three relays
/// </summary>
public class RelayControlledShade : ShadeBase, IShadesOpenCloseStop
{
RelayControlledShadeConfigProperties Config;
ISwitchedOutput OpenRelay;
ISwitchedOutput StopOrPresetRelay;
ISwitchedOutput CloseRelay;
int RelayPulseTime;
public string StopOrPresetButtonLabel { get; set; }
public RelayControlledShade(string key, string name, RelayControlledShadeConfigProperties config)
: base(key, name)
{
Config = config;
RelayPulseTime = Config.RelayPulseTime;
StopOrPresetButtonLabel = Config.StopOrPresetLabel;
}
public override bool CustomActivate()
{
//Create ISwitchedOutput objects based on props
OpenRelay = GetSwitchedOutputFromDevice(Config.Relays.Open);
StopOrPresetRelay = GetSwitchedOutputFromDevice(Config.Relays.StopOrPreset);
CloseRelay = GetSwitchedOutputFromDevice(Config.Relays.Close);
return base.CustomActivate();
}
public override void Open()
{
Debug.Console(1, this, "Opening Shade: '{0}'", this.Name);
PulseOutput(OpenRelay, RelayPulseTime);
}
public override void StopOrPreset()
{
Debug.Console(1, this, "Stopping or recalling preset on Shade: '{0}'", this.Name);
PulseOutput(StopOrPresetRelay, RelayPulseTime);
}
public override void Close()
{
Debug.Console(1, this, "Closing Shade: '{0}'", this.Name);
PulseOutput(CloseRelay, RelayPulseTime);
}
void PulseOutput(ISwitchedOutput output, int pulseTime)
{
output.On();
CTimer pulseTimer = new CTimer(new CTimerCallbackFunction((o) => output.Off()), pulseTime);
}
/// <summary>
/// Attempts to get the port on teh specified device from config
/// </summary>
/// <param name="relayConfig"></param>
/// <returns></returns>
ISwitchedOutput GetSwitchedOutputFromDevice(IOPortConfig relayConfig)
{
var portDevice = DeviceManager.GetDeviceForKey(relayConfig.PortDeviceKey);
if (portDevice != null)
{
return (portDevice as ISwitchedOutputCollection).SwitchedOutputs[relayConfig.PortNumber];
}
else
{
Debug.Console(1, this, "Error: Unable to get relay on port '{0}' from device with key '{1}'", relayConfig.PortNumber, relayConfig.PortDeviceKey);
return null;
}
}
}
public class RelayControlledShadeConfigProperties
{
public int RelayPulseTime { get; set; }
public ShadeRelaysConfig Relays { get; set; }
public string StopOrPresetLabel { get; set; }
public class ShadeRelaysConfig
{
public IOPortConfig Open { get; set; }
public IOPortConfig StopOrPreset { get; set; }
public IOPortConfig Close { get; set; }
}
}
}