Skip to content

Commit 017cd0e

Browse files
authored
Added support for Razer Keypads (#35)
1 parent 67a3590 commit 017cd0e

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

Ambilight/Ambilight.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
<Compile Include="Logic\HeadsetLogic.cs" />
185185
<Compile Include="Logic\IDeviceLogic.cs" />
186186
<Compile Include="Logic\KeyboardLogic.cs" />
187+
<Compile Include="Logic\KeypadLogic.cs" />
187188
<Compile Include="Logic\LinkLogic.cs" />
188189
<Compile Include="Logic\LogicManager.cs" />
189190
<Compile Include="Logic\MouseLogic.cs" />

Ambilight/GUI/TraySettings.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class TraySettings
2929
public bool LinkEnabled { get; private set; }
3030
public bool PadEnabled { get; private set; }
3131
public bool HeadsetEnabled { get; private set; }
32+
public bool KeypadEnabeled { get; private set; }
3233
public bool AmbiModeEnabled { get; private set; }
3334
public bool UltrawideModeEnabled { get; private set; }
3435
public bool AutostartEnabled { get; private set; }
@@ -131,6 +132,14 @@ private void InitializeTray()
131132
HeadsetEnabled = (sender as MenuItem).Checked;
132133
Properties.Settings.Default.Save();
133134
});
135+
136+
MenuItem _keypadEnabled = new MenuItem("Keypad enabled", (sender, args) =>
137+
{
138+
EnableMenuItemOnClick(sender, args);
139+
Properties.Settings.Default.keypadEnabled = (sender as MenuItem).Checked;
140+
KeypadEnabeled = (sender as MenuItem).Checked;
141+
Properties.Settings.Default.Save();
142+
});
134143

135144
MenuItem _linkEnabled = new MenuItem("LinkChroma enabled", (sender, args) =>
136145
{
@@ -173,6 +182,8 @@ private void InitializeTray()
173182
PadEnabled = Properties.Settings.Default.mousematEnabled;
174183
_headsetEnabled.Checked = Properties.Settings.Default.headsetEnabled;
175184
HeadsetEnabled = Properties.Settings.Default.headsetEnabled;
185+
_keypadEnabled.Checked = Properties.Settings.Default.keypadEnabled;
186+
KeypadEnabeled = Properties.Settings.Default.keypadEnabled;
176187
_linkEnabled.Checked = Properties.Settings.Default.linkEnabled;
177188
LinkEnabled = Properties.Settings.Default.linkEnabled;
178189
_ambiModeEnabled.Checked = Properties.Settings.Default.ambiEnabled;
@@ -199,6 +210,7 @@ private void InitializeTray()
199210
contextMenu.MenuItems.Add(_mouseEnabled);
200211
contextMenu.MenuItems.Add(_mousematEnabled);
201212
contextMenu.MenuItems.Add(_headsetEnabled);
213+
contextMenu.MenuItems.Add(_keypadEnabled);
202214
contextMenu.MenuItems.Add(_linkEnabled);
203215

204216
contextMenu.MenuItems.Add("-");
@@ -216,6 +228,7 @@ private void InitializeTray()
216228
logger.Info("Mouse Enabled: " + _mouseEnabled.Checked);
217229
logger.Info("Mousemat Enabled: " + _mousematEnabled.Checked);
218230
logger.Info("Headset Enabled: " + _headsetEnabled.Checked);
231+
logger.Info("Keypad Enabled: " + _keypadEnabled.Checked);
219232
logger.Info("ChromaLink Enabled: " + _linkEnabled.Checked);
220233
logger.Info("Ambilight mode: " + _ambiModeEnabled.Checked);
221234
logger.Info("Ultrawide mode: " + _ultrawideModeEnabled.Checked);

Ambilight/Logic/KeypadLogic.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.Drawing;
2+
using Ambilight.GUI;
3+
using Colore;
4+
using Colore.Effects.Keypad;
5+
using ColoreColor = Colore.Data.Color;
6+
7+
namespace Ambilight.Logic
8+
{
9+
10+
/// <summary>
11+
/// Handles the Ambilight Effect for the mouse
12+
/// </summary>
13+
class KeypadLogic : IDeviceLogic
14+
{
15+
private readonly TraySettings _settings;
16+
private CustomKeypadEffect _keypadGrid = CustomKeypadEffect.Create();
17+
private IChroma _chroma;
18+
19+
public KeypadLogic(TraySettings settings, IChroma chromaInstance)
20+
{
21+
this._settings = settings;
22+
this._chroma = chromaInstance;
23+
}
24+
25+
/// <summary>
26+
/// Processes a ScreenShot and creates an Ambilight Effect for the keypad
27+
/// </summary>
28+
/// <param name="newImage">ScreenShot</param>
29+
public void Process(Bitmap newImage)
30+
{
31+
Bitmap map = ImageManipulation.ResizeImage(newImage, KeypadConstants.MaxColumns, KeypadConstants.MaxRows, _settings.UltrawideModeEnabled);
32+
map = ImageManipulation.ApplySaturation(map, _settings.Saturation);
33+
ApplyPictureToGrid(map);
34+
_chroma.Keypad.SetCustomAsync(_keypadGrid);
35+
}
36+
37+
/// <summary>
38+
/// From a given resized screenshot, an ambilight effect will be created for the keyboard
39+
/// </summary>
40+
/// <param name="map">resized screenshot</param>
41+
/// <returns>EffectGrid</returns>
42+
private void ApplyPictureToGrid(Bitmap map)
43+
{
44+
//Iterating over each key and set it to the corrosponding color of the resized Screenshot
45+
for (var r = 0; r < KeypadConstants.MaxRows ; r++)
46+
{
47+
for (var c = 0; c < KeypadConstants.MaxColumns ; c++)
48+
{
49+
Color color;
50+
51+
if (_settings.AmbiModeEnabled)
52+
{
53+
color = map.GetPixel(c, KeypadConstants.MaxRows - 1);
54+
}
55+
else
56+
{
57+
color = map.GetPixel(c, r);
58+
}
59+
60+
_keypadGrid[r, c] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B);
61+
}
62+
}
63+
}
64+
}
65+
}

Ambilight/Logic/LogicManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class LogicManager
2020
private MouseLogic _mouseLogic;
2121
private LinkLogic _linkLogic;
2222
private HeadsetLogic _headsetLogic;
23+
private KeypadLogic _keypadLogic;
2324

2425
private readonly TraySettings settings;
2526

@@ -40,6 +41,7 @@ private async void StartLogic(TraySettings settings)
4041
_mouseLogic = new MouseLogic(settings, chromaInstance);
4142
_linkLogic = new LinkLogic(settings, chromaInstance);
4243
_headsetLogic = new HeadsetLogic(settings, chromaInstance);
44+
_keypadLogic = new KeypadLogic(settings, chromaInstance);
4345

4446
DesktopDuplicatorReader reader = new DesktopDuplicatorReader(this, settings);
4547
}
@@ -62,6 +64,8 @@ public void ProcessNewImage(Bitmap img)
6264
_linkLogic.Process(newImage);
6365
if (settings.HeadsetEnabled)
6466
_headsetLogic.Process(newImage);
67+
if (settings.KeypadEnabeled)
68+
_keypadLogic.Process(newImage);
6569

6670
newImage.Dispose();
6771
}

Ambilight/Properties/Settings.Designer.cs

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)