Skip to content

Commit 160999d

Browse files
committed
Merge branch 'develop'
2 parents ebab731 + e6443c0 commit 160999d

File tree

11 files changed

+234
-17
lines changed

11 files changed

+234
-17
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using TTController.Common;
7+
8+
namespace TTController.Plugin.CopySpeedController
9+
{
10+
public class CopySpeedControllerConfig : SpeedControllerConfigBase
11+
{
12+
public PortIdentifier Target { get; private set; }
13+
}
14+
15+
public class CopySpeedController : SpeedControllerBase<CopySpeedControllerConfig>
16+
{
17+
public CopySpeedController(CopySpeedControllerConfig config) : base(config) { }
18+
19+
public override IDictionary<PortIdentifier, byte> GenerateSpeeds(List<PortIdentifier> ports, ICacheProvider cache)
20+
{
21+
var data = cache.GetPortData(Config.Target);
22+
if (data?.Speed == null)
23+
return null;
24+
25+
return ports.ToDictionary(p => p, _ => data.Speed.Value);
26+
}
27+
}
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("TTController.Plugin.CopySpeedController")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("TTController.Plugin.CopySpeedController")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("e07ebb0d-b2bb-4f00-bd67-233b330987a1")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{E07EBB0D-B2BB-4F00-BD67-233B330987A1}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>TTController.Plugin.CopySpeedController</RootNamespace>
11+
<AssemblyName>TTController.Plugin.CopySpeedController</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="System.Xml.Linq" />
37+
<Reference Include="System.Data.DataSetExtensions" />
38+
<Reference Include="Microsoft.CSharp" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Net.Http" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="CopySpeedController.cs" />
45+
<Compile Include="Properties\AssemblyInfo.cs" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<ProjectReference Include="..\..\..\Source\TTController.Common\TTController.Common.csproj">
49+
<Project>{C1E69FF7-20F6-425C-B8BA-9A1116A35E52}</Project>
50+
<Name>TTController.Common</Name>
51+
</ProjectReference>
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
</Project>

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ It allows you to fully customize them by using **speed controllers**, which cont
55
The source code also provides an easy way to write your own **speed controller**, **effect** or **trigger**.
66

77
---
8-
<a href="https://github.com/devcompl/TTController/releases/latest">
9-
<img alt="undefined" src="https://img.shields.io/github/tag-date/devcompl/ttcontroller.svg?colorB=blue&label=release&style=flat"></a>
8+
<a href="https://github.com/MoshiMoshi0/TTController/releases/latest">
9+
<img alt="undefined" src="https://img.shields.io/github/tag-date/MoshiMoshi0/ttcontroller.svg?colorB=blue&label=release&style=flat"></a>
1010
<br/><br/>
1111

1212
# Quick start
@@ -60,8 +60,9 @@ The source code also provides an easy way to write your own **speed controller**
6060

6161
# Plugins
6262
### Speed Controllers:
63-
* StaticSpeedController
6463
* PwmSpeedController
64+
* StaticSpeedController
65+
* CopySpeedController
6566

6667
### Effects:
6768
* BlinkEffect
@@ -89,6 +90,8 @@ The source code also provides an easy way to write your own **speed controller**
8990

9091
> ## The documentation is still WIP, if you have problems with configuration please make a new [issue](https://github.com/devcompl/TTController/issues/new/choose).
9192
93+
> The config is by default located in `config.json` file. You can modify this in `TTController.Service.exe.Config` file by changing the value of `config-file` key.
94+
9295
## Example
9396
```json
9497
{
@@ -330,7 +333,7 @@ The source code also provides an easy way to write your own **speed controller**
330333
}
331334
```
332335

333-
> If you want to update or add a profile with **Boot** type you first need to remove `<add key="boot-profile-saved" value="" />` line from `TTController.Service.exe.Config` file and restart the service.
336+
> If you want to update or add a profile with **Boot** type, you first need to remove `<add key="boot-profile-saved" value="true" />` line or change the value to `false` in `TTController.Service.exe.Config` file and restart the service.
334337
335338
##### Examples:
336339
```json

Source/TTController.Service/App.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
88
</startup>
99
<appSettings>
10+
<add key="config-file" value="config.json" />
1011
</appSettings>
1112
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1213
<targets>

Source/TTController.Service/Controller/Definition/RiingTrioControllerDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public class RiingTrioControllerDefinition : IControllerDefinition
1111
public int VendorId => 0x264a;
1212
public IEnumerable<int> ProductIds => Enumerable.Range(0, 16).Select(x => 0x2135 + x);
1313
public int PortCount => 5;
14-
public Type ControllerProxyType => typeof(DefaultControllerProxy);
14+
public Type ControllerProxyType => typeof(RiingTrioControllerProxy);
1515
}
1616
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using TTController.Common;
7+
using TTController.Service.Controller.Definition;
8+
using TTController.Service.Hardware;
9+
10+
namespace TTController.Service.Controller.Proxy
11+
{
12+
public class RiingTrioControllerProxy : DefaultControllerProxy
13+
{
14+
public RiingTrioControllerProxy(IHidDeviceProxy device, IControllerDefinition definition)
15+
: base(device, definition) { }
16+
17+
public override bool SetRgb(byte port, byte mode, IEnumerable<LedColor> colors)
18+
{
19+
var colorCount = colors.Count();
20+
if (colorCount <= 20)
21+
return base.SetRgb(port, mode, colors);
22+
23+
var result = true;
24+
var maxPerChunk = 19;
25+
for(byte chunkId = 1; (chunkId - 1) * maxPerChunk < colorCount; chunkId++)
26+
{
27+
var chunkOffset = (chunkId - 1) * maxPerChunk;
28+
var bytes = new List<byte> { 0x32, 0x52, port, 0x24, 0x03, chunkId, 0x00 };
29+
foreach (var color in colors.Skip(chunkOffset).Take(maxPerChunk))
30+
{
31+
bytes.Add(color.G);
32+
bytes.Add(color.R);
33+
bytes.Add(color.B);
34+
}
35+
36+
result &= Device.WriteReadBytes(bytes)[3] == 0xfc;
37+
}
38+
39+
return result;
40+
}
41+
}
42+
}

Source/TTController.Service/TTController.Service.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -81,7 +81,9 @@
8181
<Compile Include="Config\Data\ComputerStateProfileData.cs" />
8282
<Compile Include="Controller\Definition\DpsgControllerDefinition.cs" />
8383
<Compile Include="Controller\Proxy\DpsgControllerProxy.cs" />
84+
<Compile Include="Controller\Proxy\RiingTrioControllerProxy.cs" />
8485
<Compile Include="Manager\SensorManager.cs" />
86+
<Compile Include="Utils\AppSettingsHelper.cs" />
8587
<Compile Include="Utils\DataCache.cs" />
8688
<Compile Include="Utils\Extensions.cs" />
8789
<Compile Include="Controller\Proxy\DefaultControllerProxy.cs" />
@@ -147,6 +149,6 @@
147149
</Target>
148150
<Target Name="CleanPlugins" AfterTargets="Clean">
149151
<MSBuild Projects="@(PluginProjects)" Targets="Clean" Properties="Configuration=$(Configuration)" />
150-
<RemoveDir Directories="$(TargetDir)Plugins" />
152+
<RemoveDir Directories="$(TargetDir)Plugins;$(TargetDir)Logs" />
151153
</Target>
152154
</Project>

Source/TTController.Service/TTService.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ public bool Initialize()
5858
foreach (var assembly in pluginAssemblies)
5959
Logger.Info("Loading assembly: {0} [{1}]", assembly.GetName().Name, assembly.GetName().Version);
6060

61-
_configManager = new ConfigManager("config.json");
61+
const string key = "config-file";
62+
if (string.IsNullOrEmpty(AppSettingsHelper.ReadValue(key)))
63+
AppSettingsHelper.WriteValue(key, "config.json");
64+
65+
_configManager = new ConfigManager(AppSettingsHelper.ReadValue(key));
6266
if (!_configManager.LoadOrCreateConfig())
6367
return false;
6468

@@ -212,16 +216,11 @@ private void ApplyComputerStateProfile(ComputerStateType state)
212216
{
213217
if (state == ComputerStateType.Boot)
214218
{
215-
var configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
216-
var configCollection = configManager.AppSettings.Settings;
217-
218219
const string key = "boot-profile-saved";
219-
if (configCollection[key] != null)
220+
if (AppSettingsHelper.ReadValue<bool>(key))
220221
return;
221222

222-
configCollection.Add(key, "");
223-
configManager.Save(ConfigurationSaveMode.Modified);
224-
ConfigurationManager.RefreshSection(configManager.AppSettings.SectionInformation.Name);
223+
AppSettingsHelper.WriteValue(key, true);
225224
}
226225

227226
Logger.Info("Applying computer state profile: {0}", state);
@@ -282,7 +281,7 @@ private bool DeviceSpeedTimerCallback()
282281
else
283282
{
284283
var speedControllers = _speedControllerManager.GetSpeedControllers(profile.Guid);
285-
var speedController = speedControllers?.FirstOrDefault(c => c.IsEnabled(_cache));
284+
var speedController = speedControllers?.FirstOrDefault(c => c.IsEnabled(_cache.AsReadOnly()));
286285
if (speedController == null)
287286
continue;
288287

@@ -313,7 +312,7 @@ public bool DeviceRgbTimerCallback()
313312
foreach (var profile in _configManager.CurrentConfig.Profiles)
314313
{
315314
var effects = _effectManager.GetEffects(profile.Guid);
316-
var effect = effects?.FirstOrDefault(e => e.IsEnabled(_cache));
315+
var effect = effects?.FirstOrDefault(e => e.IsEnabled(_cache.AsReadOnly()));
317316
if (effect == null)
318317
continue;
319318

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace TTController.Service.Utils
9+
{
10+
public static class AppSettingsHelper
11+
{
12+
public static string ReadValue(string key)
13+
{
14+
var configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
15+
var configCollection = configManager.AppSettings.Settings;
16+
17+
return configCollection[key]?.Value;
18+
}
19+
20+
public static T ReadValue<T>(string key, T defaultValue = default)
21+
{
22+
try
23+
{
24+
return (T) Convert.ChangeType(ReadValue(key), typeof(T));
25+
}
26+
catch
27+
{
28+
return defaultValue;
29+
}
30+
}
31+
32+
public static void WriteValue(string key, string value)
33+
{
34+
var configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
35+
var configCollection = configManager.AppSettings.Settings;
36+
37+
configCollection.Add(key, value);
38+
configManager.Save(ConfigurationSaveMode.Modified);
39+
ConfigurationManager.RefreshSection(configManager.AppSettings.SectionInformation.Name);
40+
}
41+
42+
public static void WriteValue<T>(string key, T value)
43+
=> WriteValue(key, value.ToString());
44+
}
45+
}

0 commit comments

Comments
 (0)