Beispiel #1
0
        /// <summary>
        /// Configure a pin as a digital input
        /// </summary>
        /// <remarks>
        /// The digital input value can be read with <see cref="ReadDigitalPin(int)"/>
        /// </remarks>
        /// <param name="pin">the pin number (as labelled on the Teensy board)</param>
        /// <param name="attributes">additional features to be configured</param>
        /// <param name="communication">the type of communication with the Wirekite device</param>
        /// <returns>the port ID of the configured digital input</returns>
        public int ConfigureDigitalInputPin(int pin, DigitalInputPinAttributes attributes, InputCommunication communication)
        {
            if (communication != InputCommunication.OnDemand && communication != InputCommunication.Precached)
            {
                throw new WirekiteException("Digital input pin witout notification must use communication \"OnDemand\" or \"Precached\"");
            }

            if ((attributes & (DigitalInputPinAttributes.TriggerRaising | DigitalInputPinAttributes.TriggerFalling)) != 0)
            {
                throw new WirekiteException("Digital input pin without callback must not use attributes \"DigiInPinTriggerRaising\" and/or \"DigiInPinTriggerFalling\"");
            }

            PortType type;

            if (communication == InputCommunication.OnDemand)
            {
                type = PortType.DigitalInputOnDemand;
            }
            else
            {
                type        = PortType.DigitalInputPrecached;
                attributes |= DigitalInputPinAttributes.TriggerRaising | DigitalInputPinAttributes.TriggerFalling;
            }

            Port port = ConfigureDigitalPin(pin, type, (UInt16)attributes);

            return(port.Id);
        }
Beispiel #2
0
        /// <summary>
        /// Configures a pin as a digitial input with notification about changes of the input value
        /// </summary>
        /// <param name="pin">the pin number (as labelled on the Teensy board)</param>
        /// <param name="attributes">additional features to be configured</param>
        /// <param name="callback">the delegate notified about changes of the input value</param>
        /// <returns>the port ID of the configured digital input</returns>
        /// <remarks>
        /// The <paramref name="attributes"/> must specify whether the notification should be triggered on
        /// the raising edge, the falling edge or both edges of the signal. The notification delegate is
        /// called on a background thread.
        /// </remarks>
        public int ConfigureDigitalInputPin(int pin, DigitalInputPinAttributes attributes, DigitalInputCallback callback)
        {
            if ((attributes & (DigitalInputPinAttributes.TriggerRaising | DigitalInputPinAttributes.TriggerFalling)) == 0)
            {
                throw new WirekiteException("Digital input pin with callback requires attribute \"DigiInPinTriggerRaising\" and/or \"DigiInPinTriggerFalling\"");
            }

            Port port = ConfigureDigitalPin(pin, PortType.DigitalInputTriggering, (UInt16)attributes);

            _digitalInputCallbacks.TryAdd(port.Id, callback);
            return(port.Id);
        }