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; } }
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()); } }
GPIOPin(GPIOController controller, int pinNumber, GPIOPinMode pinMode = GPIOPinMode.Input) { }
bool IsPinModeSupported(GPIOPinMode pinMode) { throw new NotImplementedException(); }
public void SetMode(GPIOPinMode mode) { Wrapper.pinMode(PinNum, (int)mode); }