Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change GpioDriver to be an interface and inital implementation of UnixDriver #23

Merged
merged 2 commits into from
Nov 1, 2018
Merged

Change GpioDriver to be an interface and inital implementation of UnixDriver #23

merged 2 commits into from
Nov 1, 2018

Conversation

joperezr
Copy link
Member

These changes will:

  • Move GpioDriver to be an interface per some discussions with @tarekgh and @krwq
  • Add the basic implementaiton of the UnixDriver (minus eventing which will come in a subsequent PR)

@joperezr
Copy link
Member Author

cc: @JohnTasler

{
throw new NotImplementedException();
string pinPath = $"{_gpioBasePath}/gpio{pinNumber}";
if (Directory.Exists(pinPath))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you throw an exception when directory doesn't exist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rather this be a no-op in case two different controller instances want to close the same pin at the same time. If there is only one controller, then the controller itself won't permit this to happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at least a comment explaining this is ok

}

protected internal override void OpenPin(int pinNumber)
public PinValue Read(int pinNumber)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally prefer PinValue to be bool unless we plan to support undefined states

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought of that too, but for now I went to what other frameworks do which is to define the enum. We can discuss this in tomorrow's Api Review.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the enumeration is better, because what does true mean: high or low (current value), rising or falling (event fired).


In reply to: 230099441 [](ancestors = 230099441)

{
throw new GpioException("Reading a pin value requires root permissions.");
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception when doesn't exist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The controller should take care of this by not letting you write to a pin that is not opened. I guess you could run into this in case there are two separate instances of the controller, but I wonder if we should guard against that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a comment should suffice so that someone else doesn't add it

{
while (_exportedPins.Count > 0)
{
ClosePin(_exportedPins.FirstOrDefault());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we close all pins?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is effectively what this loop will do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, I missed the loop

@joperezr joperezr merged commit fcb0145 into dotnet:master Nov 1, 2018
@joperezr joperezr deleted the AddingUnixDriver branch November 1, 2018 17:17
catch (UnauthorizedAccessException)
{
throw new GpioException("Reading a pin value requires root permissions.");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for good measure, you should store the UnauthorizedAccessException in the InnerException or GpioException.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, I'll do that.

break;
default:
throw new ArgumentException($"Invalid pin value {value}");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also pass in the argument name: nameof(value)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

}

protected internal override void Write(int pinNumber, PinValue value)
public bool isPinModeSupported(int pinNumber, PinMode mode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i [](start = 20, length = 1)

i should be I

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

joperezr pushed a commit to joperezr/iot that referenced this pull request Feb 19, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants