本文整理汇总了C#中JoystickState.GetPointOfView方法的典型用法代码示例。如果您正苦于以下问题:C# JoystickState.GetPointOfView方法的具体用法?C# JoystickState.GetPointOfView怎么用?C# JoystickState.GetPointOfView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JoystickState
的用法示例。
在下文中一共展示了JoystickState.GetPointOfView方法的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: SendActions
private void SendActions(JoystickState state)
{
int actionCode = -1;
int actionParam = -1;
int curAxisValue = 0;
// todo: timer stuff!!
// buttons first!
byte[] buttons = state.GetButtons();
int button = 0;
string pressedButtons = "";
// button combos
string sep = "";
foreach (byte b in buttons)
{
if (0 != (b & 0x80))
{
pressedButtons += sep + button.ToString("00");
sep = ",";
}
button++;
}
if ((ButtonComboKill != "") && (ButtonComboKill == pressedButtons))
{
if (null != _lastProc)
{
actionCode = (int)joyButton.comboKillProcess;
actionParam = _lastProc.Id;
}
}
else if ((ButtonComboClose != "") && (ButtonComboClose == pressedButtons))
{
if (null != _lastProc)
{
actionCode = (int)joyButton.comboCloseProcess;
actionParam = _lastProc.Id;
}
}
// single buttons
if (actionCode == -1)
{
button = 0;
bool foundButton = false;
foreach (byte b in buttons)
{
if (0 != (b & 0x80))
{
foundButton = true;
break;
}
button++;
}
if (foundButton)
{
if ((button >= 0) && (button <= 19))
{
// don't need no stinkin' enum-constants here....
actionCode = 3030 + button;
}
}
}
// pov next
if (actionCode == -1)
{
int[] pov = state.GetPointOfView();
switch (pov[0])
{
case 0:
{
actionCode = (int)joyButton.povN;
break;
}
case 9000:
{
actionCode = (int)joyButton.povE;
break;
}
case 18000:
{
actionCode = (int)joyButton.povS;
break;
}
case 27000:
{
actionCode = (int)joyButton.povW;
break;
}
}
}
if (actionCode == -1)
{
// axes next
if (Math.Abs(state.X) > _axisLimit)
{
curAxisValue = state.X;
//.........这里部分代码省略.........
示例3: 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;
}
示例4: SendActions
private void SendActions(JoystickState state)
{
int actionCode = -1;
//int curAxisValue = 0;
// todo: timer stuff!!
// buttons first!
byte[] buttons = state.GetButtons();
int button = 0;
// button combos
/*
string sep = "";
string pressedButtons = "";
foreach (byte b in buttons)
{
if ((b & 0x80) != 0)
{
pressedButtons += sep + button.ToString("00");
sep = ",";
}
button++;
}
*/
// single buttons
if (actionCode == -1)
{
button = 0;
bool foundButton = false;
foreach (byte b in buttons)
{
if (0 != (b & 0x80))
{
foundButton = true;
break;
}
button++;
}
if (foundButton)
{
if ((button >= 0) && (button <= 19))
{
// don't need no stinkin' enum-constants here....
actionCode = 3030 + button;
}
}
}
// pov next
if (actionCode == -1)
{
int[] pov = state.GetPointOfView();
switch (pov[0])
{
case 0:
actionCode = (int)joyButton.povN;
break;
case 4500:
actionCode = (int)joyButton.povNE;
break;
case 9000:
actionCode = (int)joyButton.povE;
break;
case 13500:
actionCode = (int)joyButton.povSE;
break;
case 18000:
actionCode = (int)joyButton.povS;
break;
case 22500:
actionCode = (int)joyButton.povSW;
break;
case 27000:
actionCode = (int)joyButton.povW;
break;
case 31500:
actionCode = (int)joyButton.povNW;
break;
}
}
if (actionCode == -1)
{
// axes next
if (Math.Abs(state.X) > AxisLimit)
{
//curAxisValue = state.X;
if (state.X > 0)
{
actionCode = (int)joyButton.axisXUp; // right
}
else
{
actionCode = (int)joyButton.axisXDown; // left
}
}
else if (Math.Abs(state.Y) > AxisLimit)
{
//.........这里部分代码省略.........