PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

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