@@ -18,11 +18,13 @@ struct DetentConfig {
18
18
// /< detents will be used.
19
19
float detent_strength{1 }; // /< Strength of the detents
20
20
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
22
23
float snap_point_bias{0 }; // /< Bias for the snap point, in radians, should be >= 0 for stability
23
24
float dead_zone_percent{0 .2f }; // /< Percent of the dead zone to use for the detent
24
25
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
26
28
};
27
29
28
30
// / @brief Equality operator for DetentConfig
@@ -41,107 +43,107 @@ inline bool operator==(const DetentConfig &lhs, const DetentConfig &rhs) {
41
43
42
44
// / @brief Unbounded motion, no detents
43
45
static const DetentConfig UNBOUNDED_NO_DETENTS = {
44
- .position_width = 10.0 * M_PI / 180.0 ,
46
+ .position_width = 10 .0f * ( float )( M_PI) / 180 .0f ,
45
47
.min_position = 0 ,
46
48
.max_position = -1 , // max < min indicates no bounds
47
49
.detent_strength = 0 ,
48
50
.end_strength = 1 ,
49
- .snap_point = 1.1 ,
51
+ .snap_point = 1 .1f ,
50
52
.snap_point_bias = 0 ,
51
53
};
52
54
53
55
// / @brief Bounded motion, no detents
54
56
static const DetentConfig BOUNDED_NO_DETENTS = {
55
- .position_width = 10.0 * M_PI / 180.0 ,
57
+ .position_width = 10 .0f * ( float )( M_PI) / 180 .0f ,
56
58
.min_position = 0 ,
57
59
.max_position = 10 ,
58
60
.detent_strength = 0 ,
59
61
.end_strength = 1 ,
60
- .snap_point = 1.1 ,
62
+ .snap_point = 1 .1f ,
61
63
.snap_point_bias = 0 ,
62
64
};
63
65
64
66
// / @brief Bounded motion with multiple revolutions, no detents, with end stops
65
67
static 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 ,
67
69
.min_position = 0 ,
68
70
.max_position = 72 ,
69
71
.detent_strength = 0 ,
70
72
.end_strength = 1 ,
71
- .snap_point = 1.1 ,
73
+ .snap_point = 1 .1f ,
72
74
.snap_point_bias = 0 ,
73
75
};
74
76
75
77
// / @brief On-off with strong detents
76
78
static 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 ,
78
80
.min_position = 0 ,
79
81
.max_position = 1 ,
80
82
.detent_strength = 1 ,
81
83
.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)
84
86
.snap_point_bias = 0 ,
85
87
};
86
88
87
89
// / @brief Bounded motion with strong position detents spaced 9 degrees apart
88
90
// / (coarse), with end stops
89
91
static 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 ,
91
93
.min_position = 0 ,
92
94
.max_position = 31 ,
93
95
.detent_strength = 2 ,
94
96
.end_strength = 1 ,
95
- .snap_point = 1.1 ,
97
+ .snap_point = 1 .1f ,
96
98
.snap_point_bias = 0 ,
97
99
};
98
100
99
101
// / @brief Bounded motion with no detents spaced 1 degree apart (fine), with end
100
102
// / stops
101
103
static 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 ,
103
105
.min_position = 0 ,
104
106
.max_position = 255 ,
105
107
.detent_strength = 0 ,
106
108
.end_strength = 1 ,
107
- .snap_point = 1.1 ,
109
+ .snap_point = 1 .1f ,
108
110
.snap_point_bias = 0 ,
109
111
};
110
112
111
113
// / @brief Bounded motion with position detents spaced 1 degree apart (fine),
112
114
// / with end stops
113
115
static 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 ,
115
117
.min_position = 0 ,
116
118
.max_position = 255 ,
117
119
.detent_strength = 1 ,
118
120
.end_strength = 1 ,
119
- .snap_point = 1.1 ,
121
+ .snap_point = 1 .1f ,
120
122
.snap_point_bias = 0 ,
121
123
};
122
124
123
125
// / @brief Bounded motion with position detents, end stops, and explicit
124
126
// / magnetic detents.
125
127
static const DetentConfig MAGNETIC_DETENTS = {
126
- .position_width = 7.0 * M_PI / 180.0 ,
128
+ .position_width = 7 .0f * ( float )( M_PI) / 180 .0f ,
127
129
.min_position = 0 ,
128
130
.max_position = 31 ,
129
131
.detent_positions = {2 , 10 , 21 , 22 },
130
- .detent_strength = 2.5 ,
132
+ .detent_strength = 2 .5f ,
131
133
.end_strength = 1 ,
132
- .snap_point = 0.7 ,
134
+ .snap_point = 0 .7f ,
133
135
.snap_point_bias = 0 ,
134
136
};
135
137
136
138
// / @brief Bounded motion for a return to center rotary encoder with positions
137
139
static 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 ,
139
141
.min_position = -6 ,
140
142
.max_position = 6 ,
141
143
.detent_strength = 1 ,
142
144
.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 ,
145
147
};
146
148
147
149
} // namespace espp::detail
@@ -155,23 +157,23 @@ template <> struct fmt::formatter<espp::detail::DetentConfig> {
155
157
156
158
template <typename FormatContext>
157
159
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 );
176
178
}
177
179
};
0 commit comments