Skip to content

Commit

Permalink
Added support for Razer Keypads (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojeske authored Sep 30, 2020
1 parent 67a3590 commit 017cd0e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions Ambilight/Ambilight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
<Compile Include="Logic\HeadsetLogic.cs" />
<Compile Include="Logic\IDeviceLogic.cs" />
<Compile Include="Logic\KeyboardLogic.cs" />
<Compile Include="Logic\KeypadLogic.cs" />
<Compile Include="Logic\LinkLogic.cs" />
<Compile Include="Logic\LogicManager.cs" />
<Compile Include="Logic\MouseLogic.cs" />
Expand Down
13 changes: 13 additions & 0 deletions Ambilight/GUI/TraySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class TraySettings
public bool LinkEnabled { get; private set; }
public bool PadEnabled { get; private set; }
public bool HeadsetEnabled { get; private set; }
public bool KeypadEnabeled { get; private set; }
public bool AmbiModeEnabled { get; private set; }
public bool UltrawideModeEnabled { get; private set; }
public bool AutostartEnabled { get; private set; }
Expand Down Expand Up @@ -131,6 +132,14 @@ private void InitializeTray()
HeadsetEnabled = (sender as MenuItem).Checked;
Properties.Settings.Default.Save();
});

MenuItem _keypadEnabled = new MenuItem("Keypad enabled", (sender, args) =>
{
EnableMenuItemOnClick(sender, args);
Properties.Settings.Default.keypadEnabled = (sender as MenuItem).Checked;
KeypadEnabeled = (sender as MenuItem).Checked;
Properties.Settings.Default.Save();
});

MenuItem _linkEnabled = new MenuItem("LinkChroma enabled", (sender, args) =>
{
Expand Down Expand Up @@ -173,6 +182,8 @@ private void InitializeTray()
PadEnabled = Properties.Settings.Default.mousematEnabled;
_headsetEnabled.Checked = Properties.Settings.Default.headsetEnabled;
HeadsetEnabled = Properties.Settings.Default.headsetEnabled;
_keypadEnabled.Checked = Properties.Settings.Default.keypadEnabled;
KeypadEnabeled = Properties.Settings.Default.keypadEnabled;
_linkEnabled.Checked = Properties.Settings.Default.linkEnabled;
LinkEnabled = Properties.Settings.Default.linkEnabled;
_ambiModeEnabled.Checked = Properties.Settings.Default.ambiEnabled;
Expand All @@ -199,6 +210,7 @@ private void InitializeTray()
contextMenu.MenuItems.Add(_mouseEnabled);
contextMenu.MenuItems.Add(_mousematEnabled);
contextMenu.MenuItems.Add(_headsetEnabled);
contextMenu.MenuItems.Add(_keypadEnabled);
contextMenu.MenuItems.Add(_linkEnabled);

contextMenu.MenuItems.Add("-");
Expand All @@ -216,6 +228,7 @@ private void InitializeTray()
logger.Info("Mouse Enabled: " + _mouseEnabled.Checked);
logger.Info("Mousemat Enabled: " + _mousematEnabled.Checked);
logger.Info("Headset Enabled: " + _headsetEnabled.Checked);
logger.Info("Keypad Enabled: " + _keypadEnabled.Checked);
logger.Info("ChromaLink Enabled: " + _linkEnabled.Checked);
logger.Info("Ambilight mode: " + _ambiModeEnabled.Checked);
logger.Info("Ultrawide mode: " + _ultrawideModeEnabled.Checked);
Expand Down
65 changes: 65 additions & 0 deletions Ambilight/Logic/KeypadLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.Drawing;
using Ambilight.GUI;
using Colore;
using Colore.Effects.Keypad;
using ColoreColor = Colore.Data.Color;

namespace Ambilight.Logic
{

/// <summary>
/// Handles the Ambilight Effect for the mouse
/// </summary>
class KeypadLogic : IDeviceLogic
{
private readonly TraySettings _settings;
private CustomKeypadEffect _keypadGrid = CustomKeypadEffect.Create();
private IChroma _chroma;

public KeypadLogic(TraySettings settings, IChroma chromaInstance)
{
this._settings = settings;
this._chroma = chromaInstance;
}

/// <summary>
/// Processes a ScreenShot and creates an Ambilight Effect for the keypad
/// </summary>
/// <param name="newImage">ScreenShot</param>
public void Process(Bitmap newImage)
{
Bitmap map = ImageManipulation.ResizeImage(newImage, KeypadConstants.MaxColumns, KeypadConstants.MaxRows, _settings.UltrawideModeEnabled);
map = ImageManipulation.ApplySaturation(map, _settings.Saturation);
ApplyPictureToGrid(map);
_chroma.Keypad.SetCustomAsync(_keypadGrid);
}

/// <summary>
/// From a given resized screenshot, an ambilight effect will be created for the keyboard
/// </summary>
/// <param name="map">resized screenshot</param>
/// <returns>EffectGrid</returns>
private void ApplyPictureToGrid(Bitmap map)
{
//Iterating over each key and set it to the corrosponding color of the resized Screenshot
for (var r = 0; r < KeypadConstants.MaxRows ; r++)
{
for (var c = 0; c < KeypadConstants.MaxColumns ; c++)
{
Color color;

if (_settings.AmbiModeEnabled)
{
color = map.GetPixel(c, KeypadConstants.MaxRows - 1);
}
else
{
color = map.GetPixel(c, r);
}

_keypadGrid[r, c] = new ColoreColor((byte)color.R, (byte)color.G, (byte)color.B);
}
}
}
}
}
4 changes: 4 additions & 0 deletions Ambilight/Logic/LogicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class LogicManager
private MouseLogic _mouseLogic;
private LinkLogic _linkLogic;
private HeadsetLogic _headsetLogic;
private KeypadLogic _keypadLogic;

private readonly TraySettings settings;

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

DesktopDuplicatorReader reader = new DesktopDuplicatorReader(this, settings);
}
Expand All @@ -62,6 +64,8 @@ public void ProcessNewImage(Bitmap img)
_linkLogic.Process(newImage);
if (settings.HeadsetEnabled)
_headsetLogic.Process(newImage);
if (settings.KeypadEnabeled)
_keypadLogic.Process(newImage);

newImage.Dispose();
}
Expand Down
15 changes: 15 additions & 0 deletions Ambilight/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 017cd0e

Please sign in to comment.