getCompassValues function

dynamic getCompassValues(
  1. double heading
)

Implementation

getCompassValues(double heading)
{
  double direction = heading;
  direction = direction < 0 ? (360 + direction): direction;


  double diff = direction - preValue;
  if(diff.abs() > 180) {
    if(preValue > direction) {
      diff = 360 - (direction-preValue).abs();
    } else {
      diff = (360 - (preValue-direction).abs()).toDouble();
      diff = diff * -1;
    }
  }

  turns += (diff / 360);
  preValue = direction;
  return CompassModel(turns: turns, angle: heading);
}