mirror of
https://github.com/kidoman/embd
synced 2024-06-06 02:57:47 +02:00
digitalPin: do not export if the /sys/class/gpio/... file already exists
This commit is contained in:
parent
bfcd1345fe
commit
e36e169d6c
|
@ -62,7 +62,21 @@ func (p *digitalPin) init() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *digitalPin) isExported() bool {
|
||||||
|
if _, err := os.Stat(p.basePath()); err == nil {
|
||||||
|
return true
|
||||||
|
} else if os.IsNotExist(err) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
// unknown
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *digitalPin) export() error {
|
func (p *digitalPin) export() error {
|
||||||
|
if p.isExported() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
exporter, err := os.OpenFile("/sys/class/gpio/export", os.O_WRONLY, os.ModeExclusive)
|
exporter, err := os.OpenFile("/sys/class/gpio/export", os.O_WRONLY, os.ModeExclusive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user