oop-labs-collection/labs/6/RPI.java

106 lines
2.9 KiB
Java

/*
* %W% %E% Dymik739
* Email: dymik739@109.86.70.81
*
* Copyright (C) 2023 FIOT Dev Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Class which represents the RPI (Raspberry Pi) microcomputer.
*
* @author Dymik739
* @since 0.3
*/
public class RPI extends Appliance {
/** Contains current power draw from the power supply. */
private float power = 15.0f;
/**
* Defines the delay after the startup when the power usage starts to drop
* to it's lowest value.
*/
private float postBootDecreaseIn = 10.0f;
/**
* Constructor for this class.
*
* @param plugged sets the power state on the beginning
*/
public RPI(boolean plugged) {
super(plugged);
super.setType("RPI");
}
/**
* Method which is used to simulate the device's behaviour.
* The device draws it's maximum power for postBootDecreaseIn
* seconds and gradually drops to it's lowest level, after that
* it always stays on the lowest power usage level until a
* reboot happens.
*
* @param seconds delta time to simulate for
* @param ventRPM air flow generated by the vent
*/
public void step(float seconds, float ventRPM) {
postBootDecreaseIn -= seconds;
if ((postBootDecreaseIn <= 0) && (power >= 5.0)) {
power -= seconds;
}
if (power < 5.0) {
power = 5.0f;
}
}
/**
* Custom method for unplugging the device.
* Adds the automatic resetting to the default values right after
* turning the device off.
*/
@Override
public void unplug() {
super.unplug();
power = 15f;
postBootDecreaseIn = 10f;
}
/**
* Method for getting the power draw of this device.
*
* @return current power consumption
*/
public float getPowerConsumption() {
if (super.getPowerState()) {
return power;
} else {
return 0f;
}
}
/**
* Method for printing this devices' object in a nice way.
*
* @return String containing text description of this devices' state
*/
@Override
public String toString() {
return String.format("RPI(%s, %4.1fW)",
super.getPowerState() ? "on" : "off", getPowerConsumption());
}
}