Skip to content

Commit ca5911f

Browse files
committed
Merge branch 'develop'
2 parents bf46e2a + 31d1750 commit ca5911f

File tree

27 files changed

+503
-193
lines changed

27 files changed

+503
-193
lines changed

Plugins/Devices/TTController.Plugin.DpsgController/DpsgControllerProxy.cs

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Text;
45
using TTController.Common;
@@ -13,11 +14,33 @@ public class DpsgControllerProxy : AbstractControllerProxy
1314
public DpsgControllerProxy(IHidDeviceProxy device, IControllerDefinition definition)
1415
: base(device, definition)
1516
{
16-
_availableEffects = new Dictionary<string, byte>()
17+
var effectModes = new Dictionary<string, byte>()
1718
{
18-
["ByLed"] = 0x18,
19-
["Full"] = 0x19
19+
["Flow"] = 0x00,
20+
["Spectrum"] = 0x04,
21+
["Ripple"] = 0x08,
22+
["Blink"] = 0x0c,
23+
["Pulse"] = 0x10,
24+
["Wave"] = 0x14,
2025
};
26+
27+
var effectSpeeds = new Dictionary<string, byte>()
28+
{
29+
["Extreme"] = 0x00,
30+
["Fast"] = 0x01,
31+
["Normal"] = 0x02,
32+
["Slow"] = 0x03
33+
};
34+
35+
var result = new Dictionary<string, byte>();
36+
foreach (var mkv in effectModes)
37+
foreach (var skv in effectSpeeds)
38+
result.Add($"{mkv.Key}_{skv.Key}", (byte)(mkv.Value + skv.Value));
39+
40+
result.Add("PerLed", 0x18);
41+
result.Add("Full", 0x19);
42+
43+
_availableEffects = result;
2144
}
2245

2346
public override IEnumerable<PortIdentifier> Ports
@@ -43,37 +66,62 @@ public override bool SetRgb(byte port, byte mode, IEnumerable<LedColor> colors)
4366
return Device.WriteReadBytes(bytes)?[3] == 0xfc;
4467
}
4568

46-
public override bool SetSpeed(byte port, byte speed) =>
47-
Device.WriteReadBytes(0x30, 0x41, 0x04, speed)?[3] == 0xfc;
69+
public override bool SetSpeed(byte port, byte speed)
70+
{
71+
if (speed == 0) // off
72+
return Device.WriteReadBytes(0x30, 0x41, 0x03)?[3] == 0xfc;
73+
if (speed == 1) // silent
74+
return Device.WriteReadBytes(0x30, 0x41, 0x01)?[3] == 0xfc;
75+
if (speed == 2) // performance
76+
return Device.WriteReadBytes(0x30, 0x41, 0x02)?[3] == 0xfc;
77+
78+
return Device.WriteReadBytes(0x30, 0x41, 0x04, speed)?[3] == 0xfc;
79+
}
4880

