コード例 #1
0
        public CallbackInfo AddCallback(int gpio, Edge edge, GpioCallback callback)
        {
            List <CallbackInfo> callbacks;

            lock (this.m_callbacks)
            {
                if (this.m_callbacks.ContainsKey(gpio))
                {
                    callbacks = this.m_callbacks[gpio];
                }
                else
                {
                    short ret = PiGpioNativeMethods.SetAlertFunc((ushort)gpio, this.GpioAlertCallback);
                    if (ret < 0)
                    {
                        throw new PiGPIOException(ret);
                    }
                    callbacks = new List <CallbackInfo>();
                    this.m_callbacks.Add(gpio, callbacks);
                }
            }

            CallbackInfo cbi = new CallbackInfo((uint)gpio, 0, edge, callback);

            lock (callbacks)
            {
                callbacks.Add(cbi);
            }
            return(cbi);
        }