| 193 | } |
| 194 | |
| 195 | int8_t RotaryEncoderInput::mapEncoderValueDPad(int8_t index, int32_t encoderValue, uint16_t ppr) { |
| 196 | // Calculate total number of positions based on PPR |
| 197 | int32_t totalPositions = ENCODER_RADIUS * (int32_t)(ppr / (ENCODER_PRECISION * encoderMap[index].multiplier)); |
| 198 | |
| 199 | // Calculate range of encoder values corresponding to mapped range |
| 200 | int32_t minValue = -totalPositions / 2; |
| 201 | int32_t maxValue = totalPositions / 2; |
| 202 | |
| 203 | // Calculate thresholds for left and right turns |
| 204 | int32_t leftThreshold = minValue + (maxValue - minValue) / 3; |
| 205 | int32_t rightThreshold = maxValue - (maxValue - minValue) / 3; |
| 206 | |
| 207 | if (encoderValue < leftThreshold) { |
| 208 | return -1; |
| 209 | } else if (encoderValue > rightThreshold) { |
| 210 | return 1; |
| 211 | } else { |
| 212 | return 0; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | int32_t RotaryEncoderInput::map(int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max) { |
| 217 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
nothing calls this directly
no outgoing calls
no test coverage detected