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

CLI example in a single commit #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

helios-ag
Copy link

Just a replacement for PR #5 in a single commit

@xiegeo
Copy link

xiegeo commented Oct 10, 2018

Sorry if sidetracking.

if runtime.GOARCH != "arm" {
	fmt.Println("This program can be unpredictable on other machines rather than Raspberry Pi")
	os.Exit(1)
}

Is this check suggested for users of this library? I have been relying on rpio.Open() to return an error on unsupported systems. Is there a case where rpio could cause a side-effect on other Linux systems?

@helios-ag
Copy link
Author

in BSD gpio mapped to a different place (as far as i understand to /dev/gpioc{N}, and also /dev/mem exist), so probably this could trigger some unexpected behavior

}
} else {
switch *set {
case 1:
Copy link
Collaborator

Choose a reason for hiding this comment

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

If *set is String and not Int, you can check for multiple choices, eg.: case: "0", "L", "low": and case: "1", "H", "high":

pinNumber = flag.Int("p", 0, " number of pin to use")
high = flag.Bool("h", false, " return 0 if value is HIGH, omit to set value")
low = flag.Bool("l", false, " return 0 if value is LOW, omit to set value")
set = flag.Int("s", 0, " set pin value to high(1) or low(-1)")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would make more sense to name this option v as value instead of s as set.

Also use 0 for low value makes more sense to me, than -1.
You can parse this as String instead of Int, to avoid issue with third unset value (empty string).

flag.Parse()

if os.Geteuid() != 0 {
fmt.Println("This program have to be run as root, or SUID/GUID set to 0 on execution!")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It actually does not have to be run as root, if /dev/gpiomem exists.

}

if runtime.GOARCH != "arm" {
fmt.Println("This program can be unpredictable on other machines rather than Raspberry Pi")
Copy link
Collaborator

Choose a reason for hiding this comment

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

other machines rather than Raspberry Pi

;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants