using System; using System.Collections.Generic; using System.Linq; using System.Text; using FB_USB_2011; using FuseGL.GUI; namespace HVAC_Example { public class HVAC_Example { public enum FanSpeed { OFF, LOW, MEDIUM, HIGH } internal class MyInternalHVAC_FanSpeed_Class { public FB_Monitor.DigitalOutputPort DigitalOutputPort; public FuseGL.GUI.FGLO_Texture FGLO_Texture; public MyInternalHVAC_FanSpeed_Class(FB_Monitor.DigitalOutputPort digitalOutputPort, FGLO_Texture fgloTexture) { DigitalOutputPort = digitalOutputPort; FGLO_Texture = fgloTexture; } } internal Dictionary FanSpeedLookupDictionary = new Dictionary(); internal FanSpeed currentFanSpeed = FanSpeed.OFF; public void setup_HVAC( FuseGL.GUI.FuseGL_Object displayFuseGL_Object_for_fan_speed, FB_Monitor.DigitalOutputPort _digitalOutputPort_for_fan_off, FB_Monitor.DigitalOutputPort _digitalOutputPort_for_fan_low, FB_Monitor.DigitalOutputPort _digitalOutputPort_for_fan_medium, FB_Monitor.DigitalOutputPort _digitalOutputPort_for_fan_high ) { // Setup FanSpeed textures and ports FanSpeedLookupDictionary.Add(FanSpeed.OFF, new MyInternalHVAC_FanSpeed_Class(_digitalOutputPort_for_fan_off, FGLO_Texture.MakeQuickFGLOTexture___ConvertFromExternalImagePath("HVAC_Fan_Control___FanSpeedImage___OFF", "images/HVAC/FanSpeed/Off.png"))); FanSpeedLookupDictionary.Add(FanSpeed.LOW, new MyInternalHVAC_FanSpeed_Class(_digitalOutputPort_for_fan_low, FGLO_Texture.MakeQuickFGLOTexture___ConvertFromExternalImagePath("HVAC_Fan_Control___FanSpeedImage___LOW", "images/HVAC/FanSpeed/Low.png"))); FanSpeedLookupDictionary.Add(FanSpeed.MEDIUM, new MyInternalHVAC_FanSpeed_Class(_digitalOutputPort_for_fan_medium, FGLO_Texture.MakeQuickFGLOTexture___ConvertFromExternalImagePath("HVAC_Fan_Control___FanSpeedImage___MEDIUM", "images/HVAC/FanSpeed/Medium.png"))); FanSpeedLookupDictionary.Add(FanSpeed.HIGH, new MyInternalHVAC_FanSpeed_Class(_digitalOutputPort_for_fan_high, FGLO_Texture.MakeQuickFGLOTexture___ConvertFromExternalImagePath("HVAC_Fan_Control___FanSpeedImage___HIGH", "images/HVAC/FanSpeed/High.png"))); // Hook into when the FGLO is pressed displayFuseGL_Object_for_fan_speed.MouseEvent___ClickDown += new FuseGL_Object.FuseGL_FGLO_MouseEvent(ChangeHVAC_FanSpeed_Button_Was_Pressed); // Change the image to something known to begin with ChangeFanSpeed(currentFanSpeed, displayFuseGL_Object_for_fan_speed); } void ChangeHVAC_FanSpeed_Button_Was_Pressed(object sender, FuseGL.FuseGL_GUI.MouseEventInformation MouseInfo) { switch(currentFanSpeed) { case FanSpeed.OFF: currentFanSpeed = FanSpeed.LOW; break; case FanSpeed.LOW: currentFanSpeed = FanSpeed.MEDIUM; break; case FanSpeed.MEDIUM: currentFanSpeed = FanSpeed.HIGH; break; case FanSpeed.HIGH: currentFanSpeed = FanSpeed.OFF; break; } ChangeFanSpeed(currentFanSpeed, (FuseGL.GUI.FuseGL_Object)sender); } public void ChangeFanSpeed(FanSpeed _speed, FuseGL.GUI.FuseGL_Object fanSpeedFGLO = null) { // Put some info in the trace for debugging perhaps? FuseGL.FuseGL_Debugger.Trace.Add("Changing Fan Speed to: " + _speed); // First turn off all the outputs foreach(KeyValuePair aFanSpeed in FanSpeedLookupDictionary) { aFanSpeed.Value.DigitalOutputPort.Value = FB_Monitor.DigitalOutputPort.DIGITAL_OUTPUT_OFF; } // Then if it is a valid fan speed and the dictionary has been setup properly... if(FanSpeedLookupDictionary.ContainsKey(_speed)) { // Turn that output on FanSpeedLookupDictionary[_speed].DigitalOutputPort.Value = FB_Monitor.DigitalOutputPort.DIGITAL_OUTPUT_ON; // If the FGLO to display a picture in is valid... if (fanSpeedFGLO != null) { // Change the texture to the correct one depicting the new fan speed fanSpeedFGLO.TextureIsBeingOverriddenAndControlledExternally = true; fanSpeedFGLO.TextureToOverrideWith = FanSpeedLookupDictionary[_speed].FGLO_Texture; } } return; } } }