Skip to content

Commit

Permalink
Replaced assert keyword with RunTimeException on setPulseWidth method…
Browse files Browse the repository at this point in the history
… and associated interface and javadoc
  • Loading branch information
topherbuckley committed Jun 1, 2021
1 parent cfc92cb commit ce3c1d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions IOIOLibCore/src/main/java/ioio/lib/api/PwmOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ public interface PwmOutput extends Closeable {
* the high-time within a single period of the signal. For relative control
* of the pulse with, consider using {@link #setDutyCycle(float)}.
*
* @param pulseWidthUs The pulse width, in microsecond units.
* @param pulseWidthUs The pulse width, in microsecond units. Must be larger than zero.
* @throws ConnectionLostException The connection to the IOIO has been lost.
* @throws RuntimeException pulseWidthUs must take values larger than zero.
* @see #setDutyCycle(float)
*/
void setPulseWidth(int pulseWidthUs) throws ConnectionLostException;
void setPulseWidth(int pulseWidthUs) throws ConnectionLostException, RuntimeException;

/**
* The same as {@link #setPulseWidth(int)}, but with sub-microsecond
* precision.
*/
void setPulseWidth(float pulseWidthUs)
throws ConnectionLostException;
throws ConnectionLostException, RuntimeException;
}
8 changes: 5 additions & 3 deletions IOIOLibCore/src/main/java/ioio/lib/impl/PwmImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ public void setDutyCycle(float dutyCycle) throws ConnectionLostException, Runtim
}

@Override
public void setPulseWidth(int pulseWidthUs) throws ConnectionLostException {
public void setPulseWidth(int pulseWidthUs) throws ConnectionLostException, RuntimeException {
setPulseWidth((float) pulseWidthUs);
}

@Override
public void setPulseWidth(float pulseWidthUs)
throws ConnectionLostException {
assert (pulseWidthUs >= 0);
throws ConnectionLostException, RuntimeException {
if (pulseWidthUs < 0) {
throw new RuntimeException("pulseWidthUs must be larger than 0. A pulseWidthUs of " + pulseWidthUs + " was given.");
}
float p = pulseWidthUs / baseUs_;
setPulseWidthInClocks(p);
}
Expand Down

0 comments on commit ce3c1d1

Please sign in to comment.