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

Hotfix/gpio sys issues #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions host/generic/digitalpin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package generic
import (
"errors"
"fmt"
"log"
"os"
"path"
"strconv"
Expand Down Expand Up @@ -42,6 +43,11 @@ func (p *digitalPin) init() error {
if p.initialized {
return nil
}
defer func() {
if !p.initialized {
p.unexport()
}
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

this defer should come after the p.export and not before it


var err error
if err = p.export(); err != nil {
Expand All @@ -67,8 +73,9 @@ func (p *digitalPin) export() error {
if err != nil {
return err
}
defer exporter.Close()
_, err = exporter.WriteString(strconv.Itoa(p.n))
exporter.Close()
Copy link
Contributor

Choose a reason for hiding this comment

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

why are you removing the defer?

time.Sleep(time.Second / 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this sleep supposed to accomplish, other than making thing slow?

return err
}

Expand All @@ -77,8 +84,9 @@ func (p *digitalPin) unexport() error {
if err != nil {
return err
}
defer unexporter.Close()
_, err = unexporter.WriteString(strconv.Itoa(p.n))
unexporter.Close()
time.Sleep(time.Second / 2)
return err
}

Expand Down Expand Up @@ -233,7 +241,7 @@ func (p *digitalPin) Close() error {
}

if err := p.drv.Unregister(p.id); err != nil {
return err
log.Println("Driver unregister error:", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

libraries shouldn't log in general, why do you want to log instead of returning an error?

}

if !p.initialized {
Expand Down