-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor package to use Singleton pattern #3
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
Open
awonak
wants to merge
5
commits into
main
Choose a base branch
from
singleton
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2b1f6c2
refactor EuroPi struct into perferial singletons exposed by the package.
awonak a533d4b
Define pins in main europi package file.
awonak 53750c8
big honkin refactor to better use interfaces and provide a proper Eur…
awonak 2150396
the underlying hardware for analog input and knob are different enoug…
awonak aa0839e
Do not embed hardware types. Replace GetInstance() with New() singlet…
awonak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,40 +17,38 @@ const ( | |
| ) | ||
|
|
||
| var ( | ||
| DefaultChannel = machine.I2C0 | ||
| DefaultFont = &proggy.TinySZ8pt7b | ||
| White = color.RGBA{255, 255, 255, 255} | ||
| DefaultFont = &proggy.TinySZ8pt7b | ||
| White = color.RGBA{255, 255, 255, 255} | ||
| ) | ||
|
|
||
| // Display is a wrapper around `ssd1306.Device` for drawing graphics and text to the OLED. | ||
| type Display struct { | ||
| type display struct { | ||
| ssd1306.Device | ||
|
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. Another exported field on an unexported type which is readily accesible to users. |
||
|
|
||
| font *tinyfont.Font | ||
| } | ||
|
|
||
| // NewDisplay returns a new Display struct. | ||
| func NewDisplay(channel *machine.I2C, sdaPin, sclPin machine.Pin) *Display { | ||
| func newDisplay(channel *machine.I2C, sdaPin, sclPin machine.Pin) *display { | ||
| channel.Configure(machine.I2CConfig{ | ||
| Frequency: OLEDFreq, | ||
| SDA: sdaPin, | ||
| SCL: sclPin, | ||
| }) | ||
|
|
||
| display := ssd1306.NewI2C(DefaultChannel) | ||
| display.Configure(ssd1306.Config{ | ||
| d := ssd1306.NewI2C(channel) | ||
| d.Configure(ssd1306.Config{ | ||
| Address: OLEDAddr, | ||
| Width: OLEDWidth, | ||
| Height: OLEDHeight, | ||
| }) | ||
| return &Display{Device: display, font: DefaultFont} | ||
| return &display{Device: d, font: DefaultFont} | ||
| } | ||
|
|
||
| // Font overrides the default font used by `WriteLine`. | ||
| func (d *Display) Font(font *tinyfont.Font) { | ||
| func (d *display) Font(font *tinyfont.Font) { | ||
| d.font = font | ||
| } | ||
|
|
||
| // WriteLine writes the given text to the display where x, y is the bottom leftmost pixel of the text. | ||
| func (d *Display) WriteLine(text string, x, y int16) { | ||
| func (d *display) WriteLine(text string, x, y int16) { | ||
| tinyfont.WriteLine(d, d.font, x, y, text, White) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Unexport this field maybe so that users can't access the field through
EuroPi. I'd prefer something like this be set on EuroPi initialization, maybe more on that in another comment.