Skip to content

Commit

Permalink
updates to move to new plugin mechanism
Browse files Browse the repository at this point in the history
and new joinMap mechanism
  • Loading branch information
andrew-welker committed Jun 23, 2020
1 parent 54fb41c commit 7230679
Show file tree
Hide file tree
Showing 20 changed files with 3,794 additions and 111 deletions.
7 changes: 3 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[submodule "submodules"]
path = submodules
url=https://github.com/PepperDash-Engineering/essentials-builds.git
branch = release
[submodule "submodule/essentials-builds"]
path = submodule/essentials-builds
url = https://github.com/PepperDash-Engineering/essentials-builds
13 changes: 0 additions & 13 deletions nuget.config

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.Reflection;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core;

namespace pepperdash_generic_colorlightZ6_epi.Bridge
namespace PepperDash.Essentials.Generic.ColorlightZ6.Bridge
{
public class ColorlightZ6JoinMap:JoinMapBase
public class ColorlightZ6JoinMap : JoinMapBaseAdvanced
{
public uint Brightness { get; set; }
public uint Preset { get; set; }
public uint ShowOn { get; set; }
public uint ShowOff { get; set; }
[JoinName("brightness")] public JoinDataComplete Brightness =
new JoinDataComplete(new JoinData {JoinNumber = 1, JoinSpan = 1},
new JoinMetadata
{
Label = "Brightness control",
JoinCapabilities = eJoinCapabilities.FromSIMPL,
JoinType = eJoinType.Analog
});

public ColorlightZ6JoinMap()
{
Brightness = 1;
Preset = 2;
ShowOn = 1;
ShowOff = 2;
}
[JoinName("preset")] public JoinDataComplete Preset =
new JoinDataComplete(new JoinData {JoinNumber = 2, JoinSpan = 1},
new JoinMetadata
{
Label = "Preset Recall",
JoinCapabilities = eJoinCapabilities.FromSIMPL,
JoinType = eJoinType.Analog
});

public override void OffsetJoinNumbers(uint joinStart)
{
var joinOffset = joinStart - 1;
[JoinName("showOn")] public JoinDataComplete ShowOn =
new JoinDataComplete(new JoinData {JoinNumber = 1, JoinSpan = 1},
new JoinMetadata
{
Label = "Show On",
JoinCapabilities = eJoinCapabilities.FromSIMPL,
JoinType = eJoinType.Digital
});

Brightness = Brightness + joinOffset;
Preset = Preset + joinOffset;
ShowOn = ShowOn + joinOffset;
ShowOff = ShowOff + joinOffset;
[JoinName("showOff")] public JoinDataComplete ShowOff =
new JoinDataComplete(new JoinData {JoinNumber = 1, JoinSpan = 1},
new JoinMetadata
{
Label = "Show Off",
JoinCapabilities = eJoinCapabilities.FromSIMPL,
JoinType = eJoinType.Digital
});

public ColorlightZ6JoinMap(uint joinStart) : base(joinStart, typeof (ColorlightZ6JoinMap))
{
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,28 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using Crestron.SimplSharp; // For Basic SIMPL# Classes
using Crestron.SimplSharpPro; // For Basic SIMPL#Pro classes
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.CrestronThread;
using Crestron.SimplSharpPro.DeviceSupport;
using Newtonsoft.Json;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials;
using PepperDash.Essentials.Bridges;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;
using pepperdash_generic_colorlightZ6_epi;
using pepperdash_generic_colorlightZ6_epi.Bridge;

namespace Pepperdash.Essentials.ColorlightZ6
using PepperDash.Essentials.Core.Bridges;
using PepperDash.Essentials.Generic.ColorlightZ6;
using PepperDash.Essentials.Generic.ColorlightZ6.Bridge;

namespace Pepperdash.Essentials.Generic.ColorlightZ6
{
public class ColorlightZ6Controller:ReconfigurableDevice, IBridge
public class ColorlightZ6Controller:EssentialsBridgeableDevice
{
private Thread _queueProcess;
private readonly CrestronQueue<byte[]> _myQueue = new CrestronQueue<byte[]>(100);
private CTimer _heartbeatTimer;
private const long HeartbeatTime = 1000;
private readonly ushort _id;

private readonly ColorlightZ6JoinMap _joinMap = new ColorlightZ6JoinMap();

public IBasicCommunication Communications { get; private set; }

public static void LoadPlugin()
{
Debug.Console(0, "Loading Colorlight Z6 plugin...");
PepperDash.Essentials.Core.DeviceFactory.AddFactoryForType("colorlightz6", BuildDevice);
}

public static ColorlightZ6Controller BuildDevice(DeviceConfig dc)
{
Debug.Console(0, "Creating Colorlight Z6 controller...");
var comm = CommFactory.CreateCommForDevice(dc);
var device = new ColorlightZ6Controller(comm, dc);

return device;
}

public ColorlightZ6Controller(IBasicCommunication comm, DeviceConfig dc):base(dc)
public ColorlightZ6Controller(string key, string name, IBasicCommunication comm, ColorlightZ6Properties config):base(key, name)
{

Communications = comm;

var socket = Communications as ISocketStatus;
Expand All @@ -56,16 +34,31 @@ public ColorlightZ6Controller(IBasicCommunication comm, DeviceConfig dc):base(dc

Communications.BytesReceived += CommunicationsOnBytesReceived;

var props = JsonConvert.DeserializeObject<ColorlightZ6Properties>(dc.Properties.ToString());

_id = props.Id;
_id = config.Id;

Debug.Console(0,this, "Creating Colorlight Z6 controller with id {0}", _id);
}

private void CommunicationsOnBytesReceived(object sender, GenericCommMethodReceiveBytesArgs genericCommMethodReceiveBytesArgs)
{
Debug.Console(0,this,"Device Response: {0}", BitConverter.ToString(genericCommMethodReceiveBytesArgs.Bytes));
Debug.Console(0,this,"Device Response: {0}", BitConverter.ToString(genericCommMethodReceiveBytesArgs.Bytes));

_myQueue.Enqueue(genericCommMethodReceiveBytesArgs.Bytes);

if (_queueProcess == null || _queueProcess.ThreadState == Thread.eThreadStates.ThreadFinished) return;

_queueProcess = new Thread(ProcessQueue, null);
}

private object ProcessQueue(object obj)
{
while (!_myQueue.IsEmpty)
{
var myResponse = _myQueue.Dequeue();

Debug.Console(2, this, "response: {0}", myResponse);
}
return null;
}

public override bool CustomActivate()
Expand Down Expand Up @@ -97,23 +90,38 @@ private void SendHeartbeat(object o)
Communications.SendBytes(new byte[]{0x99, 0x99, 0x04, 0x00});
}

public void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey)
public override void LinkToApi(BasicTriList trilist, uint joinStart, string joinMapKey, EiscApiAdvanced bridge)
{
Debug.Console(0, this, "Connecting to SIMPL Bridge with joinStart {0}", joinStart);

_joinMap.OffsetJoinNumbers(joinStart);
var joinMap = new ColorlightZ6JoinMap(joinStart);

Debug.Console(0, this, "Mapping SetBrightness to join {0}", _joinMap.Brightness);
trilist.SetUShortSigAction(_joinMap.Brightness, SetBrightness);
if (bridge != null)
{
bridge.AddJoinMap(Key, joinMap);
}

Debug.Console(0, this, "Mapping RecallPreset to join {0}", _joinMap.Preset);
trilist.SetUShortSigAction(_joinMap.Preset, RecallPreset);
var customJoins = JoinMapHelper.TryGetJoinMapAdvancedForDevice(joinMapKey);

Debug.Console(0, this, "Mapping SetShowOn to join {0}", _joinMap.ShowOn);
trilist.SetBoolSigAction(_joinMap.ShowOn, SetShowOn);
if (customJoins != null)
{
joinMap.SetCustomJoinData(customJoins);
}

Debug.Console(1, "Linking to Trilist '{0}'", trilist.ID.ToString("X"));
Debug.Console(0, "Linking to Bridge Type {0}", GetType().Name);


trilist.SetUShortSigAction(joinMap.Brightness.JoinNumber, SetBrightness);


trilist.SetUShortSigAction(joinMap.Preset.JoinNumber, RecallPreset);


trilist.SetBoolSigAction(joinMap.ShowOn.JoinNumber, SetShowOn);

Debug.Console(0, this, "Mapping SetShowOff to join {0}", _joinMap.ShowOff);
trilist.SetBoolSigAction(_joinMap.ShowOff, SetShowOff);

trilist.SetBoolSigAction(joinMap.ShowOff.JoinNumber, SetShowOff);
}

public void SetBrightness(ushort brightness)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Core;

namespace pepperdash_generic_colorlightZ6_epi
namespace PepperDash.Essentials.Generic.ColorlightZ6
{
public class ColorlightZ6Properties
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using PepperDash.Core;
using Pepperdash.Essentials.Generic.ColorlightZ6;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;

namespace PepperDash.Essentials.Generic.ColorlightZ6
{
public class PluginFactory: EssentialsPluginDeviceFactory<ColorlightZ6Controller>
{
public PluginFactory()
{
MinimumEssentialsFrameworkVersion = "1.5.5";

TypeNames = new List<string>{"colorlightz6"};
}

#region Overrides of EssentialsDeviceFactory<ColorlightZ6Controller>

public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
Debug.Console(0, "Creating Colorlight Z6 controller...");
var comm = CommFactory.CreateCommForDevice(dc);

var config = dc.Properties.ToObject<ColorlightZ6Properties>();

var device = new ColorlightZ6Controller(dc.Key, dc.Name, comm, config);

return device;
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,13 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="PepperDashEssentials, Version=1.4.32.38764, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="PepperDash_Core, Version=1.0.35.25073, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\submodules\PepperDashEssentials.dll</HintPath>
<HintPath>..\..\submodule\essentials-builds\PepperDash_Core.dll</HintPath>
</Reference>
<Reference Include="PepperDash_Core, Version=1.0.31.23583, Culture=neutral, processorArchitecture=MSIL">
<Reference Include="PepperDash_Essentials_Core, Version=1.5.5.26566, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\submodules\PepperDash_Core.dll</HintPath>
</Reference>
<Reference Include="PepperDash_Essentials_Core, Version=1.4.32.38755, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\submodules\PepperDash_Essentials_Core.dll</HintPath>
</Reference>
<Reference Include="PepperDash_Essentials_DM, Version=1.3.7348.38761, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\submodules\PepperDash_Essentials_DM.dll</HintPath>
<HintPath>..\..\submodule\essentials-builds\PepperDash_Essentials_Core.dll</HintPath>
</Reference>
<Reference Include="SimplSharpCustomAttributesInterface, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -94,6 +86,7 @@
<Compile Include="Bridge\ColorlightZ6JoinMap.cs" />
<Compile Include="ColorlightZ6Controller.cs" />
<Compile Include="ColorlightZ6Properties.cs" />
<Compile Include="PluginFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<None Include="Properties\ControlSystem.cfg" />
</ItemGroup>
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions submodule/essentials-builds
Submodule essentials-builds added at 39b4d0
1 change: 0 additions & 1 deletion submodules
Submodule submodules deleted from 2f4769
Binary file added submodules/Essentials Devices Common.cplz
Binary file not shown.
Binary file added submodules/Essentials Devices Common.dll
Binary file not shown.
Binary file added submodules/Essentials_DM.cplz
Binary file not shown.
Binary file added submodules/PepperDashEssentials.cpz
Binary file not shown.
Binary file added submodules/PepperDashEssentials.dll
Binary file not shown.
Binary file added submodules/PepperDash_Core.clz
Binary file not shown.
Binary file added submodules/PepperDash_Core.dll
Binary file not shown.
Loading

0 comments on commit 7230679

Please sign in to comment.