mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-11 02:35:00 +00:00
cleaned out framework files; added framework submodule; referneced p.core to reference in framework; moved essentials.sln; changed paths in sln to match; test build
This commit is contained in:
@@ -0,0 +1,251 @@
|
||||
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.Config;
|
||||
using PepperDash.Essentials.Core.Shades;
|
||||
using PepperDash.Essentials.Core.Lighting;
|
||||
|
||||
namespace PepperDash.Essentials
|
||||
{
|
||||
public class EssentialsEnvironmentDriver : PanelDriverBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Do I need this here?
|
||||
/// </summary>
|
||||
CrestronTouchpanelPropertiesConfig Config;
|
||||
|
||||
/// <summary>
|
||||
/// The list of devices this driver is responsible for controlling
|
||||
/// </summary>
|
||||
public List<IKeyed> Devices { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The parent driver for this
|
||||
/// </summary>
|
||||
EssentialsPanelMainInterfaceDriver Parent;
|
||||
|
||||
/// <summary>
|
||||
/// The list of sub drivers for the devices
|
||||
/// </summary>
|
||||
public List<PanelDriverBase> DeviceSubDrivers { get; private set; }
|
||||
|
||||
public uint BackgroundSubpageJoin { get; private set; }
|
||||
|
||||
public EssentialsEnvironmentDriver(EssentialsPanelMainInterfaceDriver parent, CrestronTouchpanelPropertiesConfig config)
|
||||
: base(parent.TriList)
|
||||
{
|
||||
Config = config;
|
||||
Parent = parent;
|
||||
|
||||
Devices = new List<IKeyed>();
|
||||
DeviceSubDrivers = new List<PanelDriverBase>();
|
||||
|
||||
Parent.AvDriver.PopupInterlock.IsShownFeedback.OutputChange += IsShownFeedback_OutputChange;
|
||||
|
||||
// Calculate the join offests for each device page and assign join actions for each button
|
||||
}
|
||||
|
||||
void IsShownFeedback_OutputChange(object sender, EventArgs e)
|
||||
{
|
||||
// Hide this driver and all sub drivers if popup interlock is not shown
|
||||
if (Parent.AvDriver.PopupInterlock.IsShownFeedback.BoolValue == false)
|
||||
{
|
||||
foreach (var driver in DeviceSubDrivers)
|
||||
{
|
||||
driver.Hide();
|
||||
}
|
||||
|
||||
base.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows this driver and all sub drivers
|
||||
/// </summary>
|
||||
public override void Show()
|
||||
{
|
||||
Parent.AvDriver.PopupInterlock.ShowInterlockedWithToggle(BackgroundSubpageJoin);
|
||||
|
||||
foreach (var driver in DeviceSubDrivers)
|
||||
{
|
||||
driver.Show();
|
||||
}
|
||||
|
||||
base.Show();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides this driver and all sub drivers
|
||||
/// </summary>
|
||||
public override void Hide()
|
||||
{
|
||||
Parent.AvDriver.PopupInterlock.HideAndClear();
|
||||
|
||||
foreach (var driver in DeviceSubDrivers)
|
||||
{
|
||||
driver.Hide();
|
||||
}
|
||||
|
||||
base.Hide();
|
||||
}
|
||||
|
||||
public override void Toggle()
|
||||
{
|
||||
if (IsVisible)
|
||||
Hide();
|
||||
else
|
||||
Show();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Reads the device keys from the config and gets the devices by key
|
||||
/// </summary>
|
||||
public void GetDevicesFromConfig(Room.Config.EssentialsEnvironmentPropertiesConfig EnvironmentPropertiesConfig)
|
||||
{
|
||||
if (EnvironmentPropertiesConfig != null)
|
||||
{
|
||||
Devices.Clear();
|
||||
DeviceSubDrivers.Clear();
|
||||
|
||||
uint column = 1;
|
||||
|
||||
foreach (var dKey in EnvironmentPropertiesConfig.DeviceKeys)
|
||||
{
|
||||
var device = DeviceManager.GetDeviceForKey(dKey);
|
||||
|
||||
if (device != null)
|
||||
{
|
||||
// Build the driver
|
||||
var devicePanelDriver = GetPanelDriverForDevice(device, column);
|
||||
|
||||
// Add new PanelDriverBase SubDriver
|
||||
if (devicePanelDriver != null)
|
||||
{
|
||||
Devices.Add(device);
|
||||
DeviceSubDrivers.Add(devicePanelDriver);
|
||||
|
||||
Debug.Console(1, "Adding '{0}' to Environment Devices", device.Key);
|
||||
|
||||
column++;
|
||||
|
||||
|
||||
// Quit if device count is exceeded
|
||||
if (column > 4)
|
||||
break;
|
||||
}
|
||||
else
|
||||
Debug.Console(1, "Unable to build environment driver for device: '{0}'", device.Key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SetupEnvironmentUiJoins();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Console(1, "Unable to get devices from config. No EnvironmentPropertiesConfig object in room config");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the appropriate panel driver for the device
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="column"></param>
|
||||
/// <returns></returns>
|
||||
PanelDriverBase GetPanelDriverForDevice(IKeyed device, uint column)
|
||||
{
|
||||
PanelDriverBase panelDriver = null;
|
||||
|
||||
uint buttonPressJoinBase = 0;
|
||||
uint buttonVisibleJoinBase = 0;
|
||||
uint stringJoinBase = 0;
|
||||
uint shadeTypeVisibleBase = 0;
|
||||
uint lightingTypeVisibleBase = 0;
|
||||
|
||||
switch (column)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
buttonPressJoinBase = UIBoolJoin.EnvironmentColumnOneButtonPressBase;
|
||||
buttonVisibleJoinBase = UIBoolJoin.EnvironmentColumnOneButtonVisibleBase;
|
||||
stringJoinBase = UIStringJoin.EnvironmentColumnOneLabelBase;
|
||||
shadeTypeVisibleBase = UIBoolJoin.EnvironmentColumnOneShadingTypeVisibleBase;
|
||||
lightingTypeVisibleBase = UIBoolJoin.EnvironmentColumnOneLightingTypeVisibleBase;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
buttonPressJoinBase = UIBoolJoin.EnvironmentColumnTwoButtonPressBase;
|
||||
buttonVisibleJoinBase = UIBoolJoin.EnvironmentColumnTwoButtonVisibleBase;
|
||||
stringJoinBase = UIStringJoin.EnvironmentColumnTwoLabelBase;
|
||||
shadeTypeVisibleBase = UIBoolJoin.EnvironmentColumnTwoShadingTypeVisibleBase;
|
||||
lightingTypeVisibleBase = UIBoolJoin.EnvironmentColumnTwoLightingTypeVisibleBase;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
buttonPressJoinBase = UIBoolJoin.EnvironmentColumnThreeButtonPressBase;
|
||||
buttonVisibleJoinBase = UIBoolJoin.EnvironmentColumnThreeButtonVisibleBase;
|
||||
stringJoinBase = UIStringJoin.EnvironmentColumnThreeLabelBase;
|
||||
shadeTypeVisibleBase = UIBoolJoin.EnvironmentColumnThreeShadingTypeVisibleBase;
|
||||
lightingTypeVisibleBase = UIBoolJoin.EnvironmentColumnThreeLightingTypeVisibleBase;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
buttonPressJoinBase = UIBoolJoin.EnvironmentColumnFourButtonPressBase;
|
||||
buttonVisibleJoinBase = UIBoolJoin.EnvironmentColumnFourButtonVisibleBase;
|
||||
stringJoinBase = UIStringJoin.EnvironmentColumnFourLabelBase;
|
||||
shadeTypeVisibleBase = UIBoolJoin.EnvironmentColumnFourShadingTypeVisibleBase;
|
||||
lightingTypeVisibleBase = UIBoolJoin.EnvironmentColumnFourLightingTypeVisibleBase;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
Debug.Console(1, "Environment Driver: Invalid column number specified");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine if device is a shade or lighting type and construct the appropriate driver
|
||||
if (device is ShadeBase)
|
||||
{
|
||||
panelDriver = new EssentialsShadeDriver(this, device.Key, buttonPressJoinBase, stringJoinBase, shadeTypeVisibleBase);
|
||||
}
|
||||
else if (device is LightingBase)
|
||||
{
|
||||
panelDriver = new EssentialsLightingDriver(this, device.Key, buttonPressJoinBase, buttonVisibleJoinBase, stringJoinBase, lightingTypeVisibleBase);
|
||||
}
|
||||
|
||||
// Return the driver
|
||||
|
||||
return panelDriver;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines the join values for the generic environment subpages
|
||||
/// </summary>
|
||||
void SetupEnvironmentUiJoins()
|
||||
{
|
||||
// Calculate which background subpage join to use
|
||||
BackgroundSubpageJoin = UIBoolJoin.EnvironmentBackgroundSubpageVisibleBase + (uint)DeviceSubDrivers.Count;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface IEnvironmentSubdriver
|
||||
{
|
||||
uint SubpageVisibleJoin { get; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
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.Config;
|
||||
using PepperDash.Essentials.Core.Lighting;
|
||||
|
||||
namespace PepperDash.Essentials
|
||||
{
|
||||
/// <summary>
|
||||
/// Supports a lighting device with up to 6 scenes
|
||||
/// </summary>
|
||||
public class EssentialsLightingDriver : PanelDriverBase, IEnvironmentSubdriver
|
||||
{
|
||||
EssentialsEnvironmentDriver Parent;
|
||||
|
||||
public LightingBase LightingDevice { get; private set; }
|
||||
|
||||
public uint SubpageVisibleJoin { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The base join number that all button visibilty joins are offset from
|
||||
/// </summary>
|
||||
uint ButtonVisibleJoinBase;
|
||||
|
||||
/// <summary>
|
||||
/// The base join number that all button presses are offset from
|
||||
/// </summary>
|
||||
uint ButtonPressJoinBase;
|
||||
|
||||
/// <summary>
|
||||
/// The base join number that all string lables are offset from
|
||||
/// </summary>
|
||||
uint StringJoinBase;
|
||||
|
||||
eLightsDeviceType DeviceType;
|
||||
|
||||
const uint DeviceNameJoinOffset = 50;
|
||||
|
||||
public EssentialsLightingDriver(EssentialsEnvironmentDriver parent, string deviceKey, uint buttonPressJoinBase, uint buttonVisibleJoinBase, uint stringJoinBase, uint subpageVisibleBase)
|
||||
: base(parent.TriList)
|
||||
{
|
||||
Parent = parent;
|
||||
|
||||
ButtonPressJoinBase = buttonPressJoinBase;
|
||||
ButtonVisibleJoinBase = buttonVisibleJoinBase;
|
||||
StringJoinBase = stringJoinBase;
|
||||
|
||||
LightingDevice = DeviceManager.GetDeviceForKey(deviceKey) as LightingBase;
|
||||
|
||||
//LightingDevice.LightingSceneChange += new EventHandler<LightingSceneChangeEventArgs>(LightingDevice_LightingSceneChange);
|
||||
|
||||
SetDeviceType();
|
||||
|
||||
SetSubpageVisibleJoin(subpageVisibleBase);
|
||||
|
||||
SetUpDeviceName();
|
||||
|
||||
SetUpButtonActions();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles setting feedback for the currently selected scene button
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
void LightingDevice_LightingSceneChange(object sender, LightingSceneChangeEventArgs e)
|
||||
{
|
||||
uint joinOffset = 1;
|
||||
|
||||
foreach (var scene in LightingDevice.LightingScenes)
|
||||
{
|
||||
if (scene == e.CurrentLightingScene)
|
||||
TriList.SetBool(ButtonPressJoinBase + joinOffset, true);
|
||||
else
|
||||
TriList.SetBool(ButtonPressJoinBase + joinOffset, false);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
TriList.SetBool(SubpageVisibleJoin, true);
|
||||
|
||||
base.Show();
|
||||
}
|
||||
|
||||
public override void Hide()
|
||||
{
|
||||
TriList.SetBool(SubpageVisibleJoin, false);
|
||||
|
||||
base.Hide();
|
||||
}
|
||||
|
||||
void SetUpDeviceName()
|
||||
{
|
||||
Parent.TriList.SetString(StringJoinBase + DeviceNameJoinOffset, LightingDevice.Name);
|
||||
}
|
||||
|
||||
void SetDeviceType()
|
||||
{
|
||||
if (LightingDevice is ILightingScenes)
|
||||
DeviceType = eLightsDeviceType.Scenes;
|
||||
}
|
||||
|
||||
void SetSubpageVisibleJoin(uint subpageVisibleBase)
|
||||
{
|
||||
SubpageVisibleJoin = subpageVisibleBase + (uint)DeviceType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drase
|
||||
/// </summary>
|
||||
void SetUpButtonActions()
|
||||
{
|
||||
if (DeviceType == eLightsDeviceType.Scenes)
|
||||
{
|
||||
uint joinOffset = ComputeJoinOffset();
|
||||
|
||||
// Clear preceding buttons
|
||||
for (uint i = 1; i < joinOffset; i++)
|
||||
{
|
||||
TriList.SetString(StringJoinBase + i, "");
|
||||
TriList.SetSigFalseAction(ButtonPressJoinBase + i, () => { });
|
||||
TriList.SetBool(ButtonVisibleJoinBase + i, false);
|
||||
}
|
||||
|
||||
foreach (var scene in LightingDevice.LightingScenes)
|
||||
{
|
||||
TriList.SetString(StringJoinBase + joinOffset, scene.Name);
|
||||
var tempScene = scene;
|
||||
TriList.SetSigFalseAction(ButtonPressJoinBase + joinOffset, () => LightingDevice.SelectScene(tempScene));
|
||||
scene.IsActiveFeedback.LinkInputSig(TriList.BooleanInput[ButtonPressJoinBase + joinOffset]);
|
||||
TriList.SetBool(ButtonVisibleJoinBase + joinOffset, true);
|
||||
|
||||
joinOffset++;
|
||||
}
|
||||
|
||||
// Clear following buttons
|
||||
for (uint i = joinOffset; i <= 6; i++)
|
||||
{
|
||||
TriList.SetString(StringJoinBase + i, "");
|
||||
TriList.SetSigFalseAction(ButtonPressJoinBase + i, () => { });
|
||||
TriList.SetBool(ButtonVisibleJoinBase + i, false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Computes the desired join offset to try to achieve the most centered appearance when using a subpage with 6 scene buttons
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
uint ComputeJoinOffset()
|
||||
{
|
||||
uint joinOffset = 0;
|
||||
|
||||
switch (LightingDevice.LightingScenes.Count)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
joinOffset = 2;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
joinOffset = 3;
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
joinOffset = 2;
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
joinOffset = 2;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
joinOffset = 2;
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
joinOffset = 1;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return joinOffset;
|
||||
}
|
||||
}
|
||||
|
||||
enum eLightsDeviceType : uint
|
||||
{
|
||||
None = 0,
|
||||
Scenes = 1,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
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.Config;
|
||||
using PepperDash.Essentials.Core.Shades;
|
||||
using PepperDash.Essentials.Devices.Common.Environment.Somfy;
|
||||
|
||||
namespace PepperDash.Essentials
|
||||
{
|
||||
public class EssentialsShadeDriver : PanelDriverBase, IEnvironmentSubdriver
|
||||
{
|
||||
EssentialsEnvironmentDriver Parent;
|
||||
|
||||
public ShadeBase ShadeDevice { get; private set; }
|
||||
|
||||
public uint SubpageVisibleJoin { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The base join number that all button presses are offset from
|
||||
/// </summary>
|
||||
uint ButtonPressJoinBase;
|
||||
|
||||
/// <summary>
|
||||
/// The base join number that all string lables are offset from
|
||||
/// </summary>
|
||||
uint StringJoinBase;
|
||||
|
||||
eShadeDeviceType DeviceType;
|
||||
|
||||
const uint DeviceNameJoinOffset = 50;
|
||||
|
||||
public EssentialsShadeDriver(EssentialsEnvironmentDriver parent, string deviceKey, uint buttonPressJoinBase, uint stringJoinBase, uint subpageVisibleBase)
|
||||
: base(parent.TriList)
|
||||
{
|
||||
Parent = parent;
|
||||
|
||||
ButtonPressJoinBase = buttonPressJoinBase;
|
||||
StringJoinBase = stringJoinBase;
|
||||
|
||||
ShadeDevice = DeviceManager.GetDeviceForKey(deviceKey) as ShadeBase;
|
||||
|
||||
SetDeviceType();
|
||||
|
||||
SetSubpageVisibleJoin(subpageVisibleBase);
|
||||
|
||||
SetUpDeviceName();
|
||||
|
||||
SetUpButtonActions();
|
||||
}
|
||||
|
||||
public override void Show()
|
||||
{
|
||||
TriList.SetBool(SubpageVisibleJoin, true);
|
||||
|
||||
base.Show();
|
||||
}
|
||||
|
||||
public override void Hide()
|
||||
{
|
||||
TriList.SetBool(SubpageVisibleJoin, false);
|
||||
|
||||
base.Hide();
|
||||
}
|
||||
|
||||
void SetUpDeviceName()
|
||||
{
|
||||
Parent.TriList.SetString(StringJoinBase + DeviceNameJoinOffset, ShadeDevice.Name);
|
||||
}
|
||||
|
||||
void SetDeviceType()
|
||||
{
|
||||
if (ShadeDevice is IShadesOpenCloseStop)
|
||||
DeviceType = eShadeDeviceType.OpenCloseStop;
|
||||
else if (ShadeDevice is IShadesOpenClose)
|
||||
DeviceType = eShadeDeviceType.OpenClose;
|
||||
}
|
||||
|
||||
void SetSubpageVisibleJoin(uint subpageVisibleBase)
|
||||
{
|
||||
SubpageVisibleJoin = subpageVisibleBase + (uint)DeviceType;
|
||||
}
|
||||
|
||||
void SetUpButtonActions()
|
||||
{
|
||||
if(DeviceType == eShadeDeviceType.OpenClose)
|
||||
{
|
||||
TriList.SetSigTrueAction(ButtonPressJoinBase + 1, ShadeDevice.Open);
|
||||
|
||||
TriList.SetSigFalseAction(ButtonPressJoinBase + 2, ShadeDevice.Close);
|
||||
}
|
||||
else if(DeviceType == eShadeDeviceType.OpenCloseStop)
|
||||
{
|
||||
TriList.SetSigFalseAction(ButtonPressJoinBase + 1, ShadeDevice.Open);
|
||||
|
||||
TriList.SetSigFalseAction(ButtonPressJoinBase + 2, (ShadeDevice as IShadesOpenCloseStop).StopOrPreset);
|
||||
|
||||
if(ShadeDevice is RelayControlledShade)
|
||||
TriList.SetString(StringJoinBase + 2, (ShadeDevice as RelayControlledShade).StopOrPresetButtonLabel);
|
||||
|
||||
TriList.SetSigFalseAction(ButtonPressJoinBase + 3, ShadeDevice.Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum eShadeDeviceType : uint
|
||||
{
|
||||
None = 0,
|
||||
OpenCloseStop = 1,
|
||||
OpenClose = 2,
|
||||
DiscreteLevel = 3
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user