Skip to content

Commit

Permalink
Eclipse autoformat-on-save invoked; no logic changes (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed May 18, 2021
1 parent f79df03 commit c7ab971
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,81 +11,81 @@

/**
*
* @author Copyright &copy; <a href="mailto:vt@freehold.crocodile.org"> Vadim Tkachenko</a> 2001-2018
* @author Copyright &copy; <a href="mailto:vt@homeclimatecontrol.com"> Vadim Tkachenko</a> 2001-2020
*/
public class DamperFactory {

private final Logger logger = LogManager.getLogger(getClass());
private final ServoController theController;

public DamperFactory(String className, String portName) {

ThreadContext.push("DamperFactory()");

try {

Class<?> controllerClass = Class.forName(className);
logger.info("Found class: " + controllerClass.getCanonicalName());

if (!ServoController.class.isAssignableFrom(controllerClass)) {
throw new IllegalArgumentException("Not a servo controller: " + controllerClass.getName());
}

logger.info("new " + className + "()");
Object controllerObject = controllerClass.newInstance();

theController = (ServoController) controllerObject;
logger.info("Controller instantiated: " + theController.getMeta());

theController.init(portName);

} catch (ClassNotFoundException ex) {

throw new IllegalArgumentException("Can't find class for name '" + className + "'", ex);

} catch (SecurityException ex) {

throw new IllegalArgumentException("Don't know how to handle", ex);

} catch (InstantiationException ex) {

throw new IllegalArgumentException("Don't know how to handle", ex);

} catch (IllegalAccessException ex) {

throw new IllegalArgumentException("Don't know how to handle", ex);

} catch (IOException ex) {

throw new IllegalArgumentException("Don't know how to handle", ex);

} finally {
ThreadContext.pop();
}
}

/**
* Get an instance of a straight (not reversed) damper with no calibration.
*
*
* @param name Human readable name.
* @param id Controller specific servo ID.
*
*
* @return Damper instance.
* @throws IOException if things go wrong.
*/
public Damper getDamper(String name, String id) throws IOException {

return getDamper(name, id, false, null, null);
}

/**
* Get an instance of a damper with range calibration only.
*
*
* @param name Human readable name.
* @param id Controller specific servo ID.
* @param reverse {@code true} if the damper needs to be reversed.
* @param rangeCalibration Range calibration object.
*
*
* @return Damper instance.
* @throws IOException if things go wrong.
*/
Expand All @@ -97,15 +97,15 @@ public Damper getDamper(

return getDamper(name, id, reverse, rangeCalibration, null);
}

/**
* Get an instance of a damper with limit calibration only.
*
*
* @param name Human readable name.
* @param id Controller specific servo ID.
* @param reverse {@code true} if the damper needs to be reversed.
* @param limitCalibration Limit calibration object.
*
*
* @return Damper instance.
* @throws IOException if things go wrong.
*/
Expand All @@ -124,7 +124,7 @@ private Damper getDamper(
boolean reverse,
RangeCalibration rangeCalibration,
LimitCalibration limitCalibration) throws IOException {

return new ServoDamper(name, theController.getServo(id), reverse, rangeCalibration, limitCalibration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Damper controlled by a RC Servo.
*
* @author Copyright &copy; <a href="mailto:vt@freehold.crocodile.org"> Vadim Tkachenko</a> 2001-2018
* @author Copyright &copy; <a href="mailto:vt@homeclimatecontrol.com"> Vadim Tkachenko</a> 2001-2020
*/
public class ServoDamper extends AbstractDamper {

Expand All @@ -28,31 +28,31 @@ public class ServoDamper extends AbstractDamper {

/**
* Create an instance with no reversing and no range or limit calibration.
*
*
* @param name Human readable name.
* @param servo Servo instance to use.
*/
public ServoDamper(String name, Servo servo) {

this(name, servo, false, null, null);
}

/**
* Create an instance with range calibration only.
*
*
* @param name Human readable name.
* @param servo Servo instance to use.
* @param reverse {@code true} if the servo movement should be reversed.
* @param rangeCalibration Range calibration object.
*/
public ServoDamper(String name, Servo servo, boolean reverse, RangeCalibration rangeCalibration) {

this(name, servo, reverse, rangeCalibration, null);
}

/**
* Create an instance with limit calibration only.
*
*
* @param name Human readable name.
* @param servo Servo instance to use.
* @param reverse {@code true} if the servo movement should be reversed.
Expand All @@ -62,12 +62,12 @@ public ServoDamper(String name, Servo servo, boolean reverse, LimitCalibration l

this(name, servo, reverse, null, limitCalibration);
}

/**
* Create an instance.
*
*
* Only one of {@code rangeCalibration} and {@code limitCalibration} can be not null at the same time.
*
*
* @param name Human readable name.
* @param servo Servo instance to use.
* @param reverse {@code true} if the servo movement should be reversed.
Expand All @@ -80,13 +80,13 @@ public ServoDamper(
boolean reverse,
RangeCalibration rangeCalibration,
LimitCalibration limitCalibration) {

super(name);

ThreadContext.push("ServoDamper()");

try {

if (servo == null ) {
throw new IllegalArgumentException("servo can't be null");
}
Expand All @@ -100,22 +100,22 @@ public ServoDamper(
logger.info("limit: " + limitCalibration);

if (rangeCalibration != null) {

servo.getMeta().setProperty("servo/range/min", Integer.toString(rangeCalibration.min));
servo.getMeta().setProperty("servo/range/max", Integer.toString(rangeCalibration.max));
}

// Until it is actually done in configuration, let's just install a crawl controller
// But only if it is specifically requested (see dz-runner script)

if (System.getProperty(getClass().getName() + ".crawl") != null) {

logger.info("Will be crawling");
servo.attach(new CrawlTransitionController(), false);
}

if (limitCalibration != null) {

servo = new LimitTransformer(servo, limitCalibration.min, limitCalibration.max);
}

Expand All @@ -125,7 +125,7 @@ public ServoDamper(
}

// VT: NOTE: This may not always be the case, there will be
// contraptions with angle range other than 0..180. This
// contraptions with angle range other than 0..180. This
// will have to be configurable. On the other hand, nobody
// complained in five years, so it should be fine as is.

Expand All @@ -142,7 +142,7 @@ public ServoDamper(
public Future<TransitionStatus> moveDamper(double throttle) {

ThreadContext.push("moveDamper");

try {

if (Double.compare(servo.getPosition(), throttle) != 0) {
Expand Down Expand Up @@ -170,7 +170,7 @@ public Future<TransitionStatus> park() {

@Override
public JmxDescriptor getJmxDescriptor() {

return new JmxDescriptor(
"dz",
"Servo based damper",
Expand Down

0 comments on commit c7ab971

Please sign in to comment.