//////////////////////////////////////////////////////////////////////// // tcu.cpp : Implementation of the class CTCU // // $Log: tcu.cpp,v $ // Revision 1.2 1997/07/23 18:31:07 nettleto // Removed temporary delay function. // // Revision 1.1 1997/06/13 18:12:15 nettleto // Initial revision // // // This is the thermal control unit code. It uses a heater to slowly // increase the temperature, and when the heater is off, the // temperature slowly decreases. Functions are provided to turn the // heater on and off manually, and to switch to and from automatic // mode, which maintains the temperature between a lower and an upper // limit. #include #include "tcu.h" #include const int TMAX = 100; const int TMIN = 0; CTCU::CTCU (int t1, int t2, int p) { Temp = 0; Low = t1; High = t2; Step = 1; Period = p; Heater_On = 0; Auto_Mode = 0; } void CTCU::Set_On () { Heater_CMutex.Lock (); Heater_On = 1; Auto_Mode = 0; Heater_CMutex.Unlock (); } void CTCU::Set_Off () { Heater_CMutex.Lock (); Heater_On = 0; Auto_Mode = 0; Heater_CMutex.Unlock (); } void CTCU::Set_Auto () { Heater_CMutex.Lock (); Auto_Mode = 1; Heater_CMutex.Unlock (); } void CTCU::Body () { while (1) { sleep (Period); Heater_CMutex.Lock (); if (Auto_Mode) { if (Temp < Low) { Heater_On = 1; } if (Temp > High) { Heater_On = 0; } } if (Heater_On) { Temp += Step; if (Temp > TMAX) { Temp = TMAX; } } else { Temp -= Step; if (Temp < TMIN) { Temp = TMIN; } } Heater_CMutex.Unlock (); } } void CTCU::Get_Status (int &tmp, int &Auto, int &On) { Heater_CMutex.Lock (); tmp = Temp; Auto = Auto_Mode; On = Heater_On; Heater_CMutex.Unlock (); }