Skip to content

Commit

Permalink
Merge pull request #936 from CasperH2O/EAtoPublic
Browse files Browse the repository at this point in the history
EA to public
  • Loading branch information
CasperH2O authored Jan 12, 2024
2 parents c93e725 + 5ebcf59 commit 0293646
Show file tree
Hide file tree
Showing 150 changed files with 30,461 additions and 26,552 deletions.
1,180 changes: 583 additions & 597 deletions HandheldCompanion.iss

Large diffs are not rendered by default.

Binary file added HandheldCompanion/ADLX_3DSettings.dll
Binary file not shown.
Binary file added HandheldCompanion/ADLX_DisplaySettings.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion HandheldCompanion/Actions/AxisActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class AxisActions : GyroActions

public AxisActions()
{
this.ActionType = ActionType.Joystick;
this.actionType = ActionType.Joystick;
this.Value = new Vector2();
}

Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Actions/ButtonActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ButtonActions : IActions

public ButtonActions()
{
this.ActionType = ActionType.Button;
this.actionType = ActionType.Button;

this.Value = false;
this.prevValue = false;
Expand Down
217 changes: 208 additions & 9 deletions HandheldCompanion/Actions/IActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public enum ActionType
Special = 6,
}

[Serializable]
public enum ActionState
{
Stopped = 0,
Running = 1,
Aborted = 2,
Succeed = 3,
Suspended = 4,
Forced = 5,
}

[Serializable]
public enum ModifierSet
{
Expand All @@ -36,7 +47,9 @@ public enum ModifierSet
public enum PressType
{
Short = 0,
Long = 1,
Long = 1, // hold for x ms and get an action
Hold = 2, // press and hold the command for x ms
Double = 3,
}

[Serializable]
Expand Down Expand Up @@ -71,15 +84,17 @@ public abstract class IActions : ICloneable
{ ModifierSet.ShiftControlAlt, new KeyCode[] { KeyCode.LShift, KeyCode.LControl, KeyCode.LMenu } },
};

public ActionType ActionType = ActionType.Disabled;
public ActionType actionType = ActionType.Disabled;
public PressType pressType = PressType.Short;
public ActionState actionState = ActionState.Stopped;

protected object Value;
protected object prevValue;

// TODO: multiple delay, delay ranges
public PressType PressType = PressType.Short;
public int LongPressTime = 450; // default value for steam
protected int pressTimer = -1; // -1 inactive, >= 0 active
public int ActionTimer = 200; // default value for steam
public int pressTimer = -1; // -1 inactive, >= 0 active

private int pressCount = 0; // used to store previous press value for double tap

public bool Turbo;
public int TurboDelay = 30;
Expand All @@ -89,6 +104,8 @@ public abstract class IActions : ICloneable
public bool Toggle;
protected bool IsToggled;

public bool Interruptable = true;

public HapticMode HapticMode = HapticMode.Off;
public HapticStrength HapticStrength = HapticStrength.Low;

Expand All @@ -110,21 +127,203 @@ public virtual void SetHaptic(ButtonFlags button, bool up)

