Exemplo n.º 1
0
        public IEnumerable <TrafficLight> DiscoverConnectedDevices()
        {
            var trafficLights = new List <TrafficLight>();

            for (var i = 0; i < deviceCount; i++)
            {
                var devType = LampAccess.FCWGetUSBType(clewareObject, i);
                logger.LogDebug("Device " + i + ": Type = " + devType);
                if (devType == (int)LampAccess.USBtype_enum.SWITCH1_DEVICE)
                {
                    var state = LampAccess.FCWGetSwitch(clewareObject, i, (int)LampAccess.SWITCH_IDs.SWITCH_0);
                    logger.LogDebug("Switch state is = " + state);
                    LampAccess.FCWSetSwitch(clewareObject, i, (int)LampAccess.SWITCH_IDs.SWITCH_0, 1);
                    System.Threading.Thread.Sleep(1000); // wait one second
                    LampAccess.FCWSetSwitch(clewareObject, i, (int)LampAccess.SWITCH_IDs.SWITCH_0, 0);

                    LampAccess.FCWSetSwitch(clewareObject, i, (int)LampAccess.SWITCH_IDs.SWITCH_1, 0);
                    LampAccess.FCWSetSwitch(clewareObject, i, (int)LampAccess.SWITCH_IDs.SWITCH_2, 0);

                    var redLight    = new Lamp(0, LampColor.Red);
                    var orangeLight = new Lamp(1, LampColor.Orange);
                    var greenLight  = new Lamp(2, LampColor.Green);

                    var trafficLight = new TrafficLight(i, new[] { greenLight, orangeLight, redLight });
                    trafficLights.Add(trafficLight);
                }
                else
                {
                    logger.LogDebug("Device is not switching device - skipping");
                }
            }

            return(trafficLights);
        }
Exemplo n.º 2
0
 private void SwitchLight(int deviceNr, int state, LampAccess.SWITCH_IDs switchID)
 {
     LampAccess.FCWSetSwitch(clewareObject, deviceNr, (int)switchID, state);
 }