@@ -31,9 +31,9 @@ struct device_error final : std::runtime_error {
3131// Interface
3232
3333struct sample {
34- const std::int32_t angle;
35- const std::int32_t distance;
36- const std::int32_t signal_strength;
34+ std::int32_t angle;
35+ std::int32_t distance;
36+ std::int32_t signal_strength;
3737};
3838
3939struct scan {
@@ -74,55 +74,57 @@ struct error_to_exception {
7474
7575 ::sweep_error_s error = nullptr ;
7676};
77- }
77+ } // namespace detail
7878
79- sweep::sweep (const char * port)
79+ inline sweep::sweep (const char * port)
8080 : device{::sweep_device_construct_simple (port, detail::error_to_exception{}), &::sweep_device_destruct} {}
8181
82- sweep::sweep (const char * port, std::int32_t bitrate)
82+ inline sweep::sweep (const char * port, std::int32_t bitrate)
8383 : device{::sweep_device_construct (port, bitrate, detail::error_to_exception{}), &::sweep_device_destruct} {}
8484
85- void sweep::start_scanning () { ::sweep_device_start_scanning (device.get (), detail::error_to_exception{}); }
85+ inline void sweep::start_scanning () { ::sweep_device_start_scanning (device.get (), detail::error_to_exception{}); }
8686
87- void sweep::stop_scanning () { ::sweep_device_stop_scanning (device.get (), detail::error_to_exception{}); }
87+ inline void sweep::stop_scanning () { ::sweep_device_stop_scanning (device.get (), detail::error_to_exception{}); }
8888
89- bool sweep::get_motor_ready () { return ::sweep_device_get_motor_ready (device.get (), detail::error_to_exception{}); }
89+ inline bool sweep::get_motor_ready () { return ::sweep_device_get_motor_ready (device.get (), detail::error_to_exception{}); }
9090
91- std::int32_t sweep::get_motor_speed () { return ::sweep_device_get_motor_speed (device.get (), detail::error_to_exception{}); }
91+ inline std::int32_t sweep::get_motor_speed () {
92+ return ::sweep_device_get_motor_speed (device.get (), detail::error_to_exception{});
93+ }
9294
93- void sweep::set_motor_speed (std::int32_t speed) {
95+ inline void sweep::set_motor_speed (std::int32_t speed) {
9496 ::sweep_device_set_motor_speed (device.get(), speed, detail::error_to_exception{});
9597}
9698
97- std::int32_t sweep::get_sample_rate () { return ::sweep_device_get_sample_rate (device.get (), detail::error_to_exception{}); }
99+ inline std::int32_t sweep::get_sample_rate () {
100+ return ::sweep_device_get_sample_rate (device.get (), detail::error_to_exception{});
101+ }
98102
99- void sweep::set_sample_rate (std::int32_t rate) {
103+ inline void sweep::set_sample_rate (std::int32_t rate) {
100104 ::sweep_device_set_sample_rate (device.get(), rate, detail::error_to_exception{});
101105}
102106
103- scan sweep::get_scan () {
107+ inline scan sweep::get_scan () {
104108 using scan_owner = std::unique_ptr<::sweep_scan, decltype (&::sweep_scan_destruct)>;
105109
106- scan_owner releasing_scan{::sweep_device_get_scan (device.get (), detail::error_to_exception{}), &::sweep_scan_destruct};
110+ const scan_owner releasing_scan{::sweep_device_get_scan (device.get (), detail::error_to_exception{}), &::sweep_scan_destruct};
107111
108- auto num_samples = ::sweep_scan_get_number_of_samples (releasing_scan.get ());
109-
110- scan result;
111- result.samples .reserve (num_samples);
112+ const auto num_samples = ::sweep_scan_get_number_of_samples (releasing_scan.get ());
112113
114+ scan result{std::vector<sample>(num_samples)};
113115 for (std::int32_t n = 0 ; n < num_samples; ++n) {
114- auto angle = :: sweep_scan_get_angle (releasing_scan. get (), n);
115- auto distance = ::sweep_scan_get_distance (releasing_scan.get (), n);
116- auto signal = ::sweep_scan_get_signal_strength (releasing_scan.get (), n);
117-
118- result. samples . push_back (sample{angle, distance, signal});
116+ // clang-format off
117+ result. samples [n]. angle = ::sweep_scan_get_angle (releasing_scan.get (), n);
118+ result. samples [n]. distance = ::sweep_scan_get_distance (releasing_scan.get (), n);
119+ result. samples [n]. signal_strength = :: sweep_scan_get_signal_strength (releasing_scan. get (), n);
120+ // clang-format on
119121 }
120122
121123 return result;
122124}
123125
124- void sweep::reset () { ::sweep_device_reset (device.get (), detail::error_to_exception{}); }
126+ inline void sweep::reset () { ::sweep_device_reset (device.get (), detail::error_to_exception{}); }
125127
126- } // ns
128+ } // namespace sweep
127129
128130#endif
0 commit comments