Skip to content

Commit

Permalink
make accelerometer stable
Browse files Browse the repository at this point in the history
I've noticed an issue when pitching forward or backward. I expect only the "up" or "down" directions to be registered, but instead, "left" and/or "right" are also triggered for a brief period.
  • Loading branch information
pepper-jelly authored and pepper-jelly committed Jul 23, 2024
1 parent d30f930 commit 392df3d
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/joyaccelerometersensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,34 +187,28 @@ JoySensorDirection JoyAccelerometerSensor::calculateSensorDirection()
bool inPitch = pitch_abs < range;
bool inRoll = roll_abs < range;

if (inPitch && !inRoll)
if (!inPitch && !inRoll)
{
if (roll > 0)
return SENSOR_LEFT;
else
return SENSOR_RIGHT;
} else if (!inPitch && inRoll)
{
if (pitch > 0)
return SENSOR_UP;
else
return SENSOR_DOWN;
} else // in both or in none
{
if (pitch > 0)
{
if (roll > 0)
return SENSOR_LEFT_UP;
else
return SENSOR_RIGHT_UP;
return pitch > 0 ? SENSOR_LEFT_UP : SENSOR_LEFT_DOWN;
} else
{
if (roll > 0)
return SENSOR_LEFT_DOWN;
else
return SENSOR_RIGHT_DOWN;
return pitch > 0 ? SENSOR_RIGHT_UP : SENSOR_RIGHT_DOWN;
}
}

if (inPitch && !inRoll)
{
return roll > 0 ? SENSOR_LEFT : SENSOR_RIGHT;
}

if (!inPitch && inRoll)
{
return pitch > 0 ? SENSOR_UP : SENSOR_DOWN;
}

return SENSOR_CENTERED;
}

/**
Expand Down

0 comments on commit 392df3d

Please sign in to comment.