4981
public override PortData GetPortData(byte port)
5082
{
51-
// 0x31, 0x33 // VIN
52-
// 0x31, 0x34 // VVOut12
53-
// 0x31, 0x35 // VVout5
54-
// 0x31, 0x36 // VVOut33
55-
// 0x31, 0x37 // VIOut12
56-
// 0x31, 0x38 // VIOut5
57-
// 0x31, 0x39 // VIOut33
58-
// 0x31, 0x3a // Temp
59-
// 0x31, 0x3b // FanSpeed
60-
// WATTS = VVOut33 * VIOut33
61-
// EFF = (int)((VVOut12 * VIOut12 + VVOut5 * VIOut5 + VVOut33 * VIOut33) / 10.0)
62-
63-
byte[] GetData(byte b) => Device.WriteReadBytes(0x31, b)?.Skip(3).Take(2).ToArray();
64-
string GetDataAsString(byte b) => $"{string.Concat(GetData(b)?.Select(x => $"{x:X2}") ?? Enumerable.Empty<string>())}";
83+
float GetData(byte b)
84+
{
85+
var bytes = Device.WriteReadBytes(0x31, b)?.Skip(3).Take(2).ToArray();
86+
if (bytes == null || bytes.Length == 0)
87+
return float.NaN;
88+
89+
var value = bytes[1] << 8 | bytes[0];
90+
var exponent = (value & 0x7800) >> 11;
91+
var sign = (value & 0x8000) >> 15;
92+
var fraction = (value & 0x7ff);
93+
94+
if (sign == 1)
95+
exponent -= 16;
96+
97+
return (float)Math.Pow(2.0, exponent) * fraction;
98+
}
99+
100+
var vin = GetData(0x33);
101+
var vvOut12 = GetData(0x34);
102+
var vvOut5 = GetData(0x35);
103+
var vvOut33 = GetData(0x36);
104+
var viOut12 = GetData(0x37);
105+
var viOut5 = GetData(0x38);
106+
var viOut33 = GetData(0x39);
107+
var temp = GetData(0x3a);
108+
var fanRpm = GetData(0x3b);
109+
110+
var watts = vvOut12 * viOut12 + vvOut5 * viOut5 + vvOut33 * viOut33;
111+
//var efficiency = lut[(int)(watts / 10.0)];
65112

66113
var data = new PortData()
67114
{
68-
["VIN"] = GetDataAsString(0x33),
69-
["VVOut12"] = GetDataAsString(0x34),
70-
["VVout5"] = GetDataAsString(0x35),
71-
["VVOut33"] = GetDataAsString(0x36),
72-
["VIOut12"] = GetDataAsString(0x37),
73-
["VIOut5"] = GetDataAsString(0x38),
74-
["VIOut33"] = GetDataAsString(0x39),
75-
["Temp"] = GetDataAsString(0x3a),
76-
["FanSpeed"] = GetDataAsString(0x3b)
115+
Temperature = temp,
116+
Rpm = (int)fanRpm,
117+
["VIN"] = vin,
118+
["VVOut12"] = vvOut12,
119+
["VVOut5"] = vvOut5,
120+
["VVOut33"] = vvOut33,
121+
["VIOut12"] = viOut12,
122+
["VIOut5"] = viOut5,
123+
["VIOut33"] = viOut33,
124+
["Watts"] = watts,
77125
};
78126

79127
return data;
@@ -87,8 +135,7 @@ public override PortData GetPortData(byte port)
87135
}
88136

89137
public override void SaveProfile()
90-
{
91-
}
138+
=> Device.WriteReadBytes(0x30, 0x43, 0x01);
92139

93140
public override bool Init()
94141
{

Plugins/Devices/TTController.Plugin.RiingController/RiingControllerProxy.cs

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,79 @@
88

99
namespace TTController.Plugin.RiingController
1010
{
11-
public class RiingControllerProxy : DefaultControllerProxy
11+
public class RiingControllerProxy : AbstractControllerProxy
1212
{
13+
private readonly IReadOnlyDictionary<string, byte> _availableEffects;
14+
1315
public RiingControllerProxy(IHidDeviceProxy device, IControllerDefinition definition)
1416
: base(device, definition)
15-
{ }
17+
{
18+
_availableEffects = new Dictionary<string, byte>()
19+
{
20+
["Flow"] = 0x01,
21+
["Full"] = 0x00
22+
};
23+
}
24+
public override IEnumerable<PortIdentifier> Ports => Enumerable.Range(1, Definition.PortCount)
25+
.Select(x => new PortIdentifier(Device.VendorId, Device.ProductId, (byte)x));
26+
27+
public override IEnumerable<string> EffectTypes => _availableEffects.Keys;
28+
29+
public override bool SetRgb(byte port, byte mode, IEnumerable<LedColor> colors)
30+
{
31+
var bytes = new List<byte> { 0x32, 0x52, port, mode };
32+
foreach (var color in colors)
33+
{
34+
bytes.Add(color.R);
35+
bytes.Add(color.G);
36+
bytes.Add(color.B);
37+
}
38+
39+
var result = Device.WriteReadBytes(bytes)?[3] ?? -1;
40+
return result == 0xfe || result == 0x00;
41+
}
1642

1743
public override bool SetSpeed(byte port, byte speed) =>
1844
Device.WriteReadBytes(0x32, 0x51, port, 0x03, speed)?[3] == 0xfc;
1945

20-
protected override Dictionary<string, byte> GenerateAvailableEffects()
46+
47+
public override PortData GetPortData(byte port)
2148
{
22-
return new Dictionary<string, byte>()
49+
var result = Device.WriteReadBytes(0x33, 0x51, port);
50+
if (result == null)
51+
return null;
52+
53+
if (result[3] == 0xfe)
54+
return null;
55+
56+
var data = new PortData
2357
{
24-
["Flow"] = 0x01,
25-
["Full"] = 0x00
58+
PortId = result[3],
59+
Speed = result[5],
60+
Rpm = (result[7] << 8) + result[6],
61+
["Unknown"] = result[4]
2662
};
63+
64+
return data;
2765
}
66+
67+
public override byte? GetEffectByte(string effectType)
68+
{
69+
if (effectType == null)
70+
return null;
71+
return _availableEffects.TryGetValue(effectType, out var value) ? value : (byte?)null;
72+
}
73+
74+
public override void SaveProfile() =>
75+
Device.WriteReadBytes(0x32, 0x53);
76+
77+
public override bool Init() =>
78+
Device.WriteReadBytes(0xfe, 0x33)?[3] == 0xfc;
79+
80+
public override bool IsValidPort(PortIdentifier port) =>
81+
port.ControllerProductId == Device.ProductId
82+
&& port.ControllerVendorId == Device.VendorId
83+
&& port.Id >= 1
84+
&& port.Id <= Definition.PortCount;
2885
}
2986
}

Plugins/Devices/TTController.Plugin.RiingPlusController/RiingPlusControllerDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ public class RiingPlusControllerDefinition : IControllerDefinition
1111
public int VendorId => 0x264a;
1212
public IEnumerable<int> ProductIds => Enumerable.Range(0, 16).Select(x => 0x1fa5 + x);
1313
public int PortCount => 5;
14-
public Type ControllerProxyType => typeof(DefaultControllerProxy);
14+
public Type ControllerProxyType => typeof(RiingPlusControllerProxy);
1515
}
1616
}

