-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c9ed67
commit 66227ec
Showing
16 changed files
with
633 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/ChromaControl.SDK.Synapse.Sample/ChromaControl.SDK.Synapse.Sample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ChromaControl.SDK.Synapse\ChromaControl.SDK.Synapse.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the Chroma Control Contributors under one or more agreements. | ||
// The Chroma Control Contributors licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using ChromaControl.SDK.Synapse.Extensions; | ||
using ChromaControl.SDK.Synapse.Sample; | ||
|
||
var builder = Host.CreateApplicationBuilder(args); | ||
|
||
builder.Services.AddSynapseSDK(); | ||
builder.Services.AddHostedService<Worker>(); | ||
|
||
await builder.Build().RunAsync(); |
12 changes: 12 additions & 0 deletions
12
src/ChromaControl.SDK.Synapse.Sample/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"ChromaControl.SDK.Synapse.Sample": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"environmentVariables": { | ||
"DOTNET_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Licensed to the Chroma Control Contributors under one or more agreements. | ||
// The Chroma Control Contributors licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using ChromaControl.SDK.Synapse.Enums; | ||
using ChromaControl.SDK.Synapse.Structs; | ||
using System.Drawing; | ||
|
||
namespace ChromaControl.SDK.Synapse.Sample; | ||
|
||
/// <summary> | ||
/// The worker. | ||
/// </summary> | ||
public partial class Worker : IHostedService | ||
{ | ||
private readonly ILogger<Worker> _logger; | ||
private readonly ISynapseSDK _sdk; | ||
|
||
private Color _colorCache; | ||
|
||
[LoggerMessage(Level = LogLevel.Information, Message = "Starting Synapse SDK...")] | ||
private static partial void LogStartMessage(ILogger logger); | ||
|
||
[LoggerMessage(Level = LogLevel.Information, Message = "Stopping Synapse SDK...")] | ||
private static partial void LogStopMessage(ILogger logger); | ||
|
||
[LoggerMessage(Level = LogLevel.Information, Message = "Synapse Status Changed To {status}")] | ||
private static partial void LogStatusMessage(ILogger logger, SynapseStatus status); | ||
|
||
[LoggerMessage(Level = LogLevel.Information, Message = "Synapse Color Set To [{r}, {g}, {b}]")] | ||
private static partial void LogEffectMessage(ILogger logger, byte r, byte g, byte b); | ||
|
||
/// <summary> | ||
/// Creates a <see cref="Worker"/> instance. | ||
/// </summary> | ||
/// <param name="logger">The <see cref="ILogger{TCategoryName}"/>.</param> | ||
/// <param name="sdk">The <see cref="ISynapseSDK"/>.</param> | ||
public Worker(ILogger<Worker> logger, ISynapseSDK sdk) | ||
{ | ||
_logger = logger; | ||
_sdk = sdk; | ||
_sdk.StatusChanged += StatusChanged; | ||
_sdk.EffectReceived += EffectReceived; | ||
} | ||
|
||
/// <summary> | ||
/// Starts the worker. | ||
/// </summary> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> | ||
/// <returns>A <see cref="Task"/> representing the worker starting.</returns> | ||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
LogStartMessage(_logger); | ||
|
||
_sdk.StartSDK(new("00000000-0000-0000-0000-000000000000")); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
/// <summary> | ||
/// Stops the worker. | ||
/// </summary> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param> | ||
/// <returns>A <see cref="Task"/> representing the worker stopping.</returns> | ||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
LogStopMessage(_logger); | ||
|
||
_sdk.StopSDK(); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private void StatusChanged(object? sender, SynapseStatus e) | ||
{ | ||
LogStatusMessage(_logger, e); | ||
} | ||
|
||
private void EffectReceived(object? sender, SynapseEffect e) | ||
{ | ||
if (_colorCache != e.Color1) | ||
{ | ||
_colorCache = e.Color1; | ||
|
||
LogEffectMessage(_logger, e.Color1.R, e.Color1.G, e.Color1.B); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/ChromaControl.SDK.Synapse.Sample/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/ChromaControl.SDK.Synapse/ChromaControl.SDK.Synapse.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the Chroma Control Contributors under one or more agreements. | ||
// The Chroma Control Contributors licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace ChromaControl.SDK.Synapse.Enums; | ||
|
||
internal enum SynapseEventType | ||
{ | ||
Effect = 1, | ||
Status = 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Licensed to the Chroma Control Contributors under one or more agreements. | ||
// The Chroma Control Contributors licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace ChromaControl.SDK.Synapse.Enums; | ||
|
||
/// <summary> | ||
/// Synapse return result. | ||
/// </summary> | ||
public enum SynapseResult : long | ||
{ | ||
/// <summary> | ||
/// Invalid. | ||
/// </summary> | ||
Invalid = -1L, | ||
|
||
/// <summary> | ||
/// Success. | ||
/// </summary> | ||
Success = 0L, | ||
|
||
/// <summary> | ||
/// Access denied. | ||
/// </summary> | ||
AccessDenied = 5L, | ||
|
||
/// <summary> | ||
/// Invalid handle. | ||
/// </summary> | ||
InvalidHandle = 6L, | ||
|
||
/// <summary> | ||
/// Invalid access. | ||
/// </summary> | ||
InvalidAccess = 12L, | ||
|
||
/// <summary> | ||
/// Not supported. | ||
/// </summary> | ||
NotSupported = 50L, | ||
|
||
/// <summary> | ||
/// Invalid parameter. | ||
/// </summary> | ||
InvalidParameter = 87L, | ||
|
||
/// <summary> | ||
/// The service does not exist. | ||
/// </summary> | ||
ServiceNotExist = 1060L, | ||
|
||
/// <summary> | ||
/// The service has not been started. | ||
/// </summary> | ||
ServiceNotActive = 1062L, | ||
|
||
/// <summary> | ||
/// Cannot start more than one instance of the specified program. | ||
/// </summary> | ||
SingleInstanceApp = 1152L, | ||
|
||
/// <summary> | ||
/// Device not connected. | ||
/// </summary> | ||
DeviceNotConnected = 1167L, | ||
|
||
/// <summary> | ||
/// Element not found. | ||
/// </summary> | ||
NotFound = 1168L, | ||
|
||
/// <summary> | ||
/// Request aborted. | ||
/// </summary> | ||
RequestAborted = 1235L, | ||
|
||
/// <summary> | ||
/// Requested operation is not performed because the user has not been authenticated. | ||
/// </summary> | ||
NotAuthenticated = 1244L, | ||
|
||
/// <summary> | ||
/// An attempt was made to perform an initialization operation when initialization has already been completed. | ||
/// </summary> | ||
AlreadyInitialized = 1247L, | ||
|
||
/// <summary> | ||
/// Resource not available or disabled. | ||
/// </summary> | ||
ResourceDisabled = 4309L, | ||
|
||
/// <summary> | ||
/// Device not available or supported. | ||
/// </summary> | ||
DeviceNotAvailable = 4319L, | ||
|
||
/// <summary> | ||
/// The group or resource is not in the correct state to perform the requested operation. | ||
/// </summary> | ||
NotValidState = 5023L, | ||
|
||
/// <summary> | ||
/// Insufficient access rights, administrator privilege required. | ||
/// </summary> | ||
InsufficientAccessRights = 8344L, | ||
|
||
/// <summary> | ||
/// No more items. | ||
/// </summary> | ||
NoMoreItems = 259L, | ||
|
||
/// <summary> | ||
/// General failure. | ||
/// </summary> | ||
Failed = 2147483647L | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to the Chroma Control Contributors under one or more agreements. | ||
// The Chroma Control Contributors licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace ChromaControl.SDK.Synapse.Enums; | ||
|
||
/// <summary> | ||
/// Synapse status. | ||
/// </summary> | ||
public enum SynapseStatus | ||
{ | ||
/// <summary> | ||
/// <see cref="Live"/> occurs when all expected conditions are met. | ||
/// </summary> | ||
Live = 1, | ||
|
||
/// <summary> | ||
/// <see cref="NotLive"/> occurs when one of the expected conditions is not fulfilled. | ||
/// </summary> | ||
NotLive = 2 | ||
} |
25 changes: 25 additions & 0 deletions
25
src/ChromaControl.SDK.Synapse/Extensions/ServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Licensed to the Chroma Control Contributors under one or more agreements. | ||
// The Chroma Control Contributors licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace ChromaControl.SDK.Synapse.Extensions; | ||
|
||
/// <summary> | ||
/// Extension methods for adding the Synapse SDK to an <see cref="IServiceCollection" />. | ||
/// </summary> | ||
public static class ServiceCollectionSynapseExtensions | ||
{ | ||
/// <summary> | ||
/// Add an <see cref="ISynapseSDK"/> registration. | ||
/// </summary> | ||
/// <param name="services">The <see cref="IServiceCollection"/> to register with.</param> | ||
/// <returns>The original <see cref="IServiceCollection"/>.</returns> | ||
public static IServiceCollection AddSynapseSDK(this IServiceCollection services) | ||
{ | ||
services.AddSingleton<ISynapseSDK>(new SynapseSDK()); | ||
|
||
return services; | ||
} | ||
} |
Oops, something went wrong.