162 lines
4.4 KiB
Go
162 lines
4.4 KiB
Go
|
package display
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"image"
|
||
|
"log"
|
||
|
"math/rand"
|
||
|
"time"
|
||
|
|
||
|
"gitea.unprism.ru/yotia/display-test/pkg/mt12232a"
|
||
|
"github.com/stianeikeland/go-rpio/v4"
|
||
|
)
|
||
|
|
||
|
type displayMt12232a struct {
|
||
|
logger *log.Logger
|
||
|
|
||
|
// GPIO pins
|
||
|
dev mt12232a.Device
|
||
|
}
|
||
|
|
||
|
func newMt12232a(logger *log.Logger) (Display, error) {
|
||
|
dev, err := mt12232a.New(log.New(logger.Writer(), "display-mt12864 : ", log.LstdFlags))
|
||
|
if err != nil {
|
||
|
return nil, fmt.Errorf("mt12864 create: %w", err)
|
||
|
}
|
||
|
// Allocate bits
|
||
|
bits := make([][]byte, 32)
|
||
|
for i := 0; i < 32; i++ {
|
||
|
bits[i] = make([]byte, 122)
|
||
|
}
|
||
|
|
||
|
// if err := dev.PowerOn(); err != nil {
|
||
|
// return nil, fmt.Errorf("power on: %w", err)
|
||
|
// }
|
||
|
|
||
|
d := displayMt12232a{
|
||
|
logger: logger,
|
||
|
dev: dev,
|
||
|
}
|
||
|
|
||
|
// Temp debug draw
|
||
|
d.logger.Println(d.dev.ReadStatus(0)&0xF0, d.dev.ReadStatus(1)&0xF0)
|
||
|
//d.logger.Println("Draw...")
|
||
|
//d.test()
|
||
|
//d.logger.Println("Draw finished")
|
||
|
|
||
|
return &d, nil
|
||
|
}
|
||
|
|
||
|
func (d *displayMt12232a) test() {
|
||
|
d.logger.Println("Write")
|
||
|
d.dev.WriteCodeL(0xB8)
|
||
|
d.dev.WriteCodeL(0x13)
|
||
|
d.dev.WriteDataL(47)
|
||
|
d.logger.Println("Read")
|
||
|
// d.dev.WriteCodeL(0xB8)
|
||
|
d.dev.WriteCodeL(0x13)
|
||
|
d.logger.Println(d.dev.ReadDataL())
|
||
|
d.logger.Println(d.dev.ReadDataL())
|
||
|
|
||
|
//color := []byte{1, 0, 1, 0, 1, 0, 1, 0}
|
||
|
//color := []byte{1, 0, 1, 0, 1, 0, 0, 0}
|
||
|
|
||
|
//color := []byte{0, 0, 0, 0, 0, 0, 0, 0}
|
||
|
//color := byte(3)
|
||
|
start := time.Now()
|
||
|
//d.dev.WriteCodeL(0xB8)
|
||
|
//d.dev.WriteCodeL(0x13)
|
||
|
//d.dev.WriteDatasL([]byte{0, 0, 0, 0, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 0, 0, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 1, 0, 0, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 1, 1, 0, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 1, 1, 1, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 1, 1, 1, 1, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 1, 1, 1, 1, 1, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 1, 1, 1, 1, 1, 1, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 1, 1, 1, 1, 1, 1, 1})
|
||
|
//
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 0, 0, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 1, 0, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 1, 0, 1, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 1, 0, 1, 0, 1, 0})
|
||
|
//d.dev.WriteCodeL(0xB8 | 1)
|
||
|
//d.dev.WriteCodeL(0x13)
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 0, 0, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 1, 0, 0, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 1, 0, 1, 0, 0, 0})
|
||
|
//d.dev.WriteDatasL([]byte{1, 0, 1, 0, 1, 0, 1, 0})
|
||
|
|
||
|
for p := byte(0); p < 4; p++ {
|
||
|
d.dev.WriteCodeL(p | 0xB8)
|
||
|
d.dev.WriteCodeL(0x13)
|
||
|
for c := 0; c < 61; c++ {
|
||
|
d.dev.WriteDatasL([]byte{byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2)})
|
||
|
}
|
||
|
d.dev.WriteCodeR(p | 0xB8)
|
||
|
d.dev.WriteCodeR(0x00)
|
||
|
for c := 0; c < 61; c++ {
|
||
|
d.dev.WriteDatasR([]byte{byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2), byte(rand.Int() % 2)})
|
||
|
}
|
||
|
}
|
||
|
end := time.Now()
|
||
|
d.logger.Println(end.Sub(start))
|
||
|
// for p := byte(0); p < 8; p++ {
|
||
|
// d.dev.WriteCodeL(p | 0xB8)
|
||
|
// d.dev.WriteCodeL(0x40)
|
||
|
// for c := 0; c < 64; c++ {
|
||
|
// d.dev.WriteDataL(Logo128[p][c])
|
||
|
// }
|
||
|
// d.dev.WriteCodeR(p | 0xB8)
|
||
|
// d.dev.WriteCodeR(0x40)
|
||
|
// for c := 64; c < 128; c++ {
|
||
|
// d.dev.WriteDataR(Logo128[p][c])
|
||
|
// }
|
||
|
// }
|
||
|
//d.dev.WriteCodeL(0xAF) // Display on
|
||
|
//d.dev.WriteCodeR(0xAF) // Display on
|
||
|
|
||
|
}
|
||
|
|
||
|
func (d *displayMt12232a) GetBounds() image.Rectangle {
|
||
|
return image.Rect(0, 0, 122, 32)
|
||
|
}
|
||
|
|
||
|
func (d *displayMt12232a) Flush(img *image.Gray) error {
|
||
|
for p := byte(0); p < 4; p++ {
|
||
|
d.dev.WriteCodeL((3 - p) | 0xB8)
|
||
|
d.dev.WriteCodeL(0x13)
|
||
|
for c := 0; c < 61; c++ {
|
||
|
d.dev.WriteDatasL([]byte{
|
||
|
img.Pix[int(p<<3+7)*122+c],
|
||
|
img.Pix[int(p<<3+6)*122+c],
|
||
|
img.Pix[int(p<<3+5)*122+c],
|
||
|
img.Pix[int(p<<3+4)*122+c],
|
||
|
img.Pix[int(p<<3+3)*122+c],
|
||
|
img.Pix[int(p<<3+2)*122+c],
|
||
|
img.Pix[int(p<<3+1)*122+c],
|
||
|
img.Pix[int(p<<3+0)*122+c],
|
||
|
})
|
||
|
}
|
||
|
d.dev.WriteCodeR((3 - p) | 0xB8)
|
||
|
d.dev.WriteCodeR(0x00)
|
||
|
for c := 61; c < 122; c++ {
|
||
|
d.dev.WriteDatasR([]byte{
|
||
|
img.Pix[int(p<<3+7)*122+c],
|
||
|
img.Pix[int(p<<3+6)*122+c],
|
||
|
img.Pix[int(p<<3+5)*122+c],
|
||
|
img.Pix[int(p<<3+4)*122+c],
|
||
|
img.Pix[int(p<<3+3)*122+c],
|
||
|
img.Pix[int(p<<3+2)*122+c],
|
||
|
img.Pix[int(p<<3+1)*122+c],
|
||
|
img.Pix[int(p<<3+0)*122+c],
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (d *displayMt12232a) Close() error {
|
||
|
return rpio.Close()
|
||
|
}
|