Skip to content

Commit

Permalink
Remove wait_until_motor_ready from public API, until error handling i…
Browse files Browse the repository at this point in the history
…s resolved
  • Loading branch information
dcyoung committed Apr 22, 2017
1 parent 0e30a5a commit c86f73a
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 43 deletions.
13 changes: 2 additions & 11 deletions libsweep/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void sweep_device_start_scanning(sweep_device_s device, sweep_error_s* error)

Signals the `sweep_device_s` to start scanning.
If the motor is stationary (0Hz), will automatically set motor speed to default 5Hz.
Will block until the the motor speed is stable (uses `sweep_device_wait_until_motor_ready` internally).
Will block until the device is ready (calibration routine complete + motor speed is stable).
Starts internal background thread to accumulate and queue up scans. Scans can then be retrieved using `sweep_device_get_scan`.
In case of error a `sweep_error_s` will be written into `error`.

Expand All @@ -207,20 +207,11 @@ Signals the `sweep_device_s` to stop scanning.
Blocks for ~35ms to allow time for the trailing data stream to collect and flush internally, before sending a second stop command and validate the response.
In case of error a `sweep_error_s` will be written into `error`.
```c++
void sweep_device_wait_until_motor_ready(sweep_device_s device, sweep_error_s* error)
```

Blocks until the `sweep_device_s` is ready, or the method times out (after 8 seconds). A device is ready when the motor speed has stabilized to the current setting, and the calibration routine is complete. The worst case wait time is around 6 seconds, which includes both motor stabilization and calibration. For visual reference, the blue LED on the device will blink unil the device is ready. This method is useful when the device is powered on, or when adjusting motor speed. If the device is NOT ready, it will respond to certain commands (`DS` or `MS`) with a status code indicating a failure to execute the command. Therefore, it is best practice to avoid this entirely by calling `sweep_device_wait_until_motor_ready` before calling a command that requires a ready device.
In case of error a `sweep_error_s` will be written into `error`.

```c++
bool sweep_device_get_motor_ready(sweep_device_s device, sweep_error_s* error)
```

Returns `true` if the device is ready. A device is ready if the motor speed has stabilized to the current setting, and the calibration routine is complete.
This method can be used to create a non-blocking alternative to `sweep_device_wait_until_motor_ready` in user programs.
For visual reference, the blue LED on the device will blink during calibration/speed stabilization, and stop blinking when the device is ready.
Returns `true` if the device is ready. A device is ready when the motor speed has stabilized to the current setting, and the calibration routine is complete. For visual reference, the blue LED on the device will blink unil the device is ready. This method is useful when the device is powered on, or when adjusting motor speed. If the device is NOT ready, it will respond to certain commands (`DS` or `MS`) with a status code indicating a failure to execute the command.
In case of error a `sweep_error_s` will be written into `error`.

