示例#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);
        }
示例#2
0
        public void Dispose()
        {
            if (deviceCount > 0)
            {
                LampAccess.FCWCloseCleware(clewareObject);
            }

            LampAccess.FCWUnInitObject(clewareObject); // free the allocated object
        }
示例#3
0
        public ClewareLampControlWindows(ILogger <ClewareLampControlWindows> logger)
        {
            // Please note that OpenCleware should be called only once in the initialisation of your programm,
            // not every time a cleware function is called
            clewareObject = LampAccess.FCWInitObject();
            deviceCount   = LampAccess.FCWOpenCleware(clewareObject);

            idToSwitchIDMap.Add(0, LampAccess.SWITCH_IDs.SWITCH_0);
            idToSwitchIDMap.Add(1, LampAccess.SWITCH_IDs.SWITCH_1);
            idToSwitchIDMap.Add(2, LampAccess.SWITCH_IDs.SWITCH_2);

            this.logger = logger;
        }
示例#4
0
 private void SwitchLight(int deviceNr, int state, LampAccess.SWITCH_IDs switchID)
 {
     LampAccess.FCWSetSwitch(clewareObject, deviceNr, (int)switchID, state);
 }