| /******************************************************************************* |
| * Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Pierre Allard, |
| * Regent L'Archeveque - initial API and implementation |
| * |
| * SPDX-License-Identifier: EPL-1.0 |
| *******************************************************************************/ |
| package org.eclipse.apogy.examples.rover.impl; |
| |
| public class PowerSystemCustomImpl extends PowerSystemImpl { |
| |
| @Override |
| public void changeActiveBatteryTo(int batteryIndex) { |
| // If the index is in the permitted range |
| if ((batteryIndex >= 0) && (batteryIndex < this.getBatteries().size())) { |
| // If there is currently an active battery |
| if (this.getActiveBattery() != null) { |
| // If this index corresponds to the current battery |
| if (this.getActiveBattery() == this.getBatteries().get(batteryIndex)) { |
| // Just return; nothing else needs to be done |
| return; |
| } |
| // Otherwise, it's referring to a different battery |
| else { |
| // Deactivate the currently active battery |
| this.getActiveBattery().deactivate(); |
| } |
| } |
| |
| // Switch to the new battery |
| this.setActiveBattery(this.getBatteries().get(batteryIndex)); |
| |
| // Activate the new battery |
| this.getActiveBattery().activate(); |
| } |
| } |
| |
| } // PowerSystemImpl |