```c++
Expand Down
2 changes: 1 addition & 1 deletion libsweep/include/sweep/sweep.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ SWEEP_API void sweep_device_start_scanning(sweep_device_s device, sweep_error_s*
SWEEP_API void sweep_device_stop_scanning(sweep_device_s device, sweep_error_s* error);

// Blocks until the device is ready (calibration complete and motor speed stabilized)
SWEEP_API void sweep_device_wait_until_motor_ready(sweep_device_s device, sweep_error_s* error);
void sweep_device_wait_until_motor_ready(sweep_device_s device, sweep_error_s* error);

// Retrieves a scan from the queue (will block until scan is available)
SWEEP_API sweep_scan_s sweep_device_get_scan(sweep_device_s device, sweep_error_s* error);
Expand Down
3 changes: 0 additions & 3 deletions libsweep/include/sweep/sweep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class sweep {
sweep(const char* port, std::int32_t bitrate);
void start_scanning();
void stop_scanning();
void wait_until_motor_ready();
bool get_motor_ready();
std::int32_t get_motor_speed();
void set_motor_speed(std::int32_t speed);
Expand Down Expand Up @@ -87,8 +86,6 @@ void sweep::start_scanning() { ::sweep_device_start_scanning(device.get(), detai

void sweep::stop_scanning() { ::sweep_device_stop_scanning(device.get(), detail::error_to_exception{}); }

void sweep::wait_until_motor_ready() { ::sweep_device_wait_until_motor_ready(device.get(), detail::error_to_exception{}); }

bool sweep::get_motor_ready() { return ::sweep_device_get_motor_ready(device.get(), detail::error_to_exception{}); }

std::int32_t sweep::get_motor_speed() { return ::sweep_device_get_motor_speed(device.get(), detail::error_to_exception{}); }
Expand Down
4 changes: 1 addition & 3 deletions sweepjs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ sweep = new Sweep('/dev/ttyUSB0');
sweep.startScanning();
sweep.stopScanning();

// waits until device is ready (calibration routine complete and motor speed stabilized)
sweep.waitUntilMotorReady();
// ready === true if device is ready, false otherwise
// true if device is ready (calibration routine complete + motor speed stabilized)
ready = sweep.getMotorReady();
// integer value between 0:10 (in HZ)
speed = sweep.getMotorSpeed();
Expand Down
11 changes: 0 additions & 11 deletions sweepjs/sweepjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ NAN_MODULE_INIT(Sweep::Init) {

SetPrototypeMethod(fnTp, "startScanning", startScanning);
SetPrototypeMethod(fnTp, "stopScanning", stopScanning);
SetPrototypeMethod(fnTp, "waitUntilMotorReady", waitUntilMotorReady);
SetPrototypeMethod(fnTp, "scan", scan);
SetPrototypeMethod(fnTp, "getMotorReady", getMotorReady);
SetPrototypeMethod(fnTp, "getMotorSpeed", getMotorSpeed);
Expand Down Expand Up @@ -135,16 +134,6 @@ NAN_METHOD(Sweep::stopScanning) {
::sweep_device_stop_scanning(self->device.get(), ErrorToNanException{});
}

NAN_METHOD(Sweep::waitUntilMotorReady) {
auto* const self = Nan::ObjectWrap::Unwrap<Sweep>(info.Holder());

if (info.Length() != 0) {
return Nan::ThrowTypeError("No arguments expected");
}

::sweep_device_wait_until_motor_ready(self->device.get(), ErrorToNanException{});
}

class AsyncScanWorker final : public Nan::AsyncWorker {
public:
AsyncScanWorker(Nan::Callback* callback, std::shared_ptr<::sweep_device> device)
Expand Down
1 change: 0 additions & 1 deletion sweepjs/sweepjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class Sweep final : public Nan::ObjectWrap {

static NAN_METHOD(startScanning);
static NAN_METHOD(stopScanning);
static NAN_METHOD(waitUntilMotorReady);

static NAN_METHOD(scan);

Expand Down
1 change: 0 additions & 1 deletion sweeppy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class Sweep:
def start_scanning(self) -> None
def stop_scanning(self) -> None
def wait_until_motor_ready(self) -> None
def get_motor_ready(self) -> bool
def get_motor_speed(self) -> int (Hz)
def set_motor_speed(self, speed) -> None
Expand Down
12 changes: 0 additions & 12 deletions sweeppy/sweeppy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
libsweep.sweep_device_stop_scanning.restype = None
libsweep.sweep_device_stop_scanning.argtypes = [ctypes.c_void_p, ctypes.c_void_p]

libsweep.sweep_device_wait_until_motor_ready.restype = None
libsweep.sweep_device_wait_until_motor_ready.argtypes = [ctypes.c_void_p, ctypes.c_void_p]

libsweep.sweep_device_get_scan.restype = ctypes.c_void_p
libsweep.sweep_device_get_scan.argtypes = [ctypes.c_void_p, ctypes.c_void_p]

Expand Down Expand Up @@ -147,15 +144,6 @@ def stop_scanning(_):
if error:
raise _error_to_exception(error)

def wait_until_motor_ready(_):
_._assert_scoped()

error = ctypes.c_void_p()
libsweep.sweep_device_wait_until_motor_ready(_.device, ctypes.byref(error))

if error:
raise _error_to_exception(error)

def get_motor_ready(_):
_._assert_scoped()

Expand Down

0 comments on commit c86f73a

Please sign in to comment.