Skip to content

Commit

Permalink
Stops scanning and flushes serial device on destruction, resolves #23
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h committed Jan 25, 2017
1 parent 9fbe17d commit 860e417
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libsweep/examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ int main() {
sweep_scan_destruct(scan);
}

// Stop capturing scans
sweep_device_stop_scanning(sweep, &error);
check(error);

// Shut down and cleanup Sweep device
sweep_device_destruct(sweep);
return EXIT_SUCCESS;
Expand Down
3 changes: 3 additions & 0 deletions libsweep/examples/example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ int main() try {
std::cout << "angle " << sample.angle << " distance " << sample.distance << " strength " << sample.signal_strength << "\n";
}
}

device.stop_scanning();

} catch (const sweep::device_error& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
3 changes: 3 additions & 0 deletions libsweep/examples/viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ int main() try {
pointCloud = std::move(localPointCloud);
}
}

device.stop_scanning();

} catch (const sweep::device_error& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
4 changes: 4 additions & 0 deletions libsweep/serial_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ sweep_serial_device_s sweep_serial_device_construct(const char* port, int32_t bi
void sweep_serial_device_destruct(sweep_serial_device_s serial) {
SWEEP_ASSERT(serial);

sweep_serial_error_s ignore = NULL;
sweep_serial_device_flush(serial, &ignore);
(void)ignore; // nothing we can do here

free(serial);
}

Expand Down
4 changes: 4 additions & 0 deletions libsweep/sweep.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ sweep_device_s sweep_device_construct(const char* port, int32_t bitrate, sweep_e
void sweep_device_destruct(sweep_device_s device) {
SWEEP_ASSERT(device);

sweep_error_s ignore = NULL;
sweep_device_stop_scanning(device, &ignore);
(void)ignore; // nothing we can do here

sweep_serial_device_destruct(device->serial);

free(device);
Expand Down

0 comments on commit 860e417

Please sign in to comment.