Pārlūkot izejas kodu

Made errors cleaner when no GRID is found.

Also removed debug messages from fan profile.
Tankernn 8 gadi atpakaļ
vecāks
revīzija
4bd43e5a1b

+ 0 - 1
src/main/java/eu/tankernn/grid/FanSpeedProfile.java

@@ -18,7 +18,6 @@ public class FanSpeedProfile {
 
 
 	public int getSpeedPercentage(double cpuTemp, double gpuTemp) {
 	public int getSpeedPercentage(double cpuTemp, double gpuTemp) {
 		double temp = (cpuTemp * cpuWeightPercent + gpuTemp * gpuWeightPercent) / 100;
 		double temp = (cpuTemp * cpuWeightPercent + gpuTemp * gpuWeightPercent) / 100;
-		System.out.println(temp);
 		double currentTemp = MIN_TEMP;
 		double currentTemp = MIN_TEMP;
 
 
 		for (int i : getPercentages()) {
 		for (int i : getPercentages()) {

+ 13 - 18
src/main/java/eu/tankernn/grid/model/Communicator.java

@@ -59,17 +59,15 @@ public class Communicator {
 	 * Sends test data to the device to check availability.
 	 * Sends test data to the device to check availability.
 	 * 
 	 * 
 	 * @return If the ping was successful (the device responded correctly)
 	 * @return If the ping was successful (the device responded correctly)
+	 * @throws InterruptedException
+	 * @throws IOException
 	 */
 	 */
-	private boolean ping() {
-		byte[] buffer = null;
+	private boolean ping() throws IOException, InterruptedException {
 		try {
 		try {
-			buffer = writeData(new byte[] { (byte) 0xc0 });
-		} catch (IOException e) {
-			e.printStackTrace();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
+			return writeData(new byte[] { (byte) 0xc0 })[0] == 0x21;
+		} catch (ArrayIndexOutOfBoundsException e) {
+			return false;
 		}
 		}
-		return buffer[0] == 0x21;
 	}
 	}
 
 
 	/**
 	/**
@@ -97,13 +95,9 @@ public class Communicator {
 	 */
 	 */
 	private byte[] serialRead() {
 	private byte[] serialRead() {
 		try {
 		try {
-			if (input.available() > 0) {
-				byte[] buffer = new byte[input.available()];
-				input.read(buffer);
-				return buffer;
-			} else {
-				System.err.println("Failed to read data. No data to read");
-			}
+			byte[] buffer = new byte[input.available()];
+			input.read(buffer);
+			return buffer.length > 0 ? buffer : new byte[32];
 		} catch (IOException e) {
 		} catch (IOException e) {
 			System.err.println("Failed to read data. (" + e.toString() + ")");
 			System.err.println("Failed to read data. (" + e.toString() + ")");
 		}
 		}
@@ -114,10 +108,11 @@ public class Communicator {
 	 * This method sends a byte array command over the serial communication
 	 * This method sends a byte array command over the serial communication
 	 * afterwards the method calls the read method
 	 * afterwards the method calls the read method
 	 * 
 	 * 
-	 * @param command an array of bytes as a command
+	 * @param command
+	 *            an array of bytes as a command
 	 * @return The response data from the device
 	 * @return The response data from the device
-	 * @throws IOException 
-	 * @throws InterruptedException 
+	 * @throws IOException
+	 * @throws InterruptedException
 	 */
 	 */
 	public byte[] writeData(byte[] command) throws IOException, InterruptedException {
 	public byte[] writeData(byte[] command) throws IOException, InterruptedException {
 		sleep(50);
 		sleep(50);