getCompassValues function
calculating compass turn from heading value
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);
}