#SYMBOL_NAME "ViewSonic PRO 8100 Parser and Poller"
#CATEGORY "24" // Misc
#DEFINE_CONSTANT POLL_INTERVAL 3000 // 5 minutes in tenths of seconds
#DEFINE_CONSTANT WARM_TIME 1200 // 2 minutes in tenths of seconds
#DEFINE_CONSTANT COOL_TIME 1800 // 3 minutes in tenths of seconds
DIGITAL_INPUT Poll, Power_On, Power_Off;
STRING_INPUT FromDevice$[255];
ANALOG_OUTPUT LampHours;
DIGITAL_OUTPUT Warming_FB, Cooling_FB;
STRING_OUTPUT ToDevice$, ToTouchPanel$;
INTEGER iLampHours;
INTEGER iState; // 0: Off, 1: Warming, 2: Cooling, 3: On
INTEGER iWarmCoolTimer;
INTEGER iPollTimer;
FUNCTION UpdateStatus()
{
? ? STRING sStatus[50];
? ??
? ? IF(iState = 1)
? ? ? ? sStatus = "Lamp warming up... ";
? ? ELSE IF(iState = 2)
? ? ? ? sStatus = "Lamp cooling down... ";
? ? ELSE IF(iState = 3)
? ? ? ? sStatus = "Projector on... ";
? ? ELSE
? ? ? ? sStatus = "Projector off... ";
? ??
? ? ToTouchPanel$ = sStatus + "Lamp Hours: " + ITOA(iLampHours);
}
CHANGE FromDevice$
{
? ? IF (LEN(FromDevice$) >= 5 && LEFT(FromDevice$, 2) = "\x1E\x00" && RIGHT(FromDevice$, 2) = "\x00\x00")
? ? {
? ? ? ? iLampHours = BYTE(FromDevice$, 3);
? ? ? ? LampHours = iLampHours;
? ? ? ? UpdateStatus();
? ? }
? ? CLEARBUFFER(FromDevice$);
}
FUNCTION PollLampHours()
{
? ? ToDevice$ = "\xBE\xEF\x1A\x0C\x00\x56\x6A\x52\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00";
}
FUNCTION HandleWarmingCooling()
{
? ? IF(iState = 1 || iState = 2)
? ? {
? ? ? ? iWarmCoolTimer = iWarmCoolTimer - 1;
? ? ? ? IF(iWarmCoolTimer <= 0)
? ? ? ? {
? ? ? ? ? ? IF(iState = 1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Warming_FB = 0;
? ? ? ? ? ? ? ? iState = 3;
? ? ? ? ? ? ? ? PollLampHours(); // Poll immediately after warming up
? ? ? ? ? ? }
? ? ? ? ? ? ELSE
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Cooling_FB = 0;
? ? ? ? ? ? ? ? iState = 0;
? ? ? ? ? ? }
? ? ? ? ? ? UpdateStatus();
? ? ? ? }
? ? }
}
PUSH Power_On
{
? ? iState = 1;
? ? Warming_FB = 1;
? ? iWarmCoolTimer = WARM_TIME;
? ? UpdateStatus();
}
PUSH Power_Off
{
? ? iState = 2;
? ? Cooling_FB = 1;
? ? iWarmCoolTimer = COOL_TIME;
? ? UpdateStatus();
}
FUNCTION Main()
{
? ? iPollTimer = POLL_INTERVAL; // Initialize poll timer
? ? WHILE(1)
? ? {
? ? ? ? HandleWarmingCooling();
? ? ? ??
? ? ? ? IF(iState = 3)
? ? ? ? {
? ? ? ? ? ? iPollTimer = iPollTimer - 1;
? ? ? ? ? ? IF(iPollTimer <= 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? PollLampHours();
? ? ? ? ? ? ? ? iPollTimer = POLL_INTERVAL;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ??
? ? ? ? DELAY(10);
? ? }
}
PUSH Poll
{
? ? IF(iState = 3)
? ? {
? ? ? ? PollLampHours();
? ? ? ? iPollTimer = POLL_INTERVAL; // Reset the poll timer
? ? }
}
?
Donald