-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Hey Adam! Been looking a bit through the code and I thought to take note of some things that called out to me.
Documentation
EuroPi struct needs better naming or documentation. I'd guess K1 and K2 are the knobs, but it is hard to be sure. Adding a comment or changing them to Knob1 and Knob2 would be pretty good (I'd opt for the second since it would make comments superfluous, which is an especially good thing!). Same goes for NewAI and NewDI functions, their naming seems evil to me hahah 🙃
API
I feel like you should be making better use of the tinygo drivers package and it's interfaces. A lot of stuff here has wrappers that feel superfluous to me. An example is the Display. Instead of having a *Display in the EuroPi struct could you not use a drivers.Displayer and have the font stored in the EuroPi struct too if needed?
I also feel like the DigitalReader could be a struct instead of an interface. Though this would prevent mocking (never mocked tinygo programs myself though).
After some thinking... Shouldn't all of Europi's fields be non-interface types? What exactly is the advantage of having them as interface types? Seems to me they should be at most structs that embed interfaces which implement the IO functionality.
Heap
yep, I think strconv.Itoa is causing those awful heap alloc. Instead I'd have a static byte array of the size of the display and use the strconv.AppendInt function to avoid heap allocations altogether.
type display struct {
// ...
buf [16]byte
}
// ...
n := copy(disp.buf[:], "my knob is at ")
strconv.AppendInt(a[:n:16], number, 10) // if append exceeds capacity then you have a problem