public virtual void Execute(ButtonFlags button, bool value)
{
switch(PressType)
if (actionState == ActionState.Suspended)
{
// bypass output
this.Value = false;
this.prevValue = value;
return;
}
else if (actionState == ActionState.Forced)
{
// bypass output
value = true;
}

switch (pressType)
{
case PressType.Long:
{
if (value || (pressTimer <= LongPressTime && pressTimer >= 0))
if (value)
{
// update state
actionState = ActionState.Running;

// update timer
pressTimer += TimerManager.GetPeriod();

if (pressTimer >= ActionTimer)
{
// update state
actionState = ActionState.Succeed;
}
else
{
// bypass output
this.Value = false;
this.prevValue = value;
return;
}
}
else
{
// key was released too early
if (actionState == ActionState.Running)
{
// update state
actionState = ActionState.Aborted;

// update timer
pressTimer = Math.Max(50, pressTimer);
}
else if (actionState == ActionState.Succeed)
{
// update state
actionState = ActionState.Stopped;

// update timer
pressTimer = -1;
}
else if (actionState == ActionState.Stopped)
{
// update timer
pressTimer = -1;
}

if (actionState == ActionState.Aborted)
{
// set to aborted for a time equal to the actions was "running"
if (pressTimer >= 0)
{
// update state
actionState = ActionState.Aborted;

// update timer
pressTimer -= TimerManager.GetPeriod();
}
else
{
// update state
actionState = ActionState.Stopped;

// update timer
pressTimer = -1;
}
}
}
}
break;

case PressType.Hold:
{
if (value || (pressTimer <= ActionTimer && pressTimer >= 0))
{
// update state
actionState = ActionState.Running;

// update timer
pressTimer += TimerManager.GetPeriod();

// bypass output (simple)
value = true;
}
else if(pressTimer >= LongPressTime)
else if (pressTimer >= ActionTimer)
{
// update state
actionState = ActionState.Stopped;

// reset var(s)
pressTimer = -1;
}
}
break;

case PressType.Double:
{
if (value)
{
// increase press count
if ((bool)prevValue != value)
pressCount++;
}

switch (pressCount)
{
default:
{
if (actionState != ActionState.Stopped)
{
// update timer
pressTimer += TimerManager.GetPeriod();

if (pressTimer >= 50)
{
// update state
actionState = ActionState.Stopped;

// reset var(s)
pressCount = 0;
pressTimer = 0;
}
}

// bypass output
this.Value = false;
this.prevValue = value;
return;
}

case 1:
{
// update state
actionState = ActionState.Running;

// update timer
pressTimer += TimerManager.GetPeriod();

// too slow to press again ?
if (pressTimer > ActionTimer)
{
// update state
actionState = ActionState.Aborted;

// reset var(s)
pressCount = 0;
pressTimer = 0;
}

// bypass output
this.Value = false;
this.prevValue = value;
return;
}

case 2:
{
// on time
if (pressTimer <= ActionTimer && value)
{
// update state
actionState = ActionState.Succeed;

// reset var(s)
pressCount = 2;
pressTimer = ActionTimer;
}
else
{
// update state
actionState = ActionState.Stopped;

// reset var(s)
pressCount = 0;
pressTimer = 0;
}
}
break;
}
}
break;
}

if (Toggle)
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Actions/KeyboardActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class KeyboardActions : IActions

public KeyboardActions()
{
this.ActionType = ActionType.Keyboard;
this.actionType = ActionType.Keyboard;

this.Value = false;
this.prevValue = false;
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Actions/MouseActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class MouseActions : GyroActions

public MouseActions()
{
this.ActionType = ActionType.Mouse;
this.actionType = ActionType.Mouse;

this.Value = false;
this.prevValue = false;
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Actions/SpecialActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SpecialActions : IActions

public SpecialActions()
{
this.ActionType = ActionType.Special;
this.actionType = ActionType.Special;
}

public SpecialActions(SpecialActionsType type) : this()
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Actions/TriggerActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TriggerActions : IActions

public TriggerActions()
{
this.ActionType = ActionType.Trigger;
this.actionType = ActionType.Trigger;
this.Value = (short)0;
}

Expand Down
12 changes: 9 additions & 3 deletions HandheldCompanion/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@
<setting name="PlatformRTSSEnabled" serializeAs="String">
<value>True</value>
</setting>
<setting name="PlatformHWiNFOEnabled" serializeAs="String">
<value>True</value>
</setting>
<setting name="QuickToolsLocation" serializeAs="String">
<value>3</value>
</setting>
Expand Down Expand Up @@ -227,6 +224,9 @@
<setting name="LEDAmbilightVerticalBlackBarDetection" serializeAs="String">
<value>False</value>
</setting>
<setting name="LEDUseSecondColor" serializeAs="String">
<value>False</value>
</setting>
<setting name="LEDSettingsLevel" serializeAs="String">
<value>0</value>
</setting>
Expand All @@ -245,6 +245,12 @@
<setting name="LegionControllerPassthrough" serializeAs="String">
<value>False</value>
</setting>
<setting name="OnScreenDisplayToggle" serializeAs="String">
<value>False</value>
</setting>
<setting name="LastOnScreenDisplayLevel" serializeAs="String">
<value>2</value>
</setting>
</HandheldCompanion.Properties.Settings>
</userSettings>
</configuration>
4 changes: 4 additions & 0 deletions HandheldCompanion/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@

<math:MathConverter x:Key="Math" />

<Style BasedOn="{StaticResource {x:Static ui:ThemeKeys.ExpanderCardStyleKey}}" TargetType="Expander">
<Setter Property="HorizontalAlignment" Value="Stretch" />
</Style>

</ResourceDictionary>
</Application.Resources>
</Application>
5 changes: 0 additions & 5 deletions HandheldCompanion/Controllers/DS4Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ public override void SetLightColor(byte R, byte G, byte B)
});
}

public override void Cleanup()
{
TimerManager.Tick -= UpdateInputs;
}

public override string GetGlyph(ButtonFlags button)
{
switch (button)
Expand Down
5 changes: 0 additions & 5 deletions HandheldCompanion/Controllers/DualSenseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ public override void SetLightColor(byte R, byte G, byte B)
});
}

public override void Cleanup()
{
TimerManager.Tick -= UpdateInputs;
}

public override string GetGlyph(ButtonFlags button)
{
switch (button)
Expand Down
Loading

0 comments on commit 0293646

Please sign in to comment.