@@ -18,11 +18,13 @@ struct DetentConfig {
1818 // /< detents will be used.
1919 float detent_strength{1 }; // /< Strength of the detents
2020 float end_strength{1 }; // /< Strength of the end detents
21- float snap_point{1.1 }; // /< Position of the snap point, in radians, should be >= 0.5 for stability
21+ float snap_point{
22+ 1 .1f }; // /< Position of the snap point, in radians, should be >= 0.5 for stability
2223 float snap_point_bias{0 }; // /< Bias for the snap point, in radians, should be >= 0 for stability
2324 float dead_zone_percent{0 .2f }; // /< Percent of the dead zone to use for the detent
2425 float dead_zone_abs_max_radians{
25- M_PI / 180 .0f }; // /< Absolute maximum of the dead zone to use for the detent in radians
26+ (float )(M_PI) /
27+ 180 .0f }; // /< Absolute maximum of the dead zone to use for the detent in radians
2628};
2729
2830// / @brief Equality operator for DetentConfig
@@ -41,107 +43,107 @@ inline bool operator==(const DetentConfig &lhs, const DetentConfig &rhs) {
4143
4244// / @brief Unbounded motion, no detents
4345static const DetentConfig UNBOUNDED_NO_DETENTS = {
44- .position_width = 10.0 * M_PI / 180.0 ,
46+ .position_width = 10 .0f * ( float )( M_PI) / 180 .0f ,
4547 .min_position = 0 ,
4648 .max_position = -1 , // max < min indicates no bounds
4749 .detent_strength = 0 ,
4850 .end_strength = 1 ,
49- .snap_point = 1.1 ,
51+ .snap_point = 1 .1f ,
5052 .snap_point_bias = 0 ,
5153};
5254
5355// / @brief Bounded motion, no detents
5456static const DetentConfig BOUNDED_NO_DETENTS = {
55- .position_width = 10.0 * M_PI / 180.0 ,
57+ .position_width = 10 .0f * ( float )( M_PI) / 180 .0f ,
5658 .min_position = 0 ,
5759 .max_position = 10 ,
5860 .detent_strength = 0 ,
5961 .end_strength = 1 ,
60- .snap_point = 1.1 ,
62+ .snap_point = 1 .1f ,
6163 .snap_point_bias = 0 ,
6264};
6365
6466// / @brief Bounded motion with multiple revolutions, no detents, with end stops
6567static const DetentConfig MULTI_REV_NO_DETENTS = {
66- .position_width = 10.0 * M_PI / 180.0 ,
68+ .position_width = 10 .0f * ( float )( M_PI) / 180 .0f ,
6769 .min_position = 0 ,
6870 .max_position = 72 ,
6971 .detent_strength = 0 ,
7072 .end_strength = 1 ,
71- .snap_point = 1.1 ,
73+ .snap_point = 1 .1f ,
7274 .snap_point_bias = 0 ,
7375};
7476
7577// / @brief On-off with strong detents
7678static const DetentConfig ON_OFF_STRONG_DETENTS = {
77- .position_width = 60.0 * M_PI / 180.0 ,
79+ .position_width = 60 .0f * ( float )( M_PI) / 180 .0f ,
7880 .min_position = 0 ,
7981 .max_position = 1 ,
8082 .detent_strength = 1 ,
8183 .end_strength = 1 ,
82- .snap_point = 0.55 , // Note the snap point is slightly past the midpoint (0.5); compare to
83- // normal detents which use a snap point *past* the next value (i.e. > 1)
84+ .snap_point = 0 .55f , // Note the snap point is slightly past the midpoint (0.5); compare to
85+ // normal detents which use a snap point *past* the next value (i.e. > 1)
8486 .snap_point_bias = 0 ,
8587};
8688
8789// / @brief Bounded motion with strong position detents spaced 9 degrees apart
8890// / (coarse), with end stops
8991static const DetentConfig COARSE_VALUES_STRONG_DETENTS = {
90- .position_width = 8 .225f * M_PI / 180.0 ,
92+ .position_width = 8 .225f * ( float )( M_PI) / 180 .0f ,
9193 .min_position = 0 ,
9294 .max_position = 31 ,
9395 .detent_strength = 2 ,
9496 .end_strength = 1 ,
95- .snap_point = 1.1 ,
97+ .snap_point = 1 .1f ,
9698 .snap_point_bias = 0 ,
9799};
98100
99101// / @brief Bounded motion with no detents spaced 1 degree apart (fine), with end
100102// / stops
101103static const DetentConfig FINE_VALUES_NO_DETENTS = {
102- .position_width = 1 .0f * M_PI / 180.0 ,
104+ .position_width = 1 .0f * ( float )( M_PI) / 180 .0f ,
103105 .min_position = 0 ,
104106 .max_position = 255 ,
105107 .detent_strength = 0 ,
106108 .end_strength = 1 ,
107- .snap_point = 1.1 ,
109+ .snap_point = 1 .1f ,
108110 .snap_point_bias = 0 ,
109111};
110112
111113// / @brief Bounded motion with position detents spaced 1 degree apart (fine),
112114// / with end stops
113115static const DetentConfig FINE_VALUES_WITH_DETENTS = {
114- .position_width = 1 .0f * M_PI / 180.0 ,
116+ .position_width = 1 .0f * ( float )( M_PI) / 180 .0f ,
115117 .min_position = 0 ,
116118 .max_position = 255 ,
117119 .detent_strength = 1 ,
118120 .end_strength = 1 ,
119- .snap_point = 1.1 ,
121+ .snap_point = 1 .1f ,
120122 .snap_point_bias = 0 ,
121123};
122124
123125// / @brief Bounded motion with position detents, end stops, and explicit
124126// / magnetic detents.
125127static const DetentConfig MAGNETIC_DETENTS = {
126- .position_width = 7.0 * M_PI / 180.0 ,
128+ .position_width = 7 .0f * ( float )( M_PI) / 180 .0f ,
127129 .min_position = 0 ,
128130 .max_position = 31 ,
129131 .detent_positions = {2 , 10 , 21 , 22 },
130- .detent_strength = 2.5 ,
132+ .detent_strength = 2 .5f ,
131133 .end_strength = 1 ,
132- .snap_point = 0.7 ,
134+ .snap_point = 0 .7f ,
133135 .snap_point_bias = 0 ,
134136};
135137
136138// / @brief Bounded motion for a return to center rotary encoder with positions
137139static const DetentConfig RETURN_TO_CENTER_WITH_DETENTS = {
138- .position_width = 60.0 * M_PI / 180.0 ,
140+ .position_width = 60 .0f * ( float )( M_PI) / 180 .0f ,
139141 .min_position = -6 ,
140142 .max_position = 6 ,
141143 .detent_strength = 1 ,
142144 .end_strength = 1 ,
143- .snap_point = 0.55 ,
144- .snap_point_bias = 0.4 ,
145+ .snap_point = 0 .55f ,
146+ .snap_point_bias = 0 .4f ,
145147};
146148
147149} // namespace espp::detail
@@ -155,23 +157,23 @@ template <> struct fmt::formatter<espp::detail::DetentConfig> {
155157
156158 template <typename FormatContext>
157159 auto format (espp::detail::DetentConfig const &detent_config, FormatContext &ctx) const {
158- return fmt::format_to (ctx. out (),
159- " DetentConfig: \n "
160- " \t position_width: {} radians ({} degrees) \n "
161- " \t min_position : {}\n "
162- " \t max_position : {}\n "
163- " \t range of motion : {:.2f} to {:.2f} degrees \n "
164- " \t detent_positions: {} \n "
165- " \t detent_strength : {}\n "
166- " \t end_strength : {}\n "
167- " \t snap_point : {}\n "
168- " \t snap_point_bias : {}" ,
169- detent_config. position_width , detent_config. position_width * 180.0 / M_PI ,
170- detent_config.min_position , detent_config.max_position ,
171- detent_config.min_position * detent_config.position_width * 180.0 / M_PI ,
172- detent_config.max_position * detent_config.position_width * 180.0 / M_PI,
173- detent_config.detent_positions , detent_config. detent_strength ,
174- detent_config.end_strength , detent_config.snap_point ,
175- detent_config.snap_point_bias );
160+ return fmt::format_to (
161+ ctx. out (),
162+ " DetentConfig: \n "
163+ " \t position_width : {} radians ({} degrees) \n "
164+ " \t min_position : {}\n "
165+ " \t max_position : {} \n "
166+ " \t range of motion: {:.2f} to {:.2f} degrees \n "
167+ " \t detent_positions : {}\n "
168+ " \t detent_strength : {}\n "
169+ " \t end_strength : {}\n "
170+ " \t snap_point : {}\n "
171+ " \t snap_point_bias: {} " ,
172+ detent_config.position_width , detent_config.position_width * 180 . 0f / ( float )(M_PI) ,
173+ detent_config.min_position , detent_config.max_position ,
174+ detent_config.min_position * detent_config.position_width * 180 .0f / ( float )( M_PI) ,
175+ detent_config. max_position * detent_config.position_width * 180 . 0f / ( float )(M_PI) ,
176+ detent_config. detent_positions , detent_config.detent_strength , detent_config.end_strength ,
177+ detent_config. snap_point , detent_config.snap_point_bias );
176178 }
177179};
0 commit comments