mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
Added -1 -> +1 bounding to button control functions
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2206 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
d218e18ded
commit
5f71795d67
@ -200,41 +200,41 @@ void GCSControlGadget::buttonState(ButtonNumber number, bool pressed)
|
|||||||
case 1://Roll
|
case 1://Roll
|
||||||
if (buttonSettings[number].ActionID==1)
|
if (buttonSettings[number].ActionID==1)
|
||||||
{//increase
|
{//increase
|
||||||
obj->getField("Roll")->setValue(obj->getField("Roll")->getValue().toDouble()+buttonSettings[number].Amount);
|
obj->getField("Roll")->setValue(bound(obj->getField("Roll")->getValue().toDouble()+buttonSettings[number].Amount));
|
||||||
}
|
}
|
||||||
if (buttonSettings[number].ActionID==2)
|
if (buttonSettings[number].ActionID==2)
|
||||||
{//decrease
|
{//decrease
|
||||||
obj->getField("Roll")->setValue(obj->getField("Roll")->getValue().toDouble()-buttonSettings[number].Amount);
|
obj->getField("Roll")->setValue(bound(obj->getField("Roll")->getValue().toDouble()-buttonSettings[number].Amount));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2://Pitch
|
case 2://Pitch
|
||||||
if (buttonSettings[number].ActionID==1)
|
if (buttonSettings[number].ActionID==1)
|
||||||
{//increase
|
{//increase
|
||||||
obj->getField("Pitch")->setValue(obj->getField("Pitch")->getValue().toDouble()+buttonSettings[number].Amount);
|
obj->getField("Pitch")->setValue(bound(obj->getField("Pitch")->getValue().toDouble()+buttonSettings[number].Amount));
|
||||||
}
|
}
|
||||||
if (buttonSettings[number].ActionID==2)
|
if (buttonSettings[number].ActionID==2)
|
||||||
{//decrease
|
{//decrease
|
||||||
obj->getField("Pitch")->setValue(obj->getField("Pitch")->getValue().toDouble()-buttonSettings[number].Amount);
|
obj->getField("Pitch")->setValue(bound(obj->getField("Pitch")->getValue().toDouble()-buttonSettings[number].Amount));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3://Yaw
|
case 3://Yaw
|
||||||
if (buttonSettings[number].ActionID==1)
|
if (buttonSettings[number].ActionID==1)
|
||||||
{//increase
|
{//increase
|
||||||
obj->getField("Yaw")->setValue(obj->getField("Yaw")->getValue().toDouble()+buttonSettings[number].Amount);
|
obj->getField("Yaw")->setValue(wrap(obj->getField("Yaw")->getValue().toDouble()+buttonSettings[number].Amount));
|
||||||
}
|
}
|
||||||
if (buttonSettings[number].ActionID==2)
|
if (buttonSettings[number].ActionID==2)
|
||||||
{//decrease
|
{//decrease
|
||||||
obj->getField("Yaw")->setValue(obj->getField("Yaw")->getValue().toDouble()-buttonSettings[number].Amount);
|
obj->getField("Yaw")->setValue(wrap(obj->getField("Yaw")->getValue().toDouble()-buttonSettings[number].Amount));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4://Throttle
|
case 4://Throttle
|
||||||
if (buttonSettings[number].ActionID==1)
|
if (buttonSettings[number].ActionID==1)
|
||||||
{//increase
|
{//increase
|
||||||
obj->getField("Throttle")->setValue(obj->getField("Throttle")->getValue().toDouble()+buttonSettings[number].Amount);
|
obj->getField("Throttle")->setValue(bound(obj->getField("Throttle")->getValue().toDouble()+buttonSettings[number].Amount));
|
||||||
}
|
}
|
||||||
if (buttonSettings[number].ActionID==2)
|
if (buttonSettings[number].ActionID==2)
|
||||||
{//decrease
|
{//decrease
|
||||||
obj->getField("Throttle")->setValue(obj->getField("Throttle")->getValue().toDouble()-buttonSettings[number].Amount);
|
obj->getField("Throttle")->setValue(bound(obj->getField("Throttle")->getValue().toDouble()-buttonSettings[number].Amount));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5://Armed
|
case 5://Armed
|
||||||
@ -301,3 +301,18 @@ void GCSControlGadget::axesValues(QListInt16 values)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double GCSControlGadget::bound(double input)
|
||||||
|
{
|
||||||
|
if (input > 1.0)return 1.0;
|
||||||
|
if (input <-1.0)return -1.0;
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
double GCSControlGadget::wrap(double input)
|
||||||
|
{
|
||||||
|
while (input > 1.0)input -= 2.0;
|
||||||
|
while (input <-1.0)input += 2.0;
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
@ -69,6 +69,8 @@ private:
|
|||||||
int throttleChannel;
|
int throttleChannel;
|
||||||
int controlsMode;
|
int controlsMode;
|
||||||
buttonSettingsStruct buttonSettings[8];
|
buttonSettingsStruct buttonSettings[8];
|
||||||
|
double bound(double input);
|
||||||
|
double wrap(double input);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sticksChangedRemotely(double leftX, double leftY, double rightX, double rightY);
|
void sticksChangedRemotely(double leftX, double leftY, double rightX, double rightY);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user