本文整理汇总了C#中JoystickState.GetSlider方法的典型用法代码示例。如果您正苦于以下问题:C# JoystickState.GetSlider方法的具体用法?C# JoystickState.GetSlider怎么用?C# JoystickState.GetSlider使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JoystickState
的用法示例。
在下文中一共展示了JoystickState.GetSlider方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: mainloop
/// <summary>
/// Updates the rcoverride values and controls the mode changes
/// </summary>
void mainloop()
{
while (enabled)
{
try
{
System.Threading.Thread.Sleep(50);
//joystick stuff
joystick.Poll();
state = joystick.CurrentJoystickState;
int[] slider = state.GetSlider();
if (elevons)
{
//g.channel_roll.set_pwm(BOOL_TO_SIGN(g.reverse_elevons) * (BOOL_TO_SIGN(g.reverse_ch2_elevon) * int(ch2_temp - elevon2_trim) - BOOL_TO_SIGN(g.reverse_ch1_elevon) * int(ch1_temp - elevon1_trim)) / 2 + 1500);
//g.channel_pitch.set_pwm( (BOOL_TO_SIGN(g.reverse_ch2_elevon) * int(ch2_temp - elevon2_trim) + BOOL_TO_SIGN(g.reverse_ch1_elevon) * int(ch1_temp - elevon1_trim)) / 2 + 1500);
ushort roll = pickchannel(1, JoyChannels[1].axis, false, JoyChannels[1].expo);
ushort pitch = pickchannel(2, JoyChannels[2].axis, false, JoyChannels[2].expo);
if (getJoystickAxis(1) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech1 = (ushort)(BOOL_TO_SIGN(JoyChannels[1].reverse) * ((int)(pitch - 1500) - (int)(roll - 1500)) / 2 + 1500);
if (getJoystickAxis(2) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech2 = (ushort)(BOOL_TO_SIGN(JoyChannels[2].reverse) * ((int)(pitch - 1500) + (int)(roll - 1500)) / 2 + 1500);
}
else
{
if (getJoystickAxis(1) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech1 = pickchannel(1, JoyChannels[1].axis, JoyChannels[1].reverse, JoyChannels[1].expo);//(ushort)(((int)state.Rz / 65.535) + 1000);
if (getJoystickAxis(2) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech2 = pickchannel(2, JoyChannels[2].axis, JoyChannels[2].reverse, JoyChannels[2].expo);//(ushort)(((int)state.Y / 65.535) + 1000);
}
if (getJoystickAxis(3) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech3 = pickchannel(3, JoyChannels[3].axis, JoyChannels[3].reverse, JoyChannels[3].expo);//(ushort)(1000 - ((int)slider[0] / 65.535) + 1000);
if (getJoystickAxis(4) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech4 = pickchannel(4, JoyChannels[4].axis, JoyChannels[4].reverse, JoyChannels[4].expo);//(ushort)(((int)state.X / 65.535) + 1000);
if (getJoystickAxis(5) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech5 = pickchannel(5, JoyChannels[5].axis, JoyChannels[5].reverse, JoyChannels[5].expo);
if (getJoystickAxis(6) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech6 = pickchannel(6, JoyChannels[6].axis, JoyChannels[6].reverse, JoyChannels[6].expo);
if (getJoystickAxis(7) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech7 = pickchannel(7, JoyChannels[7].axis, JoyChannels[7].reverse, JoyChannels[7].expo);
if (getJoystickAxis(8) != Joystick.joystickaxis.None)
MainV2.comPort.MAV.cs.rcoverridech8 = pickchannel(8, JoyChannels[8].axis, JoyChannels[8].reverse, JoyChannels[8].expo);
//UAS
if (elevons)
{
if (JoyChannels[1].reverse && elevRev1)
MainV2.comPort.MAV.cs.controlleroverridech1 = (ushort)(65535 - (((int)state.X + (int)(65535 - state.Y)) / 2));
else if(JoyChannels[1].reverse)
MainV2.comPort.MAV.cs.controlleroverridech1 = (ushort)(65535 - ((int)state.X + (int)state.Y) / 2);
else if(elevRev1)
MainV2.comPort.MAV.cs.controlleroverridech1 = (ushort)(((int)state.X + (int)(65535 - state.Y)) / 2);
else
MainV2.comPort.MAV.cs.controlleroverridech1 = (ushort)(((int)state.X + (int)state.Y) / 2);
if (JoyChannels[2].reverse && elevRev2)
MainV2.comPort.MAV.cs.controlleroverridech2 = (ushort)(65535 - (((int)state.X + (int)(65535 - state.Y)) / 2));
else if (JoyChannels[2].reverse)
MainV2.comPort.MAV.cs.controlleroverridech2 = (ushort)(65535 - ((int)state.X + (int)state.Y) / 2);
else if (elevRev2)
MainV2.comPort.MAV.cs.controlleroverridech2 = (ushort)(((int)state.X + (int)(65535 - state.Y)) / 2);
else
MainV2.comPort.MAV.cs.controlleroverridech2 = (ushort)(((int)state.X + (int)state.Y) / 2);
}
else
{
if (JoyChannels[1].reverse)
MainV2.comPort.MAV.cs.controlleroverridech1 = (ushort)(65535 - state.X);
else
MainV2.comPort.MAV.cs.controlleroverridech1 = (ushort)state.X;
if (JoyChannels[2].reverse)
MainV2.comPort.MAV.cs.controlleroverridech2 = (ushort)(65535 - state.Y);
else
MainV2.comPort.MAV.cs.controlleroverridech2 = (ushort)state.Y;
}
if (JoyChannels[3].reverse)
MainV2.comPort.MAV.cs.controlleroverridech3 = (ushort)(65535 - state.GetSlider()[0]);
else
MainV2.comPort.MAV.cs.controlleroverridech1 = (ushort)state.GetSlider()[0];
if (JoyChannels[4].reverse)
MainV2.comPort.MAV.cs.controlleroverridech4 = (ushort)(65535 - state.Rz);
else
MainV2.comPort.MAV.cs.controlleroverridech4 = (ushort)state.Rz;
int pov = state.GetPointOfView()[0];
switch (pov)
{
case 0: //PITCH UP
MainV2.comPort.MAV.cs.trim_y += 20;
break;
case 9000: //ROLL RIGHT
MainV2.comPort.MAV.cs.trim_x -= 20;
break;
case 18000: //PITCH DOWN
//.........这里部分代码省略.........
示例2: GetStateAsText
private string GetStateAsText(JoystickState state)
{
string strText = string.Empty;
string joyState = string.Format("Axis : {0:+0000;-0000} / {1:+0000;-0000} / {2:+0000;-0000}\n", state.X,
state.Y, state.Z);
joyState += string.Format("Rotation: {0:+0000;-0000} / {1:+0000;-0000} / {2:+0000;-0000}\n\n", state.Rx, state.Ry,
state.Rz);
int[] slider = state.GetSlider();
joyState += string.Format("Slider : 0: {0:+0000;-0000} 1: {1:+0000;-0000}\n\n", slider[0], slider[1]);
int[] pov = state.GetPointOfView();
switch (pov[0])
{
case 0:
{
joyState += string.Format("POV : North\n");
break;
}
case 4500:
{
joyState += string.Format("POV : NorthEast\n");
break;
}
case 9000:
{
joyState += string.Format("POV : East\n");
break;
}
case 13500:
{
joyState += string.Format("POV : SouthEast\n");
break;
}
case 18000:
{
joyState += string.Format("POV : South\n");
break;
}
case 22500:
{
joyState += string.Format("POV : SouthWest\n");
break;
}
case 27000:
{
joyState += string.Format("POV : West\n");
break;
}
case 31500:
{
joyState += string.Format("POV : NorthWest\n");
break;
}
default:
{
break;
}
}
// Fill up text with which buttons are pressed
byte[] buttons = state.GetButtons();
int button = 0;
foreach (byte b in buttons)
{
if (0 != (b & 0x80))
{
strText += button.ToString("00 ");
}
button++;
}
if (strText != string.Empty)
{
joyState += "Buttons : " + strText;
}
return joyState;
}
示例3: mainloop
/// <summary>
/// Updates the rcoverride values and controls the mode changes
/// </summary>
void mainloop()
{
while (enabled)
{
try
{
System.Threading.Thread.Sleep(50);
//joystick stuff
joystick.Poll();
state = joystick.CurrentJoystickState;
int[] slider = state.GetSlider();
if (elevons)
{
//g.channel_roll.set_pwm(BOOL_TO_SIGN(g.reverse_elevons) * (BOOL_TO_SIGN(g.reverse_ch2_elevon) * int(ch2_temp - elevon2_trim) - BOOL_TO_SIGN(g.reverse_ch1_elevon) * int(ch1_temp - elevon1_trim)) / 2 + 1500);
//g.channel_pitch.set_pwm( (BOOL_TO_SIGN(g.reverse_ch2_elevon) * int(ch2_temp - elevon2_trim) + BOOL_TO_SIGN(g.reverse_ch1_elevon) * int(ch1_temp - elevon1_trim)) / 2 + 1500);
ushort roll = pickchannel(1, JoyChannels[1].axis, false, JoyChannels[1].expo);
ushort pitch = pickchannel(2, JoyChannels[2].axis, false, JoyChannels[2].expo);
if (getJoystickAxis(1) != Joystick.joystickaxis.None)
MainV2.cs.rcoverridech1 = (ushort)(BOOL_TO_SIGN(JoyChannels[1].reverse) * ((int)(pitch - 1500) - (int)(roll - 1500)) / 2 + 1500);
if (getJoystickAxis(2) != Joystick.joystickaxis.None)
MainV2.cs.rcoverridech2 = (ushort)(BOOL_TO_SIGN(JoyChannels[2].reverse) * ((int)(pitch - 1500) + (int)(roll - 1500)) / 2 + 1500);
}
else
{
if (getJoystickAxis(1) != Joystick.joystickaxis.None)
MainV2.cs.rcoverridech1 = pickchannel(1, JoyChannels[1].axis, JoyChannels[1].reverse, JoyChannels[1].expo);//(ushort)(((int)state.Rz / 65.535) + 1000);
if (getJoystickAxis(2) != Joystick.joystickaxis.None)
MainV2.cs.rcoverridech2 = pickchannel(2, JoyChannels[2].axis, JoyChannels[2].reverse, JoyChannels[2].expo);//(ushort)(((int)state.Y / 65.535) + 1000);
}
if (getJoystickAxis(3) != Joystick.joystickaxis.None)
MainV2.cs.rcoverridech3 = pickchannel(3, JoyChannels[3].axis, JoyChannels[3].reverse, JoyChannels[3].expo);//(ushort)(1000 - ((int)slider[0] / 65.535) + 1000);
if (getJoystickAxis(4) != Joystick.joystickaxis.None)
MainV2.cs.rcoverridech4 = pickchannel(4, JoyChannels[4].axis, JoyChannels[4].reverse, JoyChannels[4].expo);//(ushort)(((int)state.X / 65.535) + 1000);
foreach (JoyButton but in JoyButtons)
{
if (but.buttonno != -1 && getButtonState(but.buttonno))
{
MainV2.instance.Invoke((System.Windows.Forms.MethodInvoker)delegate()
{
try
{
MainV2.comPort.setMode(but.mode);
}
catch { System.Windows.Forms.MessageBox.Show("Failed to change Modes"); }
});
}
}
//Console.WriteLine("{0} {1} {2} {3}", MainV2.cs.rcoverridech1, MainV2.cs.rcoverridech2, MainV2.cs.rcoverridech3, MainV2.cs.rcoverridech4);
}
catch (Exception ex) { Console.WriteLine("Joystick thread error "+ex.ToString()); } // so we cant fall out
}
}
示例4: ReassignJystValues
public PlaneAttributes ReassignJystValues(JoystickState joyState)
{
PlaneAttributes planeAttrib = new PlaneAttributes();
switch (MapAileron_comboBox.SelectedIndex)
{
case 0: planeAttrib.aileron = joyState.X; break; // X
case 1: planeAttrib.aileron = joyState.Y; break;// Y
case 2: planeAttrib.aileron = joyState.Z; break;// Z
case 3: planeAttrib.aileron = joyState.GetSlider()[0]; break;// Slider1
case 4: planeAttrib.aileron = joyState.GetSlider()[1]; break;// Slider2
default:
break;
}
switch (MapElevator_comboBox.SelectedIndex)
{
case 0: planeAttrib.elevator = joyState.X; break; // X
case 1: planeAttrib.elevator = joyState.Y; break;// Y
case 2: planeAttrib.elevator = joyState.Z; break;// Z
case 3: planeAttrib.elevator = joyState.GetSlider()[0]; break;// Slider1
case 4: planeAttrib.elevator = joyState.GetSlider()[1]; break;// Slider2
default:
break;
}
switch (MapRudder_comboBox.SelectedIndex)
{
case 0: planeAttrib.rudder = joyState.X; break; // X
case 1: planeAttrib.rudder = joyState.Y; break;// Y
case 2: planeAttrib.rudder = joyState.Z; break;// Z
case 3: planeAttrib.rudder = joyState.GetSlider()[0]; break;// Slider1
case 4: planeAttrib.rudder = joyState.GetSlider()[1]; break;// Slider2
default:
break;
}
switch (MapThrottle_comboBox.SelectedIndex)
{
case 0: planeAttrib.throttle = joyState.X; break; // X
case 1: planeAttrib.throttle = joyState.Y; break;// Y
case 2: planeAttrib.throttle = joyState.Z; break;// Z
case 3: planeAttrib.throttle = joyState.GetSlider()[0]; break;// Slider1
case 4: planeAttrib.throttle = joyState.GetSlider()[1]; break;// Slider2
default:
break;
}
return planeAttrib;
}