Skip to content

Commit

Permalink
Merge pull request #214 from calibx/develop
Browse files Browse the repository at this point in the history
December fixes
  • Loading branch information
calibx committed Dec 19, 2022
2 parents ad135a1 + e4a1590 commit edc85b5
Show file tree
Hide file tree
Showing 12 changed files with 351 additions and 85 deletions.
4 changes: 4 additions & 0 deletions MsfsPlugin/MsfsPlugin/MsfsPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="folder\AirlinerDynamicFolder.cs" />
<Compile Include="folder\APDynamicFolder.cs" />
<Compile Include="folder\ATCDynamicFolder.cs" />
<Compile Include="folder\NavDynamicFolder.cs" />
<Compile Include="folder\ComDynamicSFolder.cs" />
<Compile Include="folder\ComDynamicFolder.cs" />
<Compile Include="folder\LightsDynamicFolder.cs" />
Expand Down Expand Up @@ -131,6 +132,9 @@
<EmbeddedResource Include="Resources\DefaultProfile30win.lp4" />
<EmbeddedResource Include="Resources\DefaultProfile40win.lp4" />
<EmbeddedResource Include="Resources\DefaultProfile50win.lp4" />
<None Include="Resources\LoupedeckPackageRazor.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Resources\LoupedeckPackage.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 1 addition & 1 deletion MsfsPlugin/MsfsPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("4.3.0.7478")]
[assembly: AssemblyVersion("2.3.0")]
[assembly: AssemblyVersion("2.4.0")]
5 changes: 2 additions & 3 deletions MsfsPlugin/MsfsPlugin/Resources/LoupedeckPackage.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
type: plugin4
name: MSFS
displayName: Microsoft Flight Simulator
version: 2.3.0
version: 2.4.0
author: CaliBx
copyright: CaliBx

supportedDevices:
- LoupedeckCt
- LoupedeckLive
- LoupedeckLiveS
- RazorStreamController

- RazerStreamController


pluginFileName: MSFSPlugin.dll
Expand Down
20 changes: 20 additions & 0 deletions MsfsPlugin/MsfsPlugin/Resources/LoupedeckPackageRazor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
type: plugin4
name: MSFS
displayName: Microsoft Flight Simulator
version: 2.4.0
author: CaliBx
copyright: CaliBx

supportedDevices:
- LoupedeckCt
- LoupedeckLive
- LoupedeckLiveS
- RazerStreamController


pluginFileName: MSFSPlugin.dll
pluginFolderWin: ./bin/win/
license: Apache-2.0 license
licenseUrl: http://www.apache.org/licenses/
homePageUrl: https://github.com/calibx/msfsdeck
supportPageUrl: https://github.com/calibx/msfsdeck/discussions
9 changes: 5 additions & 4 deletions MsfsPlugin/MsfsPlugin/encoder/SimRateEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@

class SimRateEncoder : DefaultEncoder
{
public SimRateEncoder() : base("Sim Rate", "Simulation rate encoder", "Misc", true, 0, 128, 1) => this._bindings.Add(MsfsData.Instance.Register(new Binding(BindingKeys.SIM_RATE)));
public SimRateEncoder() : base("Sim Rate", "Simulation rate encoder", "Misc", true, 0, 12800, 100) => this._bindings.Add(MsfsData.Instance.Register(new Binding(BindingKeys.SIM_RATE)));
protected override void RunCommand(String actionParameter) => this.SetValue(0);
protected override Int64 GetValue() => this._bindings[0].ControllerValue;
protected override String GetDisplayValue() => this._bindings[0].ControllerValue.ToString();
protected override String GetDisplayValue() => (this._bindings[0].ControllerValue / 100f).ToString();
protected override void SetValue(Int64 newValue) => this._bindings[0].SetControllerValue(newValue);
protected override void ApplyAdjustment(String actionParameter, Int32 ticks)
{
if (ticks > 0)
{
var newValue = this.GetValue() * 2;
this.SetValue(newValue > 128 ? 128 : newValue);
this.SetValue(newValue > 12800 ? 12800 : newValue);
} else
{
this.SetValue(this.GetValue() / 2);
var newValue = this.GetValue() / 2;
this.SetValue(newValue < 25 ? 25 : newValue);
}
this.ActionImageChanged();
}
Expand Down
8 changes: 8 additions & 0 deletions MsfsPlugin/MsfsPlugin/event/BindingKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ public enum BindingKeys
ICON_SIZE,
SIM_RATE,
SPOILERS_ARM,
NAV1_ACTIVE_FREQUENCY,
NAV2_ACTIVE_FREQUENCY,
NAV1_STBY_FREQUENCY,
NAV2_STBY_FREQUENCY,
NAV1_AVAILABLE,
NAV2_AVAILABLE,
NAV1_RADIO_SWAP,
NAV2_RADIO_SWAP,
}
}

