2017-12-23 23:22:30 +00:00
|
|
|
|
using System;
|
2014-10-26 22:11:57 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-12-26 12:53:55 +00:00
|
|
|
|
using System.Linq;
|
2014-10-26 22:11:57 +00:00
|
|
|
|
using System.Xml;
|
2017-12-26 12:53:55 +00:00
|
|
|
|
using System.Xml.Linq;
|
2017-12-23 23:22:30 +00:00
|
|
|
|
using SCJMapper_V2.Actions;
|
|
|
|
|
using SCJMapper_V2.Devices.Joystick;
|
|
|
|
|
|
|
|
|
|
namespace SCJMapper_V2.Devices.Options
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// set of parameters to tune the Joystick
|
|
|
|
|
/// </summary>
|
2017-04-14 22:33:21 +00:00
|
|
|
|
public class DeviceTuningParameter : ICloneable
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
|
|
|
|
|
|
2017-04-14 22:33:21 +00:00
|
|
|
|
|
2017-01-11 23:13:48 +00:00
|
|
|
|
private string m_nodetext = ""; // v_pitch - js1_x
|
2016-12-30 01:04:21 +00:00
|
|
|
|
private string m_action = ""; // v_pitch
|
|
|
|
|
private string m_cmdCtrl = ""; // js1_x, js1_y, js1_rotz ...
|
2017-01-11 23:13:48 +00:00
|
|
|
|
private string m_class = ""; // joystick OR xboxpad
|
2014-12-22 00:34:09 +00:00
|
|
|
|
private int m_devInstanceNo = -1; // jsN - instance in XML
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
string m_option = ""; // the option name (level where it applies)
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
private string m_deviceName = "";
|
2017-12-26 12:53:55 +00:00
|
|
|
|
private bool m_isStrafe = false; // default
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2017-12-26 12:53:55 +00:00
|
|
|
|
private bool m_expEnabled = false; // default
|
2016-12-30 01:04:21 +00:00
|
|
|
|
private string m_exponent = "1.000";
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2017-12-26 12:53:55 +00:00
|
|
|
|
private bool m_ptsEnabled = false; // default
|
2016-12-30 01:04:21 +00:00
|
|
|
|
private List<string> m_PtsIn = new List<string>( );
|
|
|
|
|
private List<string> m_PtsOut = new List<string>( );
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2017-12-26 12:53:55 +00:00
|
|
|
|
private bool m_invertEnabled = false; // default
|
2015-04-26 21:14:56 +00:00
|
|
|
|
|
2017-04-14 22:33:21 +00:00
|
|
|
|
private DeviceCls m_deviceRef = null; // Ref
|
|
|
|
|
|
|
|
|
|
private DeviceOptionParameter m_deviceoptionRef = null; // will be used only while editing the Options !!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Clone this object
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A deep Clone of this object</returns>
|
2017-12-26 12:53:55 +00:00
|
|
|
|
public object Clone()
|
2017-04-14 22:33:21 +00:00
|
|
|
|
{
|
2017-12-26 12:53:55 +00:00
|
|
|
|
var dt = (DeviceTuningParameter)this.MemberwiseClone( ); // self and all value types
|
2017-04-14 22:33:21 +00:00
|
|
|
|
// more objects to deep copy
|
|
|
|
|
// --> NO cloning as this Ref will be overwritten when editing
|
|
|
|
|
dt.m_deviceoptionRef = null; // just reset
|
|
|
|
|
|
|
|
|
|
return dt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Check clone against This
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="clone"></param>
|
|
|
|
|
/// <returns>True if the clone is identical but not a shallow copy</returns>
|
|
|
|
|
internal bool CheckClone( DeviceTuningParameter clone )
|
|
|
|
|
{
|
|
|
|
|
bool ret = true;
|
|
|
|
|
// object vars first
|
|
|
|
|
ret &= ( this.m_nodetext == clone.m_nodetext ); // immutable string - shallow copy is OK
|
|
|
|
|
ret &= ( this.m_action == clone.m_action ); // immutable string - shallow copy is OK
|
|
|
|
|
ret &= ( this.m_cmdCtrl == clone.m_cmdCtrl );// immutable string - shallow copy is OK
|
|
|
|
|
ret &= ( this.m_class == clone.m_class ); // immutable string - shallow copy is OK
|
|
|
|
|
ret &= ( this.m_devInstanceNo == clone.m_devInstanceNo );
|
|
|
|
|
ret &= ( this.m_option == clone.m_option );
|
|
|
|
|
ret &= ( this.m_deviceName == clone.m_deviceName );
|
|
|
|
|
ret &= ( this.m_isStrafe == clone.m_isStrafe );
|
|
|
|
|
ret &= ( this.m_expEnabled == clone.m_expEnabled );
|
|
|
|
|
ret &= ( this.m_exponent == clone.m_exponent );
|
|
|
|
|
ret &= ( this.m_ptsEnabled == clone.m_ptsEnabled );
|
|
|
|
|
ret &= ( this.m_PtsIn == clone.m_PtsIn );
|
|
|
|
|
ret &= ( this.m_PtsOut == clone.m_PtsOut );
|
|
|
|
|
ret &= ( this.m_invertEnabled == clone.m_invertEnabled );
|
|
|
|
|
ret &= ( this.m_deviceRef == clone.m_deviceRef );
|
|
|
|
|
|
|
|
|
|
// check m_deviceoptionRef
|
|
|
|
|
// --> NO check as this is assigned and used only while editing the Options
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2014-12-20 20:15:45 +00:00
|
|
|
|
|
2017-01-11 23:13:48 +00:00
|
|
|
|
public DeviceTuningParameter( string optName )
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
2017-01-11 23:13:48 +00:00
|
|
|
|
m_option = optName;
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 22:33:21 +00:00
|
|
|
|
public DeviceTuningParameter( string optName, DeviceCls device )
|
|
|
|
|
{
|
|
|
|
|
m_option = optName;
|
|
|
|
|
GameDevice = device;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-26 22:11:57 +00:00
|
|
|
|
#region Properties
|
|
|
|
|
|
2014-11-19 22:58:05 +00:00
|
|
|
|
public DeviceCls GameDevice
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
2017-04-14 22:33:21 +00:00
|
|
|
|
get { return m_deviceRef; }
|
2016-12-30 01:04:21 +00:00
|
|
|
|
set {
|
2017-04-14 22:33:21 +00:00
|
|
|
|
m_deviceRef = value;
|
2017-01-11 23:13:48 +00:00
|
|
|
|
m_class = "";
|
2014-11-18 22:50:35 +00:00
|
|
|
|
m_devInstanceNo = -1;
|
2017-04-14 22:33:21 +00:00
|
|
|
|
if ( m_deviceRef == null ) return; // got a null device
|
|
|
|
|
|
|
|
|
|
m_class = m_deviceRef.DevClass;
|
|
|
|
|
m_devInstanceNo = m_deviceRef.XmlInstance;
|
2014-12-22 00:34:09 +00:00
|
|
|
|
}
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-11-18 22:50:35 +00:00
|
|
|
|
public int DevInstanceNo
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
2014-11-18 22:50:35 +00:00
|
|
|
|
get { return m_devInstanceNo; }
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
public string DeviceName
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
|
|
|
|
get { return m_deviceName; }
|
|
|
|
|
set { m_deviceName = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 23:13:48 +00:00
|
|
|
|
public string DeviceClass
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
2017-01-11 23:13:48 +00:00
|
|
|
|
get { return m_class; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string OptionName
|
|
|
|
|
{
|
|
|
|
|
get { return m_option; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string NodeText
|
|
|
|
|
{
|
|
|
|
|
get { return m_nodetext; }
|
|
|
|
|
set { m_nodetext = value; DecomposeCommand( ); }
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
public string CommandCtrl
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
|
|
|
|
get { return m_cmdCtrl; }
|
|
|
|
|
set { m_cmdCtrl = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
public bool IsStrafeCommand
|
|
|
|
|
{
|
|
|
|
|
get { return m_isStrafe; }
|
|
|
|
|
set { m_isStrafe = value; }
|
|
|
|
|
}
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2017-04-14 22:33:21 +00:00
|
|
|
|
public DeviceOptionParameter DeviceoptionRef
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
2017-04-14 22:33:21 +00:00
|
|
|
|
get { return m_deviceoptionRef; }
|
2016-12-30 01:04:21 +00:00
|
|
|
|
set {
|
2017-04-14 22:33:21 +00:00
|
|
|
|
m_deviceoptionRef = value;
|
|
|
|
|
if ( m_deviceoptionRef != null )
|
|
|
|
|
m_deviceoptionRef.Action = m_action;
|
2015-01-13 23:04:04 +00:00
|
|
|
|
}
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool InvertUsed
|
|
|
|
|
{
|
2015-04-26 21:14:56 +00:00
|
|
|
|
get { return m_invertEnabled; }
|
|
|
|
|
set { m_invertEnabled = value; }
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ExponentUsed
|
|
|
|
|
{
|
|
|
|
|
get { return m_expEnabled; }
|
|
|
|
|
set { m_expEnabled = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
public string Exponent
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
|
|
|
|
get { return m_exponent; }
|
|
|
|
|
set { m_exponent = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool NonLinCurveUsed
|
|
|
|
|
{
|
|
|
|
|
get { return m_ptsEnabled; }
|
|
|
|
|
set { m_ptsEnabled = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
public List<string> NonLinCurvePtsIn
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
|
|
|
|
get { return m_PtsIn; }
|
|
|
|
|
set { m_PtsIn = value; }
|
|
|
|
|
}
|
2016-12-30 01:04:21 +00:00
|
|
|
|
public List<string> NonLinCurvePtsOut
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
|
|
|
|
get { return m_PtsOut; }
|
|
|
|
|
set { m_PtsOut = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2017-05-06 00:20:42 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Reset all items that will be assigned dynamically while scanning the actions
|
|
|
|
|
/// - currently DeviceoptionRef, NodeText
|
|
|
|
|
/// </summary>
|
2017-12-26 12:53:55 +00:00
|
|
|
|
public void ResetDynamicItems()
|
2014-12-28 17:58:20 +00:00
|
|
|
|
{
|
2017-05-06 00:20:42 +00:00
|
|
|
|
// using the public property to ensure the complete processing of the assignment
|
|
|
|
|
// GameDevice = null;
|
2017-04-14 22:33:21 +00:00
|
|
|
|
DeviceoptionRef = null;
|
2017-01-11 23:13:48 +00:00
|
|
|
|
NodeText = "";
|
2014-12-28 17:58:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 12:53:55 +00:00
|
|
|
|
public void AssignDynamicItems( DeviceCls dev, DeviceOptionParameter devOptionRef, string nodeText )
|
2017-05-06 00:20:42 +00:00
|
|
|
|
{
|
|
|
|
|
// using the public property to ensure the complete processing of the assignment
|
|
|
|
|
NodeText = nodeText; // must be first - the content is used later for DeviceOptionRef assignment
|
|
|
|
|
GameDevice = dev;
|
|
|
|
|
DeviceoptionRef = devOptionRef;
|
|
|
|
|
}
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Derive values from a command (e.g. v_pitch - js1_x)
|
|
|
|
|
/// </summary>
|
2017-12-26 12:53:55 +00:00
|
|
|
|
private void DecomposeCommand()
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
2014-12-20 20:15:45 +00:00
|
|
|
|
// populate from input
|
2014-11-18 22:50:35 +00:00
|
|
|
|
// something like "v_pitch - js1_x" OR "v_pitch - xi_thumbl" OR "v_pitch - ximod+xi_thumbl+xi_mod"
|
2017-01-11 23:13:48 +00:00
|
|
|
|
string cmd = ActionTreeNode.CommandFromNodeText( NodeText );
|
|
|
|
|
m_action = ActionTreeNode.ActionFromNodeText( NodeText );
|
2014-11-18 22:50:35 +00:00
|
|
|
|
m_cmdCtrl = "";
|
2016-12-30 01:04:21 +00:00
|
|
|
|
if ( !string.IsNullOrWhiteSpace( cmd ) ) {
|
2014-11-18 22:50:35 +00:00
|
|
|
|
// decomp gamepad entries - could have modifiers so check for contains...
|
|
|
|
|
if ( cmd.Contains( "xi_thumblx" ) ) {
|
|
|
|
|
// gamepad
|
|
|
|
|
m_cmdCtrl = "xi_thumblx";
|
2017-04-14 22:33:21 +00:00
|
|
|
|
m_deviceName = m_deviceRef.DevName;
|
2017-12-26 12:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
else if ( cmd.Contains( "xi_thumbly" ) ) {
|
2014-11-18 22:50:35 +00:00
|
|
|
|
// gamepad
|
|
|
|
|
m_cmdCtrl = "xi_thumbly";
|
2017-04-14 22:33:21 +00:00
|
|
|
|
m_deviceName = m_deviceRef.DevName;
|
2017-12-26 12:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
else if ( cmd.Contains( "xi_thumbrx" ) ) {
|
2014-11-18 22:50:35 +00:00
|
|
|
|
// gamepad
|
|
|
|
|
m_cmdCtrl = "xi_thumbrx";
|
2017-04-14 22:33:21 +00:00
|
|
|
|
m_deviceName = m_deviceRef.DevName;
|
2017-12-26 12:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
else if ( cmd.Contains( "xi_thumbry" ) ) {
|
2014-11-18 22:50:35 +00:00
|
|
|
|
// gamepad
|
|
|
|
|
m_cmdCtrl = "xi_thumbry";
|
2017-04-14 22:33:21 +00:00
|
|
|
|
m_deviceName = m_deviceRef.DevName;
|
2014-11-18 22:50:35 +00:00
|
|
|
|
}
|
2017-12-26 12:53:55 +00:00
|
|
|
|
// assume joystick
|
|
|
|
|
else {
|
2014-11-18 22:50:35 +00:00
|
|
|
|
// get parts
|
|
|
|
|
m_cmdCtrl = JoystickCls.ActionFromJsCommand( cmd ); //js1_x -> x; js2_rotz -> rotz
|
2017-04-14 22:33:21 +00:00
|
|
|
|
m_deviceName = m_deviceRef.DevName;
|
2014-11-18 22:50:35 +00:00
|
|
|
|
}
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 22:33:21 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Rounds a string to 3 decimals (if it is a number..)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="valString">A value string</param>
|
|
|
|
|
/// <returns>A rounded value string - or the string if not a number</returns>
|
|
|
|
|
private string RoundString( string valString )
|
|
|
|
|
{
|
|
|
|
|
double d = 0;
|
|
|
|
|
if ( ( !string.IsNullOrEmpty( valString ) ) && double.TryParse( valString, out d ) ) {
|
|
|
|
|
return d.ToString( "0.000" );
|
2017-12-26 12:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2017-04-14 22:33:21 +00:00
|
|
|
|
return valString;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Format an XML -options- node from the tuning contents
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The XML string or an empty string</returns>
|
2017-12-26 12:53:55 +00:00
|
|
|
|
public string Options_toXML()
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
2016-12-30 01:04:21 +00:00
|
|
|
|
if ( ( /*SensitivityUsed ||*/ ExponentUsed || InvertUsed || NonLinCurveUsed ) == false ) return ""; // not used
|
2017-01-11 23:13:48 +00:00
|
|
|
|
if ( DevInstanceNo < 1 ) return ""; // no device to assign it to..
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
string tmp = "";
|
2017-01-11 23:13:48 +00:00
|
|
|
|
tmp += string.Format( "\t<options type=\"{0}\" instance=\"{1}\">\n", m_class, m_devInstanceNo.ToString( ) );
|
2016-12-30 01:04:21 +00:00
|
|
|
|
tmp += string.Format( "\t\t<{0} ", m_option );
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
|
|
|
|
if ( InvertUsed ) {
|
2016-12-30 01:04:21 +00:00
|
|
|
|
tmp += string.Format( "invert=\"1\" " );
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
2016-12-30 01:04:21 +00:00
|
|
|
|
/*
|
2014-10-26 22:11:57 +00:00
|
|
|
|
if ( SensitivityUsed ) {
|
2016-12-30 01:04:21 +00:00
|
|
|
|
tmp += string.Format( "sensitivity=\"{0}\" ", Sensitivity );
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
2016-12-30 01:04:21 +00:00
|
|
|
|
*/
|
2014-10-26 22:11:57 +00:00
|
|
|
|
if ( NonLinCurveUsed ) {
|
|
|
|
|
// add exp to avoid merge of things...
|
2016-12-30 01:04:21 +00:00
|
|
|
|
tmp += string.Format( "exponent=\"1.00\" > \n" ); // CIG get to default expo 2.something if not set to 1 here
|
|
|
|
|
tmp += string.Format( "\t\t\t<nonlinearity_curve>\n" );
|
|
|
|
|
tmp += string.Format( "\t\t\t\t<point in=\"{0}\" out=\"{1}\"/>\n", m_PtsIn[0], m_PtsOut[0] );
|
|
|
|
|
tmp += string.Format( "\t\t\t\t<point in=\"{0}\" out=\"{1}\"/>\n", m_PtsIn[1], m_PtsOut[1] );
|
|
|
|
|
tmp += string.Format( "\t\t\t\t<point in=\"{0}\" out=\"{1}\"/>\n", m_PtsIn[2], m_PtsOut[2] );
|
|
|
|
|
tmp += string.Format( "\t\t\t</nonlinearity_curve>\n" );
|
|
|
|
|
tmp += string.Format( "\t\t</{0}> \n", m_option );
|
2017-12-26 12:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
else if ( ExponentUsed ) {
|
2014-10-26 22:11:57 +00:00
|
|
|
|
// only exp used
|
2016-12-30 01:04:21 +00:00
|
|
|
|
tmp += string.Format( "exponent=\"{0}\" /> \n", Exponent );
|
2017-12-26 12:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
else {
|
2014-10-26 22:11:57 +00:00
|
|
|
|
// neither exp or curve
|
2016-12-30 01:04:21 +00:00
|
|
|
|
tmp += string.Format( " /> \n" );// nothing...
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-30 01:04:21 +00:00
|
|
|
|
tmp += string.Format( "\t</options>\n \n" );
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Read the options from the XML
|
2014-12-22 17:05:21 +00:00
|
|
|
|
/// can get only the 3 ones for Move Pitch, Yaw, Roll right now
|
2014-10-26 22:11:57 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reader">A prepared XML reader</param>
|
2014-12-22 17:05:21 +00:00
|
|
|
|
/// <param name="instance">the Joystick instance number</param>
|
2014-10-26 22:11:57 +00:00
|
|
|
|
/// <returns></returns>
|
2017-12-26 12:53:55 +00:00
|
|
|
|
public Boolean Options_fromXML( XElement option, string type, int instance )
|
2014-10-26 22:11:57 +00:00
|
|
|
|
{
|
2017-12-26 12:53:55 +00:00
|
|
|
|
/*
|
|
|
|
|
<flight_move_pitch exponent="1.00" >
|
|
|
|
|
<nonlinearity_curve>
|
|
|
|
|
<point in="0.182" out="0.028"/>
|
|
|
|
|
<point in="0.629" out="0.235"/>
|
|
|
|
|
<point in="0.895" out="0.629"/>
|
|
|
|
|
</nonlinearity_curve>
|
|
|
|
|
</flight_move_pitch>
|
|
|
|
|
*/
|
2017-01-11 23:13:48 +00:00
|
|
|
|
m_class = type;
|
2014-11-18 22:50:35 +00:00
|
|
|
|
m_devInstanceNo = instance;
|
2017-12-26 12:53:55 +00:00
|
|
|
|
m_option = option.Name.LocalName;
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2014-12-22 17:05:21 +00:00
|
|
|
|
// derive from flight_move_pitch || flight_move_yaw || flight_move_roll (nothing bad should arrive here)
|
2016-12-30 01:04:21 +00:00
|
|
|
|
string[] e = m_option.ToLowerInvariant( ).Split( new char[] { '_' } );
|
2014-11-18 22:50:35 +00:00
|
|
|
|
if ( e.Length > 2 ) m_cmdCtrl = e[2]; // TODO - see if m_cmdCtrl is needed to be derived here
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2017-12-26 12:53:55 +00:00
|
|
|
|
string invert = (string)option.Attribute( "invert" );
|
|
|
|
|
if ( !string.IsNullOrEmpty(invert) ) {
|
|
|
|
|
InvertUsed = false;
|
|
|
|
|
if ( invert == "1" ) InvertUsed = true;
|
|
|
|
|
}
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
2017-12-26 12:53:55 +00:00
|
|
|
|
string exponent = (string)option.Attribute( "exponent" );
|
|
|
|
|
if ( !string.IsNullOrEmpty( exponent ) ) {
|
|
|
|
|
Exponent = RoundString( exponent );
|
|
|
|
|
ExponentUsed = true;
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
2017-12-26 12:53:55 +00:00
|
|
|
|
|
2014-10-26 22:11:57 +00:00
|
|
|
|
// we may have a nonlin curve...
|
2017-12-26 12:53:55 +00:00
|
|
|
|
XElement nlc = option.Element( "nonlinearity_curve" );
|
|
|
|
|
if ( nlc != null ) {
|
|
|
|
|
m_PtsIn.Clear( ); m_PtsOut.Clear( ); // reset pts
|
|
|
|
|
IEnumerable<XElement> points = from x in nlc.Elements( )
|
|
|
|
|
where ( x.Name == "point" )
|
|
|
|
|
select x;
|
|
|
|
|
foreach ( XElement point in points ) {
|
|
|
|
|
string ptIn = RoundString( (string)point.Attribute( "in" ) );
|
|
|
|
|
string ptOut = RoundString( (string)point.Attribute( "out" ) );
|
|
|
|
|
m_PtsIn.Add( ptIn ); m_PtsOut.Add( ptOut ); m_ptsEnabled = true;
|
2014-10-26 22:11:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-26 12:53:55 +00:00
|
|
|
|
// sanity check - we've have to have 3 pts here - else we subst
|
|
|
|
|
// add 2nd
|
|
|
|
|
if ( m_PtsIn.Count < 2 ) {
|
|
|
|
|
m_PtsIn.Add( "0.500" ); m_PtsOut.Add( "0.500" );
|
|
|
|
|
log.Info( "Options_fromXML: got only one nonlin point, added (0.5|0.5)" );
|
|
|
|
|
}
|
|
|
|
|
// add 3rd
|
|
|
|
|
if ( m_PtsIn.Count < 3 ) {
|
|
|
|
|
m_PtsIn.Add( "0.750" ); m_PtsOut.Add( "0.750" );
|
|
|
|
|
log.Info( "Options_fromXML: got only two nonlin points, added (0.75|0.75)" );
|
|
|
|
|
}
|
2014-10-26 22:11:57 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|