86 lines
1.6 KiB
Go
86 lines
1.6 KiB
Go
package display
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"image"
|
|
"log"
|
|
|
|
"periph.io/x/conn/v3/i2c"
|
|
"periph.io/x/conn/v3/i2c/i2creg"
|
|
"periph.io/x/devices/v3/ssd1306"
|
|
"periph.io/x/host/v3"
|
|
)
|
|
|
|
type displaySsd1306 struct {
|
|
logger *log.Logger
|
|
|
|
bus i2c.BusCloser
|
|
dev *ssd1306.Dev
|
|
img *image.Gray
|
|
}
|
|
|
|
func newSsd1306(logger *log.Logger) (Display, error) {
|
|
if _, err := host.Init(); err != nil {
|
|
return nil, fmt.Errorf("drivers init: %w(may be i2c is disabled)", err)
|
|
}
|
|
|
|
// Setup device
|
|
bus, err := i2creg.Open("")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("open i2c bus: %w", err)
|
|
}
|
|
opts := ssd1306.Opts{
|
|
W: 128,
|
|
H: 32,
|
|
Rotated: false,
|
|
Sequential: true,
|
|
SwapTopBottom: false,
|
|
}
|
|
dev, err := ssd1306.NewI2C(bus, &opts)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("create i2c: %w", err)
|
|
}
|
|
|
|
_ = displaySsd1306{
|
|
logger: logger,
|
|
bus: bus,
|
|
dev: dev,
|
|
}
|
|
|
|
return nil, fmt.Errorf("IMPLEMENTATION COMMENTED")
|
|
}
|
|
|
|
func (d *displaySsd1306) GetBounds() image.Rectangle {
|
|
return d.dev.Bounds()
|
|
}
|
|
|
|
func (d *displaySsd1306) Test(ctx context.Context) error {
|
|
return nil
|
|
}
|
|
|
|
func (d *displaySsd1306) Flush(crystal, page byte) {
|
|
//return d.dev.Draw(img.Bounds(), d.img, image.Point{})
|
|
}
|
|
|
|
func (d *displaySsd1306) FlushByMask(mask uint32) {
|
|
//return d.dev.Draw(img.Bounds(), d.img, image.Point{})
|
|
}
|
|
|
|
func (d *displaySsd1306) Close() error {
|
|
if err := d.bus.Close(); err != nil {
|
|
d.logger.Println("ERROR: close i2c bus:", err.Error())
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (d *displaySsd1306) GetImg() *image.Gray {
|
|
return nil
|
|
}
|
|
func (d *displaySsd1306) LockImg() {
|
|
|
|
}
|
|
func (d *displaySsd1306) UnlockImg() {
|
|
|
|
}
|