2525 * @author Thomas Sommer
2626 * @ingroup modm_driver_adns9800
2727 */
28- namespace modm {
28+ namespace modm
29+ {
2930
3031// / @brief Relative motion since the last read
31- struct adns9800 ::Data {
32- const modm::Vector<int16_t , 2 > delta;
32+ struct adns9800 ::Data
33+ {
34+ const modm::Vector<DeltaType, 2 > delta;
3335
3436protected:
35- static constexpr size_t length = 6 ;
36- Data (std::span<uint8_t , length> buffer)
37- : delta{
38- buffer[3 ] << 8 | buffer[2 ], // delta x
39- buffer[5 ] << 8 | buffer[4 ] // delta y
40- } {}
41-
42- template <class , class >
43- friend class Adns9800 ;
37+ static constexpr size_t length = 6 ;
38+ Data (std::span<uint8_t , length> buffer)
39+ : delta{
40+ static_cast <DeltaType>(buffer[3 ] << 8 | buffer[2 ]),
41+ static_cast <DeltaType>(buffer[5 ] << 8 | buffer[4 ])
42+ }
43+ {}
44+
45+ template <class , class >
46+ friend class Adns9800 ;
4447};
4548
4649// / @brief Relative motion and laser fault detection flags
47- struct adns9800 ::Data_Fails : public adns9800::Data {
48- const bool LaserFaultDetected: 1 ;
49- const bool LaserPowerValid: 1 ;
50- const bool isRunningSROMCode: 1 ;
50+ struct adns9800 ::Data_Fails : public adns9800::Data
51+ {
52+ const bool LaserFaultDetected : 1 ;
53+ const bool LaserPowerValid : 1 ;
54+ const bool isRunningSROMCode : 1 ;
5155
5256protected:
53- Data_Fails (std::span<uint8_t , length> buffer)
54- : Data(buffer),
55- LaserFaultDetected (buffer[0 ] & Bit6),
56- LaserPowerValid(buffer[0 ] & Bit5),
57- isRunningSROMCode(buffer[1 ] & Bit6) {
58- }
59-
60- template <class , class >
61- friend class Adns9800 ;
57+ Data_Fails (std::span<uint8_t , length> buffer)
58+ : Data(buffer),
59+ LaserFaultDetected (buffer[0 ] & Bit6),
60+ LaserPowerValid(buffer[0 ] & Bit5),
61+ isRunningSROMCode(buffer[1 ] & Bit6)
62+ { }
63+
64+ template <class , class >
65+ friend class Adns9800 ;
6266};
6367
6468// / @brief Relative motion, laser fault detection flags and metrics from the shutter unit.
65- struct adns9800 ::Data_Fails_Monitoring
66- : public adns9800::Data_Fails {
67- struct Statistics {
68- /* *
69- * Number of features visible by the sensor in the current frame. Range 0 to 169.
70- * Total number of features: 4 * surface_quality.
71- * Changes are expected when moving over a surface.
72- * Convergates to 0 if there is no surface below the sensor.
73- * surface_quality remains fairly high throughout the Z-height.
74- */
75- const uint8_t surface_quality;
76- // pixel_sum containes the average pixel value. Range 0 to 223.
77- // It reports the upper byte of a 17-bit counter which sums all 900 pixels in the current frame
78- const uint8_t pixel_sum;
79- // Minium and maximum Pixel value in current frame. Range: 0 to 127.
80- const uint8_t max_pixel;
81- const uint8_t min_pixel;
82- } statistics;
83-
84- uint8_t getAveragePixelValue () const {
85- return statistics.pixel_sum << 9 / FrameSize;
86- }
87-
88- struct Shutter {
89- // exposure <= ShutterConfig::exposure_max!
90- const PeriodType exposure;
91- // ShutterConfig::period_min <= period <= ShutterConfig::period_max!
92- const PeriodType period;
93- } shutter;
94-
95- Duration getExposureTime () const { return Duration (shutter.exposure ); };
96- Duration getFrameTime () const { return Duration (shutter.period ); };
69+ struct adns9800 ::Data_Fails_Monitoring : public adns9800::Data_Fails
70+ {
71+ struct Statistics
72+ {
73+ /* *
74+ * Number of features visible by the sensor in the current frame. Range 0 to 169.
75+ * Total number of features: 4 * surface_quality.
76+ * Changes are expected when moving over a surface.
77+ * Convergates to 0 if there is no surface below the sensor.
78+ * surface_quality remains fairly high throughout the Z-height.
79+ */
80+ const uint8_t surface_quality;
81+ // pixel_sum containes the average pixel value. Range 0 to 223.
82+ // It reports the upper byte of a 17-bit counter which sums all 900 pixels in the current
83+ // frame
84+ const uint8_t pixel_sum;
85+ // Minium and maximum Pixel value in current frame. Range: 0 to 127.
86+ const uint8_t max_pixel;
87+ const uint8_t min_pixel;
88+ } statistics;
89+
90+ uint8_t
91+ getAveragePixelValue () const
92+ {
93+ return statistics.pixel_sum << 9 / FrameSize;
94+ }
95+
96+ struct Shutter
97+ {
98+ // exposure <= ShutterConfig::exposure_max!
99+ const PeriodType exposure;
100+ // ShutterConfig::period_min <= period <= ShutterConfig::period_max!
101+ const PeriodType period;
102+ } shutter;
103+
104+ Duration
105+ getExposureTime () const
106+ {
107+ return Duration (shutter.exposure );
108+ };
109+ Duration
110+ getFrameTime () const
111+ {
112+ return Duration (shutter.period );
113+ };
114+
97115protected:
98- static constexpr size_t length = 14 ;
99- Data_Fails_Monitoring (std::span<uint8_t , length> buffer)
100- : Data_Fails(buffer.subspan<0 , Data_Fails::length>()),
101- statistics{
102- surface_quality : buffer[6 ],
103- pixel_sum : buffer[7 ],
104- max_pixel : buffer[8 ],
105- min_pixel : buffer[9 ]
106- },
107- shutter{
108- exposure : buffer[10 ] << 8 | buffer[11 ],
109- period : buffer[12 ] << 8 | buffer[13 ],
110- } {}
111-
112- template <class , class >
113- friend class Adns9800 ;
116+ static constexpr size_t length = 14 ;
117+ Data_Fails_Monitoring (std::span<uint8_t , length> buffer)
118+ : Data_Fails(buffer.subspan<0 , Data_Fails::length>()),
119+ statistics{
120+ surface_quality : buffer[6 ],
121+ pixel_sum : buffer[7 ],
122+ max_pixel : buffer[8 ],
123+ min_pixel : buffer[9 ]
124+ },
125+ shutter{
126+ exposure : static_cast <PeriodType>(buffer[10 ] << 8 | buffer[11 ]),
127+ period : static_cast <PeriodType>(buffer[12 ] << 8 | buffer[13 ])
128+ }
129+ {}
130+
131+ template <class , class >
132+ friend class Adns9800 ;
114133};
115- } // namespace modm
134+ } // namespace modm
0 commit comments