Beispiel #1
0
        async private void GPIOConnector_ChangeGPIOs(object sender, IPropertySet propertys)
        {
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            { // your code should be here
                m_GPIOEnvironmentConnectors.ProcessPropertysFromGPIOConnector(propertys);

                var con = m_GPIOEnvironmentConnectors.getGPIOOConnectorByOutputPropertySet(propertys);

                if (con == null)
                {
                    return;
                }


                GPIOOBank inputbank = con.ActiveInputs;
                for (int i = 0; i < m_ConfigProcessItems.ProcessItems.Count; i++)
                {
                    ConfigProcessItem item = m_ConfigProcessItems.ProcessItems[i];
                    for (int j = 0; j < item.GPIOInputProcessItems.Count; j++)
                    {
                        GPIOOProcessItem pItem = item.GPIOInputProcessItems[j];

                        GPIOObject obj = inputbank.getGPIOByName(pItem.GPIOName);
                        if (obj != null)
                        {
                            if (obj.PinValue != obj.InitValue)
                            {
                                ProcessFingerEvent ev = new ProcessFingerEvent();
                                GPIOObjectProcess OutObjectProcess = new GPIOObjectProcess();
                                GPIOObjectProcess InObjectProcess  = new GPIOObjectProcess();


                                //item.GPIOOutputProcessItems
                                OutObjectProcess.GPIOEnvironmentConnector = m_GPIOEnvironmentConnectors.getGPIOOConnectorByHostName(pItem.ConnectorName);
                                OutObjectProcess.GPIOObject = obj;

                                InObjectProcess.GPIOEnvironmentConnector = con;
                                InObjectProcess.GPIOObject = obj;

                                ev.GPIOOutputs.Add(OutObjectProcess);
                                ev.GPIOInputs.Add(InObjectProcess);
                                ev.AccessRights = 0x1;

                                m_EventQueue.Enqueue(ev);
                            }
                        }
                    }
                }
            });
        }
        /*
         * public IList<ConfigProcessItem> ProcessItems
         * {
         *  get
         *  {
         *      return m_ProcessItems;
         *  }
         *
         *
         * }
         */
        public bool createProcessEvents(IList <ProcessGPIOEvents> processGPIOEvents)
        {
            processGPIOEvents.Clear();

            ProcessGPIOEvents processGPIOEvent;
            var map = new Dictionary <string, ProcessGPIOEvents>();

            foreach (GPIOEnvironmentConnector con in m_GPIOEnvironmentConnectors.EnvironmentConnectors)
            {
                var m_InOutBanks = con.ActiveGPIOInOutBanks.InOutBanks;

                for (int i = 0; i < m_InOutBanks.Count; i++)
                {
                    GPIOOBank bank = m_InOutBanks[i];

                    foreach (GPIOObjects OutPuts in bank.GPIOBanks)
                    {
                        foreach (GPIOObject GPIOObj in OutPuts.GPIOs)
                        {
                            if (GPIOObj.IsEnabled && GPIOObj.IsEventEnabled)
                            {
                                string eventName = GPIOObj.EventName;

                                eventName = Regex.Replace(eventName, @"\s", "");//remove with spaces

                                string eventKey;

                                GPIOObject.GPIOTyp type = GPIOObj.GPIOtyp;

                                string[] array = eventName.Split(".");
                                if (array.Length > 1)
                                {
                                    eventKey = array[0];
                                    if (array[1].Equals("output", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        type = GPIOObject.GPIOTyp.output;
                                    }
                                    if (array[1].Equals("input", StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        type = GPIOObject.GPIOTyp.input;
                                    }
                                }
                                else
                                {
                                    eventKey = eventName;
                                }

                                bool containsKey = map.TryGetValue(eventKey, out processGPIOEvent);

                                if (processGPIOEvent == null)
                                {
                                    processGPIOEvent = new ProcessGPIOEvents(eventKey);
                                    map[eventKey]    = processGPIOEvent;
                                    //processGPIOEvent.AccessRights = GPIOObj.EventAccessRights;
                                    processGPIOEvents.Add(processGPIOEvent);
                                }

                                switch (type)
                                {
                                case GPIOObject.GPIOTyp.output:
                                {        //output object determines Access rights
                                         //   GPIOOProcessItem gPIOOProcessItem = new GPIOOProcessItem(eventKey);
                                    GPIOObjectProcess OutObjectProcess = new GPIOObjectProcess();
                                    OutObjectProcess.GPIOEnvironmentConnector = con;
                                    OutObjectProcess.GPIOObject   = GPIOObj;
                                    processGPIOEvent.AccessRights = GPIOObj.EventAccessRights;
                                    processGPIOEvent.GPIOOutputs.Add(OutObjectProcess);
                                    break;
                                }

                                case GPIOObject.GPIOTyp.input:
                                {
                                    //  GPIOOProcessItem gPIOOProcessItem = new GPIOOProcessItem(eventKey);
                                    GPIOObjectProcess OutObjectProcess = new GPIOObjectProcess();
                                    OutObjectProcess.GPIOEnvironmentConnector = con;
                                    OutObjectProcess.GPIOObject = GPIOObj;
                                    processGPIOEvent.GPIOInputs.Add(OutObjectProcess);
                                    break;
                                }
                                }
                            }
                        }
                    }
                }
            }

            return(processGPIOEvents.Count > 0);
        }