예제 #1
0
        internal GPIOPin(uint number, GPIOPinSharingMode sharingMode, GPIOPinSharingMode openMode)
        {
            Disposed         = false;
            PinNumber        = number;
            _SharingMode     = sharingMode;
            _OpenMode        = openMode;
            Mode             = GPIOPinMode.Input;
            PinPath          = GPIOController.GPIO_PATH + "/gpio" + PinNumber;
            ConnectionStatus = ConnectionStatus.Connected;
            switch (_OpenMode)
            {
            case GPIOPinSharingMode.Exclusive:
                try
                {
                    File.WriteAllText(PinPath + GPIO_PIN_DIRECTION, GPIO_PIN_DIRECTION_IN);
                    File.WriteAllText(PinPath + GPIO_PIN_VALUE, "0");
                    File.WriteAllText(PinPath + GPIO_PIN_ACTIVE_LOW, "0");
                    File.WriteAllText(PinPath + GPIO_PIN_EDGE, "both");
                }
                catch
                {
                    Close(false);
                }
                break;

            default:
            case GPIOPinSharingMode.ReadOnlySharedAccess:

                break;
            }
        }
예제 #2
0
        public async Task <VoidResult <AccessStatus> > SetMode(GPIOPinMode mode)
        {
            if (!Disposed)
            {
                await Task.Yield();

                switch (OpenMode)
                {
                case GPIOPinSharingMode.Exclusive:
                    switch (mode)
                    {
                    case GPIOPinMode.Input:
                        try
                        {
                            File.WriteAllText(PinPath + GPIO_PIN_DIRECTION, GPIO_PIN_DIRECTION_IN);
                            File.WriteAllText(PinPath + GPIO_PIN_ACTIVE_LOW, "0");
                            File.WriteAllText(PinPath + GPIO_PIN_EDGE, "both");
                            return(new VoidResult <AccessStatus>(AccessStatus.Success, null));
                        }
                        catch (Exception ex)
                        {
                            //TODO: реализовать разбор ошибок, если возможно.
                            return(new VoidResult <AccessStatus>(AccessStatus.UnknownError, ex));
                        }

                    case GPIOPinMode.Output:
                        try
                        {
                            File.WriteAllText(PinPath + GPIO_PIN_DIRECTION, GPIO_PIN_DIRECTION_OUT);
                            File.WriteAllText(PinPath + GPIO_PIN_VALUE, "0");
                            File.WriteAllText(PinPath + GPIO_PIN_ACTIVE_LOW, "0");
                            File.WriteAllText(PinPath + GPIO_PIN_EDGE, "none");
                            return(new VoidResult <AccessStatus>(AccessStatus.Success, null));
                        }
                        catch (Exception ex)
                        {
                            //TODO: реализовать разбор ошибок, если возможно.
                            return(new VoidResult <AccessStatus>(AccessStatus.UnknownError, ex));
                        }

                    default:
                        return(new VoidResult <AccessStatus>(AccessStatus.NotSupported, new NotImplementedException("Данный режим работы контакта GPIO не поддерживается.")));
                    }

                default:
                    return(new VoidResult <AccessStatus>(AccessStatus.DeniedBySystem, new NotSupportedException("Данный режим работы контакта GPIO не поддерживается.")));
                }
            }
            else
            {
                throw new ObjectDisposedException(ToString());
            }
        }
예제 #3
0
 GPIOPin(GPIOController controller, int pinNumber, GPIOPinMode pinMode = GPIOPinMode.Input)
 {
 }
예제 #4
0
 bool IsPinModeSupported(GPIOPinMode pinMode)
 {
     throw new NotImplementedException();
 }
예제 #5
0
 public void SetMode(GPIOPinMode mode)
 {
     Wrapper.pinMode(PinNum, (int)mode);
 }