lots of updates srry

This commit is contained in:
Fennel Kora 2024-04-13 20:02:33 -04:00
parent cde3d2459e
commit 77183117af

View file

@ -1,8 +1,11 @@
//for all arrays, index 0 is driver's side, index 1 is passenger's side
public class Climate { public class Climate {
public int[] targetTemp; //array to store temps, index 0 is driver, index 1 i passenger private int[] targetTemp; //array to store temp preference entered by user
public int[] currentTemp; private int[] currentTemp; //stores current internal temp from last check
public boolean coolingActive; private int externalTemp; //stores current external temp from last check
public boolean heatingActive; private boolean[] coolingActive; //whether cooling is toggled on (true) or off (false)
private boolean[] heatingActive; //whether heating is toggled on (true) or off (false)
public enum fanLevels {OFF, LOW, MED, HI}; //standardization of fan levels public enum fanLevels {OFF, LOW, MED, HI}; //standardization of fan levels
fanLevels[] fanSpeed; //array to store fan speeds, zones match temp indices fanLevels[] fanSpeed; //array to store fan speeds, zones match temp indices
@ -17,10 +20,77 @@ public class Climate {
targetTemp[1] = passengerZone; targetTemp[1] = passengerZone;
} }
public void updateCurrentTemps() { //queries temp sensors for current cabin temp private int avgTargetTemp() { //gets internal target average for ease of calculation
HelperFunctions tSensor = new HelperFunctions(); return (targetTemp[0] + targetTemp[1])/2;
currentTemp = tSensor.tempSensors();
} }
private void updateCurrentTemps() { //queries temp sensors for current cabin temp
HelperFunctions tSensor = new HelperFunctions();
currentTemp = tSensor.internalTempSensors();
externalTemp = tSensor.externalTempSensors();
}
public int[] getTargetTemps() {
return targetTemp;
}
public int[] getCurrentTemps() {
return currentTemp;
}
public void activateClimate() {
updateCurrentTemps(); //check current temps before actioning logic
if (externalTemp >= avgTargetTemp()) { //puts logic into "cooling" mode
//driver's side
if (targetTemp[0]+1 < currentTemp[0]) {coolingActive[0] = true;} //provides 1 deg buffer to prevent excessive activation/deactivation
if (targetTemp[0] >= currentTemp[0]) {coolingActive[0] = false;}
//passenger's side
if (targetTemp[1]+1 < currentTemp[1]) {coolingActive[1] = true;}
if (targetTemp[1] >= currentTemp[1]) {coolingActive[1] = false;}
} else if (externalTemp < avgTargetTemp()) { //puts logic into "heating" mode
//driver's side
if (targetTemp[0]-1 > currentTemp[0]) {heatingActive[0] = true;}
if (targetTemp[0] <= currentTemp[0]) {heatingActive[0] = false;}
//passenger's side
if (targetTemp[1]-1 > currentTemp[1]) {heatingActive[1] = true;}
if (targetTemp[1] <= currentTemp[1]) {heatingActive[1] = false;}
}
}
public void setFanSpeeds(String driver, String passenger) { //maps a string passed in to the appropriate enum value
switch (driver) {
case "OFF":
fanSpeed[0] = fanLevels.OFF;
break;
case "LOW":
fanSpeed[0] = fanLevels.LOW;
break;
case "MED":
fanSpeed[0] = fanLevels.MED;
break;
case "HI":
fanSpeed[0] = fanLevels.HI;
break;
}
switch (passenger) {
case "OFF":
fanSpeed[1] = fanLevels.OFF;
break;
case "LOW":
fanSpeed[2] = fanLevels.LOW;
break;
case "MED":
fanSpeed[3] = fanLevels.MED;
break;
case "HI":
fanSpeed[4] = fanLevels.HI;
break;
}
}
public String[] getFanSpeeds() {
String[] workingString = {fanSpeed[0].toString(), fanSpeed[1].toString()};
return workingString;
}
} }