Exemplo n.º 1
0
        public bool SetGpioValue(int pin, Enums.GpioPinMode mode, Enums.GpioPinState state)
        {
            if (!IsWiringPiInstalled())
            {
                return(false);
            }

            if (!PiGpioController.IsAllowedToExecute || !IsDriverProperlyInitialized)
            {
                return(false);
            }

            if (!PinController.IsValidPin(pin))
            {
                CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid.");
                return(false);
            }

            try {
                if (SetMode(pin, mode))
                {
                    return(WriteValue(pin, state));
                }

                return(false);
            }
            finally {
                Pin?pinConfig = GetPinConfig(pin);
                if (pinConfig != null)
                {
                    CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig);
                }
            }
        }
Exemplo n.º 2
0
 public SetGpioDelayedRequest(int pinNumber, Enums.GpioPinMode pinMode, Enums.GpioPinState pinState, int delay)
 {
     PinNumber = pinNumber;
     PinMode   = pinMode;
     PinState  = pinState;
     Delay     = delay;
 }
Exemplo n.º 3
0
        private bool WriteValue(int pinNumber, Enums.GpioPinState state)
        {
            if (!PinController.IsValidPin(pinNumber))
            {
                CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid.");
                return(false);
            }

            (COMMAND_KEY + $" write {pinNumber} {(int) state}").ExecuteBash(false);
            return(true);
        }
Exemplo n.º 4
0
        public bool SetGpioValue(int pin, Enums.GpioPinState state)
        {
            if (!IsWiringPiInstalled())
            {
                return(false);
            }

            if (!PiGpioController.IsAllowedToExecute || !IsDriverProperlyInitialized)
            {
                return(false);
            }

            if (!PinController.IsValidPin(pin))
            {
                CastDriver <IGpioControllerDriver>(this)?.Logger.Log("The specified pin is invalid.");
                return(false);
            }

            try {
                Pin?pinConfig = GetPinConfig(pin);

                if (pinConfig == null)
                {
                    return(false);
                }

                if (pinConfig.Mode != Enums.GpioPinMode.Output)
                {
                    CastDriver <IGpioControllerDriver>(this)?.Logger.Warning($"Pin cannot be configured to {state.ToString()} as it is not in output mode.");
                    return(false);
                }

                return(WriteValue(pin, state));
            }
            finally {
                Pin?pinConfig = GetPinConfig(pin);
                if (pinConfig != null)
                {
                    CastDriver <IGpioControllerDriver>(this).UpdatePinConfig(pinConfig);
                }
            }
        }
Exemplo n.º 5
0
 public SetGpioRequest(int pinNumber, Enums.GpioPinMode pinMode, Enums.GpioPinState pinState)
 {
     PinNumber = pinNumber;
     PinMode   = pinMode;
     PinState  = pinState;
 }
Exemplo n.º 6
0
 internal CurrentValue(Enums.GpioPinState state, bool digitalValue, Enums.GpioPinMode pinMode, Enums.PinEventState eventState) : base(state, digitalValue, pinMode, eventState)
 {
 }