Skip to content

Commit

Permalink
Merge pull request #4 from nicolasdeory/dev
Browse files Browse the repository at this point in the history
Merge Dev to Master
  • Loading branch information
nicolasdeory authored Mar 30, 2020
2 parents 05bff8d + 84770d6 commit 73469c7
Show file tree
Hide file tree
Showing 9 changed files with 463 additions and 141 deletions.
1 change: 1 addition & 0 deletions LedDashboard/LedDashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="Modules\Common\KeyboardHookService.cs" />
<Compile Include="Modules\FourierAudioLED\FFTUtil.cs" />
<Compile Include="Modules\FourierAudioLED\FourierAudioLED.cs" />
<Compile Include="Modules\LeagueOfLegends\ChampionModules\Common\AbilityModes.cs" />
<Compile Include="Modules\LeagueOfLegends\ChampionModules\VelKozModule.cs" />
<Compile Include="Modules\LeagueOfLegends\ChampionModule.cs" />
<Compile Include="Modules\LeagueOfLegends\LeagueOfLegendsModule.cs" />
Expand Down
42 changes: 35 additions & 7 deletions LedDashboard/LedManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using LedDashboard.Modules.BlinkWhite;
using LedDashboard.Modules.LeagueOfLegends;
using System;
using System.Collections.Generic;

namespace LedDashboard
{
Expand All @@ -24,6 +25,8 @@ class LedManager
bool reverseOrder;
LightController lightController;

private Dictionary<string, Dictionary<string, string>> ModuleOptions = new Dictionary<string, Dictionary<string, string>>();

LEDModule CurrentLEDModule
{
get
Expand Down Expand Up @@ -88,7 +91,7 @@ private void OnProcessChanged(string name)
{
if (name == "League of Legends" && !(CurrentLEDModule is LeagueOfLegendsModule)) // TODO: Account for client disconnections
{
LEDModule lolModule = LeagueOfLegendsModule.Create(preferredMode, ledCount);
LEDModule lolModule = LeagueOfLegendsModule.Create(preferredMode, ledCount, ModuleOptions["lol"]);
lolModule.NewFrameReady += UpdateLEDDisplay;
CurrentLEDModule = lolModule;
} else if (name == "")
Expand Down Expand Up @@ -164,31 +167,56 @@ public byte[] ToByteArray(bool reverseOrder = false)
public void SetController(LightControllerType type, int ledCount = 0, bool reverseOrder = false)
{
((IDisposable)lightController).Dispose();
//bool wasEnabled = lightController.IsEnabled();
if (type == LightControllerType.LED_Strip)
{
lightController = SACNController.Create();
this.preferredMode = LightingMode.Line;
InitLeds(this.preferredMode, ledCount, reverseOrder);
} else if (type == LightControllerType.RazerChroma)
{
lightController = RazerChromaController.Create();
this.preferredMode = LightingMode.Keyboard;
InitLeds(this.preferredMode);
}
RestartManager(this.preferredMode, ledCount, reverseOrder);
}

private void RestartManager(LightingMode preferredMode, int ledCount, bool reverseOrder)
{
InitLeds(this.preferredMode, ledCount, reverseOrder);
CurrentLEDModule = null; // restart the whole service (force module reload)
ProcessListenerService.Restart();
// lightController.SetEnabled(wasEnabled);
}

private void RestartManager()
{
InitLeds(this.preferredMode, this.ledCount, this.reverseOrder);
CurrentLEDModule = null;
ProcessListenerService.Restart();
}

/// <summary>
/// Sends LED data to a wireless LED strip using the E1.31 sACN protocol.
/// </summary>
public async void SendData(LightingMode mode)
public void SendData(LightingMode mode)
{
//await SACNController.Send(this.ToByteArray(reverseOrder));
lightController.SendData(this.leds.Length, this.ToByteArray(this.reverseOrder), mode);
}

public void SetModuleOption(string moduleId, string option, string value)
{
if (!ModuleOptions.ContainsKey(moduleId))
{
ModuleOptions.Add(moduleId, new Dictionary<string, string>());
}
if(ModuleOptions[moduleId].ContainsKey(option))
{
ModuleOptions[moduleId][option] = value;
} else
{
ModuleOptions[moduleId].Add(option, value);
}
RestartManager();

}

}
}
34 changes: 32 additions & 2 deletions LedDashboard/MainUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class MainUI : Form
PictureBox box;
Graphics canvas;
LedManager ledManager;
FormsPlot plt;
//FormsPlot plt;
Button chromabtn;
Button ledstripbtn;
ComboBox lolModeSelector;

List<KeyboardKey> keyboardLayout;
LightingMode currentLightingMode = LightingMode.Keyboard;
Expand Down Expand Up @@ -53,17 +54,46 @@ public MainUI()
ledstripbtn.Location = new Point(0, 350);
ledstripbtn.Click += UseLEDStripClicked;

Label lolModeLabel = new Label();
lolModeLabel.Text = "League of Legends Ability Cast mode";
lolModeLabel.Location = new Point(300, 280);
lolModeLabel.Size = new Size(200, 20);
lolModeSelector = new ComboBox();
lolModeSelector.Location = new Point(300, 300);
lolModeSelector.Items.Add("Normal Cast");
lolModeSelector.Items.Add("Quick Cast");
lolModeSelector.Items.Add("Quick Cast with Indicator");
lolModeSelector.SelectedIndex = 0;
lolModeSelector.SelectedIndexChanged += LolModeSelectionChanged;

/*plt = new FormsPlot();
plt.Location = new Point(0, 100);
plt.Size = new Size(800, 200);*/

this.Controls.AddRange(new Control[] { box, /*plt,*/ chromabtn, ledstripbtn });


this.Controls.AddRange(new Control[] { box, chromabtn, ledstripbtn, lolModeLabel, lolModeSelector });

Gradient.GeneratePalettes();

ledManager = new LedManager();
ledManager.DisplayUpdated += UpdateUI;
// TODO: Add selector for League of Legends cast modes (Normal, Quick Cast, Quick Cast with Indicator)
ledManager.SetModuleOption("lol", "castMode", "quickindicator");

}

