Skip to content

Commit

Permalink
intitial plugin creationg with base features
Browse files Browse the repository at this point in the history
- overall online status
- individual outlet naming, online, power
  • Loading branch information
ngenovese11 committed Nov 17, 2020
1 parent 92544e9 commit 601470a
Show file tree
Hide file tree
Showing 23 changed files with 833 additions and 108 deletions.
2 changes: 1 addition & 1 deletion ApcEpi.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApcEpi", "src/ApcEpi.csproj", "{9D249E47-8F95-4437-A6BB-563510287AD1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApcEpi", "src\ApcEpi.csproj", "{9D249E47-8F95-4437-A6BB-563510287AD1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
10 changes: 10 additions & 0 deletions src/Abstractions/IApDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using PepperDash.Core;
using PepperDash.Essentials.Core;

namespace ApcEpi.Abstractions
{
public interface IApDevice : IKeyName, IOnline, ICommunicationMonitor, IHasFeedback
{

}
}
20 changes: 20 additions & 0 deletions src/Abstractions/IApDeviceBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;

namespace ApcEpi.Abstractions
{
public interface IApDeviceBuilder : IKeyName
{
ICommunicationMonitor Monitor { get; }
IBasicCommunication Coms { get; }
ReadOnlyDictionary<uint, IApOutlet> Outlets { get; }
CTimer Poll { get; }

EssentialsDevice Build();
}
}
16 changes: 16 additions & 0 deletions src/Abstractions/IApOutlet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;

namespace ApcEpi.Abstractions
{
public interface IApOutlet : IKeyName, IOnline, IPower
{
int OutletIndex { get; }
StringFeedback NameFeedback { get; }
}
}
9 changes: 9 additions & 0 deletions src/Abstractions/IOutletName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using PepperDash.Essentials.Core;

namespace ApcEpi.Abstractions
{
public interface IOutletName : IApDevice
{
bool TryGetOutletNameFeedback(uint outletIndex, out StringFeedback result);
}
}
9 changes: 9 additions & 0 deletions src/Abstractions/IOutletOnline.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using PepperDash.Essentials.Core;

namespace ApcEpi.Abstractions
{
public interface IOutletOnline : IApDevice
{
bool TryGetOutletOnlineFeedback(uint outletIndex, out BoolFeedback result);
}
}
12 changes: 12 additions & 0 deletions src/Abstractions/IOutletPower.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using PepperDash.Essentials.Core;

namespace ApcEpi.Abstractions
{
public interface IOutletPower : IApDevice
{
bool TryGetOutletPowerFeedback(uint outletIndex, out BoolFeedback result);
void ToggleOutletPower(uint outletIndex);
void TurnOutletOff(uint outletIndex);
void TurnOutletOn(uint outletIndex);
}
}
25 changes: 19 additions & 6 deletions src/ApcEpi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
</Reference>
<Reference Include="SimplSharpNewtonsoft, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpNewtonsoft.dll</HintPath>
<HintPath>..\packages\PepperDashEssentials\lib\net35\SimplSharpNewtonsoft.dll</HintPath>
</Reference>
<Reference Include="SimplSharpPro, Version=1.5.3.17, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -88,18 +88,31 @@
</Reference>
<Reference Include="SimplSharpReflectionInterface, Version=1.0.5583.25238, Culture=neutral, PublicKeyToken=1099c178b3b54c3b, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpReflectionInterface.dll</HintPath>
<HintPath>..\..\..\..\..\ProgramData\Crestron\SDK\SimplSharpReflectionInterface.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
</ItemGroup>
<ItemGroup>
<Compile Include="EssentialsPluginBridgeJoinMapTemplate.cs" />
<Compile Include="EssentialsPluginDeviceTemplate.cs" />
<Compile Include="EssentialsPluginConfigObjectTemplate.cs" />
<Compile Include="EssentialsPluginFactoryTemplate.cs" />
<Compile Include="Abstractions\IApDeviceBuilder.cs" />
<Compile Include="Abstractions\IApOutlet.cs" />
<Compile Include="Abstractions\IOutletName.cs" />
<Compile Include="Abstractions\IOutletOnline.cs" />
<Compile Include="Abstractions\IOutletPower.cs" />
<Compile Include="Builders\Ap89XxBuilder.cs" />
<Compile Include="Config\ApDeviceConfig.cs" />
<Compile Include="Devices\ApDevice.cs" />
<Compile Include="Abstractions\IApDevice.cs" />
<Compile Include="Entities\Outlet\ApOutlet.cs" />
<Compile Include="Entities\Outlet\ApOutletOnline.cs" />
<Compile Include="Services\NameCommands\ApOutletName.cs" />
<Compile Include="Entities\Outlet\ApOutletPower.cs" />
<Compile Include="JoinMaps\ApDeviceJoinMap.cs" />
<Compile Include="Factories\Ap89XxFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\PowerCommands\ApOutletPowerCommands.cs" />
<Compile Include="Services\StatusCommands\ApOutletStatusCommands.cs" />
<None Include="Properties\ControlSystem.cfg" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
Expand Down
63 changes: 63 additions & 0 deletions src/Builders/Ap89XxBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Linq;
using ApcEpi.Abstractions;
using ApcEpi.Config;
using ApcEpi.Devices;
using ApcEpi.Entities.Outlet;
using Crestron.SimplSharp;
using PepperDash.Core;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Core.Devices;

namespace ApcEpi.Builders
{
public class Ap89XxBuilder : IApDeviceBuilder
{
public static IApDeviceBuilder GetFromDeviceConfig(DeviceConfig dc)
{
var config = dc.Properties.ToObject<ApDeviceConfig>();
var coms = CommFactory.CreateCommForDevice(dc);

return new Ap89XxBuilder(dc.Key, dc.Name, coms, config);
}

private Ap89XxBuilder(string key, string name, IBasicCommunication coms, ApDeviceConfig config)
{
Coms = coms;
Name = name;
Key = key;
Outlets = BuildOutletsFromConfig(config, coms);
Monitor = new GenericCommunicationMonitoredDevice(
Key,
Name,
Coms,
"about\r");

Poll = new CTimer(_ => ApDevice.PollDevice(coms), null, Timeout.Infinite, 5000);
}

public static ReadOnlyDictionary<uint, IApOutlet> BuildOutletsFromConfig(ApDeviceConfig config, IBasicCommunication coms)
{
var outlets = config
.Outlets
.Select(x => new ApOutlet(x.Key, x.Value.Name, x.Value.OutletIndex, coms))
.ToDictionary<ApOutlet, uint, IApOutlet>(outlet => (uint) outlet.OutletIndex, outlet => outlet);

return new ReadOnlyDictionary<uint, IApOutlet>(outlets);
}

public string Key { get; private set; }
public string Name { get; private set; }
public ICommunicationMonitor Monitor { get; private set; }
public IBasicCommunication Coms { get; private set; }
public ReadOnlyDictionary<uint, IApOutlet> Outlets { get; private set; }
public CTimer Poll { get; private set; }

public EssentialsDevice Build()
{
Debug.Console(1, this, "Building...");
return new ApDevice(this);
}
}
}
24 changes: 24 additions & 0 deletions src/Config/ApDeviceConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using PepperDash.Core;

namespace ApcEpi.Config
{
public class ApDeviceConfig
{
public ControlPropertiesConfig Control { get; set; }
public Dictionary<string, ApOutletConfig> Outlets { get; set; }
}

public class ApOutletConfig
{
public string Name { get; set; }
public int OutletIndex { get; set; }
public int DelayOn { get; set; }
public int DelayOff { get; set; }
}
}
Loading

0 comments on commit 601470a

Please sign in to comment.