It seems there is a rounding issue in encodeDirection() function.
When the function receives the value from 359.5 to 359.9 it rounds the Direction in degree value to 360 which in turn create an issue by producing the wrong value 180 but the encode value should be between 0-179.
It seems there is a rounding issue in encodeDirection() function. When the function receives the value from 359.5 to 359.9 it rounds the Direction in degree value to 360 which in turn create an issue by producing the wrong value 180 but the encode value should be between 0-179.
static uint8_t encodeDirection(float Direction, uint8_t *EWDirection) { unsigned int direction_int = (unsigned int) roundf(Direction);
Example: Input Direction in degree : 359.5
unsigned int direction_int = (unsigned int) roundf(Direction); // direction_int =360 if (direction_int < 180) { *EWDirection = 0; } else { *EWDirection = 1; // EWDirection = 1 direction_int -= 180; // direction_int = 180 } return (uint8_t) intRangeMax(direction_int, 0, UINT8_MAX); // return 180 (wrong output)