Source/TTController.Common/Plugin/DefaultControllerProxy.cs renamed to Plugins/Devices/TTController.Plugin.RiingPlusController/RiingPlusControllerProxy.cs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using TTController.Common;
7+
using TTController.Common.Plugin;
38

4-
namespace TTController.Common.Plugin
9+
namespace TTController.Plugin.RiingPlusController
510
{
6-
public class DefaultControllerProxy : AbstractControllerProxy
11+
public class RiingPlusControllerProxy : AbstractControllerProxy
712
{
813
private readonly IReadOnlyDictionary<string, byte> _availableEffects;
914

10-
public DefaultControllerProxy(IHidDeviceProxy device, IControllerDefinition definition)
15+
public RiingPlusControllerProxy(IHidDeviceProxy device, IControllerDefinition definition)
1116
: base(device, definition)
1217
{
13-
_availableEffects = GenerateAvailableEffects();
18+
var effectModes = new Dictionary<string, byte>()
19+
{
20+
["Flow"] = 0x00,
21+
["Spectrum"] = 0x04,
22+
["Ripple"] = 0x08,
23+
["Blink"] = 0x0c,
24+
["Pulse"] = 0x10,
25+
["Wave"] = 0x14,
26+
};
27+
28+
var effectSpeeds = new Dictionary<string, byte>()
29+
{
30+
["Extreme"] = 0x00,
31+
["Fast"] = 0x01,
32+
["Normal"] = 0x02,
33+
["Slow"] = 0x03
34+
};
35+
36+
var result = new Dictionary<string, byte>();
37+
foreach (var mkv in effectModes)
38+
foreach (var skv in effectSpeeds)
39+
result.Add($"{mkv.Key}_{skv.Key}", (byte)(mkv.Value + skv.Value));
40+
41+
result.Add("PerLed", 0x18);
42+
result.Add("Full", 0x19);
43+
44+
_availableEffects = result;
1445
}
1546

1647
public override IEnumerable<PortIdentifier> Ports => Enumerable.Range(1, Definition.PortCount)
@@ -72,36 +103,5 @@ public override bool IsValidPort(PortIdentifier port) =>
72103
&& port.ControllerVendorId == Device.VendorId
73104
&& port.Id >= 1
74105
&& port.Id <= Definition.PortCount;
75-
76-
protected virtual Dictionary<string, byte> GenerateAvailableEffects()
77-
{
78-
var effectModes = new Dictionary<string, byte>()
79-
{
80-
["Flow"] = 0x00,
81-
["Spectrum"] = 0x04,
82-
["Ripple"] = 0x08,
83-
["Blink"] = 0x0c,
84-
["Pulse"] = 0x10,
85-
["Wave"] = 0x14,
86-
};
87-
88-
var effectSpeeds = new Dictionary<string, byte>()
89-
{
90-
["Extreme"] = 0x00,
91-
["Fast"] = 0x01,
92-
["Normal"] = 0x02,
93-
["Slow"] = 0x03
94-
};
95-
96-
var result = new Dictionary<string, byte>();
97-
foreach (var mkv in effectModes)
98-
foreach (var skv in effectSpeeds)
99-
result.Add($"{mkv.Key}_{skv.Key}", (byte)(mkv.Value + skv.Value));
100-
101-
result.Add("ByLed", 0x18);
102-
result.Add("Full", 0x19);
103-
104-
return result;
105-
}
106106
}
107107
}

0 commit comments

Comments
 (0)