-
Notifications
You must be signed in to change notification settings - Fork 156
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ package generic | |
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path" | ||
"strconv" | ||
|
@@ -42,6 +43,11 @@ func (p *digitalPin) init() error { | |
if p.initialized { | ||
return nil | ||
} | ||
defer func() { | ||
if !p.initialized { | ||
p.unexport() | ||
} | ||
}() | ||
|
||
var err error | ||
if err = p.export(); err != nil { | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are you removing the defer? |
||
time.Sleep(time.Second / 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
|
||
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
There was a problem hiding this comment.
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