Skip to content

Commit

Permalink
JoystickBase: make lost joystick overrideable
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Feb 15, 2024
1 parent 93d827f commit af5a687
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 35 deletions.
83 changes: 49 additions & 34 deletions ExtLibs/ArduPilot/Joystick/JoystickBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ public abstract class JoystickBase: IDisposable

private Func<MAVLinkInterface> _Interface;

private Action _LostAction;

protected SynchronizationContext _context;

protected MAVLinkInterface Interface
{
get { return _Interface(); }
}

public Action LostAction
{
get { if(_LostAction != null) return _LostAction; return delegate () { }; }
set { _LostAction = value; }
}

public JoystickBase(Func<MAVLinkInterface> currentInterface)
{
this._Interface = currentInterface;
Expand Down Expand Up @@ -84,6 +92,14 @@ public JoystickBase(Func<MAVLinkInterface> currentInterface)
{
loadconfig();
}

_LostAction = new Action(delegate
{
_context.Send(delegate
{
CustomMessageBox.Show("Lost Joystick", "Lost Joystick");
}, null);
});
}

public void loadconfig(string joystickconfigbuttonin = "joystickbuttons.xml",
Expand Down Expand Up @@ -604,38 +620,38 @@ void ProcessButtonEvent(JoyButton but, bool buttondown)
const int RESXul = 1024;
const int RESXl = 1024;
const int RESKul = 100;
/*
ushort expou(ushort x, ushort k)
{
// k*x*x*x + (1-k)*x
return ((ulong)x*x*x/0x10000*k/(RESXul*RESXul/0x10000) + (RESKul-k)*x+RESKul/2)/RESKul;
}
// expo-funktion:
// ---------------
// kmplot
// f(x,k)=exp(ln(x)*k/10) ;P[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
// f(x,k)=x*x*x*k/10 + x*(1-k/10) ;P[0,1,2,3,4,5,6,7,8,9,10]
// f(x,k)=x*x*k/10 + x*(1-k/10) ;P[0,1,2,3,4,5,6,7,8,9,10]
// f(x,k)=1+(x-1)*(x-1)*(x-1)*k/10 + (x-1)*(1-k/10) ;P[0,1,2,3,4,5,6,7,8,9,10]
short expo(short x, short k)
{
if (k == 0) return x;
short y;
bool neg = x < 0;
if (neg) x = -x;
if (k < 0)
{
y = RESXu - expou((ushort)(RESXu - x), (ushort)-k);
}
else
{
y = expou((ushort)x, (ushort)k);
}
return neg ? -y : y;
}
/*
ushort expou(ushort x, ushort k)
{
// k*x*x*x + (1-k)*x
return ((ulong)x*x*x/0x10000*k/(RESXul*RESXul/0x10000) + (RESKul-k)*x+RESKul/2)/RESKul;
}
// expo-funktion:
// ---------------
// kmplot
// f(x,k)=exp(ln(x)*k/10) ;P[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
// f(x,k)=x*x*x*k/10 + x*(1-k/10) ;P[0,1,2,3,4,5,6,7,8,9,10]
// f(x,k)=x*x*k/10 + x*(1-k/10) ;P[0,1,2,3,4,5,6,7,8,9,10]
// f(x,k)=1+(x-1)*(x-1)*(x-1)*k/10 + (x-1)*(1-k/10) ;P[0,1,2,3,4,5,6,7,8,9,10]
short expo(short x, short k)
{
if (k == 0) return x;
short y;
bool neg = x < 0;
if (neg) x = -x;
if (k < 0)
{
y = RESXu - expou((ushort)(RESXu - x), (ushort)-k);
}
else
{
y = expou((ushort)x, (ushort)k);
}
return neg ? -y : y;
}
*/


Expand Down Expand Up @@ -1113,8 +1129,7 @@ protected virtual void mainloop()
{
log.Error(ex);
clearRCOverride();
_context.Send(
delegate { CustomMessageBox.Show("Lost Joystick", "Lost Joystick"); }, null);
LostAction();
return;
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion build - Clean.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set PATH=%PATH%;C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin;C:\Program Files (x86)\Microsoft Visual Studio\Preview\Community\MSBuild\15.0\Bin;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin
set PATH=%PATH%;C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin;C:\Program Files (x86)\Microsoft Visual Studio\Preview\Community\MSBuild\15.0\Bin;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin

"MSBuild.exe" MissionPlanner.sln /m /p:Configuration=Debug /verbosity:d /t:Clean
"MSBuild.exe" MissionPlanner.sln /m /p:Configuration=Release /verbosity:d /t:Clean
Expand Down

0 comments on commit af5a687

Please sign in to comment.