pollAndCompute.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package camsucks;
  7. import javafx.application.Platform;
  8. /**
  9. *
  10. * This class, when run, enters an infinite loop. This loop will if the right
  11. * conditions are met first poll the FAN RPM and FAN AMP of each fan Then it
  12. * will poll the CPU temperature After that if the program isn't set to manual
  13. * the loop will compute the percentage to send according to the cpu temperature
  14. * as last step this loop will send the desired percentage to the fans (this
  15. * could be the computed or the manually chosen percentage
  16. *
  17. * @author Roel
  18. */
  19. class pollAndCompute implements Runnable {
  20. private ComputerModel model;
  21. private Thread t;
  22. private int ticks;
  23. public pollAndCompute(ComputerModel model) {
  24. ticks = 0;
  25. this.model = model;
  26. }
  27. @Override
  28. public void run() {
  29. while (true) {
  30. //System.out.println("Polling...");
  31. if (model.isExtraPoll()) {
  32. ticks++;
  33. if (!model.getGrid().isSame() || ticks > 2) {
  34. //System.out.println("polling some extra shit ");
  35. ticks = 0;
  36. Platform.runLater(() -> {
  37. for (int i = 1; i < 7; i++) {
  38. model.getGrid().pollFanAMP(i);
  39. model.getGrid().pollFanRPM(i);
  40. }
  41. });
  42. }
  43. }
  44. model.poll();
  45. //System.out.println("Computing...");
  46. if (!model.isManual()) {
  47. model.compute();
  48. }
  49. model.getGrid().setFanSpeed(model.getPercentageToSend());
  50. try {
  51. Thread.sleep(1000);
  52. } catch (InterruptedException ex) {
  53. System.out.println("Thread got interrupted");
  54. }
  55. }
  56. }
  57. /*public void start(){
  58. System.out.println("Starting");
  59. if(t == null){
  60. t = new Thread(this, "Poll and Compute");
  61. t.start();
  62. }
  63. }*/
  64. }