/firmware/src/shared/CoolingFan.cc

http://github.com/makerbot/G3Firmware · C++ · 77 lines · 58 code · 15 blank · 4 comment · 6 complexity · 51609d18e5d58377b18c6f8ab72f7f30 MD5 · raw file

  1. #include "Configuration.hh"
  2. #include "CoolingFan.hh"
  3. //#include "ExtruderMotor.hh"
  4. #include "Eeprom.hh"
  5. #include "EepromMap.hh"
  6. #ifdef IS_EXTRUDER_BOARD
  7. #include "ExtruderBoard.hh"
  8. #endif
  9. #define FAN_ENABLED 1
  10. #define FAN_DISABLED 0
  11. #define DEFAULT_COOLING_FAN_SETPOINT_C 50
  12. #define DEFAULT_COOLING_FAN_ENABLE FAN_DISABLED
  13. // TODO: Come up with a unified strategy for these.
  14. // EEPROM map
  15. #define ENABLE_OFFSET 0
  16. #define SETPOINT_C_OFFSET 1
  17. CoolingFan::CoolingFan(Heater& heater_in, uint16_t eeprom_base_in) :
  18. heater(heater_in),
  19. eeprom_base(eeprom_base_in)
  20. {
  21. reset();
  22. }
  23. void CoolingFan::reset() {
  24. setSetpoint(eeprom::getEeprom16(eeprom_base + SETPOINT_C_OFFSET,
  25. DEFAULT_COOLING_FAN_SETPOINT_C));
  26. if (eeprom::getEeprom8(eeprom_base + ENABLE_OFFSET,
  27. DEFAULT_COOLING_FAN_ENABLE) == FAN_ENABLED) {
  28. enable();
  29. }
  30. else {
  31. disable();
  32. }
  33. }
  34. void CoolingFan::setSetpoint(int temperature) {
  35. setPoint = temperature;
  36. }
  37. void CoolingFan::enable() {
  38. enabled = true;
  39. }
  40. void CoolingFan::disable() {
  41. enabled = false;
  42. setFanRunning(false);
  43. }
  44. void CoolingFan::manageCoolingFan() {
  45. // TODO: only change the state if necessary
  46. if (enabled) {
  47. if (heater.get_current_temperature() > setPoint) {
  48. setFanRunning(true);
  49. }
  50. else {
  51. setFanRunning(false);
  52. }
  53. }
  54. }
  55. void CoolingFan::setFanRunning(bool state)
  56. {
  57. #ifdef IS_EXTRUDER_BOARD
  58. ExtruderBoard::getBoard().setFanRunning(state);
  59. #else
  60. #warning cooling fan feature disabled
  61. #endif
  62. }