private boolean setMode(int modeWord) { boolean res = false; if (connection.isConnected()) { if (modeWord == Mode.YELLOW_LIGHT_DISABLE.getValue()) { modeWord = previousModeWord; } else if (modeWord == Mode.EXPOSITION_WITH_CALIBRATION_LIGHTS.getValue() || modeWord == Mode.DIAMETER_EXPOSITION.getValue() || modeWord == Mode.CALIBRATE_DIAMETER.getValue() || modeWord == Mode.LENGTH_EXPOSITION.getValue() || modeWord == Mode.YELLOW_LIGHT_ENABLE.getValue()) { if ((previousModeWord & Mode.CALIBRATION_ARM_UNLOCK.getValue()) > 0) { modeWord |= Mode.CALIBRATION.getValue(); } else { modeWord |= previousModeWord; } } else { previousModeWord = modeWord; } dlog.d("setMode: " + modeWord); res = connection.writeRegister(MEMORY_AREA_B2, Register.MODE.getValue(), new int[] {modeWord}); } return res; }
private boolean setFrequencies(int trackFrequency, int cylinderFrequency) { boolean res = false; if (connection.isConnected()) { dlog.d("setFrequencies: " + trackFrequency + ", " + cylinderFrequency); TrackDirection trackDir = (trackFrequency > 0 ? TrackDirection.FORWARD : TrackDirection.STOP); boolean r1 = connection.writeRegister( MEMORY_AREA_B2, Register.FREQCHANGER1.getValue(), new int[] {trackDir.getValue(), trackFrequency}); TrackDirection cylinderDir = (cylinderFrequency > 0 ? TrackDirection.FORWARD : TrackDirection.STOP); boolean r2 = connection.writeRegister( MEMORY_AREA_B2, Register.FREQCHANGER2.getValue(), new int[] {cylinderDir.getValue(), cylinderFrequency}); res = r1 && r2; if (res) { frequencyChangeListener.onMotor1FrequencyChanged(trackFrequency); frequencyChangeListener.onMotor2FrequencyChanged(cylinderFrequency); } } return res; }
public boolean connect() { boolean res = false; if (connection != null && !connection.isConnected()) { dlog.d("connect"); res = connection.connect(); } return res; }
public boolean reconnect() { boolean res = false; dlog.d("reconnect"); disconnect(); res = connect(); return res; }
public boolean disconnect() { boolean res = false; if (connection.isConnected()) { dlog.d("disconnect"); res = connection.disconnect(); } return res; }
private boolean setDelay(Register delayRegister, int delay) { boolean res = false; if (connection.isConnected()) { dlog.d("setDelay " + delayRegister.name() + "(" + delayRegister.getValue() + "): " + delay); res = connection.writeBcdRegister(MEMORY_AREA_B2, delayRegister.getValue(), new int[] {delay}); } return res; }
private boolean setLights(Lights l) { boolean res = false; if (connection.isConnected()) { dlog.d("setLights: " + l.getValue()); res = connection.writeRegister( MEMORY_AREA_B2, Register.LIGHTS.getValue(), new int[] {l.getValue()}); } return res; }
private boolean setServoNullPosition(int position) { boolean res = false; if (connection.isConnected()) { dlog.d("setServoNullPosition: " + position); res = connection.writeRegister( MEMORY_AREA_B2, Register.SERVO_NULL_POSITION.getValue(), new int[] {position}); } return res; }
private boolean setCylinderDistanceWithoutModeChanging(int distance) { boolean res = false; if (connection.isConnected()) { dlog.d("setCylinderDistanceWithoutModeChanging: " + distance); res = connection.writeRegister( MEMORY_AREA_B2, Register.CYLINDER_DISTANCE.getValue(), new int[] {distance}); } return res; }
private boolean setCylinderDistance(int distance) { boolean res = false; if (connection.isConnected()) { dlog.d("setCylinderDistance: " + distance); boolean r1 = connection.writeRegister( MEMORY_AREA_B2, Register.CYLINDER_DISTANCE.getValue(), new int[] {distance}); boolean r2 = setMode(Mode.DIAMETER_SETTING.getValue()); res = r1 && r2; } return res; }