private void LolModeSelectionChanged(object sender, EventArgs e)
{
if(lolModeSelector.SelectedIndex == 0)
{
ledManager.SetModuleOption("lol", "castMode", "normal");
} else if (lolModeSelector.SelectedIndex == 1) {
ledManager.SetModuleOption("lol", "castMode", "quick");
} else if (lolModeSelector.SelectedIndex == 2)
{
ledManager.SetModuleOption("lol", "castMode", "quickindicator");
}
}

bool updatingUI = false;
Expand Down
16 changes: 15 additions & 1 deletion LedDashboard/Modules/Common/KeyboardHookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ public static KeyboardHookService Instance
public event MouseEventHandler OnMouseClicked; // TODO: Check window in focus. i.e for league of legends make sure it's when the client window is in focus.

/// <summary>
/// Raised when a key is pressed
/// Raised when a key is pressed (down)
/// </summary>
public event KeyPressEventHandler OnKeyPressed;

/// <summary>
/// Raised when a key is released
/// </summary>
public event KeyEventHandler OnKeyReleased;


//public event KeyEventHandler OnKeyDown; // this shouldn't be needed

public static void Init()
{
_instance = new KeyboardHookService();
Expand All @@ -44,6 +52,7 @@ private KeyboardHookService()

m_GlobalHook.MouseClick += OnMouseClick;
m_GlobalHook.KeyPress += OnKeyPress;
m_GlobalHook.KeyUp += OnKeyRelease;
}

private void OnMouseClick(object sender, MouseEventArgs e)
Expand All @@ -56,5 +65,10 @@ private void OnKeyPress(object sender, KeyPressEventArgs e)
OnKeyPressed?.Invoke(sender, e);
}

private void OnKeyRelease(object sender, KeyEventArgs e)
{
OnKeyReleased?.Invoke(sender, e);
}

}
}
Loading

0 comments on commit 73469c7

Please sign in to comment.