GRID.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package eu.tankernn.grid.model;
  2. import java.io.IOException;
  3. import java.util.Arrays;
  4. import java.util.stream.IntStream;
  5. import java.util.stream.Stream;
  6. import eu.tankernn.grid.Fan;
  7. /**
  8. * This class uses the communicator class to communicate with the GRID+
  9. * controller.
  10. *
  11. * @author Frans
  12. */
  13. public class GRID {
  14. private Communicator communicator = new Communicator();
  15. private Fan[] fans = IntStream.range(0, 6).mapToObj(i -> new Fan(communicator, i)).toArray(Fan[]::new);
  16. /**
  17. * This method simply runs the disconnect method of the communicator.
  18. */
  19. public void disconnect() {
  20. communicator.disconnect();
  21. }
  22. /**
  23. * Gets the fan at the specified index.
  24. *
  25. * @param index
  26. * The fan index (0-5)
  27. * @return The fan object
  28. */
  29. public Fan getFan(int index) {
  30. return fans[index];
  31. }
  32. public Communicator getCommunicator() {
  33. return communicator;
  34. }
  35. public double getTotalWattage() {
  36. return fanStream().mapToDouble(Fan::getWattage).sum();
  37. }
  38. public void pollFans() throws IOException, InterruptedException {
  39. if (communicator.isConnected())
  40. for (Fan f : fans)
  41. f.poll();
  42. }
  43. public void updateFanSpeeds(double cpuTemp, double gpuTemp, int minSpeed) {
  44. fanStream().forEach(f -> f.update(cpuTemp, gpuTemp, minSpeed));
  45. }
  46. public Stream<Fan> fanStream() {
  47. return Arrays.stream(fans);
  48. }
  49. }