2 changes: 2 additions & 0 deletions MsfsPlugin/MsfsPlugin/folder/APDynamicFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.Collections.Generic;
using System.Diagnostics;

using Loupedeck.MsfsPlugin.tools;

Expand Down Expand Up @@ -95,6 +96,7 @@ public override String GetAdjustmentDisplayName(String actionParameter, PluginIm
}
public override BitmapImage GetCommandImage(String actionParameter, PluginImageSize imageSize)
{
Debug.WriteLine(actionParameter);
var bitmapBuilder = new BitmapBuilder(imageSize);
switch (actionParameter)
{
Expand Down
135 changes: 65 additions & 70 deletions MsfsPlugin/MsfsPlugin/folder/ComDynamicSFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class ComDynamicSFolder : PluginDynamicFolder, Notifiable
{
protected readonly List<Binding> _bindings = new List<Binding>();
private Boolean isCom1active = true;
public ComDynamicSFolder()
{
this.DisplayName = "COM (for S)";
Expand All @@ -23,30 +24,20 @@ public ComDynamicSFolder()
this._bindings.Add(MsfsData.Instance.Register(new Binding(BindingKeys.COM2_AVAILABLE)));
this._bindings.Add(MsfsData.Instance.Register(new Binding(BindingKeys.COM1_RADIO_SWAP)));
this._bindings.Add(MsfsData.Instance.Register(new Binding(BindingKeys.COM2_RADIO_SWAP)));

MsfsData.Instance.Register(this);

}
public override PluginDynamicFolderNavigation GetNavigationArea(DeviceType _) => PluginDynamicFolderNavigation.None;
public override PluginDynamicFolderNavigation GetNavigationArea(DeviceType _) => PluginDynamicFolderNavigation.EncoderArea;
public override IEnumerable<String> GetButtonPressActionNames(DeviceType deviceType)
{
return new[]
{
this.CreateCommandName("COM1"),
this.CreateCommandName("COM1 Active Int"),
this.CreateCommandName("COM1 Active Float"),
this.CreateCommandName("COM1 Standby Int"),
this.CreateCommandName("COM1 Standby Float"),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName(""),
this.CreateCommandName("COM2"),
this.CreateCommandName("COM2 Active Int"),
this.CreateCommandName("COM2 Active Float"),
this.CreateCommandName("COM2 Standby Int"),
Expand All @@ -58,54 +49,63 @@ public override IEnumerable<String> GetEncoderRotateActionNames(DeviceType devic
{
return new[]
{
this.CreateAdjustmentName ("COM1 Int Encoder"),
this.CreateAdjustmentName ("COM2 Int Encoder"),
this.CreateAdjustmentName (""),
this.CreateAdjustmentName ("COM1 Float Encoder"),
this.CreateAdjustmentName ("COM2 Float Encoder"),
this.CreateAdjustmentName ("Int"),
this.CreateAdjustmentName ("Float"),
};
}

public override IEnumerable<String> GetEncoderPressActionNames(DeviceType deviceType)
{
return new[]
{
this.CreateCommandName("COM1 Int Reset"),
this.CreateCommandName("COM2 Int Reset"),
this.CreateCommandName (""),
this.CreateCommandName("COM1 Float Reset"),
this.CreateCommandName("COM2 Float Reset"),
this.CreateCommandName("Int Reset"),
this.CreateCommandName("Float Reset"),
};
}
public override String GetAdjustmentDisplayName(String actionParameter, PluginImageSize imageSize)
{
Debug.WriteLine(actionParameter);

var bindingIndex = this.isCom1active ? 2 : 3;
var ret = "";
switch (actionParameter)
{
case "COM1 Int Encoder":
ret = "COM1\n" + Math.Truncate(this._bindings[2].ControllerValue / 1000000f) + ".";
break;
case "COM1 Float Encoder":
var com1dbl = Math.Round(this._bindings[2].ControllerValue / 1000000f - Math.Truncate(this._bindings[2].ControllerValue / 1000000f), 3).ToString();
ret = "COM1\n" + (com1dbl.Length > 2 ? com1dbl.Substring(2) : com1dbl).PadRight(3, '0');
case "Int":
ret = "COM\n" + Math.Truncate(this._bindings[bindingIndex].ControllerValue / 1000000f) + ".";
break;
case "COM2 Int Encoder":
ret = "COM2\n" + Math.Truncate(this._bindings[3].ControllerValue / 1000000f) + ".";
break;
case "COM2 Float Encoder":
var com2dbl = Math.Round(this._bindings[3].ControllerValue / 1000000f - Math.Truncate(this._bindings[3].ControllerValue / 1000000f), 3).ToString();
ret = "COM2\n" + (com2dbl.Length > 2 ? com2dbl.Substring(2) : com2dbl).PadRight(3, '0');
case "Float":
var com1dbl = Math.Round(this._bindings[bindingIndex].ControllerValue / 1000000f - Math.Truncate(this._bindings[bindingIndex].ControllerValue / 1000000f), 3).ToString();
ret = "COM\n" + (com1dbl.Length > 2 ? com1dbl.Substring(2) : com1dbl).PadRight(3, '0');
break;
}
return ret;
}
public override BitmapImage GetCommandImage(String actionParameter, PluginImageSize imageSize)
{
var bitmapBuilder = new BitmapBuilder(imageSize);
Debug.WriteLine(actionParameter);

switch (actionParameter)
{
case "COM1":
bitmapBuilder.SetBackgroundImage(ImageTool.GetAvailableDisableImage(this._bindings[4].MsfsValue));
if (this.isCom1active)
{
bitmapBuilder.DrawText("=> COM1");
} else
{
bitmapBuilder.DrawText("COM1");
}

break;
case "COM2":
bitmapBuilder.SetBackgroundImage(ImageTool.GetAvailableDisableImage(this._bindings[5].MsfsValue));
if (!this.isCom1active)
{
bitmapBuilder.DrawText("=> COM2");
} else
{
bitmapBuilder.DrawText("COM2");
}
break;
case "COM1 Active Int":
bitmapBuilder.SetBackgroundImage(ImageTool.GetAvailableDisableImage(this._bindings[4].MsfsValue));
bitmapBuilder.DrawText((this._bindings[0].ControllerValue == 0 ? "0" : this._bindings[0].ControllerValue.ToString().Substring(0, 3)) + ".", new BitmapColor(0, 255, 0), 40);
Expand Down Expand Up @@ -138,7 +138,6 @@ public override BitmapImage GetCommandImage(String actionParameter, PluginImageS
bitmapBuilder.SetBackgroundImage(ImageTool.GetAvailableDisableImage(this._bindings[5].MsfsValue));
bitmapBuilder.DrawText(this._bindings[3].ControllerValue == 0 ? "0" : this._bindings[3].ControllerValue.ToString().Substring(3, 3), new BitmapColor(255, 255, 0), 40);
break;

}
return bitmapBuilder.ToImage();
}
Expand All @@ -147,59 +146,55 @@ public override void RunCommand(String actionParameter)
{
switch (actionParameter)
{
case "COM1 Active":
case "COM1":
this.isCom1active = true;
break;
case "COM2":
this.isCom1active = false;
break;
case "COM1 Active Int":
case "COM1 Active Float":
case "COM1 Standby":
case "COM1 Standby Int":
case "COM1 Standby Float":
case "COM1 Int Reset":
case "COM1 Float Reset":
this._bindings[4].SetControllerValue(1);
this._bindings[6].SetControllerValue(1);
break;
case "COM2 Active":
case "COM2 Active Int":
case "COM2 Active Float":
case "COM2 Standby":
case "COM2 Standby Int":
case "COM2 Standby Float":
case "COM2 Int Reset":
case "COM2 Float Reset":
this._bindings[5].SetControllerValue(1);
this._bindings[7].SetControllerValue(1);
break;
case "Int Reset":
case "Float Reset":
if (this.isCom1active)
{
this._bindings[6].SetControllerValue(1);
} else
{
this._bindings[7].SetControllerValue(1);
}
break;

}
}

public override void ApplyAdjustment(String actionParameter, Int32 ticks)
{
var bindingIndex = this.isCom1active ? 2 : 3;
Debug.WriteLine(actionParameter);
switch (actionParameter)
{
case "COM1 Int Encoder":
var com1int = Int32.Parse(this._bindings[2].ControllerValue.ToString().Substring(0, 3));
var com1dbl = Int32.Parse(this._bindings[2].ControllerValue.ToString().Substring(3, 3));
case "Int":
var com1int = Int32.Parse(this._bindings[bindingIndex].ControllerValue.ToString().Substring(0, 3));
var com1dbl = Int32.Parse(this._bindings[bindingIndex].ControllerValue.ToString().Substring(3, 3));
var newInt = ConvertTool.ApplyAdjustment(com1int, ticks, 118, 136, 1, true);
this._bindings[2].SetControllerValue(newInt * 1000000 + com1dbl * 1000);
this._bindings[bindingIndex].SetControllerValue(newInt * 1000000 + com1dbl * 1000);
break;
case "COM1 Float Encoder":
var com1dbl1 = Int32.Parse(this._bindings[2].ControllerValue.ToString().Substring(3, 3));
var com1int1 = Int32.Parse(this._bindings[2].ControllerValue.ToString().Substring(0, 3));
case "Float":
var com1dbl1 = Int32.Parse(this._bindings[bindingIndex].ControllerValue.ToString().Substring(3, 3));
var com1int1 = Int32.Parse(this._bindings[bindingIndex].ControllerValue.ToString().Substring(0, 3));
var newFloat = ConvertTool.ApplyAdjustment(com1dbl1, ticks, 0, 995, 5, true);
this._bindings[2].SetControllerValue(com1int1 * 1000000 + newFloat * 1000);
break;
case "COM2 Int Encoder":
var com2int = Int32.Parse(this._bindings[3].ControllerValue.ToString().Substring(0, 3));
var com2dbl = Int32.Parse(this._bindings[3].ControllerValue.ToString().Substring(3, 3));
var newInt2 = ConvertTool.ApplyAdjustment(com2int, ticks, 118, 136, 1, true);
this._bindings[3].SetControllerValue(newInt2 * 1000000 + com2dbl * 1000);
this._bindings[bindingIndex].SetControllerValue(com1int1 * 1000000 + newFloat * 1000);
break;
case "COM2 Float Encoder":
var com2dbl2 = Int32.Parse(this._bindings[3].ControllerValue.ToString().Substring(3, 3));
var com2int2 = Int32.Parse(this._bindings[3].ControllerValue.ToString().Substring(0, 3));
var newFloat2 = ConvertTool.ApplyAdjustment(com2dbl2, ticks, 0, 995, 5, true);
this._bindings[3].SetControllerValue(com2int2 * 1000000 + newFloat2 * 1000);
break;

}
this.EncoderActionNamesChanged();
this.ButtonActionNamesChanged();
Expand Down
Loading

0 comments on commit edc85b5

Please sign in to comment.