Ejemplo n.º 1
0
        int AddChangeSubscriber(GpioSubscriber subscriber)
        {
            int hash = subscriber.GetHashCode();

            m_monitor |= (uint)1 << subscriber.GpioNumber;
            m_lock.WaitOne();
            m_changeSubscribers.Add(hash, subscriber);
            m_lock.ReleaseMutex();
            m_pi.ExecuteCommand(CommandCode.PI_CMD_NB, m_handle, (int)m_monitor);
            return(hash);
        }
Ejemplo n.º 2
0
        public void WaitForEdge(int gpioNum, GpioEdge edge, int maxWaitingTimeInMs)
        {
            if (!m_run)
            {
                throw new Exception("GPIO Listener Thread not started!");
            }
            var tmpSubscriber = new GpioSubscriber(gpioNum, edge);
            int hash          = AddChangeSubscriber(tmpSubscriber);
            var result        = tmpSubscriber.WaitForChange(maxWaitingTimeInMs);

            RemoveChangeSubscriber(hash);
            if (!result)
            {
                throw new TimeoutException("Timeout waiting for level change on GPIO " + gpioNum);
            }
        }