Checkpoint
This commit is contained in:
54 files changed
+6815
-486
No files matched your search
+256
-35
@@ -2,55 +2,276 @@ package audio
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/internal/calc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Buffer struct {
|
// Buffer of audio samples.
|
||||||
Buf []byte
|
type Buffer interface {
|
||||||
|
// Channels is the number of channels.
|
||||||
|
Channels() int
|
||||||
|
|
||||||
|
// Len is the number of samples per channel.
|
||||||
|
Len() int
|
||||||
|
|
||||||
|
// ReadFrom reads the buffer from r.
|
||||||
|
ReadFrom(r io.Reader) (int, error)
|
||||||
|
|
||||||
|
// Samples returns the buffer as float32s
|
||||||
|
Samples() *Float32Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
type Int8Buffer struct {
|
||||||
|
Buf []int8
|
||||||
Ch int
|
Ch int
|
||||||
Format Format
|
floats *Float32Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBuffer returns a buffer of n samples and ch channels.
|
func NewInt8Buffer(size, channels int) *Int8Buffer {
|
||||||
func NewBuffer(n, ch int, f Format) *Buffer {
|
samples := size * channels
|
||||||
if ch < 1 {
|
return &Int8Buffer{
|
||||||
ch = 1
|
Buf: make([]int8, samples),
|
||||||
}
|
Ch: channels,
|
||||||
return &Buffer{
|
floats: NewFloat32Buffer(size, channels, nil),
|
||||||
Buf: make([]byte, n*ch*f.BytesPerSample()),
|
|
||||||
Ch: ch,
|
|
||||||
Format: f,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Buffer) Decode(data any, order binary.ByteOrder) (n int, err error) {
|
func (b *Int8Buffer) Channels() int {
|
||||||
switch data := data.(type) {
|
return b.Ch
|
||||||
case []int8:
|
}
|
||||||
var x byte
|
|
||||||
for n, x = range b.Buf {
|
func (b *Int8Buffer) Len() int {
|
||||||
data[n] = int8(x)
|
return len(b.Buf) / b.Ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Int8Buffer) ReadFrom(r io.Reader) (int, error) {
|
||||||
|
if err := binary.Read(r, nil, b.Buf); err != nil {
|
||||||
|
return 0, err
|
||||||
}
|
}
|
||||||
case []uint8:
|
for i, sample := range b.Buf {
|
||||||
n = copy(data, b.Buf)
|
b.floats.Buf[i] = float32(sample) / math.MaxInt8
|
||||||
case []int16:
|
|
||||||
for n = range data {
|
|
||||||
data[n] = int16(order.Uint16(b.Buf[n<<1:]))
|
|
||||||
}
|
}
|
||||||
case []int32:
|
return len(b.Buf), nil
|
||||||
for n = range data {
|
}
|
||||||
data[n] = int32(order.Uint32(b.Buf[n<<2:]))
|
|
||||||
|
func (b *Int8Buffer) Samples() *Float32Buffer {
|
||||||
|
return b.floats
|
||||||
|
}
|
||||||
|
|
||||||
|
type Int16Buffer struct {
|
||||||
|
Buf []int16
|
||||||
|
Ch int
|
||||||
|
Order binary.ByteOrder
|
||||||
|
floats *Float32Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewInt16Buffer(size, channels int, order binary.ByteOrder) *Int16Buffer {
|
||||||
|
if order == nil {
|
||||||
|
order = binary.LittleEndian
|
||||||
}
|
}
|
||||||
case []float32:
|
samples := size * channels
|
||||||
for n = range data {
|
return &Int16Buffer{
|
||||||
data[n] = math.Float32frombits(order.Uint32(b.Buf[n<<2:]))
|
Buf: make([]int16, samples),
|
||||||
|
Ch: channels,
|
||||||
|
Order: order,
|
||||||
|
floats: NewFloat32Buffer(size, channels, nil),
|
||||||
}
|
}
|
||||||
case []float64:
|
}
|
||||||
for n = range data {
|
|
||||||
data[n] = math.Float64frombits(order.Uint64(b.Buf[n<<3:]))
|
func (b *Int16Buffer) Channels() int {
|
||||||
|
return b.Ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Int16Buffer) Len() int {
|
||||||
|
return len(b.Buf) / b.Ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Int16Buffer) ReadFrom(r io.Reader) (int, error) {
|
||||||
|
if err := binary.Read(r, b.Order, b.Buf); err != nil {
|
||||||
|
return 0, err
|
||||||
}
|
}
|
||||||
default:
|
for i, sample := range b.Buf {
|
||||||
return 0, fmt.Errorf("can't decode to %T", data)
|
b.floats.Buf[i] = float32(sample) / math.MaxInt16
|
||||||
}
|
}
|
||||||
|
return len(b.Buf), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Int16Buffer) Samples() *Float32Buffer {
|
||||||
|
return b.floats
|
||||||
|
}
|
||||||
|
|
||||||
|
type Int32Buffer struct {
|
||||||
|
Buf []int32
|
||||||
|
Ch int
|
||||||
|
Order binary.ByteOrder
|
||||||
|
floats *Float32Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewInt32Buffer(size, channels int, order binary.ByteOrder) *Int32Buffer {
|
||||||
|
if order == nil {
|
||||||
|
order = binary.LittleEndian
|
||||||
|
}
|
||||||
|
samples := size * channels
|
||||||
|
return &Int32Buffer{
|
||||||
|
Buf: make([]int32, samples),
|
||||||
|
Ch: channels,
|
||||||
|
Order: order,
|
||||||
|
floats: NewFloat32Buffer(size, channels, nil),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Int32Buffer) Channels() int {
|
||||||
|
return b.Ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Int32Buffer) Len() int {
|
||||||
|
return len(b.Buf) / b.Ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Int32Buffer) ReadFrom(r io.Reader) (int, error) {
|
||||||
|
if err := binary.Read(r, b.Order, b.Buf); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
for i, sample := range b.Buf {
|
||||||
|
b.floats.Buf[i] = float32(sample) / math.MaxInt32
|
||||||
|
}
|
||||||
|
return len(b.Buf), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Int32Buffer) Samples() *Float32Buffer {
|
||||||
|
return b.floats
|
||||||
|
}
|
||||||
|
|
||||||
|
type Float32Buffer struct {
|
||||||
|
Buf []float32
|
||||||
|
Ch int
|
||||||
|
Order binary.ByteOrder
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFloat32Buffer(size, channels int, order binary.ByteOrder) *Float32Buffer {
|
||||||
|
if order == nil {
|
||||||
|
order = binary.BigEndian
|
||||||
|
}
|
||||||
|
samples := size * channels
|
||||||
|
return &Float32Buffer{
|
||||||
|
Buf: make([]float32, samples),
|
||||||
|
Ch: channels,
|
||||||
|
Order: order,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) Channels() int {
|
||||||
|
return b.Ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) Len() int {
|
||||||
|
return len(b.Buf) / b.Ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) ReadFrom(r io.Reader) (int, error) {
|
||||||
|
if err := binary.Read(r, b.Order, b.Buf); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return len(b.Buf), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) CopyChannel(dst []float32, ch int) {
|
||||||
|
if b.Ch == 1 {
|
||||||
|
copy(dst, b.Buf)
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, l := ch, len(b.Buf); i < l; i += b.Ch {
|
||||||
|
dst[i/b.Ch] = b.Buf[i]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) Samples() *Float32Buffer {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) AsMono() *Float32Buffer {
|
||||||
|
if b.Ch <= 1 {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
o := NewFloat32Buffer(b.Len(), 1, b.Order)
|
||||||
|
for i, l := 0, b.Len(); i < l; i++ {
|
||||||
|
for c := 0; c < b.Ch; c++ {
|
||||||
|
o.Buf[i] += b.Buf[i*b.Ch+c]
|
||||||
|
}
|
||||||
|
o.Buf[i] /= float32(b.Ch)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) AsStereo() *Float32Buffer {
|
||||||
|
if b.Ch == 2 {
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
if b.Ch != 1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
o = NewFloat32Buffer(b.Len(), 2, b.Order)
|
||||||
|
j int
|
||||||
|
)
|
||||||
|
for i, l := 0, b.Len(); i < l; i, j = i+1, j+2 {
|
||||||
|
o.Buf[j+0] = b.Buf[i]
|
||||||
|
o.Buf[j+1] = b.Buf[i]
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) StereoPan(pan float32) {
|
||||||
|
if b.Ch != 2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if pan < 0 || pan > 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if almostEqualF32(pan, 0.5) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if pan < 0.5 {
|
||||||
|
for i, l := 1, len(b.Buf); i < l; i += 2 {
|
||||||
|
b.Buf[i] *= (pan * 2)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i, l := 0, len(b.Buf); i < l; i += 2 {
|
||||||
|
b.Buf[i] *= ((1 - pan) * 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) PeakRMS(channel int) float32 {
|
||||||
|
if b.Ch == 1 {
|
||||||
|
return float32(calc.RMS(b.Buf))
|
||||||
|
}
|
||||||
|
return float32(calc.RMSOffset[float32](b.Buf, channel, b.Ch))
|
||||||
|
//return PeakRMS(b.Buf, channel, b.Ch)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Float32Buffer) Mean(channel int) float32 {
|
||||||
|
//return Mean(b.Buf, channel, b.Ch)
|
||||||
|
if b.Ch == 1 {
|
||||||
|
return float32(calc.Mean(b.Buf))
|
||||||
|
}
|
||||||
|
return float32(calc.MeanOffset[float32](b.Buf, channel, b.Ch))
|
||||||
|
}
|
||||||
|
|
||||||
|
const float32EqualityThreshold = 1e-6
|
||||||
|
|
||||||
|
func almostEqualF32(a, b float32) bool {
|
||||||
|
return abs(a-b) <= float32EqualityThreshold
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ Buffer = (*Int8Buffer)(nil)
|
||||||
|
_ Buffer = (*Int16Buffer)(nil)
|
||||||
|
_ Buffer = (*Int32Buffer)(nil)
|
||||||
|
_ Buffer = (*Float32Buffer)(nil)
|
||||||
|
)
|
||||||
+105
-4
@@ -3,6 +3,9 @@ package audio
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/internal/calc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrFormat = errors.New("invalid audio format")
|
var ErrFormat = errors.New("invalid audio format")
|
||||||
@@ -17,17 +20,19 @@ const (
|
|||||||
Int16BEFormat
|
Int16BEFormat
|
||||||
Int32LEFormat
|
Int32LEFormat
|
||||||
Int32BEFormat
|
Int32BEFormat
|
||||||
|
Float32LEFormat
|
||||||
|
Float32BEFormat
|
||||||
invalidFormat
|
invalidFormat
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f Format) Order() binary.ByteOrder {
|
func (f Format) Order() binary.ByteOrder {
|
||||||
switch f {
|
switch f {
|
||||||
case Int16LEFormat, Int32LEFormat:
|
case Int16LEFormat, Int32LEFormat, Float32LEFormat:
|
||||||
return binary.LittleEndian
|
return binary.LittleEndian
|
||||||
case Int16BEFormat, Int32BEFormat:
|
case Int16BEFormat, Int32BEFormat, Float32BEFormat:
|
||||||
return binary.BigEndian
|
return binary.BigEndian
|
||||||
default:
|
default:
|
||||||
return binary.NativeEndian
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,9 +42,105 @@ func (f Format) BytesPerSample() int {
|
|||||||
return 8
|
return 8
|
||||||
case Int16LEFormat, Int16BEFormat:
|
case Int16LEFormat, Int16BEFormat:
|
||||||
return 16
|
return 16
|
||||||
case Int32LEFormat, Int32BEFormat:
|
case Int32LEFormat, Int32BEFormat, Float32LEFormat, Float32BEFormat:
|
||||||
return 32
|
return 32
|
||||||
default:
|
default:
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f Format) NewBuffer(size, channels int) Buffer {
|
||||||
|
switch f {
|
||||||
|
case Int8Format:
|
||||||
|
return NewInt8Buffer(size, channels)
|
||||||
|
case Int16LEFormat, Int16BEFormat:
|
||||||
|
return NewInt16Buffer(size, channels, f.Order())
|
||||||
|
case Int32LEFormat, Int32BEFormat:
|
||||||
|
return NewInt32Buffer(size, channels, f.Order())
|
||||||
|
case Float32LEFormat, Float32BEFormat:
|
||||||
|
return NewFloat32Buffer(size, channels, f.Order())
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Min(samples []float32) (min float32) {
|
||||||
|
if len(samples) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
min = math.MaxFloat32
|
||||||
|
for _, sample := range samples {
|
||||||
|
if sample < min {
|
||||||
|
min = sample
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func abs(v float32) float32 {
|
||||||
|
if v < 0 {
|
||||||
|
return -v
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func Max(samples []float32) (max float32) {
|
||||||
|
if len(samples) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
max = -math.MaxFloat32
|
||||||
|
for _, sample := range samples {
|
||||||
|
if sample > max {
|
||||||
|
max = sample
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func Abs(samples []float32) {
|
||||||
|
if len(samples) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, sample := range samples {
|
||||||
|
samples[i] = abs(sample)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Normalize(samples []float32) {
|
||||||
|
if len(samples) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var max float32
|
||||||
|
for _, sample := range samples {
|
||||||
|
if abs := abs(sample); abs > max {
|
||||||
|
max = abs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if max != 0 {
|
||||||
|
for i := range samples {
|
||||||
|
samples[i] /= max
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Clamp(sample float32) float32 {
|
||||||
|
if sample < -1 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if sample > +1 {
|
||||||
|
return +1
|
||||||
|
}
|
||||||
|
return sample
|
||||||
|
}
|
||||||
|
|
||||||
|
func RMS(samples []float32, channel, channels int) float64 {
|
||||||
|
if channels == 1 {
|
||||||
|
return calc.RMS(samples)
|
||||||
|
}
|
||||||
|
return calc.RMSOffset(samples, channel, channels)
|
||||||
|
}
|
||||||
+141
-26
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"go.maze.io/harmon/config"
|
"go.maze.io/harmon/config"
|
||||||
@@ -12,6 +13,8 @@ import (
|
|||||||
"periph.io/x/conn/v3/physic"
|
"periph.io/x/conn/v3/physic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const streamBuffers = 16
|
||||||
|
|
||||||
type Stream interface {
|
type Stream interface {
|
||||||
hardware.Driver
|
hardware.Driver
|
||||||
|
|
||||||
@@ -22,9 +25,115 @@ type Stream interface {
|
|||||||
SampleRate() physic.Frequency
|
SampleRate() physic.Frequency
|
||||||
|
|
||||||
// Samples is a channel of interleaved audio samples.
|
// Samples is a channel of interleaved audio samples.
|
||||||
Samples() <-chan []int16
|
Samples(size int) <-chan Buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Processor interface {
|
||||||
|
Process(Buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
type StreamReader struct {
|
||||||
|
Opener func() (io.Reader, error)
|
||||||
|
|
||||||
|
// Format is the audio sample format.
|
||||||
|
Format Format
|
||||||
|
|
||||||
|
// Ch is the number of channels.
|
||||||
|
Ch int
|
||||||
|
|
||||||
|
// Rate is the sampling rate.
|
||||||
|
Rate physic.Frequency
|
||||||
|
|
||||||
|
// quit signal channel.
|
||||||
|
quit chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStreamReader(open func() (io.Reader, error), f Format, ch int, rate physic.Frequency) Stream {
|
||||||
|
return &StreamReader{
|
||||||
|
Opener: open,
|
||||||
|
Format: f,
|
||||||
|
Ch: ch,
|
||||||
|
Rate: rate,
|
||||||
|
quit: make(chan struct{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *StreamReader) Halt() error {
|
||||||
|
if r.quit != nil {
|
||||||
|
close(r.quit)
|
||||||
|
r.quit = nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *StreamReader) Type() string {
|
||||||
|
return "stream"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *StreamReader) Channels() int {
|
||||||
|
return r.Ch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *StreamReader) SampleRate() physic.Frequency {
|
||||||
|
return r.Rate
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *StreamReader) Samples(size int) <-chan Buffer {
|
||||||
|
samples := make(chan Buffer, streamBuffers)
|
||||||
|
go r.stream(samples, size)
|
||||||
|
return samples
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *StreamReader) stream(samples chan<- Buffer, size int) {
|
||||||
|
defer close(samples)
|
||||||
|
|
||||||
|
var (
|
||||||
|
log = logrus.WithField("audio", "stream")
|
||||||
|
ring [streamBuffers]Buffer
|
||||||
|
curr int
|
||||||
|
)
|
||||||
|
for i := 0; i < streamBuffers; i++ {
|
||||||
|
ring[i] = r.Format.NewBuffer(size*r.Ch, r.Ch)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debug("starting with %d buffers", streamBuffers)
|
||||||
|
for {
|
||||||
|
log.Debug("opening stream")
|
||||||
|
f, err := r.Opener()
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Warn("opening stream failed, retrying...")
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
n, err := ring[curr].ReadFrom(f)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Warn("stream closed, retrying...")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
log.WithField("samples", n).Trace("stream samples")
|
||||||
|
select {
|
||||||
|
case <-r.quit:
|
||||||
|
if c, ok := f.(io.Closer); ok {
|
||||||
|
if err = c.Close(); err != nil {
|
||||||
|
log.WithError(err).Warn("closing stream failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
case samples <- ring[curr]:
|
||||||
|
default:
|
||||||
|
log.Warn("dropped samples, buffer overrun")
|
||||||
|
}
|
||||||
|
|
||||||
|
curr = (curr + 1) % streamBuffers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
type Reader struct {
|
type Reader struct {
|
||||||
io.Reader
|
io.Reader
|
||||||
|
|
||||||
@@ -66,60 +175,66 @@ func (r Reader) SampleRate() physic.Frequency {
|
|||||||
return r.Rate
|
return r.Rate
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) Read(b *Buffer) (n int, err error) {
|
func (r *Reader) Read(b Buffer) (n int, err error) {
|
||||||
if b == nil {
|
return b.ReadFrom(r.Reader)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
l := len(b.Buf)
|
|
||||||
l -= l % (b.Ch * b.Format.BytesPerSample()) // align to samples
|
|
||||||
n, err = r.Reader.Read(b.Buf[:l]) // read
|
|
||||||
n /= (b.Ch * b.Format.BytesPerSample()) // return sample count
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) read(send chan []int16) {
|
const numBuf = 16
|
||||||
const numBuf = 16
|
|
||||||
|
|
||||||
|
func (r *Reader) stream(send chan Buffer, rate physic.Frequency) {
|
||||||
var (
|
var (
|
||||||
b = NewBuffer(int(r.Rate/physic.Hertz), r.Ch, r.Format)
|
b = r.Format.NewBuffer(int(rate/physic.Hertz), r.Ch) //NewBuffer(int(rate/physic.Hertz), r.Ch, r.Format)
|
||||||
order = r.Format.Order()
|
buf [numBuf]Buffer
|
||||||
buf [numBuf][]int16
|
|
||||||
n int
|
n int
|
||||||
)
|
)
|
||||||
for i := range buf {
|
|
||||||
buf[i] = make([]int16, int(r.Rate/physic.Hertz)*r.Ch)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"buffers": numBuf,
|
||||||
|
"rate_in": r.Rate,
|
||||||
|
"rate_out": rate,
|
||||||
|
}).Info("audio stream starting")
|
||||||
for {
|
for {
|
||||||
if _, err := r.Read(b); err != nil {
|
if _, err := r.Read(b); err != nil {
|
||||||
|
logrus.WithError(err).Warn("audio stream interrupted")
|
||||||
close(send)
|
close(send)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
samples, _ := b.Decode(buf[n], order)
|
//samples, err := b.Decode(buf[n], order)
|
||||||
|
samples, err := b.ReadFrom(r.Reader)
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Warn("samples decode failed")
|
||||||
|
continue
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case send <- buf[n][:samples]:
|
case send <- buf[n]:
|
||||||
default:
|
default:
|
||||||
|
logrus.WithField("samples", samples).Warn("samples dropped, buffer overrun")
|
||||||
}
|
}
|
||||||
|
|
||||||
n = (n + 1) % numBuf
|
n = (n + 1) % numBuf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) Samples() <-chan []int16 {
|
func (r *Reader) Samples(rate physic.Frequency) <-chan Buffer {
|
||||||
samples := make(chan []int16)
|
samples := make(chan Buffer, numBuf)
|
||||||
go r.read(samples)
|
go r.stream(samples, rate)
|
||||||
return samples
|
return samples
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Open a stream backed by a file (or a FIFO).
|
// Open a stream backed by a file (or a FIFO).
|
||||||
func Open(name string, f Format, ch int, rate physic.Frequency) (Stream, error) {
|
func Open(name string, f Format, ch int, rate physic.Frequency) Stream {
|
||||||
|
/*
|
||||||
r, err := os.OpenFile(name, os.O_RDONLY, 0)
|
r, err := os.OpenFile(name, os.O_RDONLY, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return NewReader(r, f, ch, rate), nil
|
return NewReader(r, f, ch, rate), nil
|
||||||
|
*/
|
||||||
|
return NewStreamReader(func() (io.Reader, error) {
|
||||||
|
return os.OpenFile(name, os.O_RDONLY, 0)
|
||||||
|
}, f, ch, rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func openFile(config config.Audio) (Stream, error) {
|
func openFile(config config.Audio) (Stream, error) {
|
||||||
@@ -154,7 +269,7 @@ func openFile(config config.Audio) (Stream, error) {
|
|||||||
"channels": config.Channels,
|
"channels": config.Channels,
|
||||||
"rate": rate,
|
"rate": rate,
|
||||||
}).Debug("open audio driver")
|
}).Debug("open audio driver")
|
||||||
return Open(config.Path, f, config.Channels, rate)
|
return Open(config.Path, f, config.Channels, rate), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|||||||
+30
-12
@@ -2,12 +2,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
|
|
||||||
"go.maze.io/harmon"
|
"go.maze.io/harmon"
|
||||||
"go.maze.io/harmon/config"
|
"go.maze.io/harmon/config"
|
||||||
@@ -17,14 +17,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configFlag := flag.String("config", "", "configuration file path (default: auto detect)")
|
cmd := &cli.Command{
|
||||||
debugFlag := flag.Bool("debug", false, "enable debug log messages")
|
Name: "harmon",
|
||||||
traceFlag := flag.Bool("trace", false, "enable trace log messages (very noisy!)")
|
Usage: "Harmon is a playful music player frontend",
|
||||||
flag.Parse()
|
Action: runFunc,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{Name: "config", Usage: "configuration file path"},
|
||||||
|
&cli.BoolFlag{Name: "debug", Usage: "enable debug log messages"},
|
||||||
|
&cli.BoolFlag{Name: "trace", Usage: "enable trace log messages (noisy!)"},
|
||||||
|
},
|
||||||
|
Commands: []*cli.Command{
|
||||||
|
scanCommand,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
if *traceFlag {
|
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func runFunc(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
if cmd.Bool("trace") {
|
||||||
logrus.SetLevel(logrus.TraceLevel)
|
logrus.SetLevel(logrus.TraceLevel)
|
||||||
} else if *debugFlag {
|
} else if cmd.Bool("debug") {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,13 +49,14 @@ func main() {
|
|||||||
"host_arch": runtime.GOARCH,
|
"host_arch": runtime.GOARCH,
|
||||||
}).Info("Harmon starting")
|
}).Info("Harmon starting")
|
||||||
|
|
||||||
if *configFlag == "" {
|
configFile := cmd.String("config")
|
||||||
if *configFlag = findConfigFile(); *configFlag == "" {
|
if configFile == "" {
|
||||||
|
if configFile = findConfigFile(); configFile == "" {
|
||||||
logrus.Fatal("could not auto detect configuration file; supply one with -config")
|
logrus.Fatal("could not auto detect configuration file; supply one with -config")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := config.Load(*configFlag)
|
config, err := config.Load(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Fatal("configuration file contains errors")
|
logrus.WithError(err).Fatal("configuration file contains errors")
|
||||||
}
|
}
|
||||||
@@ -52,7 +68,7 @@ func main() {
|
|||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
signals := make(chan os.Signal)
|
signals := make(chan os.Signal, 1)
|
||||||
signal.Notify(signals, os.Interrupt)
|
signal.Notify(signals, os.Interrupt)
|
||||||
signal.Notify(signals, os.Kill)
|
signal.Notify(signals, os.Kill)
|
||||||
go func(signals <-chan os.Signal, cancel func()) {
|
go func(signals <-chan os.Signal, cancel func()) {
|
||||||
@@ -62,6 +78,8 @@ func main() {
|
|||||||
}(signals, cancel)
|
}(signals, cancel)
|
||||||
|
|
||||||
if err = controller.Run(ctx); err != nil && err != context.Canceled {
|
if err = controller.Run(ctx); err != nil && err != context.Canceled {
|
||||||
logrus.WithError(err).Fatal("terminating by fatal error")
|
//logrus.WithError(err).Fatal("terminating by fatal error")
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/go-daq/smbus"
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var scanCommand = &cli.Command{
|
||||||
|
Name: "scan",
|
||||||
|
Category: "i2c",
|
||||||
|
Usage: "Scan the I2C bus for active devices",
|
||||||
|
Action: scanFunc,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.IntFlag{Name: "bus", Usage: "I²C bus to use", Value: 1},
|
||||||
|
&cli.IntFlag{Name: "first", Usage: "First address", Value: 0x03},
|
||||||
|
&cli.IntFlag{Name: "last", Usage: "Last address", Value: 0x77},
|
||||||
|
&cli.BoolFlag{Name: "error", Usage: "Print errors"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanFunc(ctx context.Context, cmd *cli.Command) error {
|
||||||
|
bus, err := smbus.OpenFile(int(cmd.Int("bus")))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer bus.Close()
|
||||||
|
|
||||||
|
var (
|
||||||
|
first = int(cmd.Int("first"))
|
||||||
|
last = int(cmd.Int("last"))
|
||||||
|
errs []error
|
||||||
|
)
|
||||||
|
|
||||||
|
fmt.Println(" 0 1 2 3 4 5 6 7 8 9 a b c d e f")
|
||||||
|
for i := 0; i < 128; i += 16 {
|
||||||
|
fmt.Printf("%02x: ", i)
|
||||||
|
for j := 0; j < 16; j++ {
|
||||||
|
if i+j < first || i+j > last {
|
||||||
|
fmt.Print(" ")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bus.SetAddr(uint8(i + j)); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
fmt.Print("UU ")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
useRead := ((i+j >= 0x30 && i+j <= 0x37) || (i+j >= 0x50 && i+j <= 0x5F))
|
||||||
|
if useRead || true {
|
||||||
|
_, err = bus.ReadReg(uint8(i+j), 0)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
fmt.Printf("%02x ", i+j)
|
||||||
|
errs = append(errs, nil)
|
||||||
|
} else {
|
||||||
|
fmt.Printf("-- ")
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd.Bool("error") {
|
||||||
|
for i := first; i < last; i++ {
|
||||||
|
if err := errs[i-first]; err != nil {
|
||||||
|
fmt.Printf("%02x: %v\n", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return bus.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func ioctl(fd, cmd, arg uintptr) (err error) {
|
||||||
|
_, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, cmd, arg, 0, 0, 0)
|
||||||
|
if e1 != 0 {
|
||||||
|
err = e1
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type i2cCmd struct {
|
||||||
|
rw uint8
|
||||||
|
cmd uint8
|
||||||
|
len uint32
|
||||||
|
ptr unsafe.Pointer
|
||||||
|
}
|
||||||
+4
-3
@@ -12,9 +12,10 @@ type Config struct {
|
|||||||
// Display configuration for OLED and TFT screens.
|
// Display configuration for OLED and TFT screens.
|
||||||
type Display struct {
|
type Display struct {
|
||||||
FPS int `hcl:"fps,optional"`
|
FPS int `hcl:"fps,optional"`
|
||||||
Left DisplayConfig `hcl:"left,block"`
|
Main *DisplayConfig `hcl:"main,block"`
|
||||||
Right DisplayConfig `hcl:"right,block"`
|
Left *DisplayConfig `hcl:"left,block"`
|
||||||
Color DisplayConfig `hcl:"color,block"`
|
Right *DisplayConfig `hcl:"right,block"`
|
||||||
|
Color *DisplayConfig `hcl:"color,block"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisplayConfig is the configuration for one display.
|
// DisplayConfig is the configuration for one display.
|
||||||
|
|||||||
+143
-13
@@ -2,10 +2,15 @@ package harmon
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"periph.io/x/conn/v3/physic"
|
||||||
"periph.io/x/host/v3"
|
"periph.io/x/host/v3"
|
||||||
|
|
||||||
"go.maze.io/harmon/audio"
|
"go.maze.io/harmon/audio"
|
||||||
@@ -15,16 +20,21 @@ import (
|
|||||||
"go.maze.io/harmon/internal/pixel"
|
"go.maze.io/harmon/internal/pixel"
|
||||||
"go.maze.io/harmon/player"
|
"go.maze.io/harmon/player"
|
||||||
"go.maze.io/harmon/visual"
|
"go.maze.io/harmon/visual"
|
||||||
|
"go.maze.io/harmon/visual/screensaver"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const defaultFPS = 20
|
||||||
|
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
// Left, right and color displays.
|
// Left, right and color displays.
|
||||||
|
Main hardware.Display
|
||||||
Left hardware.Display
|
Left hardware.Display
|
||||||
Right hardware.Display
|
Right hardware.Display
|
||||||
Color hardware.Display
|
Color hardware.Display
|
||||||
|
|
||||||
// Player.
|
// Player.
|
||||||
Player player.Player
|
Player player.Player
|
||||||
|
AlbumArt player.AlbumArt
|
||||||
|
|
||||||
// Audio source.
|
// Audio source.
|
||||||
Audio audio.Stream
|
Audio audio.Stream
|
||||||
@@ -34,11 +44,16 @@ type Controller struct {
|
|||||||
|
|
||||||
// Visual effects.
|
// Visual effects.
|
||||||
visual struct {
|
visual struct {
|
||||||
|
current visual.Visual
|
||||||
offline *visual.Offline
|
offline *visual.Offline
|
||||||
|
screensaver *screensaver.Stars
|
||||||
|
vumeterLeft *visual.VUMeter
|
||||||
|
vumeterRight *visual.VUMeter
|
||||||
}
|
}
|
||||||
|
|
||||||
fps time.Duration
|
fps time.Duration
|
||||||
connected bool
|
connected bool
|
||||||
|
playing bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewController(config *config.Config) (*Controller, error) {
|
func NewController(config *config.Config) (*Controller, error) {
|
||||||
@@ -59,10 +74,6 @@ func NewController(config *config.Config) (*Controller, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c := &Controller{}
|
c := &Controller{}
|
||||||
if err = c.loadPlayer(config.Player); err != nil {
|
|
||||||
c.teardown()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err = c.loadAudio(config.Audio); err != nil {
|
if err = c.loadAudio(config.Audio); err != nil {
|
||||||
c.teardown()
|
c.teardown()
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -71,6 +82,14 @@ func NewController(config *config.Config) (*Controller, error) {
|
|||||||
c.teardown()
|
c.teardown()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err = c.loadInputs(config.Input); err != nil {
|
||||||
|
c.teardown()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = c.loadPlayer(config.Player); err != nil {
|
||||||
|
c.teardown()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@@ -80,7 +99,14 @@ func (c *Controller) log() *logrus.Entry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) loadPlayer(config config.Player) (err error) {
|
func (c *Controller) loadPlayer(config config.Player) (err error) {
|
||||||
c.Player, err = player.New(config)
|
if c.Player, err = player.New(config); err == nil {
|
||||||
|
var ok bool
|
||||||
|
if c.AlbumArt, ok = c.Player.(player.AlbumArt); ok {
|
||||||
|
c.log().Debug("player supports album art, great")
|
||||||
|
} else {
|
||||||
|
c.log().Warn("player doesn't support album art... sad :-(")
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,28 +119,95 @@ func (c *Controller) loadDisplays(config config.Display) (err error) {
|
|||||||
log := c.log()
|
log := c.log()
|
||||||
|
|
||||||
if c.fps = time.Second / time.Duration(config.FPS); c.fps <= 0 {
|
if c.fps = time.Second / time.Duration(config.FPS); c.fps <= 0 {
|
||||||
log.WithField("fps", c.fps).Debug("setting default frame rate")
|
config.FPS = defaultFPS
|
||||||
c.fps = time.Second / 15
|
log.WithFields(logrus.Fields{
|
||||||
|
"fps": defaultFPS,
|
||||||
|
"rate": c.fps,
|
||||||
|
}).Debug("setting default frame rate")
|
||||||
|
c.fps = time.Second / defaultFPS
|
||||||
} else {
|
} else {
|
||||||
log.WithField("fps", c.fps).Debug("setting frame rate")
|
log.WithFields(logrus.Fields{
|
||||||
|
"fps": config.FPS,
|
||||||
|
"rate": c.fps,
|
||||||
|
}).Debug("setting frame rate")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Left, err = display.Load(config.Left); err != nil {
|
if config.Main != nil {
|
||||||
|
if c.Main, err = display.Load(*config.Main); err != nil {
|
||||||
|
return fmt.Errorf("error loading main display driver: %w", err)
|
||||||
|
}
|
||||||
|
size := c.Main.Size()
|
||||||
|
c.Left = display.MakeView(c.Main, image.Rect(0, 0, size.X/2, size.Y))
|
||||||
|
c.Right = display.MakeView(c.Main, image.Rect(size.X/2, 0, size.X, size.Y))
|
||||||
|
} else if config.Left == nil {
|
||||||
|
return errors.New("missing main or left block in display configuration")
|
||||||
|
} else if config.Right == nil {
|
||||||
|
return errors.New("missing main or right block in display configuration")
|
||||||
|
} else {
|
||||||
|
if c.Left, err = display.Load(*config.Left); err != nil {
|
||||||
return fmt.Errorf("error loading left display driver: %w", err)
|
return fmt.Errorf("error loading left display driver: %w", err)
|
||||||
} else if err = c.Left.Fill(pixel.On); err != nil {
|
} else if err = c.Left.Fill(pixel.On); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if c.Right, err = display.Load(config.Right); err != nil {
|
if c.Right, err = display.Load(*config.Right); err != nil {
|
||||||
return fmt.Errorf("error loading right display driver: %w", err)
|
return fmt.Errorf("error loading right display driver: %w", err)
|
||||||
} else if err = c.Right.Fill(pixel.Off); err != nil {
|
} else if err = c.Right.Fill(pixel.Off); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
c.Main = display.NewCombined(c.Left, c.Right)
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if c.Color, err = display.Load(config.Color); err != nil {
|
||||||
|
return fmt.Errorf("error loading color display driver: %w", err)
|
||||||
|
} else if err = c.Color.Fill(pixel.Off); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
log.WithField("type", c.Main.Type()).Info("configured main display")
|
||||||
|
log.WithField("type", c.Left.Type()).Info("configured left display")
|
||||||
|
log.WithField("type", c.Right.Type()).Info("configured right display")
|
||||||
|
|
||||||
|
rate := c.Audio.SampleRate() / physic.Frequency(config.FPS)
|
||||||
|
c.visual.screensaver = screensaver.NewStars(c.Main, 12)
|
||||||
c.visual.offline = visual.NewOffline(c.Left, c.Right, nil)
|
c.visual.offline = visual.NewOffline(c.Left, c.Right, nil)
|
||||||
|
c.visual.vumeterLeft = visual.NewVUMeter(c.Left, rate, 1, c.Audio.Channels())
|
||||||
|
c.visual.vumeterRight = visual.NewVUMeter(c.Right, rate, 2, c.Audio.Channels())
|
||||||
|
|
||||||
|
// Splash screen
|
||||||
|
/*
|
||||||
|
if err = display.DrawImage(c.Color, 40, 40, "harmon.png"); err != nil {
|
||||||
|
return fmt.Errorf("error loading splash screen: %w", err)
|
||||||
|
}
|
||||||
|
display.DrawText(c.Color, 1, 1, display.Font8x16, "Harmon")
|
||||||
|
for y := 0; y < 240; y++ {
|
||||||
|
for x := 0; x < 240; x++ {
|
||||||
|
c.Color.Set(x, y, randomColor())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err = c.Color.Refresh(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Controller) loadInputs(config config.Input) (err error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func randomColor() color.RGBA {
|
||||||
|
var b [3]byte
|
||||||
|
rand.Read(b[:])
|
||||||
|
return color.RGBA{
|
||||||
|
R: b[0],
|
||||||
|
G: b[1],
|
||||||
|
B: b[2],
|
||||||
|
A: 0xff,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Controller) teardown() {
|
func (c *Controller) teardown() {
|
||||||
log := c.log()
|
log := c.log()
|
||||||
if c.Player != nil {
|
if c.Player != nil {
|
||||||
@@ -142,11 +235,19 @@ func (c *Controller) Run(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.log().Info("Harmon controller running...")
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
fps = time.NewTicker(c.fps)
|
fps = time.NewTicker(c.fps)
|
||||||
update = time.NewTicker(25 * time.Millisecond)
|
update = time.NewTicker(25 * time.Millisecond)
|
||||||
|
rate = int(time.Second / c.fps)
|
||||||
|
)
|
||||||
|
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"fps": rate,
|
||||||
|
"rate_display": c.fps,
|
||||||
|
"rate_sample": c.Audio.SampleRate(),
|
||||||
|
}).Debug("opening audio stream")
|
||||||
|
var (
|
||||||
|
samples = c.Audio.Samples(int(c.Audio.SampleRate() / physic.Frequency(rate) / physic.Hertz))
|
||||||
last time.Time
|
last time.Time
|
||||||
frames int
|
frames int
|
||||||
)
|
)
|
||||||
@@ -154,6 +255,12 @@ func (c *Controller) Run(ctx context.Context) error {
|
|||||||
defer fps.Stop()
|
defer fps.Stop()
|
||||||
defer update.Stop()
|
defer update.Stop()
|
||||||
|
|
||||||
|
c.log().WithFields(logrus.Fields{
|
||||||
|
"rate": c.Audio.SampleRate(),
|
||||||
|
"fps": rate,
|
||||||
|
"rate_fps": c.Audio.SampleRate() / physic.Frequency(rate),
|
||||||
|
}).Info("Harmon controller running...")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-playerEvents:
|
case event := <-playerEvents:
|
||||||
@@ -164,11 +271,16 @@ func (c *Controller) Run(ctx context.Context) error {
|
|||||||
c.handleFrame()
|
c.handleFrame()
|
||||||
|
|
||||||
case now := <-update.C:
|
case now := <-update.C:
|
||||||
|
if logrus.GetLevel() >= logrus.DebugLevel {
|
||||||
if now.Sub(last) > time.Second {
|
if now.Sub(last) > time.Second {
|
||||||
c.log().WithField("fps", frames).Debug("frame rate")
|
c.log().WithField("fps", frames).Debug("frame rate")
|
||||||
last = now
|
last = now
|
||||||
frames = 0
|
frames = 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case samples := <-samples:
|
||||||
|
c.handleSamples(samples)
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
@@ -190,12 +302,14 @@ func (c *Controller) handlePlayer(event player.Event) {
|
|||||||
case player.DisconnectedEvent:
|
case player.DisconnectedEvent:
|
||||||
log.Warn("player disconnected")
|
log.Warn("player disconnected")
|
||||||
c.connected = false
|
c.connected = false
|
||||||
|
c.playing = false
|
||||||
|
|
||||||
case player.PlayEvent:
|
case player.PlayEvent:
|
||||||
log.WithField("track", event.Track).Info("now playing")
|
log.WithField("track", event.Track).Info("now playing")
|
||||||
|
|
||||||
case player.StatusEvent:
|
case player.StatusEvent:
|
||||||
log.WithField("state", event.Status).Trace("player status")
|
log.WithField("state", event.Status).Trace("player status")
|
||||||
|
c.playing = event.Status.Playing
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.WithField("event", event).Warn("unhandled event")
|
log.WithField("event", event).Warn("unhandled event")
|
||||||
@@ -205,10 +319,26 @@ func (c *Controller) handlePlayer(event player.Event) {
|
|||||||
func (c *Controller) handleFrame() {
|
func (c *Controller) handleFrame() {
|
||||||
log := c.log()
|
log := c.log()
|
||||||
if c.connected {
|
if c.connected {
|
||||||
|
if c.playing {
|
||||||
|
if err := c.visual.vumeterLeft.Render(); err != nil {
|
||||||
|
log.WithError(err).Warn("left vumeter render failed")
|
||||||
|
}
|
||||||
|
if err := c.visual.vumeterRight.Render(); err != nil {
|
||||||
|
log.WithError(err).Warn("right vumeter render failed")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := c.visual.screensaver.Refresh(); err != nil {
|
||||||
|
log.WithError(err).Warn("screensaver render failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := c.visual.offline.Render(); err != nil {
|
if err := c.visual.offline.Render(); err != nil {
|
||||||
log.WithError(err).Warn("offline render failed")
|
log.WithError(err).Warn("offline render failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Controller) handleSamples(samples audio.Buffer) {
|
||||||
|
c.visual.vumeterLeft.Process(samples)
|
||||||
|
c.visual.vumeterRight.Process(samples)
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
@@ -16,8 +16,12 @@ require (
|
|||||||
require (
|
require (
|
||||||
github.com/agext/levenshtein v1.2.1 // indirect
|
github.com/agext/levenshtein v1.2.1 // indirect
|
||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
|
||||||
|
github.com/ecc1/gpio v0.0.0-20200212231225-d40e43fcf8f5 // indirect
|
||||||
|
github.com/ecc1/spi v0.0.0-20230226182530-b0f4c20d714a // indirect
|
||||||
|
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606 // indirect
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
||||||
|
github.com/urfave/cli/v3 v3.0.0-beta1 // indirect
|
||||||
golang.org/x/mod v0.17.0 // indirect
|
golang.org/x/mod v0.17.0 // indirect
|
||||||
golang.org/x/sys v0.20.0 // indirect
|
golang.org/x/sys v0.20.0 // indirect
|
||||||
golang.org/x/text v0.21.0 // indirect
|
golang.org/x/text v0.21.0 // indirect
|
||||||
|
|||||||
@@ -6,12 +6,22 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew
|
|||||||
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
|
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/ecc1/gpio v0.0.0-20200212231225-d40e43fcf8f5 h1:caoskihCyJpXaV3oRLl+jYuE+aLRnfcIprUQ6oBxTh8=
|
||||||
|
github.com/ecc1/gpio v0.0.0-20200212231225-d40e43fcf8f5/go.mod h1:ZcIrkf+E8KutUpAcNHOHaf2NYukHYOlYTCDxV5zzn04=
|
||||||
|
github.com/ecc1/spi v0.0.0-20230226182530-b0f4c20d714a h1:wKFSDxAFrELZwZHfH8qL60cBUPx4k/As9rknIyS9HVI=
|
||||||
|
github.com/ecc1/spi v0.0.0-20230226182530-b0f4c20d714a/go.mod h1:aEx53qKDtY1Ryywz6SVx/K+n3eVGB2tsijuntsITXzA=
|
||||||
|
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606 h1:1lyGjYJXpYkF6fGQbhAIOdIaeymKQuS6RJVLVlTzc5w=
|
||||||
|
github.com/go-daq/smbus v0.0.0-20201216173259-5725b4593606/go.mod h1:KDYiP7UvrtHRqnVLE6ziKupbojinMHjFUdo+1VA7r/Q=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos=
|
github.com/hashicorp/hcl/v2 v2.23.0 h1:Fphj1/gCylPxHutVSEOf2fBOh1VE4AuLV7+kbJf3qos=
|
||||||
github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
|
github.com/hashicorp/hcl/v2 v2.23.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA=
|
||||||
github.com/kyoh86/xdg v1.2.0 h1:CERuT/ShdTDj+A2UaX3hQ3mOV369+Sj+wyn2nIRIIkI=
|
github.com/kyoh86/xdg v1.2.0 h1:CERuT/ShdTDj+A2UaX3hQ3mOV369+Sj+wyn2nIRIIkI=
|
||||||
github.com/kyoh86/xdg v1.2.0/go.mod h1:/mg8zwu1+qe76oTFUBnyS7rJzk7LLC0VGEzJyJ19DHs=
|
github.com/kyoh86/xdg v1.2.0/go.mod h1:/mg8zwu1+qe76oTFUBnyS7rJzk7LLC0VGEzJyJ19DHs=
|
||||||
|
github.com/luismesas/go-rpi v1.0.2 h1:qbtmG/pFgPtr7BiB1tR4O+5ODwBldBPoHuHDctQjnU8=
|
||||||
|
github.com/luismesas/go-rpi v1.0.2/go.mod h1:X5HClL0mGP2US8C2ISmJStxOW6WPSvmVDrnP9zNGthg=
|
||||||
|
github.com/luismesas/goPi v1.0.2 h1:JOtDgbru2ORpYQT2Ot0UwIBQMyxw84/bBlO7rkP2XhI=
|
||||||
|
github.com/luismesas/goPi v1.0.2/go.mod h1:uKBSNIiXHmmA1vNzKnlDt79VzpGygJ3XMWwhPuWH/F8=
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
@@ -19,6 +29,8 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
|
|||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg=
|
||||||
|
github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y=
|
||||||
github.com/zclconf/go-cty v1.16.0 h1:xPKEhst+BW5D0wxebMZkxgapvOE/dw7bFTlgSc9nD6w=
|
github.com/zclconf/go-cty v1.16.0 h1:xPKEhst+BW5D0wxebMZkxgapvOE/dw7bFTlgSc9nD6w=
|
||||||
github.com/zclconf/go-cty v1.16.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
|
github.com/zclconf/go-cty v1.16.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
|
||||||
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
|
golang.org/x/image v0.23.0 h1:HseQ7c2OpPKTPVzNjG5fwJsOTCiiwS4QdsYi5XU6H68=
|
||||||
@@ -26,6 +38,7 @@ golang.org/x/image v0.23.0/go.mod h1:wJJBTdLfCCf3tiHa1fNxpZmUI4mmoZvwMCPP0ddoNKY
|
|||||||
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
||||||
|
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
|||||||
@@ -10,12 +10,18 @@ import (
|
|||||||
type Display interface {
|
type Display interface {
|
||||||
Driver
|
Driver
|
||||||
|
|
||||||
|
// PowerSave puts the display to sleep.
|
||||||
|
PowerSave(on bool) error
|
||||||
|
|
||||||
// Draw an image on the display.
|
// Draw an image on the display.
|
||||||
Draw(r image.Rectangle, src image.Image, sp image.Point) error
|
Draw(r image.Rectangle, src image.Image, sp image.Point) error
|
||||||
|
|
||||||
// Size of the display.
|
// Size of the display.
|
||||||
Size() image.Point
|
Size() image.Point
|
||||||
|
|
||||||
|
// Clear the display buffer.
|
||||||
|
Clear()
|
||||||
|
|
||||||
// Fill with one color.
|
// Fill with one color.
|
||||||
Fill(color.Color) error
|
Fill(color.Color) error
|
||||||
|
|
||||||
|
|||||||
@@ -3,4 +3,7 @@ package all
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "go.maze.io/harmon/hardware/display/ssd1306" // SSD1306
|
_ "go.maze.io/harmon/hardware/display/ssd1306" // SSD1306
|
||||||
|
_ "go.maze.io/harmon/hardware/display/ssd1322" // SSD1322
|
||||||
|
//_ "go.maze.io/harmon/hardware/display/st7735" // ST7735
|
||||||
|
//_ "go.maze.io/harmon/hardware/display/st7789" // ST7789
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package display
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Combined struct {
|
||||||
|
displays []hardware.Display
|
||||||
|
size image.Point
|
||||||
|
stride int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCombined(displays ...hardware.Display) hardware.Display {
|
||||||
|
d := &Combined{
|
||||||
|
displays: displays,
|
||||||
|
size: displays[0].Size(),
|
||||||
|
stride: displays[0].Size().X,
|
||||||
|
}
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) At(x, y int) color.Color {
|
||||||
|
if x < 0 || y < 0 || y >= d.size.Y {
|
||||||
|
return color.Black
|
||||||
|
}
|
||||||
|
for _, display := range d.displays {
|
||||||
|
if x < d.size.X {
|
||||||
|
return display.At(x, y)
|
||||||
|
}
|
||||||
|
x -= d.stride
|
||||||
|
}
|
||||||
|
return color.Black
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) PowerSave(on bool) error {
|
||||||
|
for _, p := range d.displays {
|
||||||
|
if err := p.PowerSave(on); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) Bounds() image.Rectangle {
|
||||||
|
return image.Rectangle{Max: d.Size()}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) ColorModel() color.Model {
|
||||||
|
return d.displays[0].ColorModel()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) Clear() {
|
||||||
|
for _, p := range d.displays {
|
||||||
|
p.Clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
|
||||||
|
draw.Draw(d, r, src, sp, draw.Src)
|
||||||
|
return d.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) Fill(c color.Color) error {
|
||||||
|
for _, p := range d.displays {
|
||||||
|
if err := p.Fill(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) Halt() error {
|
||||||
|
for _, p := range d.displays {
|
||||||
|
if err := p.Halt(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) Refresh() error {
|
||||||
|
for _, p := range d.displays {
|
||||||
|
if err := p.Refresh(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) Set(x, y int, c color.Color) {
|
||||||
|
if x < 0 || y < 0 || y >= d.size.Y {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, p := range d.displays {
|
||||||
|
if x < d.size.X {
|
||||||
|
p.Set(x, y, c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
x -= d.stride
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Combined) Size() image.Point {
|
||||||
|
return image.Point{X: d.stride * len(d.displays), Y: d.size.Y}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Combined) Type() string {
|
||||||
|
return "combined"
|
||||||
|
}
|
||||||
@@ -167,6 +167,9 @@ func InvalidMode(mode string) error {
|
|||||||
type Conn interface {
|
type Conn interface {
|
||||||
// Tx transfers data over the bus.
|
// Tx transfers data over the bus.
|
||||||
Tx(data []byte, isCommand bool) error
|
Tx(data []byte, isCommand bool) error
|
||||||
|
|
||||||
|
// Rx receives data over the bus.
|
||||||
|
Rx(command byte, data []byte) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type i2cConn struct {
|
type i2cConn struct {
|
||||||
@@ -181,6 +184,10 @@ func (c i2cConn) Tx(data []byte, isCommand bool) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c i2cConn) Rx(command byte, data []byte) error {
|
||||||
|
return errors.New("not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
// OpenI2C opens the named I²C bus and connects to the device at addr.
|
// OpenI2C opens the named I²C bus and connects to the device at addr.
|
||||||
func OpenI2C(name, addr string) (Conn, error) {
|
func OpenI2C(name, addr string) (Conn, error) {
|
||||||
log := logrus.WithFields(logrus.Fields{
|
log := logrus.WithFields(logrus.Fields{
|
||||||
@@ -228,6 +235,21 @@ func (c spiConn) Tx(data []byte, isCommand bool) (err error) {
|
|||||||
return c.conn.Tx(data, nil)
|
return c.conn.Tx(data, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c spiConn) Rx(command byte, data []byte) (err error) {
|
||||||
|
if c.dc == nil {
|
||||||
|
return errors.New("3-wire SPI mode is not implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Tx([]byte{command}, true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := c.dc.Out(gpio.High); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// OpenSPI opens the named SPI port and connects to the device.
|
// OpenSPI opens the named SPI port and connects to the device.
|
||||||
func OpenSPI(name, resetPin, dcPin string) (Conn, error) {
|
func OpenSPI(name, resetPin, dcPin string) (Conn, error) {
|
||||||
log := logrus.WithFields(logrus.Fields{
|
log := logrus.WithFields(logrus.Fields{
|
||||||
|
|||||||
+250
-7
@@ -2,23 +2,266 @@ package display
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
|
"os"
|
||||||
|
|
||||||
"go.maze.io/harmon/internal/pixel"
|
|
||||||
"golang.org/x/image/font"
|
"golang.org/x/image/font"
|
||||||
"golang.org/x/image/font/basicfont"
|
"golang.org/x/image/font/basicfont"
|
||||||
|
"golang.org/x/image/font/inconsolata"
|
||||||
"golang.org/x/image/math/fixed"
|
"golang.org/x/image/math/fixed"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/internal/pixel"
|
||||||
|
|
||||||
|
_ "image/gif" // GIF codec
|
||||||
|
_ "image/jpeg" // JPEG codec
|
||||||
|
_ "image/png" // PNG codec
|
||||||
)
|
)
|
||||||
|
|
||||||
func DrawText(d draw.Image, x, y int, text string) {
|
var (
|
||||||
|
Font7x13 = basicfont.Face7x13
|
||||||
|
Font8x16 = inconsolata.Regular8x16
|
||||||
|
)
|
||||||
|
|
||||||
|
type Drawer interface {
|
||||||
|
Draw(r image.Rectangle, src image.Image, sp image.Point) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func DrawRectangle(d draw.Image, x, y, w, h int, c color.Color) {
|
||||||
|
for i, l := y, y+h; i < l; i++ {
|
||||||
|
DrawLine(d, x, i, x+w, i, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DrawLine(p draw.Image, x1, y1, x2, y2 int, c color.Color) {
|
||||||
|
var dx, dy, e, slope int
|
||||||
|
|
||||||
|
// Because drawing p1 -> p2 is equivalent to draw p2 -> p1,
|
||||||
|
// I sort points in x-axis order to handle only half of possible cases.
|
||||||
|
if x1 > x2 {
|
||||||
|
x1, y1, x2, y2 = x2, y2, x1, y1
|
||||||
|
}
|
||||||
|
|
||||||
|
dx, dy = x2-x1, y2-y1
|
||||||
|
// Because point is x-axis ordered, dx cannot be negative
|
||||||
|
if dy < 0 {
|
||||||
|
dy = -dy
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
|
||||||
|
// Is line a point ?
|
||||||
|
case x1 == x2 && y1 == y2:
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
|
||||||
|
// Is line an horizontal ?
|
||||||
|
case y1 == y2:
|
||||||
|
for ; dx != 0; dx-- {
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
x1++
|
||||||
|
}
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
|
||||||
|
// Is line a vertical ?
|
||||||
|
case x1 == x2:
|
||||||
|
if y1 > y2 {
|
||||||
|
y1, y2 = y2, y1
|
||||||
|
}
|
||||||
|
for ; dy != 0; dy-- {
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
y1++
|
||||||
|
}
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
|
||||||
|
// Is line a diagonal ?
|
||||||
|
case dx == dy:
|
||||||
|
if y1 < y2 {
|
||||||
|
for ; dx != 0; dx-- {
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
x1++
|
||||||
|
y1++
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for ; dx != 0; dx-- {
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
x1++
|
||||||
|
y1--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
|
||||||
|
// wider than high ?
|
||||||
|
case dx > dy:
|
||||||
|
if y1 < y2 {
|
||||||
|
// BresenhamDxXRYD(img, x1, y1, x2, y2, col)
|
||||||
|
dy, e, slope = 2*dy, dx, 2*dx
|
||||||
|
for ; dx != 0; dx-- {
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
x1++
|
||||||
|
e -= dy
|
||||||
|
if e < 0 {
|
||||||
|
y1++
|
||||||
|
e += slope
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// BresenhamDxXRYU(img, x1, y1, x2, y2, col)
|
||||||
|
dy, e, slope = 2*dy, dx, 2*dx
|
||||||
|
for ; dx != 0; dx-- {
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
x1++
|
||||||
|
e -= dy
|
||||||
|
if e < 0 {
|
||||||
|
y1--
|
||||||
|
e += slope
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.Set(x2, y2, c)
|
||||||
|
|
||||||
|
// higher than wide.
|
||||||
|
default:
|
||||||
|
if y1 < y2 {
|
||||||
|
// BresenhamDyXRYD(img, x1, y1, x2, y2, col)
|
||||||
|
dx, e, slope = 2*dx, dy, 2*dy
|
||||||
|
for ; dy != 0; dy-- {
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
y1++
|
||||||
|
e -= dx
|
||||||
|
if e < 0 {
|
||||||
|
x1++
|
||||||
|
e += slope
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// BresenhamDyXRYU(img, x1, y1, x2, y2, col)
|
||||||
|
dx, e, slope = 2*dx, dy, 2*dy
|
||||||
|
for ; dy != 0; dy-- {
|
||||||
|
p.Set(x1, y1, c)
|
||||||
|
y1--
|
||||||
|
e -= dx
|
||||||
|
if e < 0 {
|
||||||
|
x1++
|
||||||
|
e += slope
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p.Set(x2, y2, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DrawText(d draw.Image, x, y int, face font.Face, text string) {
|
||||||
var (
|
var (
|
||||||
point = fixed.Point26_6{fixed.Int26_6(x * 64), fixed.Int26_6(y * 64)}
|
fontHeight int
|
||||||
drawer = &font.Drawer{
|
fontWidth int
|
||||||
|
)
|
||||||
|
if f, ok := face.(*basicfont.Face); ok {
|
||||||
|
fontWidth = f.Advance
|
||||||
|
fontHeight = f.Height
|
||||||
|
} else {
|
||||||
|
metrics := face.Metrics()
|
||||||
|
if advance, ok := face.GlyphAdvance('X'); ok {
|
||||||
|
fontWidth = advance.Round()
|
||||||
|
}
|
||||||
|
fontHeight = metrics.Height.Ceil()
|
||||||
|
}
|
||||||
|
|
||||||
|
drawer := &font.Drawer{
|
||||||
Dst: d,
|
Dst: d,
|
||||||
Src: &image.Uniform{pixel.On},
|
Src: &image.Uniform{pixel.On},
|
||||||
Face: basicfont.Face7x13,
|
Face: face,
|
||||||
Dot: point,
|
|
||||||
}
|
}
|
||||||
)
|
drawer.Dot = fixed.P(x*fontWidth, y*fontHeight)
|
||||||
drawer.DrawString(text)
|
drawer.DrawString(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func drawCircle(d draw.Image, xc, yc, x, y int, c color.Color) {
|
||||||
|
d.Set(xc+x, yc+y, c)
|
||||||
|
d.Set(xc-x, yc+y, c)
|
||||||
|
d.Set(xc+x, yc-y, c)
|
||||||
|
d.Set(xc-x, yc-y, c)
|
||||||
|
d.Set(xc+y, yc+x, c)
|
||||||
|
d.Set(xc-y, yc+x, c)
|
||||||
|
d.Set(xc+y, yc-x, c)
|
||||||
|
d.Set(xc-y, yc-x, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DrawCircle(i draw.Image, xc, yc, r int, c color.Color) {
|
||||||
|
var (
|
||||||
|
x int
|
||||||
|
y = r
|
||||||
|
d = 3 - 2*r
|
||||||
|
)
|
||||||
|
drawCircle(i, xc, yc, x, y, c)
|
||||||
|
for y >= x {
|
||||||
|
if d > 0 {
|
||||||
|
y--
|
||||||
|
d = d + 4*(x-y) + 10
|
||||||
|
} else {
|
||||||
|
d = d + 4*x + 6
|
||||||
|
}
|
||||||
|
x++
|
||||||
|
drawCircle(i, xc, yc, x, y, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DrawImage(d draw.Image, x, y int, name string) error {
|
||||||
|
f, err := os.Open(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
i, _, err := image.Decode(f)
|
||||||
|
if err != nil {
|
||||||
|
_ = f.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r := d.Bounds()
|
||||||
|
if d, ok := d.(Drawer); ok {
|
||||||
|
r.Min = image.Pt(x, y)
|
||||||
|
return d.Draw(r, i, image.Point{})
|
||||||
|
}
|
||||||
|
|
||||||
|
draw.Draw(d, r, i, image.Point{}, draw.Src)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func Scroll(d draw.Image, xstep, ystep int) {
|
||||||
|
var (
|
||||||
|
sx, y, xend, yend, dx, dy int
|
||||||
|
r = d.Bounds()
|
||||||
|
)
|
||||||
|
if xstep < 0 {
|
||||||
|
xend = r.Max.X + xstep
|
||||||
|
if xend <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dx = 1
|
||||||
|
} else {
|
||||||
|
sx = r.Max.X - 1
|
||||||
|
xend = xstep - 1
|
||||||
|
if xend >= sx {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ystep < 0 {
|
||||||
|
yend = r.Max.Y + ystep
|
||||||
|
if yend <= 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dy = 1
|
||||||
|
} else {
|
||||||
|
y = r.Max.Y - 1
|
||||||
|
yend = ystep - 1
|
||||||
|
if yend >= y {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dy = -1
|
||||||
|
}
|
||||||
|
for ; y != yend; y += dy {
|
||||||
|
for x := sx; x != xend; x += dx {
|
||||||
|
d.Set(x, y, d.At(x, y))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,466 @@
|
|||||||
|
package display
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"go.maze.io/harmon/internal/pixel"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Font types
|
||||||
|
const (
|
||||||
|
FONT_6x8 = 0x00
|
||||||
|
FONT_7x10 = 0x01
|
||||||
|
FONT_11x18 = 0x02
|
||||||
|
FONT_16x26 = 0x03
|
||||||
|
)
|
||||||
|
|
||||||
|
// Configure initializes the display with default configuration
|
||||||
|
func Print(d hardware.Display, font int, x, y int, text string) {
|
||||||
|
fontWidth, _ := fontSize(font)
|
||||||
|
for _, char := range text {
|
||||||
|
PrintChar(d, font, x, y, byte(char))
|
||||||
|
x += fontWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func PrintChar(d hardware.Display, font int, x, y int, char byte) {
|
||||||
|
fontWidth, fontHeight := fontSize(font)
|
||||||
|
glyph := int(char-32) * fontHeight
|
||||||
|
for i := 0; i < fontHeight; i++ {
|
||||||
|
for j := 0; j < fontWidth; j++ {
|
||||||
|
var bit uint16 = 0
|
||||||
|
switch font {
|
||||||
|
case FONT_6x8:
|
||||||
|
bit = (Font6x8[i+glyph])
|
||||||
|
case FONT_7x10:
|
||||||
|
bit = (Font7x10[i+glyph])
|
||||||
|
case FONT_11x18:
|
||||||
|
bit = (Font11x18[i+glyph])
|
||||||
|
case FONT_16x26:
|
||||||
|
bit = (Font16x26[i+glyph])
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
bit = bit & (0x8000 >> j)
|
||||||
|
if bit != 0 {
|
||||||
|
d.Set(j+x, i+y, pixel.On)
|
||||||
|
} else {
|
||||||
|
d.Set(j+x, i+y, pixel.Off)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fontSize(font int) (fontWidth, fontHeight int) {
|
||||||
|
switch font {
|
||||||
|
case FONT_6x8:
|
||||||
|
fontWidth = 6
|
||||||
|
fontHeight = 8
|
||||||
|
|
||||||
|
case FONT_7x10:
|
||||||
|
fontWidth = 7
|
||||||
|
fontHeight = 10
|
||||||
|
|
||||||
|
case FONT_11x18:
|
||||||
|
fontWidth = 11
|
||||||
|
fontHeight = 18
|
||||||
|
|
||||||
|
case FONT_16x26:
|
||||||
|
fontWidth = 16
|
||||||
|
fontHeight = 26
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var Font6x8 = [...]uint16{
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // sp
|
||||||
|
0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, 0x2000, 0x0000, // !
|
||||||
|
0x5000, 0x5000, 0x5000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // "
|
||||||
|
0x5000, 0x5000, 0xf800, 0x5000, 0xf800, 0x5000, 0x5000, 0x0000, // #
|
||||||
|
0x2000, 0x7800, 0xa000, 0x7000, 0x2800, 0xf000, 0x2000, 0x0000, // $
|
||||||
|
0xc000, 0xc800, 0x1000, 0x2000, 0x4000, 0x9800, 0x1800, 0x0000, // %
|
||||||
|
0x4000, 0xa000, 0xa000, 0x4000, 0xa800, 0x9000, 0x6800, 0x0000, // &
|
||||||
|
0x3000, 0x3000, 0x2000, 0x4000, 0x0000, 0x0000, 0x0000, 0x0000, // '
|
||||||
|
0x1000, 0x2000, 0x4000, 0x4000, 0x4000, 0x2000, 0x1000, 0x0000, // (
|
||||||
|
0x4000, 0x2000, 0x1000, 0x1000, 0x1000, 0x2000, 0x4000, 0x0000, // )
|
||||||
|
0x2000, 0xa800, 0x7000, 0xf800, 0x7000, 0xa800, 0x2000, 0x0000, // *
|
||||||
|
0x0000, 0x2000, 0x2000, 0xf800, 0x2000, 0x2000, 0x0000, 0x0000, // +
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x3000, 0x3000, 0x2000, 0x0000, // ,
|
||||||
|
0x0000, 0x0000, 0x0000, 0xf800, 0x0000, 0x0000, 0x0000, 0x0000, // -
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3000, 0x3000, 0x0000, // .
|
||||||
|
0x0000, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000, 0x0000, 0x0000, // /
|
||||||
|
0x7000, 0x8800, 0x9800, 0xa800, 0xc800, 0x8800, 0x7000, 0x0000, // 0
|
||||||
|
0x2000, 0x6000, 0x2000, 0x2000, 0x2000, 0x2000, 0x7000, 0x0000, // 1
|
||||||
|
0x7000, 0x8800, 0x0800, 0x7000, 0x8000, 0x8000, 0xf800, 0x0000, // 2
|
||||||
|
0xf800, 0x0800, 0x1000, 0x3000, 0x0800, 0x8800, 0x7000, 0x0000, // 3
|
||||||
|
0x1000, 0x3000, 0x5000, 0x9000, 0xf800, 0x1000, 0x1000, 0x0000, // 4
|
||||||
|
0xf800, 0x8000, 0xf000, 0x0800, 0x0800, 0x8800, 0x7000, 0x0000, // 5
|
||||||
|
0x3800, 0x4000, 0x8000, 0xf000, 0x8800, 0x8800, 0x7000, 0x0000, // 6
|
||||||
|
0xf800, 0x0800, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000, 0x0000, // 7
|
||||||
|
0x7000, 0x8800, 0x8800, 0x7000, 0x8800, 0x8800, 0x7000, 0x0000, // 8
|
||||||
|
0x7000, 0x8800, 0x8800, 0x7800, 0x0800, 0x1000, 0xe000, 0x0000, // 9
|
||||||
|
0x0000, 0x0000, 0x2000, 0x0000, 0x2000, 0x0000, 0x0000, 0x0000, // :
|
||||||
|
0x0000, 0x0000, 0x2000, 0x0000, 0x2000, 0x2000, 0x4000, 0x0000, // ;
|
||||||
|
0x0800, 0x1000, 0x2000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0000, // <
|
||||||
|
0x0000, 0x0000, 0xf800, 0x0000, 0xf800, 0x0000, 0x0000, 0x0000, // =
|
||||||
|
0x4000, 0x2000, 0x1000, 0x0800, 0x1000, 0x2000, 0x4000, 0x0000, // >
|
||||||
|
0x7000, 0x8800, 0x0800, 0x3000, 0x2000, 0x0000, 0x2000, 0x0000, // ?
|
||||||
|
0x7000, 0x8800, 0xa800, 0xb800, 0xb000, 0x8000, 0x7800, 0x0000, // @
|
||||||
|
0x2000, 0x5000, 0x8800, 0x8800, 0xf800, 0x8800, 0x8800, 0x0000, // A
|
||||||
|
0xf000, 0x8800, 0x8800, 0xf000, 0x8800, 0x8800, 0xf000, 0x0000, // B
|
||||||
|
0x7000, 0x8800, 0x8000, 0x8000, 0x8000, 0x8800, 0x7000, 0x0000, // C
|
||||||
|
0xf000, 0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0xf000, 0x0000, // D
|
||||||
|
0xf800, 0x8000, 0x8000, 0xf000, 0x8000, 0x8000, 0xf800, 0x0000, // E
|
||||||
|
0xf800, 0x8000, 0x8000, 0xf000, 0x8000, 0x8000, 0x8000, 0x0000, // F
|
||||||
|
0x7800, 0x8800, 0x8000, 0x8000, 0x9800, 0x8800, 0x7800, 0x0000, // G
|
||||||
|
0x8800, 0x8800, 0x8800, 0xf800, 0x8800, 0x8800, 0x8800, 0x0000, // H
|
||||||
|
0x7000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x7000, 0x0000, // I
|
||||||
|
0x3800, 0x1000, 0x1000, 0x1000, 0x1000, 0x9000, 0x6000, 0x0000, // J
|
||||||
|
0x8800, 0x9000, 0xa000, 0xc000, 0xa000, 0x9000, 0x8800, 0x0000, // K
|
||||||
|
0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0xf800, 0x0000, // L
|
||||||
|
0x8800, 0xd800, 0xa800, 0xa800, 0xa800, 0x8800, 0x8800, 0x0000, // M
|
||||||
|
0x8800, 0x8800, 0xc800, 0xa800, 0x9800, 0x8800, 0x8800, 0x0000, // N
|
||||||
|
0x7000, 0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0x7000, 0x0000, // O
|
||||||
|
0xf000, 0x8800, 0x8800, 0xf000, 0x8000, 0x8000, 0x8000, 0x0000, // P
|
||||||
|
0x7000, 0x8800, 0x8800, 0x8800, 0xa800, 0x9000, 0x6800, 0x0000, // Q
|
||||||
|
0xf000, 0x8800, 0x8800, 0xf000, 0xa000, 0x9000, 0x8800, 0x0000, // R
|
||||||
|
0x7000, 0x8800, 0x8000, 0x7000, 0x0800, 0x8800, 0x7000, 0x0000, // S
|
||||||
|
0xf800, 0xa800, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, // T
|
||||||
|
0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0x7000, 0x0000, // U
|
||||||
|
0x8800, 0x8800, 0x8800, 0x8800, 0x8800, 0x5000, 0x2000, 0x0000, // V
|
||||||
|
0x8800, 0x8800, 0x8800, 0xa800, 0xa800, 0xa800, 0x5000, 0x0000, // W
|
||||||
|
0x8800, 0x8800, 0x5000, 0x2000, 0x5000, 0x8800, 0x8800, 0x0000, // X
|
||||||
|
0x8800, 0x8800, 0x5000, 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, // Y
|
||||||
|
0xf800, 0x0800, 0x1000, 0x7000, 0x4000, 0x8000, 0xf800, 0x0000, // Z
|
||||||
|
0x7800, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x7800, 0x0000, // [
|
||||||
|
0x0000, 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0000, 0x0000, /* \ */
|
||||||
|
0x7800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x7800, 0x0000, // ]
|
||||||
|
0x2000, 0x5000, 0x8800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ^
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xf800, 0x0000, // _
|
||||||
|
0x6000, 0x6000, 0x2000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, // `
|
||||||
|
0x0000, 0x0000, 0x6000, 0x1000, 0x7000, 0x9000, 0x7800, 0x0000, // a
|
||||||
|
0x8000, 0x8000, 0xb000, 0xc800, 0x8800, 0xc800, 0xb000, 0x0000, // b
|
||||||
|
0x0000, 0x0000, 0x7000, 0x8800, 0x8000, 0x8800, 0x7000, 0x0000, // c
|
||||||
|
0x0800, 0x0800, 0x6800, 0x9800, 0x8800, 0x9800, 0x6800, 0x0000, // d
|
||||||
|
0x0000, 0x0000, 0x7000, 0x8800, 0xf800, 0x8000, 0x7000, 0x0000, // e
|
||||||
|
0x1000, 0x2800, 0x2000, 0x7000, 0x2000, 0x2000, 0x2000, 0x0000, // f
|
||||||
|
0x0000, 0x0000, 0x7000, 0x9800, 0x9800, 0x6800, 0x0800, 0x0000, // g
|
||||||
|
0x8000, 0x8000, 0xb000, 0xc800, 0x8800, 0x8800, 0x8800, 0x0000, // h
|
||||||
|
0x2000, 0x0000, 0x6000, 0x2000, 0x2000, 0x2000, 0x7000, 0x0000, // i
|
||||||
|
0x1000, 0x0000, 0x1000, 0x1000, 0x1000, 0x9000, 0x6000, 0x0000, // j
|
||||||
|
0x8000, 0x8000, 0x9000, 0xa000, 0xc000, 0xa000, 0x9000, 0x0000, // k
|
||||||
|
0x6000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x7000, 0x0000, // l
|
||||||
|
0x0000, 0x0000, 0xd000, 0xa800, 0xa800, 0xa800, 0xa800, 0x0000, // m
|
||||||
|
0x0000, 0x0000, 0xb000, 0xc800, 0x8800, 0x8800, 0x8800, 0x0000, // n
|
||||||
|
0x0000, 0x0000, 0x7000, 0x8800, 0x8800, 0x8800, 0x7000, 0x0000, // o
|
||||||
|
0x0000, 0x0000, 0xb000, 0xc800, 0xc800, 0xb000, 0x8000, 0x0000, // p
|
||||||
|
0x0000, 0x0000, 0x6800, 0x9800, 0x9800, 0x6800, 0x0800, 0x0000, // q
|
||||||
|
0x0000, 0x0000, 0xb000, 0xc800, 0x8000, 0x8000, 0x8000, 0x0000, // r
|
||||||
|
0x0000, 0x0000, 0x7800, 0x8000, 0x7000, 0x0800, 0xf000, 0x0000, // s
|
||||||
|
0x2000, 0x2000, 0xf800, 0x2000, 0x2000, 0x2800, 0x1000, 0x0000, // t
|
||||||
|
0x0000, 0x0000, 0x8800, 0x8800, 0x8800, 0x9800, 0x6800, 0x0000, // u
|
||||||
|
0x0000, 0x0000, 0x8800, 0x8800, 0x8800, 0x5000, 0x2000, 0x0000, // v
|
||||||
|
0x0000, 0x0000, 0x8800, 0x8800, 0xa800, 0xa800, 0x5000, 0x0000, // w
|
||||||
|
0x0000, 0x0000, 0x8800, 0x5000, 0x2000, 0x5000, 0x8800, 0x0000, // x
|
||||||
|
0x0000, 0x0000, 0x8800, 0x8800, 0x7800, 0x0800, 0x8800, 0x0000, // y
|
||||||
|
0x0000, 0x0000, 0xf800, 0x1000, 0x2000, 0x4000, 0xf800, 0x0000, // z
|
||||||
|
0x1000, 0x2000, 0x2000, 0x4000, 0x2000, 0x2000, 0x1000, 0x0000, // {
|
||||||
|
0x2000, 0x2000, 0x2000, 0x0000, 0x2000, 0x2000, 0x2000, 0x0000, // |
|
||||||
|
0x4000, 0x2000, 0x2000, 0x1000, 0x2000, 0x2000, 0x4000, 0x0000, // }
|
||||||
|
0x4000, 0xa800, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ~
|
||||||
|
}
|
||||||
|
|
||||||
|
// start from 32[space] up to 126[~] = offset -32
|
||||||
|
var Font7x10 = [...]uint16{
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // space
|
||||||
|
0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000, // !
|
||||||
|
0x2800, 0x2800, 0x2800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // "
|
||||||
|
0x2400, 0x2400, 0x7C00, 0x2400, 0x4800, 0x7C00, 0x4800, 0x4800, 0x0000, 0x0000, // #
|
||||||
|
0x3800, 0x5400, 0x5000, 0x3800, 0x1400, 0x5400, 0x5400, 0x3800, 0x1000, 0x0000, // $
|
||||||
|
0x2000, 0x5400, 0x5800, 0x3000, 0x2800, 0x5400, 0x1400, 0x0800, 0x0000, 0x0000, // %
|
||||||
|
0x1000, 0x2800, 0x2800, 0x1000, 0x3400, 0x4800, 0x4800, 0x3400, 0x0000, 0x0000, // &
|
||||||
|
0x1000, 0x1000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // '
|
||||||
|
0x0800, 0x1000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x1000, 0x0800, // (
|
||||||
|
0x2000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x1000, 0x2000, // )
|
||||||
|
0x1000, 0x3800, 0x1000, 0x2800, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // *
|
||||||
|
0x0000, 0x0000, 0x1000, 0x1000, 0x7C00, 0x1000, 0x1000, 0x0000, 0x0000, 0x0000, // +
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x1000, 0x1000, // ,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3800, 0x0000, 0x0000, 0x0000, 0x0000, // -
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, // .
|
||||||
|
0x0800, 0x0800, 0x1000, 0x1000, 0x1000, 0x1000, 0x2000, 0x2000, 0x0000, 0x0000, // /
|
||||||
|
0x3800, 0x4400, 0x4400, 0x5400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 0
|
||||||
|
0x1000, 0x3000, 0x5000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // 1
|
||||||
|
0x3800, 0x4400, 0x4400, 0x0400, 0x0800, 0x1000, 0x2000, 0x7C00, 0x0000, 0x0000, // 2
|
||||||
|
0x3800, 0x4400, 0x0400, 0x1800, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 3
|
||||||
|
0x0800, 0x1800, 0x2800, 0x2800, 0x4800, 0x7C00, 0x0800, 0x0800, 0x0000, 0x0000, // 4
|
||||||
|
0x7C00, 0x4000, 0x4000, 0x7800, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 5
|
||||||
|
0x3800, 0x4400, 0x4000, 0x7800, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 6
|
||||||
|
0x7C00, 0x0400, 0x0800, 0x1000, 0x1000, 0x2000, 0x2000, 0x2000, 0x0000, 0x0000, // 7
|
||||||
|
0x3800, 0x4400, 0x4400, 0x3800, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // 8
|
||||||
|
0x3800, 0x4400, 0x4400, 0x4400, 0x3C00, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // 9
|
||||||
|
0x0000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, // :
|
||||||
|
0x0000, 0x0000, 0x0000, 0x1000, 0x0000, 0x0000, 0x0000, 0x1000, 0x1000, 0x1000, // ;
|
||||||
|
0x0000, 0x0000, 0x0C00, 0x3000, 0x4000, 0x3000, 0x0C00, 0x0000, 0x0000, 0x0000, // <
|
||||||
|
0x0000, 0x0000, 0x0000, 0x7C00, 0x0000, 0x7C00, 0x0000, 0x0000, 0x0000, 0x0000, // =
|
||||||
|
0x0000, 0x0000, 0x6000, 0x1800, 0x0400, 0x1800, 0x6000, 0x0000, 0x0000, 0x0000, // >
|
||||||
|
0x3800, 0x4400, 0x0400, 0x0800, 0x1000, 0x1000, 0x0000, 0x1000, 0x0000, 0x0000, // ?
|
||||||
|
0x3800, 0x4400, 0x4C00, 0x5400, 0x5C00, 0x4000, 0x4000, 0x3800, 0x0000, 0x0000, // @
|
||||||
|
0x1000, 0x2800, 0x2800, 0x2800, 0x2800, 0x7C00, 0x4400, 0x4400, 0x0000, 0x0000, // A
|
||||||
|
0x7800, 0x4400, 0x4400, 0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x0000, 0x0000, // B
|
||||||
|
0x3800, 0x4400, 0x4000, 0x4000, 0x4000, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // C
|
||||||
|
0x7000, 0x4800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4800, 0x7000, 0x0000, 0x0000, // D
|
||||||
|
0x7C00, 0x4000, 0x4000, 0x7C00, 0x4000, 0x4000, 0x4000, 0x7C00, 0x0000, 0x0000, // E
|
||||||
|
0x7C00, 0x4000, 0x4000, 0x7800, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // F
|
||||||
|
0x3800, 0x4400, 0x4000, 0x4000, 0x5C00, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // G
|
||||||
|
0x4400, 0x4400, 0x4400, 0x7C00, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // H
|
||||||
|
0x3800, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x3800, 0x0000, 0x0000, // I
|
||||||
|
0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // J
|
||||||
|
0x4400, 0x4800, 0x5000, 0x6000, 0x5000, 0x4800, 0x4800, 0x4400, 0x0000, 0x0000, // K
|
||||||
|
0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x7C00, 0x0000, 0x0000, // L
|
||||||
|
0x4400, 0x6C00, 0x6C00, 0x5400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // M
|
||||||
|
0x4400, 0x6400, 0x6400, 0x5400, 0x5400, 0x4C00, 0x4C00, 0x4400, 0x0000, 0x0000, // N
|
||||||
|
0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // O
|
||||||
|
0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // P
|
||||||
|
0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x5400, 0x3800, 0x0400, 0x0000, // Q
|
||||||
|
0x7800, 0x4400, 0x4400, 0x4400, 0x7800, 0x4800, 0x4800, 0x4400, 0x0000, 0x0000, // R
|
||||||
|
0x3800, 0x4400, 0x4000, 0x3000, 0x0800, 0x0400, 0x4400, 0x3800, 0x0000, 0x0000, // S
|
||||||
|
0x7C00, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // T
|
||||||
|
0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // U
|
||||||
|
0x4400, 0x4400, 0x4400, 0x2800, 0x2800, 0x2800, 0x1000, 0x1000, 0x0000, 0x0000, // V
|
||||||
|
0x4400, 0x4400, 0x5400, 0x5400, 0x5400, 0x6C00, 0x2800, 0x2800, 0x0000, 0x0000, // W
|
||||||
|
0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x2800, 0x2800, 0x4400, 0x0000, 0x0000, // X
|
||||||
|
0x4400, 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // Y
|
||||||
|
0x7C00, 0x0400, 0x0800, 0x1000, 0x1000, 0x2000, 0x4000, 0x7C00, 0x0000, 0x0000, // Z
|
||||||
|
0x1800, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1800, // [
|
||||||
|
0x2000, 0x2000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0000, 0x0000, /* \ */
|
||||||
|
0x3000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x3000, // ]
|
||||||
|
0x1000, 0x2800, 0x2800, 0x4400, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ^
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFE00, // _
|
||||||
|
0x2000, 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // `
|
||||||
|
0x0000, 0x0000, 0x3800, 0x4400, 0x3C00, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // a
|
||||||
|
0x4000, 0x4000, 0x5800, 0x6400, 0x4400, 0x4400, 0x6400, 0x5800, 0x0000, 0x0000, // b
|
||||||
|
0x0000, 0x0000, 0x3800, 0x4400, 0x4000, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // c
|
||||||
|
0x0400, 0x0400, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // d
|
||||||
|
0x0000, 0x0000, 0x3800, 0x4400, 0x7C00, 0x4000, 0x4400, 0x3800, 0x0000, 0x0000, // e
|
||||||
|
0x0C00, 0x1000, 0x7C00, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // f
|
||||||
|
0x0000, 0x0000, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0400, 0x7800, // g
|
||||||
|
0x4000, 0x4000, 0x5800, 0x6400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // h
|
||||||
|
0x1000, 0x0000, 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // i
|
||||||
|
0x1000, 0x0000, 0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0xE000, // j
|
||||||
|
0x4000, 0x4000, 0x4800, 0x5000, 0x6000, 0x5000, 0x4800, 0x4400, 0x0000, 0x0000, // k
|
||||||
|
0x7000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, // l
|
||||||
|
0x0000, 0x0000, 0x7800, 0x5400, 0x5400, 0x5400, 0x5400, 0x5400, 0x0000, 0x0000, // m
|
||||||
|
0x0000, 0x0000, 0x5800, 0x6400, 0x4400, 0x4400, 0x4400, 0x4400, 0x0000, 0x0000, // n
|
||||||
|
0x0000, 0x0000, 0x3800, 0x4400, 0x4400, 0x4400, 0x4400, 0x3800, 0x0000, 0x0000, // o
|
||||||
|
0x0000, 0x0000, 0x5800, 0x6400, 0x4400, 0x4400, 0x6400, 0x5800, 0x4000, 0x4000, // p
|
||||||
|
0x0000, 0x0000, 0x3400, 0x4C00, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0400, 0x0400, // q
|
||||||
|
0x0000, 0x0000, 0x5800, 0x6400, 0x4000, 0x4000, 0x4000, 0x4000, 0x0000, 0x0000, // r
|
||||||
|
0x0000, 0x0000, 0x3800, 0x4400, 0x3000, 0x0800, 0x4400, 0x3800, 0x0000, 0x0000, // s
|
||||||
|
0x2000, 0x2000, 0x7800, 0x2000, 0x2000, 0x2000, 0x2000, 0x1800, 0x0000, 0x0000, // t
|
||||||
|
0x0000, 0x0000, 0x4400, 0x4400, 0x4400, 0x4400, 0x4C00, 0x3400, 0x0000, 0x0000, // u
|
||||||
|
0x0000, 0x0000, 0x4400, 0x4400, 0x2800, 0x2800, 0x2800, 0x1000, 0x0000, 0x0000, // v
|
||||||
|
0x0000, 0x0000, 0x5400, 0x5400, 0x5400, 0x6C00, 0x2800, 0x2800, 0x0000, 0x0000, // w
|
||||||
|
0x0000, 0x0000, 0x4400, 0x2800, 0x1000, 0x1000, 0x2800, 0x4400, 0x0000, 0x0000, // x
|
||||||
|
0x0000, 0x0000, 0x4400, 0x4400, 0x2800, 0x2800, 0x1000, 0x1000, 0x1000, 0x6000, // y
|
||||||
|
0x0000, 0x0000, 0x7C00, 0x0800, 0x1000, 0x2000, 0x4000, 0x7C00, 0x0000, 0x0000, // z
|
||||||
|
0x1800, 0x1000, 0x1000, 0x1000, 0x2000, 0x2000, 0x1000, 0x1000, 0x1000, 0x1800, // {
|
||||||
|
0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, 0x1000, // |
|
||||||
|
0x3000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x1000, 0x1000, 0x1000, 0x3000, // }
|
||||||
|
0x0000, 0x0000, 0x0000, 0x7400, 0x4C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ~
|
||||||
|
}
|
||||||
|
|
||||||
|
var Font11x18 = [...]uint16{
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // sp
|
||||||
|
0x0000, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // !
|
||||||
|
0x0000, 0x1B00, 0x1B00, 0x1B00, 0x1B00, 0x1B00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // "
|
||||||
|
0x0000, 0x1980, 0x1980, 0x1980, 0x1980, 0x7FC0, 0x7FC0, 0x1980, 0x3300, 0x7FC0, 0x7FC0, 0x3300, 0x3300, 0x3300, 0x3300, 0x0000, 0x0000, 0x0000, // #
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x7580, 0x6580, 0x7400, 0x3C00, 0x1E00, 0x0700, 0x0580, 0x6580, 0x6580, 0x7580, 0x3F00, 0x1E00, 0x0400, 0x0400, 0x0000, // $
|
||||||
|
0x0000, 0x7000, 0xD800, 0xD840, 0xD8C0, 0xD980, 0x7300, 0x0600, 0x0C00, 0x1B80, 0x36C0, 0x66C0, 0x46C0, 0x06C0, 0x0380, 0x0000, 0x0000, 0x0000, // %
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x3300, 0x3300, 0x3300, 0x1E00, 0x0C00, 0x3CC0, 0x66C0, 0x6380, 0x6180, 0x6380, 0x3EC0, 0x1C80, 0x0000, 0x0000, 0x0000, // &
|
||||||
|
0x0000, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // '
|
||||||
|
0x0080, 0x0100, 0x0300, 0x0600, 0x0600, 0x0400, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0400, 0x0600, 0x0600, 0x0300, 0x0100, 0x0080, // (
|
||||||
|
0x2000, 0x1000, 0x1800, 0x0C00, 0x0C00, 0x0400, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0400, 0x0C00, 0x0C00, 0x1800, 0x1000, 0x2000, // )
|
||||||
|
0x0000, 0x0C00, 0x2D00, 0x3F00, 0x1E00, 0x3300, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // *
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0xFFC0, 0xFFC0, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // +
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0400, 0x0400, 0x0800, // ,
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x1E00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // -
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // .
|
||||||
|
0x0000, 0x0300, 0x0300, 0x0300, 0x0600, 0x0600, 0x0600, 0x0600, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x1800, 0x1800, 0x1800, 0x0000, 0x0000, 0x0000, // /
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x3300, 0x6180, 0x6180, 0x6180, 0x6D80, 0x6D80, 0x6180, 0x6180, 0x6180, 0x3300, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 0
|
||||||
|
0x0000, 0x0600, 0x0E00, 0x1E00, 0x3600, 0x2600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, // 1
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x7380, 0x6180, 0x6180, 0x0180, 0x0300, 0x0600, 0x0C00, 0x1800, 0x3000, 0x6000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, // 2
|
||||||
|
0x0000, 0x1C00, 0x3E00, 0x6300, 0x6300, 0x0300, 0x0E00, 0x0E00, 0x0300, 0x0180, 0x0180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 3
|
||||||
|
0x0000, 0x0600, 0x0E00, 0x0E00, 0x1E00, 0x1E00, 0x1600, 0x3600, 0x3600, 0x6600, 0x7F80, 0x7F80, 0x0600, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, // 4
|
||||||
|
0x0000, 0x7F00, 0x7F00, 0x6000, 0x6000, 0x6000, 0x6E00, 0x7F00, 0x6380, 0x0180, 0x0180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 5
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x3380, 0x6180, 0x6000, 0x6E00, 0x7F00, 0x7380, 0x6180, 0x6180, 0x6180, 0x3380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 6
|
||||||
|
0x0000, 0x7F80, 0x7F80, 0x0180, 0x0300, 0x0300, 0x0600, 0x0600, 0x0C00, 0x0C00, 0x0C00, 0x0800, 0x1800, 0x1800, 0x1800, 0x0000, 0x0000, 0x0000, // 7
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x6380, 0x6180, 0x6180, 0x2100, 0x1E00, 0x3F00, 0x6180, 0x6180, 0x6180, 0x6180, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 8
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x7300, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F80, 0x1D80, 0x0180, 0x6180, 0x7300, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // 9
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // :
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C00, 0x0C00, 0x0400, 0x0400, 0x0800, // ;
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0380, 0x0E00, 0x3800, 0x6000, 0x3800, 0x0E00, 0x0380, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // <
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // =
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x4000, 0x7000, 0x1C00, 0x0700, 0x0180, 0x0700, 0x1C00, 0x7000, 0x4000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // >
|
||||||
|
0x0000, 0x1F00, 0x3F80, 0x71C0, 0x60C0, 0x00C0, 0x01C0, 0x0380, 0x0700, 0x0E00, 0x0C00, 0x0C00, 0x0000, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // ?
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x3180, 0x7180, 0x6380, 0x6F80, 0x6D80, 0x6D80, 0x6F80, 0x6780, 0x6000, 0x3200, 0x3E00, 0x1C00, 0x0000, 0x0000, 0x0000, // @
|
||||||
|
0x0000, 0x0E00, 0x0E00, 0x1B00, 0x1B00, 0x1B00, 0x1B00, 0x3180, 0x3180, 0x3F80, 0x3F80, 0x3180, 0x60C0, 0x60C0, 0x60C0, 0x0000, 0x0000, 0x0000, // A
|
||||||
|
0x0000, 0x7C00, 0x7E00, 0x6300, 0x6300, 0x6300, 0x6300, 0x7E00, 0x7E00, 0x6300, 0x6180, 0x6180, 0x6380, 0x7F00, 0x7E00, 0x0000, 0x0000, 0x0000, // B
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x3180, 0x6180, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6180, 0x3180, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // C
|
||||||
|
0x0000, 0x7C00, 0x7F00, 0x6300, 0x6380, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6300, 0x6300, 0x7E00, 0x7C00, 0x0000, 0x0000, 0x0000, // D
|
||||||
|
0x0000, 0x7F80, 0x7F80, 0x6000, 0x6000, 0x6000, 0x6000, 0x7F00, 0x7F00, 0x6000, 0x6000, 0x6000, 0x6000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, // E
|
||||||
|
0x0000, 0x7F80, 0x7F80, 0x6000, 0x6000, 0x6000, 0x6000, 0x7F00, 0x7F00, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x0000, 0x0000, 0x0000, // F
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x3180, 0x6180, 0x6000, 0x6000, 0x6000, 0x6380, 0x6380, 0x6180, 0x6180, 0x3180, 0x3F80, 0x1E00, 0x0000, 0x0000, 0x0000, // G
|
||||||
|
0x0000, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x7F80, 0x7F80, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, // H
|
||||||
|
0x0000, 0x3F00, 0x3F00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x3F00, 0x3F00, 0x0000, 0x0000, 0x0000, // I
|
||||||
|
0x0000, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x0180, 0x6180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // J
|
||||||
|
0x0000, 0x60C0, 0x6180, 0x6300, 0x6600, 0x6600, 0x6C00, 0x7800, 0x7C00, 0x6600, 0x6600, 0x6300, 0x6180, 0x6180, 0x60C0, 0x0000, 0x0000, 0x0000, // K
|
||||||
|
0x0000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, // L
|
||||||
|
0x0000, 0x71C0, 0x71C0, 0x7BC0, 0x7AC0, 0x6AC0, 0x6AC0, 0x6EC0, 0x64C0, 0x60C0, 0x60C0, 0x60C0, 0x60C0, 0x60C0, 0x60C0, 0x0000, 0x0000, 0x0000, // M
|
||||||
|
0x0000, 0x7180, 0x7180, 0x7980, 0x7980, 0x7980, 0x6D80, 0x6D80, 0x6D80, 0x6580, 0x6780, 0x6780, 0x6780, 0x6380, 0x6380, 0x0000, 0x0000, 0x0000, // N
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x3300, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x3300, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // O
|
||||||
|
0x0000, 0x7E00, 0x7F00, 0x6380, 0x6180, 0x6180, 0x6180, 0x6380, 0x7F00, 0x7E00, 0x6000, 0x6000, 0x6000, 0x6000, 0x6000, 0x0000, 0x0000, 0x0000, // P
|
||||||
|
0x0000, 0x1E00, 0x3F00, 0x3300, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6580, 0x6780, 0x3300, 0x3F80, 0x1E40, 0x0000, 0x0000, 0x0000, // Q
|
||||||
|
0x0000, 0x7E00, 0x7F00, 0x6380, 0x6180, 0x6180, 0x6380, 0x7F00, 0x7E00, 0x6600, 0x6300, 0x6300, 0x6180, 0x6180, 0x60C0, 0x0000, 0x0000, 0x0000, // R
|
||||||
|
0x0000, 0x0E00, 0x1F00, 0x3180, 0x3180, 0x3000, 0x3800, 0x1E00, 0x0700, 0x0380, 0x6180, 0x6180, 0x3180, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // S
|
||||||
|
0x0000, 0xFFC0, 0xFFC0, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // T
|
||||||
|
0x0000, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // U
|
||||||
|
0x0000, 0x60C0, 0x60C0, 0x60C0, 0x3180, 0x3180, 0x3180, 0x1B00, 0x1B00, 0x1B00, 0x1B00, 0x0E00, 0x0E00, 0x0E00, 0x0400, 0x0000, 0x0000, 0x0000, // V
|
||||||
|
0x0000, 0xC0C0, 0xC0C0, 0xC0C0, 0xC0C0, 0xC0C0, 0xCCC0, 0x4C80, 0x4C80, 0x5E80, 0x5280, 0x5280, 0x7380, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, // W
|
||||||
|
0x0000, 0xC0C0, 0x6080, 0x6180, 0x3300, 0x3B00, 0x1E00, 0x0C00, 0x0C00, 0x1E00, 0x1F00, 0x3B00, 0x7180, 0x6180, 0xC0C0, 0x0000, 0x0000, 0x0000, // X
|
||||||
|
0x0000, 0xC0C0, 0x6180, 0x6180, 0x3300, 0x3300, 0x1E00, 0x1E00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // Y
|
||||||
|
0x0000, 0x3F80, 0x3F80, 0x0180, 0x0300, 0x0300, 0x0600, 0x0C00, 0x0C00, 0x1800, 0x1800, 0x3000, 0x6000, 0x7F80, 0x7F80, 0x0000, 0x0000, 0x0000, // Z
|
||||||
|
0x0F00, 0x0F00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0F00, 0x0F00, // [
|
||||||
|
0x0000, 0x1800, 0x1800, 0x1800, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0300, 0x0300, 0x0300, 0x0000, 0x0000, 0x0000, /* \ */
|
||||||
|
0x1E00, 0x1E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x1E00, 0x1E00, // ]
|
||||||
|
0x0000, 0x0C00, 0x0C00, 0x1E00, 0x1200, 0x3300, 0x3300, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ^
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFE0, 0x0000, // _
|
||||||
|
0x0000, 0x3800, 0x1800, 0x0C00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // `
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1F00, 0x3F80, 0x6180, 0x0180, 0x1F80, 0x3F80, 0x6180, 0x6380, 0x7F80, 0x38C0, 0x0000, 0x0000, 0x0000, // a
|
||||||
|
0x0000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6E00, 0x7F00, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x7F00, 0x6E00, 0x0000, 0x0000, 0x0000, // b
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x3F00, 0x7380, 0x6180, 0x6000, 0x6000, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // c
|
||||||
|
0x0000, 0x0180, 0x0180, 0x0180, 0x0180, 0x1D80, 0x3F80, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F80, 0x1D80, 0x0000, 0x0000, 0x0000, // d
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x3F00, 0x7300, 0x6180, 0x7F80, 0x7F80, 0x6000, 0x7180, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // e
|
||||||
|
0x0000, 0x07C0, 0x0FC0, 0x0C00, 0x0C00, 0x7F80, 0x7F80, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0000, 0x0000, 0x0000, // f
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x1D80, 0x3F80, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F80, 0x1D80, 0x0180, 0x6380, 0x7F00, 0x3E00, // g
|
||||||
|
0x0000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6F00, 0x7F80, 0x7180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, // h
|
||||||
|
0x0000, 0x0600, 0x0600, 0x0000, 0x0000, 0x3E00, 0x3E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, // i
|
||||||
|
0x0600, 0x0600, 0x0000, 0x0000, 0x3E00, 0x3E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x4600, 0x7E00, 0x3C00, // j
|
||||||
|
0x0000, 0x6000, 0x6000, 0x6000, 0x6000, 0x6180, 0x6300, 0x6600, 0x6C00, 0x7C00, 0x7600, 0x6300, 0x6300, 0x6180, 0x60C0, 0x0000, 0x0000, 0x0000, // k
|
||||||
|
0x0000, 0x3E00, 0x3E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0000, 0x0000, 0x0000, // l
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xDD80, 0xFFC0, 0xCEC0, 0xCCC0, 0xCCC0, 0xCCC0, 0xCCC0, 0xCCC0, 0xCCC0, 0xCCC0, 0x0000, 0x0000, 0x0000, // m
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6F00, 0x7F80, 0x7180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x0000, 0x0000, 0x0000, // n
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x3F00, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F00, 0x1E00, 0x0000, 0x0000, 0x0000, // o
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x6E00, 0x7F00, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x7F00, 0x6E00, 0x6000, 0x6000, 0x6000, 0x6000, // p
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x1D80, 0x3F80, 0x7380, 0x6180, 0x6180, 0x6180, 0x6180, 0x7380, 0x3F80, 0x1D80, 0x0180, 0x0180, 0x0180, 0x0180, // q
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6700, 0x3F80, 0x3900, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x3000, 0x0000, 0x0000, 0x0000, // r
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1E00, 0x3F80, 0x6180, 0x6000, 0x7F00, 0x3F80, 0x0180, 0x6180, 0x7F00, 0x1E00, 0x0000, 0x0000, 0x0000, // s
|
||||||
|
0x0000, 0x0000, 0x0800, 0x1800, 0x1800, 0x7F00, 0x7F00, 0x1800, 0x1800, 0x1800, 0x1800, 0x1800, 0x1800, 0x1F80, 0x0F80, 0x0000, 0x0000, 0x0000, // t
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6180, 0x6380, 0x7F80, 0x3D80, 0x0000, 0x0000, 0x0000, // u
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x60C0, 0x3180, 0x3180, 0x3180, 0x1B00, 0x1B00, 0x1B00, 0x0E00, 0x0E00, 0x0600, 0x0000, 0x0000, 0x0000, // v
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xDD80, 0xDD80, 0xDD80, 0x5500, 0x5500, 0x5500, 0x7700, 0x7700, 0x2200, 0x2200, 0x0000, 0x0000, 0x0000, // w
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6180, 0x3300, 0x3300, 0x1E00, 0x0C00, 0x0C00, 0x1E00, 0x3300, 0x3300, 0x6180, 0x0000, 0x0000, 0x0000, // x
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x6180, 0x6180, 0x3180, 0x3300, 0x3300, 0x1B00, 0x1B00, 0x1B00, 0x0E00, 0x0E00, 0x0E00, 0x1C00, 0x7C00, 0x7000, // y
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FC0, 0x7FC0, 0x0180, 0x0300, 0x0600, 0x0C00, 0x1800, 0x3000, 0x7FC0, 0x7FC0, 0x0000, 0x0000, 0x0000, // z
|
||||||
|
0x0380, 0x0780, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0E00, 0x1C00, 0x1C00, 0x0E00, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0780, 0x0380, // {
|
||||||
|
0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, 0x0600, // |
|
||||||
|
0x3800, 0x3C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0E00, 0x0700, 0x0700, 0x0E00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x0C00, 0x3C00, 0x3800, // }
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3880, 0x7F80, 0x4700, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // ~
|
||||||
|
}
|
||||||
|
|
||||||
|
var Font16x26 = [...]uint16{
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [ ]
|
||||||
|
0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03C0, 0x03C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [!]
|
||||||
|
0x1E3C, 0x1E3C, 0x1E3C, 0x1E3C, 0x1E3C, 0x1E3C, 0x1E3C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = ["]
|
||||||
|
0x01CE, 0x03CE, 0x03DE, 0x039E, 0x039C, 0x079C, 0x3FFF, 0x7FFF, 0x0738, 0x0F38, 0x0F78, 0x0F78, 0x0E78, 0xFFFF, 0xFFFF, 0x1EF0, 0x1CF0, 0x1CE0, 0x3CE0, 0x3DE0, 0x39E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [#]
|
||||||
|
0x03FC, 0x0FFE, 0x1FEE, 0x1EE0, 0x1EE0, 0x1EE0, 0x1EE0, 0x1FE0, 0x0FE0, 0x07E0, 0x03F0, 0x01FC, 0x01FE, 0x01FE, 0x01FE, 0x01FE, 0x01FE, 0x01FE, 0x3DFE, 0x3FFC, 0x0FF0, 0x01E0, 0x01E0, 0x0000, 0x0000, 0x0000, // Ascii = [$]
|
||||||
|
0x3E03, 0xF707, 0xE78F, 0xE78E, 0xE39E, 0xE3BC, 0xE7B8, 0xE7F8, 0xF7F0, 0x3FE0, 0x01C0, 0x03FF, 0x07FF, 0x07F3, 0x0FF3, 0x1EF3, 0x3CF3, 0x38F3, 0x78F3, 0xF07F, 0xE03F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [%]
|
||||||
|
0x07E0, 0x0FF8, 0x0F78, 0x1F78, 0x1F78, 0x1F78, 0x0F78, 0x0FF0, 0x0FE0, 0x1F80, 0x7FC3, 0xFBC3, 0xF3E7, 0xF1F7, 0xF0F7, 0xF0FF, 0xF07F, 0xF83E, 0x7C7F, 0x3FFF, 0x1FEF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [&]
|
||||||
|
0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03C0, 0x01C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [']
|
||||||
|
0x003F, 0x007C, 0x01F0, 0x01E0, 0x03C0, 0x07C0, 0x0780, 0x0780, 0x0F80, 0x0F00, 0x0F00, 0x0F00, 0x0F00, 0x0F00, 0x0F00, 0x0F80, 0x0780, 0x0780, 0x07C0, 0x03C0, 0x01E0, 0x01F0, 0x007C, 0x003F, 0x000F, 0x0000, // Ascii = [(]
|
||||||
|
0x7E00, 0x1F00, 0x07C0, 0x03C0, 0x01E0, 0x01F0, 0x00F0, 0x00F0, 0x00F8, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x00F8, 0x00F0, 0x00F0, 0x01F0, 0x01E0, 0x03C0, 0x07C0, 0x1F00, 0x7E00, 0x7800, 0x0000, // Ascii = [)]
|
||||||
|
0x03E0, 0x03C0, 0x01C0, 0x39CE, 0x3FFF, 0x3F7F, 0x0320, 0x0370, 0x07F8, 0x0F78, 0x1F3C, 0x0638, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [*]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0xFFFF, 0xFFFF, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [+]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x01E0, 0x01E0, 0x01E0, 0x01C0, 0x0380, // Ascii = [,]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3FFE, 0x3FFE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [-]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [.]
|
||||||
|
0x000F, 0x000F, 0x001E, 0x001E, 0x003C, 0x003C, 0x0078, 0x0078, 0x00F0, 0x00F0, 0x01E0, 0x01E0, 0x03C0, 0x03C0, 0x0780, 0x0780, 0x0F00, 0x0F00, 0x1E00, 0x1E00, 0x3C00, 0x3C00, 0x7800, 0x7800, 0xF000, 0x0000, // Ascii = [/]
|
||||||
|
0x07F0, 0x0FF8, 0x1F7C, 0x3E3E, 0x3C1E, 0x7C1F, 0x7C1F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x7C1F, 0x7C1F, 0x3C1E, 0x3E3E, 0x1F7C, 0x0FF8, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [0]
|
||||||
|
0x00F0, 0x07F0, 0x3FF0, 0x3FF0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [1]
|
||||||
|
0x0FE0, 0x3FF8, 0x3C7C, 0x003C, 0x003E, 0x003E, 0x003E, 0x003C, 0x003C, 0x007C, 0x00F8, 0x01F0, 0x03E0, 0x07C0, 0x0780, 0x0F00, 0x1E00, 0x3E00, 0x3C00, 0x3FFE, 0x3FFE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [2]
|
||||||
|
0x0FF0, 0x1FF8, 0x1C7C, 0x003E, 0x003E, 0x003E, 0x003C, 0x003C, 0x00F8, 0x0FF0, 0x0FF8, 0x007C, 0x003E, 0x001E, 0x001E, 0x001E, 0x001E, 0x003E, 0x1C7C, 0x1FF8, 0x1FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [3]
|
||||||
|
0x0078, 0x00F8, 0x00F8, 0x01F8, 0x03F8, 0x07F8, 0x07F8, 0x0F78, 0x1E78, 0x1E78, 0x3C78, 0x7878, 0x7878, 0xFFFF, 0xFFFF, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0078, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [4]
|
||||||
|
0x1FFC, 0x1FFC, 0x1FFC, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1FE0, 0x1FF8, 0x00FC, 0x007C, 0x003E, 0x003E, 0x001E, 0x003E, 0x003E, 0x003C, 0x1C7C, 0x1FF8, 0x1FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [5]
|
||||||
|
0x01FC, 0x07FE, 0x0F8E, 0x1F00, 0x1E00, 0x3E00, 0x3C00, 0x3C00, 0x3DF8, 0x3FFC, 0x7F3E, 0x7E1F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3E0F, 0x1E1F, 0x1F3E, 0x0FFC, 0x03F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [6]
|
||||||
|
0x3FFF, 0x3FFF, 0x3FFF, 0x000F, 0x001E, 0x001E, 0x003C, 0x0038, 0x0078, 0x00F0, 0x00F0, 0x01E0, 0x01E0, 0x03C0, 0x03C0, 0x0780, 0x0F80, 0x0F80, 0x0F00, 0x1F00, 0x1F00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [7]
|
||||||
|
0x07F8, 0x0FFC, 0x1F3E, 0x1E1E, 0x3E1E, 0x3E1E, 0x1E1E, 0x1F3C, 0x0FF8, 0x07F0, 0x0FF8, 0x1EFC, 0x3E3E, 0x3C1F, 0x7C1F, 0x7C0F, 0x7C0F, 0x3C1F, 0x3F3E, 0x1FFC, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [8]
|
||||||
|
0x07F0, 0x0FF8, 0x1E7C, 0x3C3E, 0x3C1E, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x3C1F, 0x3E3F, 0x1FFF, 0x07EF, 0x001F, 0x001E, 0x001E, 0x003E, 0x003C, 0x38F8, 0x3FF0, 0x1FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [9]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [:]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x01E0, 0x01E0, 0x01E0, 0x03C0, 0x0380, // Ascii = [;]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x000F, 0x003F, 0x00FC, 0x03F0, 0x0FC0, 0x3F00, 0xFE00, 0x3F00, 0x0FC0, 0x03F0, 0x00FC, 0x003F, 0x000F, 0x0003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [<]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [=]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xE000, 0xF800, 0x7E00, 0x1F80, 0x07E0, 0x01F8, 0x007E, 0x001F, 0x007E, 0x01F8, 0x07E0, 0x1F80, 0x7E00, 0xF800, 0xE000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [>]
|
||||||
|
0x1FF0, 0x3FFC, 0x383E, 0x381F, 0x381F, 0x001E, 0x001E, 0x003C, 0x0078, 0x00F0, 0x01E0, 0x03C0, 0x03C0, 0x07C0, 0x07C0, 0x0000, 0x0000, 0x0000, 0x07C0, 0x07C0, 0x07C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [?]
|
||||||
|
0x03F8, 0x0FFE, 0x1F1E, 0x3E0F, 0x3C7F, 0x78FF, 0x79EF, 0x73C7, 0xF3C7, 0xF38F, 0xF38F, 0xF38F, 0xF39F, 0xF39F, 0x73FF, 0x7BFF, 0x79F7, 0x3C00, 0x1F1C, 0x0FFC, 0x03F8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [@]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x03E0, 0x03E0, 0x07F0, 0x07F0, 0x07F0, 0x0F78, 0x0F78, 0x0E7C, 0x1E3C, 0x1E3C, 0x3C3E, 0x3FFE, 0x3FFF, 0x781F, 0x780F, 0xF00F, 0xF007, 0xF007, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [A]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x3FF8, 0x3FFC, 0x3C3E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C3E, 0x3C7C, 0x3FF0, 0x3FF8, 0x3C7E, 0x3C1F, 0x3C1F, 0x3C0F, 0x3C0F, 0x3C1F, 0x3FFE, 0x3FF8, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [B]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x01FF, 0x07FF, 0x1F87, 0x3E00, 0x3C00, 0x7C00, 0x7800, 0x7800, 0x7800, 0x7800, 0x7800, 0x7C00, 0x7C00, 0x3E00, 0x3F00, 0x1F83, 0x07FF, 0x01FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [C]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x7FF0, 0x7FFC, 0x787E, 0x781F, 0x781F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x781F, 0x781E, 0x787E, 0x7FF8, 0x7FE0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [D]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x3FFF, 0x3FFF, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3FFE, 0x3FFE, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [E]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x1FFF, 0x1FFF, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1FFF, 0x1FFF, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x1E00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [F]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x03FE, 0x0FFF, 0x1F87, 0x3E00, 0x7C00, 0x7C00, 0x7800, 0xF800, 0xF800, 0xF87F, 0xF87F, 0x780F, 0x7C0F, 0x7C0F, 0x3E0F, 0x1F8F, 0x0FFF, 0x03FE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [G]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7FFF, 0x7FFF, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [H]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x3FFF, 0x3FFF, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [I]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x1FFC, 0x1FFC, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x007C, 0x0078, 0x0078, 0x38F8, 0x3FF0, 0x3FC0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [J]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x3C1F, 0x3C1E, 0x3C3C, 0x3C78, 0x3CF0, 0x3DE0, 0x3FE0, 0x3FC0, 0x3F80, 0x3FC0, 0x3FE0, 0x3DF0, 0x3CF0, 0x3C78, 0x3C7C, 0x3C3E, 0x3C1F, 0x3C0F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [K]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3FFF, 0x3FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [L]
|
||||||
|
0x0000, 0x0000, 0x0000, 0xF81F, 0xFC1F, 0xFC1F, 0xFE3F, 0xFE3F, 0xFE3F, 0xFF7F, 0xFF77, 0xFF77, 0xF7F7, 0xF7E7, 0xF3E7, 0xF3E7, 0xF3C7, 0xF007, 0xF007, 0xF007, 0xF007, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [M]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x7C0F, 0x7C0F, 0x7E0F, 0x7F0F, 0x7F0F, 0x7F8F, 0x7F8F, 0x7FCF, 0x7BEF, 0x79EF, 0x79FF, 0x78FF, 0x78FF, 0x787F, 0x783F, 0x783F, 0x781F, 0x781F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [N]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x07F0, 0x1FFC, 0x3E3E, 0x7C1F, 0x780F, 0x780F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0x780F, 0x780F, 0x7C1F, 0x3E3E, 0x1FFC, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [O]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x3FFC, 0x3FFF, 0x3E1F, 0x3E0F, 0x3E0F, 0x3E0F, 0x3E0F, 0x3E1F, 0x3E3F, 0x3FFC, 0x3FF0, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x3E00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [P]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x07F0, 0x1FFC, 0x3E3E, 0x7C1F, 0x780F, 0x780F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0xF80F, 0x780F, 0x780F, 0x7C1F, 0x3E3E, 0x1FFC, 0x07F8, 0x007C, 0x003F, 0x000F, 0x0003, 0x0000, // Ascii = [Q]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x3FF0, 0x3FFC, 0x3C7E, 0x3C3E, 0x3C1E, 0x3C1E, 0x3C3E, 0x3C3C, 0x3CFC, 0x3FF0, 0x3FE0, 0x3DF0, 0x3CF8, 0x3C7C, 0x3C3E, 0x3C1E, 0x3C1F, 0x3C0F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [R]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x07FC, 0x1FFE, 0x3E0E, 0x3C00, 0x3C00, 0x3C00, 0x3E00, 0x1FC0, 0x0FF8, 0x03FE, 0x007F, 0x001F, 0x000F, 0x000F, 0x201F, 0x3C3E, 0x3FFC, 0x1FF0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [S]
|
||||||
|
0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [T]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x7C0F, 0x3C1E, 0x3C1E, 0x3E3E, 0x1FFC, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [U]
|
||||||
|
0x0000, 0x0000, 0x0000, 0xF007, 0xF007, 0xF807, 0x780F, 0x7C0F, 0x3C1E, 0x3C1E, 0x3E1E, 0x1E3C, 0x1F3C, 0x1F78, 0x0F78, 0x0FF8, 0x07F0, 0x07F0, 0x07F0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [V]
|
||||||
|
0x0000, 0x0000, 0x0000, 0xE003, 0xF003, 0xF003, 0xF007, 0xF3E7, 0xF3E7, 0xF3E7, 0x73E7, 0x7BF7, 0x7FF7, 0x7FFF, 0x7F7F, 0x7F7F, 0x7F7E, 0x3F7E, 0x3E3E, 0x3E3E, 0x3E3E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [W]
|
||||||
|
0x0000, 0x0000, 0x0000, 0xF807, 0x7C0F, 0x3E1E, 0x3E3E, 0x1F3C, 0x0FF8, 0x07F0, 0x07E0, 0x03E0, 0x03E0, 0x07F0, 0x0FF8, 0x0F7C, 0x1E7C, 0x3C3E, 0x781F, 0x780F, 0xF00F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [X]
|
||||||
|
0x0000, 0x0000, 0x0000, 0xF807, 0x7807, 0x7C0F, 0x3C1E, 0x3E1E, 0x1F3C, 0x0F78, 0x0FF8, 0x07F0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [Y]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x7FFF, 0x7FFF, 0x000F, 0x001F, 0x003E, 0x007C, 0x00F8, 0x00F0, 0x01E0, 0x03E0, 0x07C0, 0x0F80, 0x0F00, 0x1E00, 0x3E00, 0x7C00, 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [Z]
|
||||||
|
0x07FF, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x07FF, 0x07FF, 0x0000, // Ascii = [[]
|
||||||
|
0x7800, 0x7800, 0x3C00, 0x3C00, 0x1E00, 0x1E00, 0x0F00, 0x0F00, 0x0780, 0x0780, 0x03C0, 0x03C0, 0x01E0, 0x01E0, 0x00F0, 0x00F0, 0x0078, 0x0078, 0x003C, 0x003C, 0x001E, 0x001E, 0x000F, 0x000F, 0x0007, 0x0000, // Ascii = [\]
|
||||||
|
0x7FF0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x00F0, 0x7FF0, 0x7FF0, 0x0000, // Ascii = []]
|
||||||
|
0x00C0, 0x01C0, 0x01C0, 0x03E0, 0x03E0, 0x07F0, 0x07F0, 0x0778, 0x0F78, 0x0F38, 0x1E3C, 0x1E3C, 0x3C1E, 0x3C1E, 0x380F, 0x780F, 0x7807, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [^]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, // Ascii = [_]
|
||||||
|
0x00F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [`]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0FF8, 0x3FFC, 0x3C7C, 0x003E, 0x003E, 0x003E, 0x07FE, 0x1FFE, 0x3E3E, 0x7C3E, 0x783E, 0x7C3E, 0x7C7E, 0x3FFF, 0x1FCF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [a]
|
||||||
|
0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3DF8, 0x3FFE, 0x3F3E, 0x3E1F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C1F, 0x3C1E, 0x3F3E, 0x3FFC, 0x3BF0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [b]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03FE, 0x0FFF, 0x1F87, 0x3E00, 0x3E00, 0x3C00, 0x7C00, 0x7C00, 0x7C00, 0x3C00, 0x3E00, 0x3E00, 0x1F87, 0x0FFF, 0x03FE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [c]
|
||||||
|
0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x001F, 0x07FF, 0x1FFF, 0x3E3F, 0x3C1F, 0x7C1F, 0x7C1F, 0x7C1F, 0x781F, 0x781F, 0x7C1F, 0x7C1F, 0x3C3F, 0x3E7F, 0x1FFF, 0x0FDF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [d]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x03F8, 0x0FFC, 0x1F3E, 0x3E1E, 0x3C1F, 0x7C1F, 0x7FFF, 0x7FFF, 0x7C00, 0x7C00, 0x3C00, 0x3E00, 0x1F07, 0x0FFF, 0x03FE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [e]
|
||||||
|
0x01FF, 0x03E1, 0x03C0, 0x07C0, 0x07C0, 0x07C0, 0x7FFF, 0x7FFF, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x07C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [f]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07EF, 0x1FFF, 0x3E7F, 0x3C1F, 0x7C1F, 0x7C1F, 0x781F, 0x781F, 0x781F, 0x7C1F, 0x7C1F, 0x3C3F, 0x3E7F, 0x1FFF, 0x0FDF, 0x001E, 0x001E, 0x001E, 0x387C, 0x3FF8, // Ascii = [g]
|
||||||
|
0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3DFC, 0x3FFE, 0x3F9E, 0x3F1F, 0x3E1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [h]
|
||||||
|
0x01F0, 0x01F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x7FE0, 0x7FE0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [i]
|
||||||
|
0x00F8, 0x00F8, 0x0000, 0x0000, 0x0000, 0x0000, 0x3FF8, 0x3FF8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F8, 0x00F0, 0x71F0, 0x7FE0, // Ascii = [j]
|
||||||
|
0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C1F, 0x3C3E, 0x3C7C, 0x3CF8, 0x3DF0, 0x3DE0, 0x3FC0, 0x3FC0, 0x3FE0, 0x3DF0, 0x3CF8, 0x3C7C, 0x3C3E, 0x3C1F, 0x3C1F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [k]
|
||||||
|
0x7FF0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x01F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [l]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF79E, 0xFFFF, 0xFFFF, 0xFFFF, 0xFBE7, 0xF9E7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0xF1C7, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [m]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3DFC, 0x3FFE, 0x3F9E, 0x3F1F, 0x3E1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x3C1F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [n]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07F0, 0x1FFC, 0x3E3E, 0x3C1F, 0x7C1F, 0x780F, 0x780F, 0x780F, 0x780F, 0x780F, 0x7C1F, 0x3C1F, 0x3E3E, 0x1FFC, 0x07F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [o]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3DF8, 0x3FFE, 0x3F3E, 0x3E1F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C0F, 0x3C1F, 0x3E1E, 0x3F3E, 0x3FFC, 0x3FF8, 0x3C00, 0x3C00, 0x3C00, 0x3C00, 0x3C00, // Ascii = [p]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07EE, 0x1FFE, 0x3E7E, 0x3C1E, 0x7C1E, 0x781E, 0x781E, 0x781E, 0x781E, 0x781E, 0x7C1E, 0x7C3E, 0x3E7E, 0x1FFE, 0x0FDE, 0x001E, 0x001E, 0x001E, 0x001E, 0x001E, // Ascii = [q]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1F7F, 0x1FFF, 0x1FE7, 0x1FC7, 0x1F87, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x1F00, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [r]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x07FC, 0x1FFE, 0x1E0E, 0x3E00, 0x3E00, 0x3F00, 0x1FE0, 0x07FC, 0x00FE, 0x003E, 0x001E, 0x001E, 0x3C3E, 0x3FFC, 0x1FF0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [s]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0780, 0x0780, 0x0780, 0x7FFF, 0x7FFF, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x0780, 0x07C0, 0x03FF, 0x01FF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [t]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C1E, 0x3C3E, 0x3C7E, 0x3EFE, 0x1FFE, 0x0FDE, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [u]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF007, 0x780F, 0x780F, 0x3C1E, 0x3C1E, 0x3E1E, 0x1E3C, 0x1E3C, 0x0F78, 0x0F78, 0x0FF0, 0x07F0, 0x07F0, 0x03E0, 0x03E0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [v]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF003, 0xF1E3, 0xF3E3, 0xF3E7, 0xF3F7, 0xF3F7, 0x7FF7, 0x7F77, 0x7F7F, 0x7F7F, 0x7F7F, 0x3E3E, 0x3E3E, 0x3E3E, 0x3E3E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [w]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x7C0F, 0x3E1E, 0x3E3C, 0x1F3C, 0x0FF8, 0x07F0, 0x07F0, 0x03E0, 0x07F0, 0x07F8, 0x0FF8, 0x1E7C, 0x3E3E, 0x3C1F, 0x781F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [x]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xF807, 0x780F, 0x7C0F, 0x3C1E, 0x3C1E, 0x1E3C, 0x1E3C, 0x1F3C, 0x0F78, 0x0FF8, 0x07F0, 0x07F0, 0x03E0, 0x03E0, 0x03C0, 0x03C0, 0x03C0, 0x0780, 0x0F80, 0x7F00, // Ascii = [y]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3FFF, 0x3FFF, 0x001F, 0x003E, 0x007C, 0x00F8, 0x01F0, 0x03E0, 0x07C0, 0x0F80, 0x1F00, 0x1E00, 0x3C00, 0x7FFF, 0x7FFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [z]
|
||||||
|
0x01FE, 0x03E0, 0x03C0, 0x03C0, 0x03C0, 0x03C0, 0x01E0, 0x01E0, 0x01E0, 0x01C0, 0x03C0, 0x3F80, 0x3F80, 0x03C0, 0x01C0, 0x01E0, 0x01E0, 0x01E0, 0x03C0, 0x03C0, 0x03C0, 0x03C0, 0x03E0, 0x01FE, 0x007E, 0x0000, // Ascii = [{]
|
||||||
|
0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x01C0, 0x0000, // Ascii = [|]
|
||||||
|
0x3FC0, 0x03E0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x01C0, 0x03C0, 0x03C0, 0x01C0, 0x01E0, 0x00FE, 0x00FE, 0x01E0, 0x01C0, 0x03C0, 0x03C0, 0x01C0, 0x01E0, 0x01E0, 0x01E0, 0x01E0, 0x03E0, 0x3FC0, 0x3F00, 0x0000, // Ascii = [}]
|
||||||
|
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3F07, 0x7FC7, 0x73E7, 0xF1FF, 0xF07E, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // Ascii = [~]
|
||||||
|
}
|
||||||
@@ -2,10 +2,18 @@ package display
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
"go.maze.io/harmon/hardware"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func DrawSprite(display hardware.Display, x, y int, sprite []byte, c color.Color) error {
|
func DrawSprite(p draw.Image, x, y int, sprite []uint8, c color.Color) {
|
||||||
return nil
|
w, h, data := sprite[0], sprite[1], sprite[2:]
|
||||||
|
for dy := 0; dy < int(h); dy++ {
|
||||||
|
for dx := 0; dx < int(w); dx++ {
|
||||||
|
byteOffset := int(dy/8)*int(w) + dx
|
||||||
|
bitOffset := dy % 8
|
||||||
|
if data[byteOffset]&(1<<bitOffset) != 0 {
|
||||||
|
p.Set(x+dx, y+dy, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ type VCCMode uint8
|
|||||||
|
|
||||||
// Registers
|
// Registers
|
||||||
const (
|
const (
|
||||||
setcontrast = 0x81
|
setContrast = 0x81
|
||||||
displayAllOnResume = 0xA4
|
displayAllOnResume = 0xA4
|
||||||
displayAllOn = 0xA5
|
displayAllOn = 0xA5
|
||||||
normalDisplay = 0xA6
|
normalDisplay = 0xA6
|
||||||
|
|||||||
+158
-202
@@ -2,14 +2,13 @@
|
|||||||
package ssd1306
|
package ssd1306
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
|
"time"
|
||||||
|
|
||||||
"periph.io/x/conn/v3/gpio"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"go.maze.io/harmon/config"
|
"go.maze.io/harmon/config"
|
||||||
"go.maze.io/harmon/hardware"
|
"go.maze.io/harmon/hardware"
|
||||||
"go.maze.io/harmon/hardware/display"
|
"go.maze.io/harmon/hardware/display"
|
||||||
@@ -25,15 +24,19 @@ func init() {
|
|||||||
display.Register("ssd1306", newDriver)
|
display.Register("ssd1306", newDriver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResetValue [2]byte
|
||||||
|
|
||||||
type Display struct {
|
type Display struct {
|
||||||
conn display.Conn
|
conn display.Conn
|
||||||
rect image.Rectangle
|
|
||||||
rotate display.Rotation
|
|
||||||
bl gpio.PinOut
|
|
||||||
buffer []byte
|
buffer []byte
|
||||||
next *pixel.VerticalLSB
|
width int16
|
||||||
startPage, endPage int
|
height int16
|
||||||
startCol, endCol int
|
bufferSize int16
|
||||||
|
vccState VCCMode
|
||||||
|
canReset bool
|
||||||
|
resetCol ResetValue
|
||||||
|
resetPage ResetValue
|
||||||
|
rotation display.Rotation
|
||||||
scrolled bool
|
scrolled bool
|
||||||
halted bool
|
halted bool
|
||||||
}
|
}
|
||||||
@@ -57,11 +60,21 @@ func newDriver(config config.DisplayConfig) (hardware.Display, error) {
|
|||||||
opts.Mirror = true
|
opts.Mirror = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log := logrus.WithFields(logrus.Fields{
|
||||||
|
"type": "ssd1306",
|
||||||
|
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
|
||||||
|
"mode": config.Mode,
|
||||||
|
"rotate": opts.Rotate,
|
||||||
|
})
|
||||||
|
log.Debug("new driver")
|
||||||
|
|
||||||
|
var isSPI bool
|
||||||
switch config.Mode {
|
switch config.Mode {
|
||||||
case "", "i2c":
|
case "", "i2c":
|
||||||
conn, err = display.OpenI2C(config.Bus, config.Address)
|
conn, err = display.OpenI2C(config.Bus, config.Address)
|
||||||
case "spi":
|
case "spi":
|
||||||
conn, err = display.OpenSPI(config.Port, config.Reset, config.DC)
|
conn, err = display.OpenSPI(config.Port, config.Reset, config.DC)
|
||||||
|
isSPI = true
|
||||||
default:
|
default:
|
||||||
return nil, display.InvalidMode(config.Mode)
|
return nil, display.InvalidMode(config.Mode)
|
||||||
}
|
}
|
||||||
@@ -70,10 +83,10 @@ func newDriver(config config.DisplayConfig) (hardware.Display, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return newDisplay(conn, opts)
|
return newDisplay(conn, opts, isSPI)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDisplay(conn display.Conn, opts *display.Options) (*Display, error) {
|
func newDisplay(conn display.Conn, opts *display.Options, isSPI bool) (d *Display, err error) {
|
||||||
if opts.W < 8 || opts.W > 128 || opts.W&7 != 0 {
|
if opts.W < 8 || opts.W > 128 || opts.W&7 != 0 {
|
||||||
return nil, fmt.Errorf("invalid width %d", opts.W)
|
return nil, fmt.Errorf("invalid width %d", opts.W)
|
||||||
}
|
}
|
||||||
@@ -81,27 +94,48 @@ func newDisplay(conn display.Conn, opts *display.Options) (*Display, error) {
|
|||||||
return nil, fmt.Errorf("invalid height %d", opts.H)
|
return nil, fmt.Errorf("invalid height %d", opts.H)
|
||||||
}
|
}
|
||||||
|
|
||||||
nbPages := opts.H / 8
|
d = &Display{
|
||||||
pageSize := opts.W
|
|
||||||
d := &Display{
|
|
||||||
conn: conn,
|
conn: conn,
|
||||||
bl: opts.Backlight,
|
width: int16(opts.W),
|
||||||
rect: image.Rect(0, 0, opts.W, opts.H),
|
height: int16(opts.H),
|
||||||
rotate: opts.Rotate,
|
|
||||||
buffer: make([]byte, nbPages*pageSize),
|
|
||||||
startPage: 0,
|
|
||||||
endPage: nbPages,
|
|
||||||
startCol: 0,
|
|
||||||
endCol: opts.W,
|
|
||||||
scrolled: true, // Signal that the screen must be redrawn on first draw().
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := d.sendCommand(getInitCmd(opts)); err != nil {
|
//var zeroReset ResetValue
|
||||||
return nil, err
|
d.vccState = SwitchCapVCC
|
||||||
|
d.resetCol = ResetValue{0, uint8(d.width - 1)}
|
||||||
|
d.resetPage = ResetValue{0, uint8(d.height/8) - 1}
|
||||||
|
d.bufferSize = d.width * d.height / 8
|
||||||
|
d.buffer = make([]byte, d.bufferSize)
|
||||||
|
d.canReset = !isSPI || d.width != 128 || d.height != 64 // I2C or not 128x64
|
||||||
|
logrus.Infof("%d bytes buffer for %d pixels", d.bufferSize, d.width*d.height)
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Nanosecond)
|
||||||
|
|
||||||
|
muxr := byte(d.height - 1)
|
||||||
|
if err = d.sendCommand([]byte{
|
||||||
|
0xAE, // display off
|
||||||
|
0xA8, muxr, // multiplex ratio (height - 1)
|
||||||
|
0xD3, 0x00, // display offset 0
|
||||||
|
0x40, // display start line 0
|
||||||
|
0xA1, // segment remap a0/a1
|
||||||
|
0xC8, // scan dir reverse (C0 normal)
|
||||||
|
0xD5, 0x80, // clock divide ration (0x00=1) and osc. frequency (0x8)
|
||||||
|
0xDA, 0x12, // com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5)
|
||||||
|
0x81, 0xFF, // contrast
|
||||||
|
0xA4, // output RAM to display
|
||||||
|
0xDB, 0x40, // vcom deselect level
|
||||||
|
0x20, 0x02, // set memory addressing mode
|
||||||
|
0x00, 0x10, // set lower column start address for page addressing mode: no offset
|
||||||
|
0x8D, 0x14, // [2] charge pump setting (p62): 0x014 enable, 0x010 disable
|
||||||
|
0xD9, 0x22, // set pre-charge
|
||||||
|
0x2E, // scroll off
|
||||||
|
0xA6, // none inverted normal display mode
|
||||||
|
0xAF, // display on
|
||||||
|
}); err != nil {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return d, nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Display) sendData(data []byte) error {
|
func (d *Display) sendData(data []byte) error {
|
||||||
@@ -123,99 +157,14 @@ func (d *Display) sendCommand(data []byte) error {
|
|||||||
return d.conn.Tx(data, true)
|
return d.conn.Tx(data, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Display) calculateSubset(next []byte) (int, int, int, int, bool) {
|
func (d *Display) PowerSave(on bool) error {
|
||||||
w := d.rect.Dx()
|
var cmd byte
|
||||||
h := d.rect.Dy()
|
if on {
|
||||||
startPage := 0
|
cmd = 0xAF
|
||||||
endPage := h / 8
|
|
||||||
startCol := 0
|
|
||||||
endCol := w
|
|
||||||
if d.scrolled {
|
|
||||||
// Painting disable scrolling but if scrolling was enabled, this requires a
|
|
||||||
// full screen redraw.
|
|
||||||
d.scrolled = false
|
|
||||||
} else {
|
} else {
|
||||||
// Calculate the smallest square that need to be sent.
|
cmd = 0xAE
|
||||||
pageSize := w
|
|
||||||
|
|
||||||
// Top.
|
|
||||||
for ; startPage < endPage; startPage++ {
|
|
||||||
x := pageSize * startPage
|
|
||||||
y := pageSize * (startPage + 1)
|
|
||||||
if !bytes.Equal(d.buffer[x:y], next[x:y]) {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
return d.sendCommand([]byte{cmd})
|
||||||
// Bottom.
|
|
||||||
for ; endPage > startPage; endPage-- {
|
|
||||||
x := pageSize * (endPage - 1)
|
|
||||||
y := pageSize * endPage
|
|
||||||
if !bytes.Equal(d.buffer[x:y], next[x:y]) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if startPage == endPage {
|
|
||||||
// Early exit, the image is exactly the same.
|
|
||||||
return 0, 0, 0, 0, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Left.
|
|
||||||
for ; startCol < endCol; startCol++ {
|
|
||||||
for i := startPage; i < endPage; i++ {
|
|
||||||
x := i*pageSize + startCol
|
|
||||||
if d.buffer[x] != next[x] {
|
|
||||||
goto breakLeft
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
breakLeft:
|
|
||||||
|
|
||||||
// Right.
|
|
||||||
for ; endCol > startCol; endCol-- {
|
|
||||||
for i := startPage; i < endPage; i++ {
|
|
||||||
x := i*pageSize + endCol - 1
|
|
||||||
if d.buffer[x] != next[x] {
|
|
||||||
goto breakRight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
breakRight:
|
|
||||||
}
|
|
||||||
return startPage, endPage, startCol, endCol, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// drawInternal sends image data to the controller.
|
|
||||||
func (d *Display) drawInternal(next []byte) error {
|
|
||||||
startPage, endPage, startCol, endCol, skip := d.calculateSubset(next)
|
|
||||||
if skip {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
copy(d.buffer, next)
|
|
||||||
|
|
||||||
if d.startPage != startPage || d.endPage != endPage || d.startCol != startCol || d.endCol != endCol {
|
|
||||||
d.startPage = startPage
|
|
||||||
d.endPage = endPage
|
|
||||||
d.startCol = startCol
|
|
||||||
d.endCol = endCol
|
|
||||||
}
|
|
||||||
|
|
||||||
pageSize := d.rect.Dx()
|
|
||||||
for page := d.startPage; page < d.endPage; page++ {
|
|
||||||
err := d.sendCommand([]byte{
|
|
||||||
pageAddr | byte(page),
|
|
||||||
setLowColumn | (byte(d.startCol) & 0x0F),
|
|
||||||
setHighColumn | (byte(d.startCol) >> 4),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
pageStart := page * pageSize
|
|
||||||
err = d.sendData(d.buffer[pageStart+d.startCol : pageStart+d.endCol])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Halt turns off the display.
|
// Halt turns off the display.
|
||||||
@@ -223,7 +172,7 @@ func (d *Display) drawInternal(next []byte) error {
|
|||||||
// Sending any other command afterward reenables the display.
|
// Sending any other command afterward reenables the display.
|
||||||
func (d *Display) Halt() error {
|
func (d *Display) Halt() error {
|
||||||
d.halted = false
|
d.halted = false
|
||||||
err := d.sendCommand([]byte{0xAE})
|
err := d.PowerSave(true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
d.halted = true
|
d.halted = true
|
||||||
}
|
}
|
||||||
@@ -232,10 +181,7 @@ func (d *Display) Halt() error {
|
|||||||
|
|
||||||
// Size of the display.
|
// Size of the display.
|
||||||
func (d *Display) Size() image.Point {
|
func (d *Display) Size() image.Point {
|
||||||
if d.rotate == display.Rotate90 || d.rotate == display.Rotate270 {
|
return image.Pt(int(d.width), int(d.height))
|
||||||
return image.Pt(d.rect.Max.Y, d.rect.Max.X)
|
|
||||||
}
|
|
||||||
return d.rect.Max
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw implements display.Drawer.
|
// Draw implements display.Drawer.
|
||||||
@@ -244,74 +190,9 @@ func (d *Display) Size() image.Point {
|
|||||||
// It means that on slow bus (I²C), it may be preferable to defer Draw() calls
|
// It means that on slow bus (I²C), it may be preferable to defer Draw() calls
|
||||||
// to a background goroutine.
|
// to a background goroutine.
|
||||||
func (d *Display) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
|
func (d *Display) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
|
||||||
var next []byte
|
logrus.Debug("draw image")
|
||||||
if img, ok := src.(*pixel.VerticalLSB); ok && r.Eq(d.rect) && img.Rect.Eq(d.rect) && sp.X == 0 && sp.Y == 0 {
|
draw.Draw(d, r, src, sp, draw.Src)
|
||||||
// Exact size, full frame, image1bit encoding: fast path!
|
return d.Refresh()
|
||||||
next = img.Pix
|
|
||||||
} else {
|
|
||||||
// Double buffering.
|
|
||||||
if d.next == nil {
|
|
||||||
d.next = pixel.NewVerticalLSB(d.rect)
|
|
||||||
}
|
|
||||||
next = d.next.Pix
|
|
||||||
draw.Src.Draw(d.next, r, src, sp)
|
|
||||||
}
|
|
||||||
return d.drawInternal(next)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getInitCmd(opts *display.Options) []byte {
|
|
||||||
// Set COM output scan direction; C0 means normal; C8 means reversed
|
|
||||||
comScan := byte(0xC8)
|
|
||||||
// See page 40.
|
|
||||||
columnAddr := byte(0xA1)
|
|
||||||
if opts.Rotate == display.Rotate180 {
|
|
||||||
// Change order both horizontally and vertically.
|
|
||||||
comScan = 0xC0
|
|
||||||
columnAddr = byte(0xA0)
|
|
||||||
}
|
|
||||||
if opts.Flip {
|
|
||||||
comScan = byte(0xC0)
|
|
||||||
}
|
|
||||||
if opts.Mirror {
|
|
||||||
columnAddr = byte(0xA0)
|
|
||||||
}
|
|
||||||
// See page 40.
|
|
||||||
hwLayout := byte(0x02)
|
|
||||||
if !opts.Sequential {
|
|
||||||
hwLayout |= 0x10
|
|
||||||
}
|
|
||||||
if opts.SwapTopBottom {
|
|
||||||
hwLayout |= 0x20
|
|
||||||
}
|
|
||||||
// Set the max frequency. The problem with I²C is that it creates visible
|
|
||||||
// tear down. On SPI at high speed this is not visible. Page 23 pictures how
|
|
||||||
// to avoid tear down. For now default to max frequency.
|
|
||||||
freq := byte(0xF0)
|
|
||||||
|
|
||||||
// Initialize the device by fully resetting all values.
|
|
||||||
// Page 64 has the full recommended flow.
|
|
||||||
// Page 28 lists all the commands.
|
|
||||||
return []byte{
|
|
||||||
0xAE, // Display off
|
|
||||||
0xD3, 0x00, // Set display offset; 0
|
|
||||||
0x40, // Start display start line; 0
|
|
||||||
columnAddr, // Set segment remap; RESET is column 127.
|
|
||||||
comScan, //
|
|
||||||
0xDA, hwLayout, // Set COM pins hardware configuration; see page 40
|
|
||||||
0x81, 0xFF, // Set max contrast
|
|
||||||
0xA4, // Set display to use GDDRAM content
|
|
||||||
0xA6, // Set normal display (0xA7 for inverted 0=lit, 1=dark)
|
|
||||||
0xD5, freq, // Set osc frequency and divide ratio; power on reset value is 0x80.
|
|
||||||
0x8D, 0x14, // Enable charge pump regulator; page 62
|
|
||||||
0xD9, 0xF1, // Set pre-charge period; from adafruit driver
|
|
||||||
0xDB, 0x40, // Set Vcomh deselect level; page 32
|
|
||||||
0x2E, // Deactivate scroll
|
|
||||||
0xA8, byte(opts.H - 1), // Set multiplex ratio (number of lines to display)
|
|
||||||
0x20, 0x00, // Set memory addressing mode to horizontal
|
|
||||||
0x21, 0, uint8(opts.W - 1), // Set column address (Width)
|
|
||||||
0x22, 0, uint8(opts.H/8 - 1), // Set page address (Pages)
|
|
||||||
0xAF, // Display on
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Display) Invert(on bool) error {
|
func (d *Display) Invert(on bool) error {
|
||||||
@@ -323,29 +204,98 @@ func (d *Display) Invert(on bool) error {
|
|||||||
|
|
||||||
/* hardware.Display interface methods */
|
/* hardware.Display interface methods */
|
||||||
|
|
||||||
|
func (d *Display) Clear() {
|
||||||
|
for i := range d.buffer {
|
||||||
|
d.buffer[i] = 0x00
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Display) Fill(c color.Color) error {
|
func (d *Display) Fill(c color.Color) error {
|
||||||
//return d.Draw(d.rect, &image.Uniform{c}, image.Point{})
|
return d.Draw(d.Bounds(), &image.Uniform{c}, image.Point{})
|
||||||
return d.sendCommand([]byte{0xa7}) // invert :D
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Display) Refresh() error {
|
func (d *Display) Refresh() error {
|
||||||
if d.next == nil {
|
// Displaying pixels on SSD1306 is peculiar, because the pixels are stored in columns
|
||||||
return nil
|
// of 8-bits (1 byte). Each column is sent out on a page.
|
||||||
|
for page := 0; page < int(d.height)>>3; page++ {
|
||||||
|
if err := d.sendCommand([]byte{
|
||||||
|
0x40 | 0, // Set display start line
|
||||||
|
0x10 | 0, // Set Higher Column Start Address for Page Addressing Mode
|
||||||
|
0xb0 | byte(page&0x0f), // Define start page address
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return d.drawInternal(d.next.Pix)
|
|
||||||
|
var (
|
||||||
|
off = page * int(d.width)
|
||||||
|
end = off + int(d.width)
|
||||||
|
)
|
||||||
|
if err := d.sendData(d.buffer[off:end]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRotation changes the rotation of the device (clock-wise).
|
||||||
|
func (d *Display) SetRotation(rotation display.Rotation) error {
|
||||||
|
d.rotation = rotation
|
||||||
|
|
||||||
|
var command []byte
|
||||||
|
switch d.rotation {
|
||||||
|
case display.NoRotation:
|
||||||
|
command = []byte{
|
||||||
|
segRemap | 0x1, // Reverse horizontal mapping
|
||||||
|
comScanDec, // Reverse vertical mapping
|
||||||
|
}
|
||||||
|
case display.Rotate180:
|
||||||
|
command = []byte{
|
||||||
|
segRemap, // Normal horizontal mapping
|
||||||
|
comScanInc, // Normal vertical mapping
|
||||||
|
}
|
||||||
|
// nothing to do
|
||||||
|
default:
|
||||||
|
command = []byte{
|
||||||
|
segRemap | 0x1, // Reverse horizontal mapping
|
||||||
|
comScanDec, // Reverse vertical mapping
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.sendCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* draw.Image interface methods */
|
/* draw.Image interface methods */
|
||||||
|
|
||||||
|
func (d *Display) rotate(x, y int) (int, int) {
|
||||||
|
switch d.rotation {
|
||||||
|
case display.Rotate90:
|
||||||
|
x, y = y, x
|
||||||
|
x = int(d.width) - x - 1
|
||||||
|
case display.Rotate180:
|
||||||
|
x = int(d.width) - x - 1
|
||||||
|
y = int(d.height) - y - 1
|
||||||
|
case display.Rotate270:
|
||||||
|
x, y = y, x
|
||||||
|
y = int(d.height) - y - 1
|
||||||
|
}
|
||||||
|
return x, y
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Display) At(x, y int) color.Color {
|
func (d *Display) At(x, y int) color.Color {
|
||||||
if d.next == nil {
|
x, y = d.rotate(x, y)
|
||||||
|
if x < 0 || int16(x) >= d.width || y < 0 || int16(y) >= d.height {
|
||||||
return pixel.Off
|
return pixel.Off
|
||||||
}
|
}
|
||||||
return d.next.At(x, y)
|
|
||||||
|
byteIndex := int16(x) + int16(y/8)*d.width
|
||||||
|
if d.buffer[byteIndex]>>uint8(y%8)&0x1 == 1 {
|
||||||
|
return pixel.On
|
||||||
|
}
|
||||||
|
return pixel.Off
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Display) Bounds() image.Rectangle {
|
func (d *Display) Bounds() image.Rectangle {
|
||||||
return d.rect
|
return image.Rect(0, 0, int(d.width), int(d.height))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Display) ColorModel() color.Model {
|
func (d *Display) ColorModel() color.Model {
|
||||||
@@ -353,8 +303,14 @@ func (d *Display) ColorModel() color.Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Display) Set(x, y int, c color.Color) {
|
func (d *Display) Set(x, y int, c color.Color) {
|
||||||
if d.next == nil {
|
x, y = d.rotate(x, y)
|
||||||
d.next = pixel.NewVerticalLSB(d.rect)
|
if x < 0 || int16(x) >= d.width || y < 0 || int16(y) >= d.height {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
byteIndex := int16(x) + int16(y>>3)*d.width
|
||||||
|
if pixel.IsOn(c) {
|
||||||
|
d.buffer[byteIndex] |= 1 << uint8(y%8)
|
||||||
|
} else {
|
||||||
|
d.buffer[byteIndex] &^= 1 << uint8(y%8)
|
||||||
}
|
}
|
||||||
d.next.Set(x, y, c)
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package ssd1322
|
||||||
|
|
||||||
|
type VCCMode uint8
|
||||||
|
|
||||||
|
// Registers
|
||||||
|
const (
|
||||||
|
setContrast = 0x81
|
||||||
|
displayAllOnResume = 0xA4
|
||||||
|
displayAllOn = 0xA5
|
||||||
|
normalDisplay = 0xA6
|
||||||
|
invertDisplay = 0xA7
|
||||||
|
displayOff = 0xAE
|
||||||
|
displayOn = 0xAF
|
||||||
|
setDisplayOffset = 0xD3
|
||||||
|
setComPins = 0xDA
|
||||||
|
setVComDetect = 0xDB
|
||||||
|
setDisplayClockDiv = 0xD5
|
||||||
|
setPrecharge = 0xD9
|
||||||
|
setMultiplex = 0xA8
|
||||||
|
setLowColumn = 0x00
|
||||||
|
setHighColumn = 0x10
|
||||||
|
setStartLine = 0x40
|
||||||
|
memoryMode = 0x20
|
||||||
|
columnAddr = 0x21
|
||||||
|
pageAddr = 0x22
|
||||||
|
comScanInc = 0xC0
|
||||||
|
comScanDec = 0xC8
|
||||||
|
segRemap = 0xA0
|
||||||
|
chargePump = 0x8D
|
||||||
|
activateScroll = 0x2F
|
||||||
|
deactivateScroll = 0x2E
|
||||||
|
setVerticalScrollArea = 0xA3
|
||||||
|
rightHorizontalScroll = 0x26
|
||||||
|
leftHorizontalScroll = 0x27
|
||||||
|
verticalAndRightHorizontalScroll = 0x29
|
||||||
|
verticalAndLeftHorizontalScroll = 0x2A
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ExternalVCC VCCMode = iota + 0x1
|
||||||
|
SwitchCapVCC
|
||||||
|
)
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
// Package ssd1322 implements SSD1322 (monochrome) OLED displays.
|
||||||
|
package ssd1322
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"go.maze.io/harmon/config"
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"go.maze.io/harmon/hardware/display"
|
||||||
|
"go.maze.io/harmon/internal/pixel"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultWidth = 256
|
||||||
|
defaultHeight = 64
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
display.Register("ssd1322", newDriver)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ResetValue [2]byte
|
||||||
|
|
||||||
|
type Display struct {
|
||||||
|
conn display.Conn
|
||||||
|
buffer []byte
|
||||||
|
width int16
|
||||||
|
height int16
|
||||||
|
bufferSize int16
|
||||||
|
vccState VCCMode
|
||||||
|
canReset bool
|
||||||
|
resetCol ResetValue
|
||||||
|
resetPage ResetValue
|
||||||
|
rotation display.Rotation
|
||||||
|
scrolled bool
|
||||||
|
halted bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Display) Type() string { return "ssd1322" }
|
||||||
|
|
||||||
|
func newDriver(config config.DisplayConfig) (hardware.Display, error) {
|
||||||
|
var (
|
||||||
|
opts *display.Options
|
||||||
|
conn display.Conn
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if opts, err = display.ParseOptions(config, defaultWidth, defaultHeight); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.Rotate == display.Rotate180 {
|
||||||
|
// Let the hardware handle this rotation.
|
||||||
|
opts.Flip = true
|
||||||
|
opts.Mirror = true
|
||||||
|
}
|
||||||
|
|
||||||
|
log := logrus.WithFields(logrus.Fields{
|
||||||
|
"type": "ssd1322",
|
||||||
|
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
|
||||||
|
"mode": config.Mode,
|
||||||
|
"rotate": opts.Rotate,
|
||||||
|
})
|
||||||
|
log.Debug("new driver")
|
||||||
|
|
||||||
|
var isSPI bool
|
||||||
|
switch config.Mode {
|
||||||
|
case "", "i2c":
|
||||||
|
conn, err = display.OpenI2C(config.Bus, config.Address)
|
||||||
|
case "spi":
|
||||||
|
conn, err = display.OpenSPI(config.Port, config.Reset, config.DC)
|
||||||
|
isSPI = true
|
||||||
|
default:
|
||||||
|
return nil, display.InvalidMode(config.Mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newDisplay(conn, opts, isSPI)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDisplay(conn display.Conn, opts *display.Options, isSPI bool) (d *Display, err error) {
|
||||||
|
if opts.W < 8 || opts.W > 256 || opts.W&7 != 0 {
|
||||||
|
return nil, fmt.Errorf("invalid width %d", opts.W)
|
||||||
|
}
|
||||||
|
if opts.H < 8 || opts.H > 64 || opts.H&7 != 0 {
|
||||||
|
return nil, fmt.Errorf("invalid height %d", opts.H)
|
||||||
|
}
|
||||||
|
|
||||||
|
d = &Display{
|
||||||
|
conn: conn,
|
||||||
|
width: int16(opts.W),
|
||||||
|
height: int16(opts.H),
|
||||||
|
}
|
||||||
|
|
||||||
|
//var zeroReset ResetValue
|
||||||
|
d.vccState = SwitchCapVCC
|
||||||
|
d.resetCol = ResetValue{0, uint8(d.width - 1)}
|
||||||
|
d.resetPage = ResetValue{0, uint8(d.height/8) - 1}
|
||||||
|
d.bufferSize = d.width * d.height / 8
|
||||||
|
d.buffer = make([]byte, d.bufferSize)
|
||||||
|
d.canReset = !isSPI || d.width != 128 || d.height != 64 // I2C or not 128x64
|
||||||
|
logrus.Infof("%d bytes buffer for %d pixels", d.bufferSize, d.width*d.height)
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Nanosecond)
|
||||||
|
|
||||||
|
muxr := byte(d.height - 1)
|
||||||
|
if err = d.sendCommand([]byte{
|
||||||
|
0xFD, 0x12, // set command lock: unlock
|
||||||
|
0xA4, // display off
|
||||||
|
0xB3, 0x91, // set front clock divider to 80fps (default is 0xD0)
|
||||||
|
0xCA, muxr, // multiplex ratio (height - 1)
|
||||||
|
0xA2, 0x00, // display offset 0
|
||||||
|
0xA1, 0x00, // display start line 0
|
||||||
|
0xA0, 0x14, 0x11, // set remap and dual COM line mode
|
||||||
|
0xB5, 0x00, // set GPIO input disabled
|
||||||
|
0xAB, 0x01, // enable internal VDD regulator
|
||||||
|
0xB4, 0xA0, 0xB5, // display enhancement A: enable external VSL, normal GS display quality
|
||||||
|
0xC1, 0x7F, // set contrast current
|
||||||
|
0xC7, 0x0f, // set master contrast current control
|
||||||
|
0xB8, 0x00, 0x02, 0x08, 0x0d, 0x14, 0x1a, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, 0x50, 0x60, 0x80, 0x80, // custom gray scale table
|
||||||
|
0xB1, 0xE2, // set phase length (period 1: 5 DCLKs, period 2: 14 DCLKs)
|
||||||
|
0xD1, 0xA2, 0x20, // display enhancement B: normal, as-is
|
||||||
|
0xBB, 0x1F, // set pre-charge voltage 0.60*VCC
|
||||||
|
0xB6, 0x08, // set second pre-charge period (8 DCLKs)
|
||||||
|
0xBE, 0x07, // set VCOMH: 0x07 = 0.86*VCC
|
||||||
|
0xA6, // set display mode normal
|
||||||
|
0xA9, // exit partial display
|
||||||
|
0xAF, // display on
|
||||||
|
}); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) sendData(data []byte) error {
|
||||||
|
if d.halted {
|
||||||
|
// Transparently enable the display.
|
||||||
|
if err := d.sendCommand(nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.conn.Tx(data, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) sendCommand(data []byte) error {
|
||||||
|
if d.halted {
|
||||||
|
// Transparently enable the display.
|
||||||
|
data = append([]byte{0xAF}, data...)
|
||||||
|
d.halted = false
|
||||||
|
}
|
||||||
|
return d.conn.Tx(data, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) PowerSave(on bool) error {
|
||||||
|
var cmd []byte
|
||||||
|
if on {
|
||||||
|
cmd = []byte{
|
||||||
|
0xAB, 0x01, // enable internal VDD regulator
|
||||||
|
0xAF, // display on
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmd = []byte{
|
||||||
|
0xAB, 0x00, // disable internal VDD regulator
|
||||||
|
0xAE, // display off
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.sendCommand(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Halt turns off the display.
|
||||||
|
//
|
||||||
|
// Sending any other command afterward reenables the display.
|
||||||
|
func (d *Display) Halt() error {
|
||||||
|
d.halted = false
|
||||||
|
err := d.PowerSave(true)
|
||||||
|
if err == nil {
|
||||||
|
d.halted = true
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size of the display.
|
||||||
|
func (d *Display) Size() image.Point {
|
||||||
|
return image.Pt(int(d.width), int(d.height))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw implements display.Drawer.
|
||||||
|
//
|
||||||
|
// It draws synchronously, once this function returns, the display is updated.
|
||||||
|
// It means that on slow bus (I²C), it may be preferable to defer Draw() calls
|
||||||
|
// to a background goroutine.
|
||||||
|
func (d *Display) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
|
||||||
|
logrus.Debug("draw image")
|
||||||
|
draw.Draw(d, r, src, sp, draw.Src)
|
||||||
|
return d.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) Invert(on bool) error {
|
||||||
|
if on {
|
||||||
|
return d.sendCommand([]byte{0xA7})
|
||||||
|
}
|
||||||
|
return d.sendCommand([]byte{0xA6})
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hardware.Display interface methods */
|
||||||
|
|
||||||
|
func (d *Display) Clear() {
|
||||||
|
for i := range d.buffer {
|
||||||
|
d.buffer[i] = 0x00
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) Fill(c color.Color) error {
|
||||||
|
return d.Draw(d.Bounds(), &image.Uniform{c}, image.Point{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) Refresh() error {
|
||||||
|
var (
|
||||||
|
offset = (480 - d.width) / 2
|
||||||
|
colStart = offset / 4
|
||||||
|
colEnd = colStart + d.width/4 - 1
|
||||||
|
)
|
||||||
|
if err := d.sendCommand([]byte{
|
||||||
|
0x15, byte(colStart), byte(colEnd),
|
||||||
|
0x75, 0, byte(d.height - 1),
|
||||||
|
0x5c,
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return d.sendData(d.buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRotation changes the rotation of the device (clock-wise).
|
||||||
|
func (d *Display) SetRotation(rotation display.Rotation) error {
|
||||||
|
d.rotation = rotation
|
||||||
|
|
||||||
|
var command []byte
|
||||||
|
switch d.rotation {
|
||||||
|
case display.NoRotation:
|
||||||
|
command = []byte{
|
||||||
|
segRemap | 0x1, // Reverse horizontal mapping
|
||||||
|
comScanDec, // Reverse vertical mapping
|
||||||
|
}
|
||||||
|
case display.Rotate180:
|
||||||
|
command = []byte{
|
||||||
|
segRemap, // Normal horizontal mapping
|
||||||
|
comScanInc, // Normal vertical mapping
|
||||||
|
}
|
||||||
|
// nothing to do
|
||||||
|
default:
|
||||||
|
command = []byte{
|
||||||
|
segRemap | 0x1, // Reverse horizontal mapping
|
||||||
|
comScanDec, // Reverse vertical mapping
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.sendCommand(command)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* draw.Image interface methods */
|
||||||
|
|
||||||
|
func (d *Display) rotate(x, y int) (int, int) {
|
||||||
|
switch d.rotation {
|
||||||
|
case display.Rotate90:
|
||||||
|
x, y = y, x
|
||||||
|
x = int(d.width) - x - 1
|
||||||
|
case display.Rotate180:
|
||||||
|
x = int(d.width) - x - 1
|
||||||
|
y = int(d.height) - y - 1
|
||||||
|
case display.Rotate270:
|
||||||
|
x, y = y, x
|
||||||
|
y = int(d.height) - y - 1
|
||||||
|
}
|
||||||
|
return x, y
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) At(x, y int) color.Color {
|
||||||
|
x, y = d.rotate(x, y)
|
||||||
|
if x < 0 || int16(x) >= d.width || y < 0 || int16(y) >= d.height {
|
||||||
|
return pixel.Off
|
||||||
|
}
|
||||||
|
|
||||||
|
byteIndex := int16(x) + int16(y/8)*d.width
|
||||||
|
if d.buffer[byteIndex]>>uint8(y%8)&0x1 == 1 {
|
||||||
|
return pixel.On
|
||||||
|
}
|
||||||
|
return pixel.Off
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) Bounds() image.Rectangle {
|
||||||
|
return image.Rect(0, 0, int(d.width), int(d.height))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) ColorModel() color.Model {
|
||||||
|
return pixel.MonochromeModel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Display) Set(x, y int, c color.Color) {
|
||||||
|
x, y = d.rotate(x, y)
|
||||||
|
if x < 0 || int16(x) >= d.width || y < 0 || int16(y) >= d.height {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
byteIndex := int16(x) + int16(y>>3)*d.width
|
||||||
|
if pixel.IsOn(c) {
|
||||||
|
d.buffer[byteIndex] |= 1 << uint8(y%8)
|
||||||
|
} else {
|
||||||
|
d.buffer[byteIndex] &^= 1 << uint8(y%8)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package ssd1xxx
|
||||||
|
|
||||||
|
// Config describes the OLED configuration.
|
||||||
|
type Config struct {
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
|
ExternalVCC bool
|
||||||
|
Init []Command
|
||||||
|
Suspend []Command
|
||||||
|
Resume []Command
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command is one or more command bytes.
|
||||||
|
type Command interface {
|
||||||
|
Bytes() []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type Register byte
|
||||||
|
|
||||||
|
func (r Register) Bytes() []byte { return []byte{byte(r)} }
|
||||||
|
|
||||||
|
type RegisterArgs struct {
|
||||||
|
Register Register
|
||||||
|
Args []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r RegisterArgs) Bytes() []byte { return append([]byte{byte(r.Register)}, r.Args...) }
|
||||||
|
|
||||||
|
type RegisterFunc struct {
|
||||||
|
Register Register
|
||||||
|
Func func() []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r RegisterFunc) Bytes() []byte {
|
||||||
|
args := r.Func()
|
||||||
|
return append([]byte{byte(r.Register)}, args...)
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package st7735
|
||||||
|
|
||||||
|
import "go.maze.io/harmon/hardware/display"
|
||||||
|
|
||||||
|
// Registers
|
||||||
|
const (
|
||||||
|
NOP = 0x00
|
||||||
|
SWRESET = 0x01
|
||||||
|
RDDID = 0x04
|
||||||
|
RDDST = 0x09
|
||||||
|
SLPIN = 0x10
|
||||||
|
SLPOUT = 0x11
|
||||||
|
PTLON = 0x12
|
||||||
|
NORON = 0x13
|
||||||
|
INVOFF = 0x20
|
||||||
|
INVON = 0x21
|
||||||
|
DISPOFF = 0x28
|
||||||
|
DISPON = 0x29
|
||||||
|
CASET = 0x2A
|
||||||
|
RASET = 0x2B
|
||||||
|
RAMWR = 0x2C
|
||||||
|
RAMRD = 0x2E
|
||||||
|
PTLAR = 0x30
|
||||||
|
COLMOD = 0x3A
|
||||||
|
MADCTL = 0x36
|
||||||
|
MADCTL_MY = 0x80
|
||||||
|
MADCTL_MX = 0x40
|
||||||
|
MADCTL_MV = 0x20
|
||||||
|
MADCTL_ML = 0x10
|
||||||
|
MADCTL_RGB = 0x00
|
||||||
|
MADCTL_BGR = 0x08
|
||||||
|
MADCTL_MH = 0x04
|
||||||
|
RDID1 = 0xDA
|
||||||
|
RDID2 = 0xDB
|
||||||
|
RDID3 = 0xDC
|
||||||
|
RDID4 = 0xDD
|
||||||
|
FRMCTR1 = 0xB1
|
||||||
|
FRMCTR2 = 0xB2
|
||||||
|
FRMCTR3 = 0xB3
|
||||||
|
INVCTR = 0xB4
|
||||||
|
DISSET5 = 0xB6
|
||||||
|
PWCTR1 = 0xC0
|
||||||
|
PWCTR2 = 0xC1
|
||||||
|
PWCTR3 = 0xC2
|
||||||
|
PWCTR4 = 0xC3
|
||||||
|
PWCTR5 = 0xC4
|
||||||
|
VMCTR1 = 0xC5
|
||||||
|
PWCTR6 = 0xFC
|
||||||
|
GMCTRP1 = 0xE0
|
||||||
|
GMCTRN1 = 0xE1
|
||||||
|
VSCRDEF = 0x33
|
||||||
|
VSCRSADD = 0x37
|
||||||
|
|
||||||
|
GREENTAB Model = 0
|
||||||
|
MINI80x160 Model = 1
|
||||||
|
|
||||||
|
NO_ROTATION display.Rotation = 0
|
||||||
|
ROTATION_90 display.Rotation = 1 // 90 degrees clock-wise rotation
|
||||||
|
ROTATION_180 display.Rotation = 2
|
||||||
|
ROTATION_270 display.Rotation = 3
|
||||||
|
)
|
||||||
@@ -0,0 +1,836 @@
|
|||||||
|
package st7735
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"go.maze.io/harmon/config"
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"go.maze.io/harmon/hardware/display"
|
||||||
|
"go.maze.io/harmon/internal/spidev"
|
||||||
|
"periph.io/x/conn/v3/gpio"
|
||||||
|
"periph.io/x/conn/v3/physic"
|
||||||
|
//"periph.io/x/conn/v3/spi"
|
||||||
|
//"periph.io/x/conn/v3/spi/spireg"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
ST7735_SWRESET = 0x01
|
||||||
|
ST7735_SLPIN = 0x10
|
||||||
|
ST7735_SLPOUT = 0x11
|
||||||
|
ST7735_FRMCTR1 = 0xB1
|
||||||
|
ST7735_FRMCTR2 = 0xB2
|
||||||
|
ST7735_FRMCTR3 = 0xB3
|
||||||
|
ST7735_INVCTR = 0xB4
|
||||||
|
ST7735_INVOFF = 0x20
|
||||||
|
ST7735_INVON = 0x21
|
||||||
|
ST7735_PWCTR1 = 0xC0
|
||||||
|
ST7735_PWCTR2 = 0xC1
|
||||||
|
ST7735_PWCTR4 = 0xC3
|
||||||
|
ST7735_PWCTR5 = 0xC4
|
||||||
|
ST7735_VMCTR1 = 0xC5
|
||||||
|
ST7735_MADCTL = 0x36
|
||||||
|
ST7735_COLMOD = 0x3A
|
||||||
|
ST7735_CASET = 0x2A
|
||||||
|
ST7735_RASET = 0x2B
|
||||||
|
ST7735_RAMWR = 0x2C
|
||||||
|
ST7735_GMCTRP1 = 0xE0
|
||||||
|
ST7735_GMCTRN1 = 0xE1
|
||||||
|
ST7735_NORON = 0x13
|
||||||
|
ST7735_DISPON = 0x29
|
||||||
|
ST7735_TFTWIDTH = 80
|
||||||
|
ST7735_TFTHEIGHT = 160
|
||||||
|
ST7735_COLS = 132
|
||||||
|
ST7735_ROWS = 162
|
||||||
|
|
||||||
|
ChunkSize = 4096
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
display.Register("st7735", newDriver)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDriver(config config.DisplayConfig) (hardware.Display, error) {
|
||||||
|
var (
|
||||||
|
opts *display.Options
|
||||||
|
//port spi.PortCloser
|
||||||
|
//conn spi.Conn
|
||||||
|
conn *spidev.SPI
|
||||||
|
reset, dc, bl gpio.PinOut
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if opts, err = display.ParseOptions(config, 240, 240); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log := logrus.WithFields(logrus.Fields{
|
||||||
|
"type": "st7735",
|
||||||
|
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
|
||||||
|
"rotate": opts.Rotate,
|
||||||
|
})
|
||||||
|
log.Debug("new driver")
|
||||||
|
|
||||||
|
if reset, err = hardware.LookupPin(config.Reset); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if dc, err = hardware.LookupPin(config.DC); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if bl, err = hardware.LookupPin(config.BL); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const speed = 40000000 * physic.Hertz
|
||||||
|
log.WithFields(logrus.Fields{
|
||||||
|
"port": config.Port,
|
||||||
|
"pin_reset": reset,
|
||||||
|
"pin_dc": dc,
|
||||||
|
"pin_bl": bl,
|
||||||
|
"speed": speed,
|
||||||
|
"bits": 8,
|
||||||
|
//"mode": spi.Mode0,
|
||||||
|
}).Debug("opening SPI port")
|
||||||
|
/*
|
||||||
|
if port, err = spireg.Open(config.Port); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if conn, err = port.Connect(speed, spi.Mode0, 8); err != nil {
|
||||||
|
_ = port.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
if conn, err = spidev.Open("/dev/spidev0.0"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
conn.SetMode(0)
|
||||||
|
conn.SetBitsPerWord(8)
|
||||||
|
//conn.SetLSBFirst(false)
|
||||||
|
conn.SetSpeedHz(uint32(speed / physic.Hertz))
|
||||||
|
|
||||||
|
/*
|
||||||
|
d := &Dev{
|
||||||
|
c: conn,
|
||||||
|
dc: dc,
|
||||||
|
rst: reset,
|
||||||
|
backlight: bl,
|
||||||
|
opts: Opts{
|
||||||
|
Width: byte(opts.W),
|
||||||
|
Height: byte(opts.H),
|
||||||
|
OffsetLeft: byte(ST7735_COLS-opts.W) / 2,
|
||||||
|
OffsetTop: byte(ST7735_ROWS-opts.H) / 2,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return d, nil
|
||||||
|
*/
|
||||||
|
d := newDevice(conn, reset, dc, bl)
|
||||||
|
d.Configure(Config{
|
||||||
|
Width: int16(opts.W),
|
||||||
|
Height: int16(opts.H),
|
||||||
|
Rotation: opts.Rotate,
|
||||||
|
})
|
||||||
|
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Model uint8
|
||||||
|
|
||||||
|
// Device wraps an SPI connection.
|
||||||
|
type Device struct {
|
||||||
|
bus *spidev.SPI
|
||||||
|
dcPin gpio.PinOut
|
||||||
|
resetPin gpio.PinOut
|
||||||
|
blPin gpio.PinOut
|
||||||
|
width int16
|
||||||
|
height int16
|
||||||
|
columnOffset int16
|
||||||
|
rowOffset int16
|
||||||
|
rotation display.Rotation
|
||||||
|
batchLength int16
|
||||||
|
model Model
|
||||||
|
isBGR bool
|
||||||
|
batchData []uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config is the configuration for the display
|
||||||
|
type Config struct {
|
||||||
|
Width int16
|
||||||
|
Height int16
|
||||||
|
Rotation display.Rotation
|
||||||
|
Model Model
|
||||||
|
RowOffset int16
|
||||||
|
ColumnOffset int16
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new ST7735 connection. The SPI wire must already be configured.
|
||||||
|
// func newDevice(bus spi.Conn, resetPin, dcPin, blPin gpio.PinOut) *Device {
|
||||||
|
func newDevice(bus *spidev.SPI, resetPin, dcPin, blPin gpio.PinOut) *Device {
|
||||||
|
return &Device{
|
||||||
|
bus: bus,
|
||||||
|
dcPin: dcPin,
|
||||||
|
resetPin: resetPin,
|
||||||
|
blPin: blPin,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure initializes the display with default configuration
|
||||||
|
func (d *Device) Configure(cfg Config) {
|
||||||
|
d.model = cfg.Model
|
||||||
|
if cfg.Width != 0 {
|
||||||
|
d.width = cfg.Width
|
||||||
|
} else {
|
||||||
|
if d.model == MINI80x160 {
|
||||||
|
d.width = 80
|
||||||
|
} else {
|
||||||
|
d.width = 128
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cfg.Height != 0 {
|
||||||
|
d.height = cfg.Height
|
||||||
|
} else {
|
||||||
|
d.height = 160
|
||||||
|
}
|
||||||
|
d.rotation = cfg.Rotation
|
||||||
|
d.rowOffset = cfg.RowOffset
|
||||||
|
d.columnOffset = cfg.ColumnOffset
|
||||||
|
|
||||||
|
d.batchLength = d.width
|
||||||
|
if d.height > d.width {
|
||||||
|
d.batchLength = d.height
|
||||||
|
}
|
||||||
|
d.batchLength += d.batchLength & 1
|
||||||
|
d.batchData = make([]uint8, d.batchLength*2)
|
||||||
|
|
||||||
|
// reset the device
|
||||||
|
d.resetPin.Out(gpio.High)
|
||||||
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
d.resetPin.Out(gpio.Low)
|
||||||
|
time.Sleep(20 * time.Millisecond)
|
||||||
|
d.resetPin.Out(gpio.High)
|
||||||
|
time.Sleep(150 * time.Millisecond)
|
||||||
|
|
||||||
|
println("display reset done")
|
||||||
|
|
||||||
|
// Common initialization
|
||||||
|
d.Command(SWRESET)
|
||||||
|
time.Sleep(150 * time.Millisecond)
|
||||||
|
d.Command(SLPOUT)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
d.Command(FRMCTR1)
|
||||||
|
d.Data(0x01)
|
||||||
|
d.Data(0x2C)
|
||||||
|
d.Data(0x2D)
|
||||||
|
d.Command(FRMCTR2)
|
||||||
|
d.Data(0x01)
|
||||||
|
d.Data(0x2C)
|
||||||
|
d.Data(0x2D)
|
||||||
|
d.Command(FRMCTR3)
|
||||||
|
d.Data(0x01)
|
||||||
|
d.Data(0x2C)
|
||||||
|
d.Data(0x2D)
|
||||||
|
d.Data(0x01)
|
||||||
|
d.Data(0x2C)
|
||||||
|
d.Data(0x2D)
|
||||||
|
d.Command(INVCTR)
|
||||||
|
d.Data(0x07)
|
||||||
|
d.Command(PWCTR1)
|
||||||
|
d.Data(0xA2)
|
||||||
|
d.Data(0x02)
|
||||||
|
d.Data(0x84)
|
||||||
|
d.Command(PWCTR2)
|
||||||
|
d.Data(0xC5)
|
||||||
|
d.Command(PWCTR3)
|
||||||
|
d.Data(0x0A)
|
||||||
|
d.Data(0x00)
|
||||||
|
d.Command(PWCTR4)
|
||||||
|
d.Data(0x8A)
|
||||||
|
d.Data(0x2A)
|
||||||
|
d.Command(PWCTR5)
|
||||||
|
d.Data(0x8A)
|
||||||
|
d.Data(0xEE)
|
||||||
|
d.Command(VMCTR1)
|
||||||
|
d.Data(0x0E)
|
||||||
|
d.Command(COLMOD)
|
||||||
|
d.Data(0x05)
|
||||||
|
|
||||||
|
if d.model == GREENTAB {
|
||||||
|
d.InvertColors(false)
|
||||||
|
} else if d.model == MINI80x160 {
|
||||||
|
d.isBGR = true
|
||||||
|
d.InvertColors(true)
|
||||||
|
}
|
||||||
|
println("display config done")
|
||||||
|
|
||||||
|
// common color adjustment
|
||||||
|
d.Command(GMCTRP1)
|
||||||
|
d.Data(0x02)
|
||||||
|
d.Data(0x1C)
|
||||||
|
d.Data(0x07)
|
||||||
|
d.Data(0x12)
|
||||||
|
d.Data(0x37)
|
||||||
|
d.Data(0x32)
|
||||||
|
d.Data(0x29)
|
||||||
|
d.Data(0x2D)
|
||||||
|
d.Data(0x29)
|
||||||
|
d.Data(0x25)
|
||||||
|
d.Data(0x2B)
|
||||||
|
d.Data(0x39)
|
||||||
|
d.Data(0x00)
|
||||||
|
d.Data(0x01)
|
||||||
|
d.Data(0x03)
|
||||||
|
d.Data(0x10)
|
||||||
|
d.Command(GMCTRN1)
|
||||||
|
d.Data(0x03)
|
||||||
|
d.Data(0x1D)
|
||||||
|
d.Data(0x07)
|
||||||
|
d.Data(0x06)
|
||||||
|
d.Data(0x2E)
|
||||||
|
d.Data(0x2C)
|
||||||
|
d.Data(0x29)
|
||||||
|
d.Data(0x2D)
|
||||||
|
d.Data(0x2E)
|
||||||
|
d.Data(0x2E)
|
||||||
|
d.Data(0x37)
|
||||||
|
d.Data(0x3F)
|
||||||
|
d.Data(0x00)
|
||||||
|
d.Data(0x00)
|
||||||
|
d.Data(0x02)
|
||||||
|
d.Data(0x10)
|
||||||
|
|
||||||
|
println("display color correction done")
|
||||||
|
|
||||||
|
d.Command(NORON)
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
d.Command(DISPON)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
|
if cfg.Model == MINI80x160 {
|
||||||
|
d.Command(MADCTL)
|
||||||
|
d.Data(0xC0)
|
||||||
|
}
|
||||||
|
|
||||||
|
d.SetRotation(d.rotation)
|
||||||
|
|
||||||
|
println("display rotation set")
|
||||||
|
|
||||||
|
d.blPin.Out(gpio.High)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display does nothing, there's no buffer as it might be too big for some boards
|
||||||
|
func (d *Device) Display() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPixel sets a pixel in the screen
|
||||||
|
func (d *Device) SetPixel(x int16, y int16, c color.RGBA) {
|
||||||
|
w, h := d.size()
|
||||||
|
if x < 0 || y < 0 || x >= w || y >= h {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.FillRectangle(x, y, 1, 1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// setWindow prepares the screen to be modified at a given rectangle
|
||||||
|
func (d *Device) setWindow(x, y, w, h int16) {
|
||||||
|
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
|
||||||
|
x += d.columnOffset
|
||||||
|
y += d.rowOffset
|
||||||
|
} else {
|
||||||
|
x += d.rowOffset
|
||||||
|
y += d.columnOffset
|
||||||
|
}
|
||||||
|
d.Tx([]uint8{CASET}, true)
|
||||||
|
d.Tx([]uint8{uint8(x >> 8), uint8(x), uint8((x + w - 1) >> 8), uint8(x + w - 1)}, false)
|
||||||
|
d.Tx([]uint8{RASET}, true)
|
||||||
|
d.Tx([]uint8{uint8(y >> 8), uint8(y), uint8((y + h - 1) >> 8), uint8(y + h - 1)}, false)
|
||||||
|
d.Command(RAMWR)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetScrollWindow sets an area to scroll with fixed top and bottom parts of the display
|
||||||
|
func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) {
|
||||||
|
d.Command(VSCRDEF)
|
||||||
|
d.Tx([]uint8{
|
||||||
|
uint8(topFixedArea >> 8), uint8(topFixedArea),
|
||||||
|
uint8(d.height - topFixedArea - bottomFixedArea>>8), uint8(d.height - topFixedArea - bottomFixedArea),
|
||||||
|
uint8(bottomFixedArea >> 8), uint8(bottomFixedArea)},
|
||||||
|
false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetScroll sets the vertical scroll address of the display.
|
||||||
|
func (d *Device) SetScroll(line int16) {
|
||||||
|
d.Command(VSCRSADD)
|
||||||
|
d.Tx([]uint8{uint8(line >> 8), uint8(line)}, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpotScroll returns the display to its normal state
|
||||||
|
func (d *Device) StopScroll() {
|
||||||
|
d.Command(NORON)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillRectangle fills a rectangle at a given coordinates with a color
|
||||||
|
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
|
||||||
|
k, i := d.size()
|
||||||
|
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
|
||||||
|
x >= k || (x+width) > k || y >= i || (y+height) > i {
|
||||||
|
return errors.New("rectangle coordinates outside display area")
|
||||||
|
}
|
||||||
|
d.setWindow(x, y, width, height)
|
||||||
|
|
||||||
|
c565 := 65535
|
||||||
|
c1 := uint8(c565 >> 8)
|
||||||
|
c2 := uint8(c565)
|
||||||
|
|
||||||
|
for i = 0; i < d.batchLength; i++ {
|
||||||
|
d.batchData[i*2] = c1
|
||||||
|
d.batchData[i*2+1] = c2
|
||||||
|
}
|
||||||
|
i = width * height
|
||||||
|
for i > 0 {
|
||||||
|
if i >= d.batchLength {
|
||||||
|
d.Tx(d.batchData, false)
|
||||||
|
} else {
|
||||||
|
d.Tx(d.batchData[:i*2], false)
|
||||||
|
}
|
||||||
|
i -= d.batchLength
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillRectangle fills a rectangle at a given coordinates with a buffer
|
||||||
|
func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
|
||||||
|
k, l := d.size()
|
||||||
|
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
|
||||||
|
x >= k || (x+width) > k || y >= l || (y+height) > l {
|
||||||
|
//return errors.New("rectangle coordinates outside display area")
|
||||||
|
return fmt.Errorf("rectangle [%d %d %d %d] outside of [0 0 %d %d]", x, y, width, height, k, l)
|
||||||
|
}
|
||||||
|
k = width * height
|
||||||
|
l = int16(len(buffer))
|
||||||
|
if k != l {
|
||||||
|
return errors.New("buffer length does not match with rectangle size")
|
||||||
|
}
|
||||||
|
|
||||||
|
d.setWindow(x, y, width, height)
|
||||||
|
|
||||||
|
offset := int16(0)
|
||||||
|
for k > 0 {
|
||||||
|
for i := int16(0); i < d.batchLength; i++ {
|
||||||
|
if offset+i < l {
|
||||||
|
c565 := 65535
|
||||||
|
c1 := uint8(c565 >> 8)
|
||||||
|
c2 := uint8(c565)
|
||||||
|
d.batchData[i*2] = c1
|
||||||
|
d.batchData[i*2+1] = c2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k >= d.batchLength {
|
||||||
|
d.Tx(d.batchData, false)
|
||||||
|
} else {
|
||||||
|
d.Tx(d.batchData[:k*2], false)
|
||||||
|
}
|
||||||
|
k -= d.batchLength
|
||||||
|
offset += d.batchLength
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DrawFastVLine draws a vertical line faster than using SetPixel
|
||||||
|
func (d *Device) DrawFastVLine(x, y0, y1 int16, c color.RGBA) {
|
||||||
|
if y0 > y1 {
|
||||||
|
y0, y1 = y1, y0
|
||||||
|
}
|
||||||
|
d.FillRectangle(x, y0, 1, y1-y0+1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DrawFastHLine draws a horizontal line faster than using SetPixel
|
||||||
|
func (d *Device) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
|
||||||
|
if x0 > x1 {
|
||||||
|
x0, x1 = x1, x0
|
||||||
|
}
|
||||||
|
d.FillRectangle(x0, y, x1-x0+1, 1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillScreen fills the screen with a given color
|
||||||
|
func (d *Device) FillScreen(c color.RGBA) {
|
||||||
|
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
|
||||||
|
d.FillRectangle(0, 0, d.width, d.height, c)
|
||||||
|
} else {
|
||||||
|
d.FillRectangle(0, 0, d.height, d.width, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRotation changes the rotation of the device (clock-wise)
|
||||||
|
func (d *Device) SetRotation(rotation display.Rotation) {
|
||||||
|
madctl := uint8(0)
|
||||||
|
switch rotation % 4 {
|
||||||
|
case 0:
|
||||||
|
madctl = MADCTL_MX | MADCTL_MY
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
madctl = MADCTL_MY | MADCTL_MV
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
break
|
||||||
|
case 3:
|
||||||
|
madctl = MADCTL_MX | MADCTL_MV
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if d.isBGR {
|
||||||
|
madctl |= MADCTL_BGR
|
||||||
|
}
|
||||||
|
d.Command(MADCTL)
|
||||||
|
d.Data(madctl)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command sends a command to the display
|
||||||
|
func (d *Device) Command(command uint8) {
|
||||||
|
d.Tx([]byte{command}, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command sends a data to the display
|
||||||
|
func (d *Device) Data(data uint8) {
|
||||||
|
d.Tx([]byte{data}, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx sends data to the display
|
||||||
|
func (d *Device) Tx(data []byte, isCommand bool) {
|
||||||
|
d.dcPin.Out(gpio.Level(!isCommand))
|
||||||
|
//d.bus.Tx(data, nil)
|
||||||
|
d.bus.Transfer([]spidev.Transfer{{Tx: data}})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size returns the current size of the display.
|
||||||
|
func (d *Device) size() (w, h int16) {
|
||||||
|
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
|
||||||
|
return d.width, d.height
|
||||||
|
}
|
||||||
|
return d.height, d.width
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableBacklight enables or disables the backlight
|
||||||
|
func (d *Device) EnableBacklight(enable bool) {
|
||||||
|
if enable {
|
||||||
|
d.blPin.Out(gpio.High)
|
||||||
|
} else {
|
||||||
|
d.blPin.Out(gpio.Low)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InverColors inverts the colors of the screen
|
||||||
|
func (d *Device) InvertColors(invert bool) {
|
||||||
|
if invert {
|
||||||
|
d.Command(INVON)
|
||||||
|
} else {
|
||||||
|
d.Command(INVOFF)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBGR changes the color mode (RGB/BGR)
|
||||||
|
func (d *Device) IsBGR(bgr bool) {
|
||||||
|
d.isBGR = bgr
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
// Dev is a handle to a ST7735
|
||||||
|
type Dev struct {
|
||||||
|
c conn.Conn
|
||||||
|
|
||||||
|
// dc low when sending a command, high when sending data.
|
||||||
|
dc gpio.PinOut
|
||||||
|
// rst reset pin, active low.
|
||||||
|
rst gpio.PinOut
|
||||||
|
// backlight pin
|
||||||
|
backlight gpio.PinOut
|
||||||
|
|
||||||
|
opts Opts
|
||||||
|
}
|
||||||
|
|
||||||
|
// Opts contains the configuration fot the ST7735 device
|
||||||
|
type Opts struct {
|
||||||
|
Width byte
|
||||||
|
Height byte
|
||||||
|
OffsetLeft byte
|
||||||
|
OffsetTop byte
|
||||||
|
}
|
||||||
|
|
||||||
|
var DefaultOpts = Opts{
|
||||||
|
Width: ST7735_TFTWIDTH,
|
||||||
|
Height: ST7735_TFTHEIGHT,
|
||||||
|
OffsetLeft: (ST7735_COLS - ST7735_TFTWIDTH) / 2, // (132-80)/2 = 26
|
||||||
|
OffsetTop: (ST7735_ROWS - ST7735_TFTHEIGHT) / 2, // (162-160)/2 = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// New opens a handle to a ST7735
|
||||||
|
func New(p spi.Port, dc gpio.PinOut, rst gpio.PinOut, backlight gpio.PinOut, o *Opts) (*Dev, error) {
|
||||||
|
c, err := p.Connect(4000*physic.KiloHertz, spi.Mode0, 8)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("could not connect to device")
|
||||||
|
}
|
||||||
|
|
||||||
|
d := &Dev{
|
||||||
|
c: c,
|
||||||
|
dc: dc,
|
||||||
|
rst: rst,
|
||||||
|
backlight: backlight,
|
||||||
|
opts: *o,
|
||||||
|
}
|
||||||
|
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) Init() error {
|
||||||
|
if err := d.Backlight(true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
invert := commandAndData{[]byte{ST7735_INVON}, nil, 0} // don't invert
|
||||||
|
if false {
|
||||||
|
invert = commandAndData{[]byte{ST7735_INVOFF}, nil, 0} // invert
|
||||||
|
}
|
||||||
|
|
||||||
|
width := d.opts.Width
|
||||||
|
height := d.opts.Height
|
||||||
|
offsetLeft := d.opts.OffsetLeft
|
||||||
|
offsetTop := d.opts.OffsetTop
|
||||||
|
|
||||||
|
init := []commandAndData{
|
||||||
|
{[]byte{ST7735_SWRESET}, nil, 150 * time.Millisecond}, // software reset
|
||||||
|
{[]byte{ST7735_SLPOUT}, nil, 500 * time.Millisecond}, // out of sleep mode
|
||||||
|
{[]byte{ST7735_FRMCTR1}, []byte{0x01, 0x2C, 0x2D}, 0}, // frame rate ctrl - normal mode, rate = fosc/(1x2+40) * (LINE+2C+2D)
|
||||||
|
{[]byte{ST7735_FRMCTR2}, []byte{0x01, 0x2C, 0x2D}, 0}, // frame rate crtl - idle mode, rate = fosc(1x2+40) * (LINE+2C+2D)
|
||||||
|
{[]byte{ST7735_FRMCTR3}, []byte{0x01, 0x2C, 0x2D, 0x01, 0x2C, 0x2D}, 0}, // frame rate ctrl - partial mode
|
||||||
|
{[]byte{ST7735_INVCTR}, []byte{0x07}, 0}, // display inversion ctrl - no inversion
|
||||||
|
{[]byte{ST7735_PWCTR1}, []byte{0xA2, 0x02, 0x84}, 0}, // power control, -4.6V, auto mode
|
||||||
|
{[]byte{ST7735_PWCTR2}, []byte{0x0A, 0x00}, 0}, // power control, Opamp current small, boost frequency
|
||||||
|
{[]byte{ST7735_PWCTR4}, []byte{0x8A, 0x2A}, 0}, // power control, BCLK/2, Opamp current small & Medium low
|
||||||
|
{[]byte{ST7735_PWCTR5}, []byte{0x8A, 0xEE}, 0}, // power control
|
||||||
|
{[]byte{ST7735_VMCTR1}, []byte{0x0E}, 0}, // power control
|
||||||
|
invert,
|
||||||
|
{[]byte{ST7735_MADCTL}, []byte{0xC8}, 0}, // memory access control (directions), row addr/col addr, bottom to top refresh
|
||||||
|
{[]byte{ST7735_COLMOD}, []byte{0x05}, 0}, // set color mode, 16-bit color
|
||||||
|
{[]byte{ST7735_CASET}, []byte{0x00, offsetLeft, 0x00, width + offsetLeft - 1}, 0}, // Column addr set, XSTART = 0, XEND = ROWS-height
|
||||||
|
{[]byte{ST7735_RASET}, []byte{0x00, offsetTop, 0x00, height + offsetTop - 1}, 0}, // Row addr set, XSTART = 0, XEND = COLS-width
|
||||||
|
{[]byte{ST7735_GMCTRP1}, []byte{0x02, 0x1c, 0x07, 0x12, // set gamma
|
||||||
|
0x37, 0x32, 0x29, 0x2d, 0x29, 0x25, 0x2B, 0x39, 0x00,
|
||||||
|
0x01, 0x03, 0x10}, 0},
|
||||||
|
{[]byte{ST7735_GMCTRN1}, []byte{0x03, 0x1d, 0x07, 0x06, // set gamma
|
||||||
|
0x2E, 0x2C, 0x29, 0x2D, 0x2E, 0x2E, 0x37, 0x3F, 0x00,
|
||||||
|
0x00, 0x02, 0x10}, 0},
|
||||||
|
{[]byte{ST7735_NORON}, nil, 100 * time.Millisecond}, // normal display on
|
||||||
|
{[]byte{ST7735_DISPON}, nil, 100 * time.Millisecond}, // display on
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.sendBatch(init)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) Powersave() error {
|
||||||
|
return d.sendCommand([]byte{ST7735_SLPIN})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) SetBacklight(value bool) {
|
||||||
|
if d.backlight == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if value {
|
||||||
|
d.backlight.Out(gpio.High)
|
||||||
|
} else {
|
||||||
|
d.backlight.Out(gpio.Low)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) SetWindow(x0, y0, x1, y1 int) error {
|
||||||
|
y0 += int(d.opts.OffsetTop)
|
||||||
|
y1 += int(d.opts.OffsetTop)
|
||||||
|
|
||||||
|
x0 += int(d.opts.OffsetLeft)
|
||||||
|
x1 += int(d.opts.OffsetLeft)
|
||||||
|
|
||||||
|
commands := []commandAndData{
|
||||||
|
{[]byte{ST7735_CASET}, []byte{byte(x0 >> 8), byte(x0), byte(x1 >> 8), byte(x1)}, 0}, // column addr set
|
||||||
|
{[]byte{ST7735_RASET}, []byte{byte(y0 >> 8), byte(y0), byte(y1 >> 8), byte(y1)}, 0}, // row addr set
|
||||||
|
{[]byte{ST7735_RAMWR}, nil, 0}, // write to RAM
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.sendBatch(commands)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) DisplayImage(x, y int, img *image.RGBA) error {
|
||||||
|
offsetBounds := img.Bounds().Add(image.Point{X: x, Y: y})
|
||||||
|
maxBounds := image.Rectangle{Min: image.Point{0, 0}, Max: image.Point{int(d.opts.Width), int(d.opts.Height)}}
|
||||||
|
offsetBounds = offsetBounds.Intersect(maxBounds)
|
||||||
|
bounds := offsetBounds.Sub(image.Point{X: x, Y: y})
|
||||||
|
|
||||||
|
err := d.SetWindow(offsetBounds.Min.X, offsetBounds.Min.Y, offsetBounds.Max.X-1, offsetBounds.Max.Y-1)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
subImg := img.SubImage(bounds)
|
||||||
|
|
||||||
|
buf := []byte{}
|
||||||
|
for x := bounds.Min.X; x < bounds.Max.X; x++ {
|
||||||
|
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
|
||||||
|
c := subImg.At(x, y)
|
||||||
|
|
||||||
|
cd := RGBATo565(c.(color.RGBA))
|
||||||
|
buf = append(buf, byte(cd>>8), byte(cd))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.sendData(buf)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) Display(data []byte) error {
|
||||||
|
err := d.SetWindow(0, 0, int(d.opts.Width-1), int(d.opts.Height-1))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.sendData(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) Halt() error {
|
||||||
|
d.SetBacklight(false)
|
||||||
|
return d.Powersave()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) sendCommand(c []byte) error {
|
||||||
|
if err := d.dc.Out(gpio.Low); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return d.c.Tx(c, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) sendData(c []byte) error {
|
||||||
|
if err := d.dc.Out(gpio.High); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for offset := 0; offset < len(c); offset += ChunkSize {
|
||||||
|
end := offset + ChunkSize
|
||||||
|
if end > len(c) {
|
||||||
|
end = len(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.c.Tx(c[offset:end], nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dev) sendBatch(commands []commandAndData) error {
|
||||||
|
for _, cad := range commands {
|
||||||
|
if err := d.sendCommand(cad.cmd); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cad.data) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := d.sendData(cad.data); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cad.sleep > 0 {
|
||||||
|
time.Sleep(cad.sleep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type commandAndData struct {
|
||||||
|
cmd []byte
|
||||||
|
data []byte
|
||||||
|
sleep time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
// RGBATo565 converts a color.RGBA to uint16 used in the display
|
||||||
|
func RGBATo565(c color.RGBA) uint16 {
|
||||||
|
r, g, b, _ := c.RGBA()
|
||||||
|
return uint16((r & 0xF800) +
|
||||||
|
((g & 0xFC00) >> 5) +
|
||||||
|
((b & 0xF800) >> 11))
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
func (d *Device) At(i, j int) color.Color {
|
||||||
|
return color.Black
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Backlight(on bool) error {
|
||||||
|
return d.blPin.Out(gpio.Level(!on))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Bounds() image.Rectangle {
|
||||||
|
return image.Rect(0, 0, int(d.width), int(d.height))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Device) Clear() {}
|
||||||
|
|
||||||
|
func (d *Device) Fill(c color.Color) error {
|
||||||
|
img := image.NewRGBA(d.Bounds())
|
||||||
|
draw.Draw(img, img.Rect, &image.Uniform{c}, image.Point{}, draw.Src)
|
||||||
|
//d.DisplayImage(0, 0, img)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) ColorModel() color.Model {
|
||||||
|
return color.RGBAModel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Set(x, y int, c color.Color) {
|
||||||
|
/*
|
||||||
|
d.SetWindow(x, y, x, y)
|
||||||
|
var buf []byte
|
||||||
|
cd := RGBATo565(color.RGBAModel.Convert(c).(color.RGBA))
|
||||||
|
buf = append(buf, byte(cd>>8), byte(cd))
|
||||||
|
d.sendData(buf)
|
||||||
|
*/
|
||||||
|
d.SetPixel(int16(x), int16(y), color.RGBAModel.Convert(c).(color.RGBA))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Device) Type() string {
|
||||||
|
return "st7735"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Device) Refresh() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
|
||||||
|
buffer := make([]color.RGBA, 0, int(d.width)*int(d.height))
|
||||||
|
for y := 0; y < int(d.height); y++ {
|
||||||
|
for x := 0; x < int(d.width); x++ {
|
||||||
|
r, g, b, _ := src.At(x, y).RGBA()
|
||||||
|
buffer = append(buffer, color.RGBA{
|
||||||
|
R: uint8(r >> 8),
|
||||||
|
G: uint8(g >> 8),
|
||||||
|
B: uint8(b >> 8),
|
||||||
|
A: 0xff,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.FillRectangleWithBuffer(0, 0, d.width, d.height, buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Size() image.Point {
|
||||||
|
return image.Pt(int(d.width), int(d.height))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Device) Halt() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
package st7789
|
||||||
|
|
||||||
|
import "go.maze.io/harmon/hardware/display"
|
||||||
|
|
||||||
|
const (
|
||||||
|
ST7789_TFTWIDTH = 240
|
||||||
|
ST7789_TFTHEIGHT = 240
|
||||||
|
|
||||||
|
ST7789_NOP = 0x00
|
||||||
|
ST7789_SWRESET = 0x01
|
||||||
|
ST7789_RDDID = 0x04
|
||||||
|
ST7789_RDDST = 0x09
|
||||||
|
ST7789_RDDPM = 0x0A
|
||||||
|
ST7789_RDDMADCTL = 0x0B
|
||||||
|
ST7789_RDDCOLMOD = 0x0C
|
||||||
|
ST7789_RDDIM = 0x0D
|
||||||
|
ST7789_RDDSM = 0x0E
|
||||||
|
ST7789_RDDSDR = 0x0F
|
||||||
|
|
||||||
|
ST7789_SLPIN = 0x10
|
||||||
|
ST7789_SLPOUT = 0x11
|
||||||
|
ST7789_PTLON = 0x12
|
||||||
|
ST7789_NORON = 0x13
|
||||||
|
|
||||||
|
ST7789_INVOFF = 0x20
|
||||||
|
ST7789_INVON = 0x21
|
||||||
|
ST7789_GAMSET = 0x26
|
||||||
|
ST7789_DISPOFF = 0x28
|
||||||
|
ST7789_DISPON = 0x29
|
||||||
|
ST7789_CASET = 0x2A
|
||||||
|
ST7789_RASET = 0x2B
|
||||||
|
ST7789_RAMWR = 0x2C
|
||||||
|
ST7789_RAMRD = 0x2E
|
||||||
|
|
||||||
|
ST7789_PTLAR = 0x30
|
||||||
|
ST7789_VSCRDEF = 0x33
|
||||||
|
ST7789_TEOFF = 0x34
|
||||||
|
ST7789_TEON = 0x35
|
||||||
|
ST7789_MADCTL = 0x36
|
||||||
|
ST7789_VSCRSADD = 0x37
|
||||||
|
ST7789_IDMOFF = 0x38
|
||||||
|
ST7789_IDMON = 0x39
|
||||||
|
ST7789_COLMOD = 0x3A
|
||||||
|
ST7789_RAMWRC = 0x3C
|
||||||
|
ST7789_RAMRDC = 0x3E
|
||||||
|
|
||||||
|
ST7789_TESCAN = 0x44
|
||||||
|
ST7789_RDTESCAN = 0x45
|
||||||
|
|
||||||
|
ST7789_WRDISBV = 0x51
|
||||||
|
ST7789_RDDISBV = 0x52
|
||||||
|
ST7789_WRCTRLD = 0x53
|
||||||
|
ST7789_RDCTRLD = 0x54
|
||||||
|
ST7789_WRCACE = 0x55
|
||||||
|
ST7789_RDCABC = 0x56
|
||||||
|
ST7789_WRCABCMB = 0x5E
|
||||||
|
ST7789_RDCABCMB = 0x5F
|
||||||
|
|
||||||
|
ST7789_RDABCSDR = 0x68
|
||||||
|
|
||||||
|
ST7789_RDID1 = 0xDA
|
||||||
|
ST7789_RDID2 = 0xDB
|
||||||
|
ST7789_RDID3 = 0xDC
|
||||||
|
|
||||||
|
ST7789_RAMCTRL = 0xB0
|
||||||
|
ST7789_RGBCTRL = 0xB1
|
||||||
|
ST7789_PORCTRL = 0xB2
|
||||||
|
ST7789_FRCTRL1 = 0xB3
|
||||||
|
|
||||||
|
ST7789_GCTRL = 0xB7
|
||||||
|
ST7789_DGMEN = 0xBA
|
||||||
|
ST7789_VCOMS = 0xBB
|
||||||
|
|
||||||
|
ST7789_LCMCTRL = 0xC0
|
||||||
|
ST7789_IDSET = 0xC1
|
||||||
|
ST7789_VDVVRHEN = 0xC2
|
||||||
|
|
||||||
|
ST7789_VRHS = 0xC3
|
||||||
|
ST7789_VDVSET = 0xC4
|
||||||
|
ST7789_VCMOFSET = 0xC5
|
||||||
|
ST7789_FRCTR2 = 0xC6
|
||||||
|
ST7789_CABCCTRL = 0xC7
|
||||||
|
ST7789_REGSEL1 = 0xC8
|
||||||
|
ST7789_REGSEL2 = 0xCA
|
||||||
|
ST7789_PWMFRSEL = 0xCC
|
||||||
|
|
||||||
|
ST7789_PWCTRL1 = 0xD0
|
||||||
|
ST7789_VAPVANEN = 0xD2
|
||||||
|
ST7789_CMD2EN = 0xDF5A6902
|
||||||
|
ST7789_PVGAMCTRL = 0xE0
|
||||||
|
ST7789_NVGAMCTRL = 0xE1
|
||||||
|
ST7789_DGMLUTR = 0xE2
|
||||||
|
ST7789_DGMLUTB = 0xE3
|
||||||
|
ST7789_GATECTRL = 0xE4
|
||||||
|
ST7789_PWCTRL2 = 0xE8
|
||||||
|
ST7789_EQCTRL = 0xE9
|
||||||
|
ST7789_PROMCTRL = 0xEC
|
||||||
|
ST7789_PROMEN = 0xFA
|
||||||
|
ST7789_NVMSET = 0xFC
|
||||||
|
ST7789_PROMACT = 0xFE
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
NO_ROTATION display.Rotation = 0
|
||||||
|
ROTATION_90 display.Rotation = 1 // 90 degrees clock-wise rotation
|
||||||
|
ROTATION_180 display.Rotation = 2
|
||||||
|
ROTATION_270 display.Rotation = 3
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
FRAMERATE_111 FrameRate = 0x01
|
||||||
|
FRAMERATE_105 FrameRate = 0x02
|
||||||
|
FRAMERATE_99 FrameRate = 0x03
|
||||||
|
FRAMERATE_94 FrameRate = 0x04
|
||||||
|
FRAMERATE_90 FrameRate = 0x05
|
||||||
|
FRAMERATE_86 FrameRate = 0x06
|
||||||
|
FRAMERATE_82 FrameRate = 0x07
|
||||||
|
FRAMERATE_78 FrameRate = 0x08
|
||||||
|
FRAMERATE_75 FrameRate = 0x09
|
||||||
|
FRAMERATE_72 FrameRate = 0x0A
|
||||||
|
FRAMERATE_69 FrameRate = 0x0B
|
||||||
|
FRAMERATE_67 FrameRate = 0x0C
|
||||||
|
FRAMERATE_64 FrameRate = 0x0D
|
||||||
|
FRAMERATE_62 FrameRate = 0x0E
|
||||||
|
FRAMERATE_60 FrameRate = 0x0F // 60 is default
|
||||||
|
FRAMERATE_58 FrameRate = 0x10
|
||||||
|
FRAMERATE_57 FrameRate = 0x11
|
||||||
|
FRAMERATE_55 FrameRate = 0x12
|
||||||
|
FRAMERATE_53 FrameRate = 0x13
|
||||||
|
FRAMERATE_52 FrameRate = 0x14
|
||||||
|
FRAMERATE_50 FrameRate = 0x15
|
||||||
|
FRAMERATE_49 FrameRate = 0x16
|
||||||
|
FRAMERATE_48 FrameRate = 0x17
|
||||||
|
FRAMERATE_46 FrameRate = 0x18
|
||||||
|
FRAMERATE_45 FrameRate = 0x19
|
||||||
|
FRAMERATE_44 FrameRate = 0x1A
|
||||||
|
FRAMERATE_43 FrameRate = 0x1B
|
||||||
|
FRAMERATE_42 FrameRate = 0x1C
|
||||||
|
FRAMERATE_41 FrameRate = 0x1D
|
||||||
|
FRAMERATE_40 FrameRate = 0x1E
|
||||||
|
FRAMERATE_39 FrameRate = 0x1F
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MAX_VSYNC_SCANLINES = 254
|
||||||
|
)
|
||||||
@@ -0,0 +1,611 @@
|
|||||||
|
// Package st7789 implements a driver for the ST7789 TFT displays, it comes in various screen sizes.
|
||||||
|
//
|
||||||
|
// Datasheets: https://cdn-shop.adafruit.com/product-files/3787/3787_tft_QT154H2201__________20190228182902.pdf
|
||||||
|
//
|
||||||
|
// http://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7789V.pdf
|
||||||
|
package st7789
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"periph.io/x/conn/v3/gpio"
|
||||||
|
"periph.io/x/conn/v3/physic"
|
||||||
|
"periph.io/x/conn/v3/spi"
|
||||||
|
"periph.io/x/conn/v3/spi/spireg"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/config"
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"go.maze.io/harmon/hardware/display"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
display.Register("st7789", newDriver)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
errOutOfBounds = errors.New("rectangle coordinates outside display area")
|
||||||
|
)
|
||||||
|
|
||||||
|
// FrameRate controls the frame rate used by the display.
|
||||||
|
type FrameRate uint8
|
||||||
|
|
||||||
|
type Device struct {
|
||||||
|
conn spi.Conn
|
||||||
|
reset gpio.PinOut
|
||||||
|
dcPin gpio.PinOut
|
||||||
|
resetPin gpio.PinOut
|
||||||
|
blPin gpio.PinOut
|
||||||
|
width int16
|
||||||
|
height int16
|
||||||
|
columnOffsetCfg int16
|
||||||
|
rowOffsetCfg int16
|
||||||
|
columnOffset int16
|
||||||
|
rowOffset int16
|
||||||
|
rotation display.Rotation
|
||||||
|
frameRate FrameRate
|
||||||
|
batchLength int32
|
||||||
|
isBGR bool
|
||||||
|
vSyncLines int16
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config is the configuration for the display
|
||||||
|
type Config struct {
|
||||||
|
Width int16
|
||||||
|
Height int16
|
||||||
|
Rotation display.Rotation
|
||||||
|
RowOffset int16
|
||||||
|
ColumnOffset int16
|
||||||
|
FrameRate FrameRate
|
||||||
|
VSyncLines int16
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDriver(config config.DisplayConfig) (hardware.Display, error) {
|
||||||
|
var (
|
||||||
|
opts *display.Options
|
||||||
|
port spi.PortCloser
|
||||||
|
conn spi.Conn
|
||||||
|
reset, dc, bl gpio.PinOut
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if opts, err = display.ParseOptions(config, 240, 240); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log := logrus.WithFields(logrus.Fields{
|
||||||
|
"type": "st7789",
|
||||||
|
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
|
||||||
|
"rotate": opts.Rotate,
|
||||||
|
})
|
||||||
|
log.Debug("new driver")
|
||||||
|
|
||||||
|
if reset, err = hardware.LookupPin(config.Reset); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if dc, err = hardware.LookupPin(config.DC); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if bl, err = hardware.LookupPin(config.BL); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const speed = 40000000 * physic.Hertz
|
||||||
|
log.WithFields(logrus.Fields{
|
||||||
|
"port": config.Port,
|
||||||
|
"pin_reset": reset,
|
||||||
|
"pin_dc": dc,
|
||||||
|
"pin_bl": bl,
|
||||||
|
"speed": speed,
|
||||||
|
"bits": 8,
|
||||||
|
"mode": spi.Mode0,
|
||||||
|
}).Debug("opening SPI port")
|
||||||
|
if port, err = spireg.Open(config.Port); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if conn, err = port.Connect(speed, spi.Mode0, 8); err != nil {
|
||||||
|
_ = port.Close()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return newDisplay(conn, reset, dc, bl, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDisplay(conn spi.Conn, reset, dc, bl gpio.PinOut, opts *display.Options) (d *Device, err error) {
|
||||||
|
d = &Device{
|
||||||
|
conn: conn,
|
||||||
|
resetPin: reset,
|
||||||
|
dcPin: dc,
|
||||||
|
blPin: bl,
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Configure(Config{
|
||||||
|
Width: int16(opts.W),
|
||||||
|
Height: int16(opts.H),
|
||||||
|
Rotation: opts.Rotate,
|
||||||
|
FrameRate: FRAMERATE_60,
|
||||||
|
})
|
||||||
|
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure initializes the display with default configuration
|
||||||
|
func (d *Device) Configure(cfg Config) {
|
||||||
|
if cfg.Width != 0 {
|
||||||
|
d.width = cfg.Width
|
||||||
|
} else {
|
||||||
|
d.width = 240
|
||||||
|
}
|
||||||
|
if cfg.Height != 0 {
|
||||||
|
d.height = cfg.Height
|
||||||
|
} else {
|
||||||
|
d.height = 240
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"driver": "st7789",
|
||||||
|
"width": d.width,
|
||||||
|
"height": d.height,
|
||||||
|
}).Warn("yello!")
|
||||||
|
|
||||||
|
d.rotation = cfg.Rotation
|
||||||
|
d.rowOffsetCfg = cfg.RowOffset
|
||||||
|
d.columnOffsetCfg = cfg.ColumnOffset
|
||||||
|
|
||||||
|
if cfg.FrameRate != 0 {
|
||||||
|
d.frameRate = cfg.FrameRate
|
||||||
|
} else {
|
||||||
|
d.frameRate = FRAMERATE_60
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.VSyncLines >= 2 && cfg.VSyncLines <= 254 {
|
||||||
|
d.vSyncLines = cfg.VSyncLines
|
||||||
|
} else {
|
||||||
|
d.vSyncLines = 16
|
||||||
|
}
|
||||||
|
|
||||||
|
d.batchLength = int32(d.width)
|
||||||
|
if d.height > d.width {
|
||||||
|
d.batchLength = int32(d.height)
|
||||||
|
}
|
||||||
|
d.batchLength += d.batchLength & 1
|
||||||
|
|
||||||
|
// Reset the device
|
||||||
|
d.resetPin.Out(gpio.High)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
d.resetPin.Out(gpio.Low)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
d.resetPin.Out(gpio.High)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
|
// Common initialization
|
||||||
|
d.sendCommand(0x11)
|
||||||
|
time.Sleep(150 * time.Millisecond)
|
||||||
|
|
||||||
|
d.sendCommand(0x36, 0x00)
|
||||||
|
d.sendCommand(0x3A, 0x05)
|
||||||
|
d.sendCommand(0xB2, 0x0C, 0x0C)
|
||||||
|
d.sendCommand(0xB7, 0x35)
|
||||||
|
d.sendCommand(0xBB, 0x1A)
|
||||||
|
d.sendCommand(0xC0, 0x2C)
|
||||||
|
d.sendCommand(0xC2, 0x01)
|
||||||
|
d.sendCommand(0xC3, 0x0B)
|
||||||
|
d.sendCommand(0xC4, 0x20)
|
||||||
|
d.sendCommand(0xC6, 0x0F)
|
||||||
|
d.sendCommand(0xD0, 0xA4, 0xA1)
|
||||||
|
d.sendCommand(0x21)
|
||||||
|
d.sendCommand(ST7789_MADCTL, 0x78)
|
||||||
|
d.sendCommand(0xE0, 0x00, 0x19, 0x1E, 0x0A, 0x09, 0x15, 0x3D, 0x44, 0x51, 0x12, 0x03, 0x00, 0x3F, 0x3F)
|
||||||
|
d.sendCommand(0xE1, 0x00,
|
||||||
|
0x18,
|
||||||
|
0x1E,
|
||||||
|
0x0A,
|
||||||
|
0x09,
|
||||||
|
0x25,
|
||||||
|
0x3F,
|
||||||
|
0x43,
|
||||||
|
0x52,
|
||||||
|
0x33,
|
||||||
|
0x03,
|
||||||
|
0x00,
|
||||||
|
0x3F,
|
||||||
|
0x3F)
|
||||||
|
d.sendCommand(0x29)
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
d.blPin.Out(gpio.High) // Backlight ON
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync waits for the display to hit the next VSYNC pause
|
||||||
|
func (d *Device) Sync() {
|
||||||
|
d.SyncToScanLine(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SyncToScanLine waits for the display to hit a specific scanline
|
||||||
|
//
|
||||||
|
// A scanline value of 0 will forward to the beginning of the next VSYNC,
|
||||||
|
// even if the display is currently in a VSYNC pause.
|
||||||
|
//
|
||||||
|
// Syncline values appear to increment once for every two vertical
|
||||||
|
// lines on the display.
|
||||||
|
//
|
||||||
|
// NOTE: Use GetHighestScanLine and GetLowestScanLine to obtain the highest
|
||||||
|
// and lowest useful values. Values are affected by front and back porch
|
||||||
|
// vsync settings (derived from VSyncLines configuration option).
|
||||||
|
func (d *Device) SyncToScanLine(scanline uint16) {
|
||||||
|
scan := d.GetScanLine()
|
||||||
|
|
||||||
|
// Sometimes GetScanLine returns erroneous 0 on first call after draw, so double check
|
||||||
|
if scan == 0 {
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
if scanline == 0 {
|
||||||
|
// we dont know where we are in an ongoing vsync so go around
|
||||||
|
for scan < 1 {
|
||||||
|
time.Sleep(1 * time.Millisecond)
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
for scan > 0 {
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// go around unless we're very close to the target
|
||||||
|
for scan > scanline+4 {
|
||||||
|
time.Sleep(1 * time.Millisecond)
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
for scan < scanline {
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Backlight(on bool) error {
|
||||||
|
return d.blPin.Out(gpio.Level(on))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetScanLine reads the current scanline value from the display
|
||||||
|
func (d *Device) GetScanLine() uint16 {
|
||||||
|
data := []uint8{0x00, 0x00}
|
||||||
|
//d.Rx(GSCAN, data)
|
||||||
|
return uint16(data[0])<<8 + uint16(data[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHighestScanLine calculates the last scanline id in the frame before VSYNC pause
|
||||||
|
func (d *Device) GetHighestScanLine() uint16 {
|
||||||
|
// Last scanline id appears to be backporch/2 + 320/2
|
||||||
|
return uint16(math.Ceil(float64(d.vSyncLines)/2)/2) + 160
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLowestScanLine calculate the first scanline id to appear after VSYNC pause
|
||||||
|
func (d *Device) GetLowestScanLine() uint16 {
|
||||||
|
// First scanline id appears to be backporch/2 + 1
|
||||||
|
return uint16(math.Ceil(float64(d.vSyncLines)/2)/2) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display does nothing, there's no buffer as it might be too big for some boards
|
||||||
|
func (d *Device) Display() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPixel sets a pixel in the screen
|
||||||
|
func (d *Device) SetPixel(x int16, y int16, c color.RGBA) {
|
||||||
|
if x < 0 || y < 0 ||
|
||||||
|
(((d.rotation == NO_ROTATION || d.rotation == ROTATION_180) && (x >= d.width || y >= d.height)) ||
|
||||||
|
((d.rotation == ROTATION_90 || d.rotation == ROTATION_270) && (x >= d.height || y >= d.width))) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.FillRectangle(x, y, 1, 1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// setWindow prepares the screen to be modified at a given rectangle
|
||||||
|
func (d *Device) setWindow(x, y, w, h int16) {
|
||||||
|
x0 := x + d.columnOffset
|
||||||
|
y0 := y + d.rowOffset
|
||||||
|
x1 := x + w - 1
|
||||||
|
y1 := y + h - 1
|
||||||
|
d.sendCommand(ST7789_CASET, byte(x0>>8), byte(x0), byte(x1>>8), byte(x1))
|
||||||
|
d.sendCommand(ST7789_RASET, byte(y0>>8), byte(y0), byte(y1>>8), byte(y1))
|
||||||
|
d.sendCommand(ST7789_RAMWR)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillRectangle fills a rectangle at a given coordinates with a color
|
||||||
|
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
|
||||||
|
k, i := d.size()
|
||||||
|
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
|
||||||
|
x >= k || (x+width) > k || y >= i || (y+height) > i {
|
||||||
|
return errors.New("rectangle coordinates outside display area")
|
||||||
|
}
|
||||||
|
d.setWindow(x, y, width, height)
|
||||||
|
c565 := RGBATo565(c)
|
||||||
|
c1 := uint8(c565 >> 8)
|
||||||
|
c2 := uint8(c565)
|
||||||
|
|
||||||
|
data := make([]uint8, d.batchLength*2)
|
||||||
|
for i := int32(0); i < d.batchLength; i++ {
|
||||||
|
data[i*2] = c1
|
||||||
|
data[i*2+1] = c2
|
||||||
|
}
|
||||||
|
j := int32(width) * int32(height)
|
||||||
|
for j > 0 {
|
||||||
|
if j >= d.batchLength {
|
||||||
|
d.sendData(data)
|
||||||
|
} else {
|
||||||
|
d.sendData(data[:j*2])
|
||||||
|
}
|
||||||
|
j -= d.batchLength
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillRectangleWithBuffer fills buffer with a rectangle at a given coordinates.
|
||||||
|
func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
|
||||||
|
i, j := d.size()
|
||||||
|
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
|
||||||
|
x >= i || (x+width) > i || y >= j || (y+height) > j {
|
||||||
|
return errors.New("rectangle coordinates outside display area")
|
||||||
|
}
|
||||||
|
if int32(width)*int32(height) != int32(len(buffer)) {
|
||||||
|
return errors.New("buffer length does not match with rectangle size")
|
||||||
|
}
|
||||||
|
d.setWindow(x, y, width, height)
|
||||||
|
|
||||||
|
k := int32(width) * int32(height)
|
||||||
|
data := make([]uint8, d.batchLength*2)
|
||||||
|
offset := int32(0)
|
||||||
|
for k > 0 {
|
||||||
|
for i := int32(0); i < d.batchLength; i++ {
|
||||||
|
if offset+i < int32(len(buffer)) {
|
||||||
|
c565 := RGBATo565(buffer[offset+i])
|
||||||
|
c1 := uint8(c565 >> 8)
|
||||||
|
c2 := uint8(c565)
|
||||||
|
data[i*2] = c1
|
||||||
|
data[i*2+1] = c2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k >= d.batchLength {
|
||||||
|
d.sendData(data)
|
||||||
|
} else {
|
||||||
|
d.sendData(data[:k*2])
|
||||||
|
}
|
||||||
|
k -= d.batchLength
|
||||||
|
offset += d.batchLength
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DrawFastVLine draws a vertical line faster than using SetPixel
|
||||||
|
func (d *Device) DrawFastVLine(x, y0, y1 int16, c color.RGBA) {
|
||||||
|
if y0 > y1 {
|
||||||
|
y0, y1 = y1, y0
|
||||||
|
}
|
||||||
|
d.FillRectangle(x, y0, 1, y1-y0+1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DrawFastHLine draws a horizontal line faster than using SetPixel
|
||||||
|
func (d *Device) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
|
||||||
|
if x0 > x1 {
|
||||||
|
x0, x1 = x1, x0
|
||||||
|
}
|
||||||
|
d.FillRectangle(x0, y, x1-x0+1, 1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillScreen fills the screen with a given color
|
||||||
|
func (d *Device) FillScreen(c color.RGBA) {
|
||||||
|
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
|
||||||
|
d.FillRectangle(0, 0, d.width, d.height, c)
|
||||||
|
} else {
|
||||||
|
d.FillRectangle(0, 0, d.height, d.width, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRotation changes the rotation of the device (clock-wise)
|
||||||
|
func (d *Device) SetRotation(rotation display.Rotation) {
|
||||||
|
/*
|
||||||
|
madctl := uint8(0)
|
||||||
|
switch rotation % 4 {
|
||||||
|
case 0:
|
||||||
|
madctl = MADCTL_MX | MADCTL_MY
|
||||||
|
d.rowOffset = d.rowOffsetCfg
|
||||||
|
d.columnOffset = d.columnOffsetCfg
|
||||||
|
break
|
||||||
|
case 1:
|
||||||
|
madctl = MADCTL_MY | MADCTL_MV
|
||||||
|
d.rowOffset = d.columnOffsetCfg
|
||||||
|
d.columnOffset = d.rowOffsetCfg
|
||||||
|
break
|
||||||
|
case 2:
|
||||||
|
d.rowOffset = 0
|
||||||
|
d.columnOffset = 0
|
||||||
|
break
|
||||||
|
case 3:
|
||||||
|
madctl = MADCTL_MX | MADCTL_MV
|
||||||
|
d.rowOffset = 0
|
||||||
|
d.columnOffset = 0
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if d.isBGR {
|
||||||
|
madctl |= MADCTL_BGR
|
||||||
|
}
|
||||||
|
d.sendCommand(ST7789_MADCTL, madctl)
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rx reads data from the display
|
||||||
|
func (d *Device) Rx(command uint8, data []byte) {
|
||||||
|
d.dcPin.Out(gpio.Low)
|
||||||
|
sendCommand(d.conn, command)
|
||||||
|
|
||||||
|
d.dcPin.Out(gpio.High)
|
||||||
|
for i := range data {
|
||||||
|
data[i], _ = sendCommand(d.conn, 0xFF)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendCommand(bus spi.Conn, command byte) (byte, error) {
|
||||||
|
answer := []byte{0}
|
||||||
|
err := bus.Tx(
|
||||||
|
[]byte{command},
|
||||||
|
[]byte(""),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return answer[0], nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size returns the current size of the display.
|
||||||
|
func (d *Device) size() (w, h int16) {
|
||||||
|
if d.rotation == NO_ROTATION || d.rotation == ROTATION_180 {
|
||||||
|
return d.width, d.height
|
||||||
|
}
|
||||||
|
return d.height, d.width
|
||||||
|
}
|
||||||
|
|
||||||
|
// EnableBacklight enables or disables the backlight
|
||||||
|
func (d *Device) EnableBacklight(enable bool) {
|
||||||
|
if enable {
|
||||||
|
d.blPin.Out(gpio.High)
|
||||||
|
} else {
|
||||||
|
d.blPin.Out(gpio.Low)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InvertColors inverts the colors of the screen
|
||||||
|
func (d *Device) InvertColors(invert bool) {
|
||||||
|
if invert {
|
||||||
|
d.sendCommand(ST7789_INVON)
|
||||||
|
} else {
|
||||||
|
d.sendCommand(ST7789_INVOFF)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBGR changes the color mode (RGB/BGR)
|
||||||
|
func (d *Device) IsBGR(bgr bool) {
|
||||||
|
d.isBGR = bgr
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetScrollArea sets an area to scroll with fixed top and bottom parts of the display.
|
||||||
|
func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) {
|
||||||
|
d.sendCommand(ST7789_VSCRDEF,
|
||||||
|
uint8(topFixedArea>>8), uint8(topFixedArea),
|
||||||
|
uint8(d.height-topFixedArea-bottomFixedArea>>8), uint8(d.height-topFixedArea-bottomFixedArea),
|
||||||
|
uint8(bottomFixedArea>>8), uint8(bottomFixedArea))
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetScroll sets the vertical scroll address of the display.
|
||||||
|
func (d *Device) SetScroll(line int16) {
|
||||||
|
d.sendCommand(ST7789_VSCRSADD, uint8(line>>8), uint8(line))
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopScroll returns the display to its normal state.
|
||||||
|
func (d *Device) StopScroll() {
|
||||||
|
d.sendCommand(ST7789_NORON)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RGBATo565 converts a color.RGBA to uint16 used in the display
|
||||||
|
func RGBATo565(c color.RGBA) uint16 {
|
||||||
|
r, g, b, _ := c.RGBA()
|
||||||
|
return uint16((r & 0xF800) +
|
||||||
|
((g & 0xFC00) >> 5) +
|
||||||
|
((b & 0xF800) >> 11))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) At(x, y int) color.Color {
|
||||||
|
return color.Black
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Bounds() image.Rectangle {
|
||||||
|
if d.rotation == display.Rotate90 || d.rotation == display.Rotate270 {
|
||||||
|
return image.Rect(0, 0, int(d.height), int(d.width))
|
||||||
|
}
|
||||||
|
return image.Rect(0, 0, int(d.width), int(d.height))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Clear() {
|
||||||
|
d.FillRectangle(0, 0, d.width, d.height, color.RGBA{A: 0xff})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Device) ColorModel() color.Model {
|
||||||
|
return color.RGBAModel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Fill(c color.Color) error {
|
||||||
|
rgba := color.RGBAModel.Convert(c).(color.RGBA)
|
||||||
|
d.FillRectangle(0, 0, d.width, d.height, rgba)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) sendData(data []byte) (err error) {
|
||||||
|
if err = d.dcPin.Out(gpio.High); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return d.conn.Tx(data, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) sendCommand(cmd byte, args ...byte) (err error) {
|
||||||
|
if err = d.dcPin.Out(gpio.Low); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = d.conn.Tx([]byte{cmd}, nil); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(args) > 0 {
|
||||||
|
return d.sendData(args)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Set(x, y int, c color.Color) {
|
||||||
|
var (
|
||||||
|
rc = RGBATo565(color.RGBAModel.Convert(c).(color.RGBA))
|
||||||
|
xo = x + int(d.columnOffset)
|
||||||
|
yo = y + int(d.rowOffset)
|
||||||
|
)
|
||||||
|
d.sendCommand(0x2A, byte(xo>>8), byte(xo), byte(xo>>8), byte(xo)) // column addr
|
||||||
|
d.sendCommand(0x2B, byte(yo>>8), byte(yo), byte(yo>>8), byte(yo)) // row addr
|
||||||
|
d.sendCommand(0x2C, byte(rc>>8), byte(rc)) // pixel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Size() image.Point {
|
||||||
|
if d.rotation == display.Rotate90 || d.rotation == display.Rotate270 {
|
||||||
|
return image.Pt(int(d.height), int(d.width))
|
||||||
|
}
|
||||||
|
return image.Pt(int(d.width), int(d.height))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Device) Type() string {
|
||||||
|
return "st7789"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Device) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
|
||||||
|
//draw.Draw(d, r, src, sp, draw.Src)
|
||||||
|
logrus.Warnf("make slice %d (%dx%d)", d.height*d.width, d.height, d.width)
|
||||||
|
var (
|
||||||
|
buffer = make([]color.RGBA, int(d.height)*int(d.width))
|
||||||
|
bounds = src.Bounds()
|
||||||
|
)
|
||||||
|
for y := 0; y < bounds.Max.Y && y < int(d.height); y++ {
|
||||||
|
for x := 0; x < bounds.Max.X && x < int(d.width); x++ {
|
||||||
|
r, g, b, a := src.At(x, y).RGBA()
|
||||||
|
buffer[y*int(d.width)+x] = color.RGBA{R: uint8(r / 0x100), G: uint8(g / 0x100), B: uint8(b / 0x100), A: uint8(a / 0x100)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.FillRectangleWithBuffer(0, 0, d.width, d.height, buffer)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Device) Halt() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (Device) Refresh() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package st7789
|
||||||
|
|
||||||
|
// Registers
|
||||||
|
const (
|
||||||
|
NOP = 0x00
|
||||||
|
SWRESET = 0x01
|
||||||
|
RDDID = 0x04
|
||||||
|
RDDST = 0x09
|
||||||
|
SLPIN = 0x10
|
||||||
|
SLPOUT = 0x11
|
||||||
|
PTLON = 0x12
|
||||||
|
NORON = 0x13
|
||||||
|
INVOFF = 0x20
|
||||||
|
INVON = 0x21
|
||||||
|
DISPOFF = 0x28
|
||||||
|
DISPON = 0x29
|
||||||
|
CASET = 0x2A
|
||||||
|
RASET = 0x2B
|
||||||
|
RAMWR = 0x2C
|
||||||
|
RAMRD = 0x2E
|
||||||
|
PTLAR = 0x30
|
||||||
|
COLMOD = 0x3A
|
||||||
|
MADCTL = 0x36
|
||||||
|
MADCTL_MY = 0x80
|
||||||
|
MADCTL_MX = 0x40
|
||||||
|
MADCTL_MV = 0x20
|
||||||
|
MADCTL_ML = 0x10
|
||||||
|
MADCTL_RGB = 0x00
|
||||||
|
MADCTL_BGR = 0x08
|
||||||
|
MADCTL_MH = 0x04
|
||||||
|
RDID1 = 0xDA
|
||||||
|
RDID2 = 0xDB
|
||||||
|
RDID3 = 0xDC
|
||||||
|
RDID4 = 0xDD
|
||||||
|
FRMCTR1 = 0xB1
|
||||||
|
RGBCTRL = 0xB1
|
||||||
|
FRMCTR2 = 0xB2
|
||||||
|
PORCTRL = 0xB2
|
||||||
|
FRMCTR3 = 0xB3
|
||||||
|
INVCTR = 0xB4
|
||||||
|
DISSET5 = 0xB6
|
||||||
|
PWCTR1 = 0xC0
|
||||||
|
PWCTR2 = 0xC1
|
||||||
|
PWCTR3 = 0xC2
|
||||||
|
PWCTR4 = 0xC3
|
||||||
|
PWCTR5 = 0xC4
|
||||||
|
VMCTR1 = 0xC5
|
||||||
|
FRCTRL2 = 0xC6
|
||||||
|
PWCTR6 = 0xFC
|
||||||
|
GMCTRP1 = 0xE0
|
||||||
|
GMCTRN1 = 0xE1
|
||||||
|
GSCAN = 0x45
|
||||||
|
VSCRDEF = 0x33
|
||||||
|
VSCRSADD = 0x37
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MAX_VSYNC_SCANLINES = 254
|
||||||
|
defaultWidth = 240
|
||||||
|
defaultHeight = 240
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Allowable frame rate codes for FRCTRL2 (Identifier is in Hz)
|
||||||
|
FrameRate111 FrameRate = 0x01
|
||||||
|
FrameRate105 FrameRate = 0x02
|
||||||
|
FrameRate99 FrameRate = 0x03
|
||||||
|
FrameRate94 FrameRate = 0x04
|
||||||
|
FrameRate90 FrameRate = 0x05
|
||||||
|
FrameRate86 FrameRate = 0x06
|
||||||
|
FrameRate82 FrameRate = 0x07
|
||||||
|
FrameRate78 FrameRate = 0x08
|
||||||
|
FrameRate75 FrameRate = 0x09
|
||||||
|
FrameRate72 FrameRate = 0x0A
|
||||||
|
FrameRate69 FrameRate = 0x0B
|
||||||
|
FrameRate67 FrameRate = 0x0C
|
||||||
|
FrameRate64 FrameRate = 0x0D
|
||||||
|
FrameRate62 FrameRate = 0x0E
|
||||||
|
FrameRate60 FrameRate = 0x0F // 60 is default
|
||||||
|
FrameRate58 FrameRate = 0x10
|
||||||
|
FrameRate57 FrameRate = 0x11
|
||||||
|
FrameRate55 FrameRate = 0x12
|
||||||
|
FrameRate53 FrameRate = 0x13
|
||||||
|
FrameRate52 FrameRate = 0x14
|
||||||
|
FrameRate50 FrameRate = 0x15
|
||||||
|
FrameRate49 FrameRate = 0x16
|
||||||
|
FrameRate48 FrameRate = 0x17
|
||||||
|
FrameRate46 FrameRate = 0x18
|
||||||
|
FrameRate45 FrameRate = 0x19
|
||||||
|
FrameRate44 FrameRate = 0x1A
|
||||||
|
FrameRate43 FrameRate = 0x1B
|
||||||
|
FrameRate42 FrameRate = 0x1C
|
||||||
|
FrameRate41 FrameRate = 0x1D
|
||||||
|
FrameRate40 FrameRate = 0x1E
|
||||||
|
FrameRate39 FrameRate = 0x1F
|
||||||
|
)
|
||||||
@@ -0,0 +1,586 @@
|
|||||||
|
// Package st7789 provides a driver for Sitronix ST7789 IPS TFT displays.
|
||||||
|
package st7789
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"go.maze.io/harmon/config"
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"go.maze.io/harmon/hardware/display"
|
||||||
|
"periph.io/x/conn/v3/gpio"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
display.Register("st7789", newDriver)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FrameRate controls the frame rate used by the display.
|
||||||
|
type FrameRate uint8
|
||||||
|
|
||||||
|
// Driver wraps an SPI connection.
|
||||||
|
type Driver struct {
|
||||||
|
conn display.Conn
|
||||||
|
//dcPin gpio.PinOut
|
||||||
|
//csPin gpio.PinOut
|
||||||
|
resetPin gpio.PinOut
|
||||||
|
blPin gpio.PinOut
|
||||||
|
width int16
|
||||||
|
height int16
|
||||||
|
columnOffsetCfg int16
|
||||||
|
rowOffsetCfg int16
|
||||||
|
columnOffset int16
|
||||||
|
rowOffset int16
|
||||||
|
rotation display.Rotation
|
||||||
|
frameRate FrameRate
|
||||||
|
batchLength int32
|
||||||
|
isBGR bool
|
||||||
|
vSyncLines int16
|
||||||
|
}
|
||||||
|
|
||||||
|
// Config is the configuration for the display
|
||||||
|
type Config struct {
|
||||||
|
Width int16
|
||||||
|
Height int16
|
||||||
|
Rotation display.Rotation
|
||||||
|
RowOffset int16
|
||||||
|
ColumnOffset int16
|
||||||
|
FrameRate FrameRate
|
||||||
|
VSyncLines int16
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDriver(config config.DisplayConfig) (hardware.Display, error) {
|
||||||
|
var (
|
||||||
|
opts *display.Options
|
||||||
|
conn display.Conn
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
if opts, err = display.ParseOptions(config, defaultWidth, defaultHeight); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var reset, bl gpio.PinOut
|
||||||
|
if bl, err = hardware.LookupPin(config.BL); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if reset, err = hardware.LookupPin(config.Reset); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log := logrus.WithFields(logrus.Fields{
|
||||||
|
"type": "st7789",
|
||||||
|
"size": fmt.Sprintf("%dx%d", opts.W, opts.H),
|
||||||
|
"rotate": opts.Rotate,
|
||||||
|
})
|
||||||
|
log.Debug("new driver")
|
||||||
|
|
||||||
|
if conn, err = display.OpenSPI(config.Port, config.Reset, config.DC); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
d := &Driver{
|
||||||
|
conn: conn,
|
||||||
|
blPin: bl,
|
||||||
|
resetPin: reset,
|
||||||
|
}
|
||||||
|
if err = d.Configure(Config{
|
||||||
|
Width: int16(opts.W),
|
||||||
|
Height: int16(opts.H),
|
||||||
|
Rotation: opts.Rotate,
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return d, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a new ST7789 connection. The SPI wire must already be configured.
|
||||||
|
func New(conn display.Conn, resetPin, blPin gpio.PinOut) Driver {
|
||||||
|
return Driver{
|
||||||
|
conn: conn,
|
||||||
|
resetPin: resetPin,
|
||||||
|
blPin: blPin,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure initializes the display with default configuration
|
||||||
|
func (d *Driver) Configure(cfg Config) error {
|
||||||
|
if cfg.Width != 0 {
|
||||||
|
d.width = cfg.Width
|
||||||
|
} else {
|
||||||
|
d.width = 240
|
||||||
|
}
|
||||||
|
if cfg.Height != 0 {
|
||||||
|
d.height = cfg.Height
|
||||||
|
} else {
|
||||||
|
d.height = 240
|
||||||
|
}
|
||||||
|
|
||||||
|
d.rotation = cfg.Rotation
|
||||||
|
d.rowOffsetCfg = cfg.RowOffset
|
||||||
|
d.columnOffsetCfg = cfg.ColumnOffset
|
||||||
|
|
||||||
|
if cfg.FrameRate != 0 {
|
||||||
|
d.frameRate = cfg.FrameRate
|
||||||
|
} else {
|
||||||
|
d.frameRate = FrameRate60
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.VSyncLines >= 2 && cfg.VSyncLines <= 254 {
|
||||||
|
d.vSyncLines = cfg.VSyncLines
|
||||||
|
} else {
|
||||||
|
d.vSyncLines = 16
|
||||||
|
}
|
||||||
|
|
||||||
|
d.batchLength = int32(d.width)
|
||||||
|
if d.height > d.width {
|
||||||
|
d.batchLength = int32(d.height)
|
||||||
|
}
|
||||||
|
d.batchLength += d.batchLength & 1
|
||||||
|
|
||||||
|
// Reset the device
|
||||||
|
d.resetPin.Out(gpio.High)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
d.resetPin.Out(gpio.Low)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
d.resetPin.Out(gpio.High)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
|
// Common initialization
|
||||||
|
d.Command(SWRESET) // Soft reset
|
||||||
|
time.Sleep(150 * time.Millisecond) //
|
||||||
|
|
||||||
|
d.Command(SLPOUT) // Exit sleep mode
|
||||||
|
time.Sleep(500 * time.Millisecond) //
|
||||||
|
|
||||||
|
// Memory initialization
|
||||||
|
d.Command(COLMOD) // Set color mode
|
||||||
|
d.Data(0x55) // 16-bit color
|
||||||
|
time.Sleep(10 * time.Millisecond) //
|
||||||
|
|
||||||
|
d.SetRotation(d.rotation) // Memory orientation
|
||||||
|
|
||||||
|
d.setWindow(0, 0, d.width, d.height) // Full draw window
|
||||||
|
d.FillScreen(color.RGBA{0, 0, 0, 255}) // Clear screen
|
||||||
|
|
||||||
|
// Framerate
|
||||||
|
d.Command(FRCTRL2) // Frame rate for normal mode
|
||||||
|
d.Data(uint8(d.frameRate)) // Default is 60Hz
|
||||||
|
|
||||||
|
// Frame vertical sync and "porch"
|
||||||
|
//
|
||||||
|
// Front and back porch controls vertical scanline sync time before and after
|
||||||
|
// a frame, where memory can be safely written without tearing.
|
||||||
|
//
|
||||||
|
fp := uint8(d.vSyncLines / 2) // Split the desired pause half and half
|
||||||
|
bp := uint8(d.vSyncLines - int16(fp)) // between front and back porch.
|
||||||
|
|
||||||
|
d.Command(PORCTRL)
|
||||||
|
d.Data(bp) // Back porch 5bit (0x7F max 0x08 default)
|
||||||
|
d.Data(fp) // Front porch 5bit (0x7F max 0x08 default)
|
||||||
|
d.Data(0x00) // Seprarate porch (TODO: what is this?)
|
||||||
|
d.Data(0x22) // Idle mode porch (4bit-back 4bit-front 0x22 default)
|
||||||
|
d.Data(0x22) // Partial mode porch (4bit-back 4bit-front 0x22 default)
|
||||||
|
|
||||||
|
// Ready to display
|
||||||
|
d.Command(INVON) // Inversion ON
|
||||||
|
time.Sleep(10 * time.Millisecond) //
|
||||||
|
|
||||||
|
d.Command(NORON) // Normal mode ON
|
||||||
|
time.Sleep(10 * time.Millisecond) //
|
||||||
|
|
||||||
|
d.Command(DISPON) // Screen ON
|
||||||
|
time.Sleep(10 * time.Millisecond) //
|
||||||
|
|
||||||
|
d.blPin.Out(gpio.High) // Backlight ON
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Sync waits for the display to hit the next VSYNC pause
|
||||||
|
func (d *Driver) Sync() {
|
||||||
|
d.SyncToScanLine(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SyncToScanLine waits for the display to hit a specific scanline
|
||||||
|
//
|
||||||
|
// A scanline value of 0 will forward to the beginning of the next VSYNC,
|
||||||
|
// even if the display is currently in a VSYNC pause.
|
||||||
|
//
|
||||||
|
// Syncline values appear to increment once for every two vertical
|
||||||
|
// lines on the display.
|
||||||
|
//
|
||||||
|
// NOTE: Use GetHighestScanLine and GetLowestScanLine to obtain the highest
|
||||||
|
// and lowest useful values. Values are affected by front and back porch
|
||||||
|
// vsync settings (derived from VSyncLines configuration option).
|
||||||
|
func (d *Driver) SyncToScanLine(scanline uint16) {
|
||||||
|
scan := d.GetScanLine()
|
||||||
|
|
||||||
|
// Sometimes GetScanLine returns erroneous 0 on first call after draw, so double check
|
||||||
|
if scan == 0 {
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
if scanline == 0 {
|
||||||
|
// we dont know where we are in an ongoing vsync so go around
|
||||||
|
for scan < 1 {
|
||||||
|
time.Sleep(1 * time.Millisecond)
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
for scan > 0 {
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// go around unless we're very close to the target
|
||||||
|
for scan > scanline+4 {
|
||||||
|
time.Sleep(1 * time.Millisecond)
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
for scan < scanline {
|
||||||
|
scan = d.GetScanLine()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetScanLine reads the current scanline value from the display
|
||||||
|
func (d *Driver) GetScanLine() uint16 {
|
||||||
|
data := []uint8{0x00, 0x00}
|
||||||
|
d.conn.Rx(GSCAN, data)
|
||||||
|
return uint16(data[0])<<8 + uint16(data[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetHighestScanLine calculates the last scanline id in the frame before VSYNC pause
|
||||||
|
func (d *Driver) GetHighestScanLine() uint16 {
|
||||||
|
// Last scanline id appears to be backporch/2 + 320/2
|
||||||
|
return uint16(math.Ceil(float64(d.vSyncLines)/2)/2) + 160
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLowestScanLine calculate the first scanline id to appear after VSYNC pause
|
||||||
|
func (d *Driver) GetLowestScanLine() uint16 {
|
||||||
|
// First scanline id appears to be backporch/2 + 1
|
||||||
|
return uint16(math.Ceil(float64(d.vSyncLines)/2)/2) + 1
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Refresh does nothing, there's no buffer as it might be too big for some boards
|
||||||
|
func (d *Driver) Refresh() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPixel sets a pixel in the screen
|
||||||
|
func (d *Driver) SetPixel(x int16, y int16, c color.RGBA) {
|
||||||
|
if x < 0 || y < 0 ||
|
||||||
|
(((d.rotation == display.NoRotation || d.rotation == display.Rotate180) && (x >= d.width || y >= d.height)) ||
|
||||||
|
((d.rotation == display.Rotate90 || d.rotation == display.Rotate270) && (x >= d.height || y >= d.width))) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
d.FillRectangle(x, y, 1, 1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// setWindow prepares the screen to be modified at a given rectangle
|
||||||
|
func (d *Driver) setWindow(x, y, w, h int16) {
|
||||||
|
x += d.columnOffset
|
||||||
|
y += d.rowOffset
|
||||||
|
d.conn.Tx([]uint8{CASET}, true)
|
||||||
|
d.conn.Tx([]uint8{uint8(x >> 8), uint8(x), uint8((x + w - 1) >> 8), uint8(x + w - 1)}, false)
|
||||||
|
d.conn.Tx([]uint8{RASET}, true)
|
||||||
|
d.conn.Tx([]uint8{uint8(y >> 8), uint8(y), uint8((y + h - 1) >> 8), uint8(y + h - 1)}, false)
|
||||||
|
d.Command(RAMWR)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Clear() {
|
||||||
|
d.FillRectangle(0, 0, d.width, d.height, color.RGBA{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillRectangle fills a rectangle at a given coordinates with a color
|
||||||
|
func (d *Driver) FillRectangle(x, y, width, height int16, c color.RGBA) error {
|
||||||
|
k, i := int16(d.Size().X), int16(d.Size().Y)
|
||||||
|
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
|
||||||
|
x >= k || (x+width) > k || y >= i || (y+height) > i {
|
||||||
|
return errors.New("rectangle coordinates outside display area")
|
||||||
|
}
|
||||||
|
d.setWindow(x, y, width, height)
|
||||||
|
c565 := RGBATo565(c)
|
||||||
|
c1 := uint8(c565 >> 8)
|
||||||
|
c2 := uint8(c565)
|
||||||
|
|
||||||
|
data := make([]uint8, d.batchLength*2)
|
||||||
|
for i := int32(0); i < d.batchLength; i++ {
|
||||||
|
data[i*2] = c1
|
||||||
|
data[i*2+1] = c2
|
||||||
|
}
|
||||||
|
j := int32(width) * int32(height)
|
||||||
|
for j > 0 {
|
||||||
|
if j >= d.batchLength {
|
||||||
|
d.conn.Tx(data, false)
|
||||||
|
} else {
|
||||||
|
d.conn.Tx(data[:j*2], false)
|
||||||
|
}
|
||||||
|
j -= d.batchLength
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillRectangleWithBuffer fills buffer with a rectangle at a given coordinates.
|
||||||
|
func (d *Driver) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
|
||||||
|
i, j := int16(d.Size().X), int16(d.Size().Y)
|
||||||
|
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
|
||||||
|
x >= i || (x+width) > i || y >= j || (y+height) > j {
|
||||||
|
return errors.New("rectangle coordinates outside display area")
|
||||||
|
}
|
||||||
|
if int32(width)*int32(height) != int32(len(buffer)) {
|
||||||
|
return errors.New("buffer length does not match with rectangle size")
|
||||||
|
}
|
||||||
|
d.setWindow(x, y, width, height)
|
||||||
|
|
||||||
|
k := int32(width) * int32(height)
|
||||||
|
data := make([]uint8, d.batchLength*2)
|
||||||
|
offset := int32(0)
|
||||||
|
for k > 0 {
|
||||||
|
for i := int32(0); i < d.batchLength; i++ {
|
||||||
|
if offset+i < int32(len(buffer)) {
|
||||||
|
c565 := RGBATo565(buffer[offset+i])
|
||||||
|
c1 := uint8(c565 >> 8)
|
||||||
|
c2 := uint8(c565)
|
||||||
|
data[i*2] = c1
|
||||||
|
data[i*2+1] = c2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if k >= d.batchLength {
|
||||||
|
d.conn.Tx(data, false)
|
||||||
|
//d.Tx(data, false)
|
||||||
|
} else {
|
||||||
|
d.conn.Tx(data[:k*2], false)
|
||||||
|
//d.Tx(data[:k*2], false)
|
||||||
|
}
|
||||||
|
k -= d.batchLength
|
||||||
|
offset += d.batchLength
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DrawFastVLine draws a vertical line faster than using SetPixel
|
||||||
|
func (d *Driver) DrawFastVLine(x, y0, y1 int16, c color.RGBA) {
|
||||||
|
if y0 > y1 {
|
||||||
|
y0, y1 = y1, y0
|
||||||
|
}
|
||||||
|
d.FillRectangle(x, y0, 1, y1-y0+1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DrawFastHLine draws a horizontal line faster than using SetPixel
|
||||||
|
func (d *Driver) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
|
||||||
|
if x0 > x1 {
|
||||||
|
x0, x1 = x1, x0
|
||||||
|
}
|
||||||
|
d.FillRectangle(x0, y, x1-x0+1, 1, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillScreen fills the screen with a given color
|
||||||
|
func (d *Driver) FillScreen(c color.RGBA) {
|
||||||
|
if d.rotation == display.NoRotation || d.rotation == display.Rotate180 {
|
||||||
|
d.FillRectangle(0, 0, d.width, d.height, c)
|
||||||
|
} else {
|
||||||
|
d.FillRectangle(0, 0, d.height, d.width, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRotation changes the rotation of the device (clock-wise)
|
||||||
|
func (d *Driver) SetRotation(rotation display.Rotation) {
|
||||||
|
madctl := uint8(0)
|
||||||
|
switch rotation % 4 {
|
||||||
|
case display.NoRotation:
|
||||||
|
madctl = MADCTL_MX | MADCTL_MY
|
||||||
|
d.rowOffset = d.rowOffsetCfg
|
||||||
|
d.columnOffset = d.columnOffsetCfg
|
||||||
|
break
|
||||||
|
case display.Rotate90:
|
||||||
|
madctl = MADCTL_MY | MADCTL_MV
|
||||||
|
d.rowOffset = d.columnOffsetCfg
|
||||||
|
d.columnOffset = d.rowOffsetCfg
|
||||||
|
break
|
||||||
|
case display.Rotate180:
|
||||||
|
d.rowOffset = 0
|
||||||
|
d.columnOffset = 0
|
||||||
|
break
|
||||||
|
case display.Rotate270:
|
||||||
|
madctl = MADCTL_MX | MADCTL_MV
|
||||||
|
d.rowOffset = 0
|
||||||
|
d.columnOffset = 0
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if d.isBGR {
|
||||||
|
madctl |= MADCTL_BGR
|
||||||
|
}
|
||||||
|
d.Command(MADCTL)
|
||||||
|
d.Data(madctl)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Command sends a command to the display.
|
||||||
|
func (d *Driver) Command(command uint8) error {
|
||||||
|
//d.Tx([]byte{command}, true)
|
||||||
|
return d.conn.Tx([]byte{command}, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data sends data to the display.
|
||||||
|
func (d *Driver) Data(data uint8) error {
|
||||||
|
//d.Tx([]byte{data}, false)
|
||||||
|
return d.conn.Tx([]byte{data}, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx sends data to the display
|
||||||
|
/*
|
||||||
|
func (d *Driver) Tx(data []byte, isCommand bool) {
|
||||||
|
if isCommand {
|
||||||
|
d.dcPin.Out(gpio.Low)
|
||||||
|
} else {
|
||||||
|
d.dcPin.Out(gpio.High)
|
||||||
|
}
|
||||||
|
d.csPin.Out(gpio.Low)
|
||||||
|
d.bus.Tx(data, nil)
|
||||||
|
d.csPin.Out(gpio.High)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rx reads data from the display
|
||||||
|
func (d *Driver) Rx(command uint8, data []byte) {
|
||||||
|
d.dcPin.Out(gpio.Low)
|
||||||
|
d.csPin.Out(gpio.Low)
|
||||||
|
sendCommand(d.bus, command)
|
||||||
|
|
||||||
|
d.dcPin.Out(gpio.High)
|
||||||
|
for i := range data {
|
||||||
|
data[i], _ = sendCommand(d.bus, 0xFF)
|
||||||
|
}
|
||||||
|
d.csPin.Out(gpio.High)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendCommand(bus spi.Conn, command byte) (byte, error) {
|
||||||
|
answer := []byte{0}
|
||||||
|
err := bus.Tx(
|
||||||
|
[]byte{command},
|
||||||
|
[]byte(""),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return answer[0], nil
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Size returns the current size of the display.
|
||||||
|
/*
|
||||||
|
func (d *Driver) Size() (w, h int16) {
|
||||||
|
if d.rotation == display.NoRotation || d.rotation == display.Rotate180 {
|
||||||
|
return d.width, d.height
|
||||||
|
}
|
||||||
|
return d.height, d.width
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// EnableBacklight enables or disables the backlight
|
||||||
|
func (d *Driver) EnableBacklight(enable bool) {
|
||||||
|
if enable {
|
||||||
|
d.blPin.Out(gpio.High)
|
||||||
|
} else {
|
||||||
|
d.blPin.Out(gpio.Low)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InvertColors inverts the colors of the screen
|
||||||
|
func (d *Driver) InvertColors(invert bool) {
|
||||||
|
if invert {
|
||||||
|
d.Command(INVON)
|
||||||
|
} else {
|
||||||
|
d.Command(INVOFF)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsBGR changes the color mode (RGB/BGR)
|
||||||
|
func (d *Driver) IsBGR(bgr bool) {
|
||||||
|
d.isBGR = bgr
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetScrollArea sets an area to scroll with fixed top and bottom parts of the display.
|
||||||
|
func (d *Driver) SetScrollArea(topFixedArea, bottomFixedArea int16) {
|
||||||
|
d.Command(VSCRDEF)
|
||||||
|
d.conn.Tx([]uint8{
|
||||||
|
uint8(topFixedArea >> 8), uint8(topFixedArea),
|
||||||
|
uint8(d.height - topFixedArea - bottomFixedArea>>8), uint8(d.height - topFixedArea - bottomFixedArea),
|
||||||
|
uint8(bottomFixedArea >> 8), uint8(bottomFixedArea)},
|
||||||
|
false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetScroll sets the vertical scroll address of the display.
|
||||||
|
func (d *Driver) SetScroll(line int16) {
|
||||||
|
d.Command(VSCRSADD)
|
||||||
|
d.conn.Tx([]uint8{uint8(line >> 8), uint8(line)}, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopScroll returns the display to its normal state.
|
||||||
|
func (d *Driver) StopScroll() {
|
||||||
|
d.Command(NORON)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RGBATo565 converts a color.RGBA to uint16 used in the display
|
||||||
|
func RGBATo565(c color.RGBA) uint16 {
|
||||||
|
r, g, b, _ := c.RGBA()
|
||||||
|
return uint16((r & 0xF800) +
|
||||||
|
((g & 0xFC00) >> 5) +
|
||||||
|
((b & 0xF800) >> 11))
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hardware.Display interface methods */
|
||||||
|
|
||||||
|
func (Driver) Type() string {
|
||||||
|
return "st7789"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) At(x, y int) color.Color {
|
||||||
|
return color.Black // not supported!
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Bounds() image.Rectangle {
|
||||||
|
if d.rotation == display.NoRotation || d.rotation == display.Rotate180 {
|
||||||
|
return image.Rect(0, 0, int(d.width), int(d.height))
|
||||||
|
}
|
||||||
|
return image.Rect(0, 0, int(d.height), int(d.width))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) ColorModel() color.Model {
|
||||||
|
return color.RGBAModel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Fill(c color.Color) error {
|
||||||
|
return d.FillRectangle(0, 0, d.width, d.height, color.RGBAModel.Convert(c).(color.RGBA))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Halt() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Set(x, y int, c color.Color) {
|
||||||
|
d.SetPixel(int16(x), int16(y), color.RGBAModel.Convert(c).(color.RGBA))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Size() image.Point {
|
||||||
|
if d.rotation == display.NoRotation || d.rotation == display.Rotate180 {
|
||||||
|
return image.Pt(int(d.width), int(d.height))
|
||||||
|
}
|
||||||
|
return image.Pt(int(d.height), int(d.width))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Driver) Draw(r image.Rectangle, src image.Image, sp image.Point) error {
|
||||||
|
var buffer []color.RGBA
|
||||||
|
for y := r.Min.Y; y < r.Max.Y; y++ {
|
||||||
|
for x := r.Min.X; x < r.Max.X; x++ {
|
||||||
|
buffer = append(buffer, color.RGBAModel.Convert(src.At(x, y)).(color.RGBA))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return d.FillRectangleWithBuffer(int16(sp.X), int16(sp.Y), int16(r.Dx()), int16(r.Dy()), buffer)
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package display
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
)
|
||||||
|
|
||||||
|
// View is a (partial) view on the display.
|
||||||
|
type View struct {
|
||||||
|
hardware.Display
|
||||||
|
Window image.Rectangle
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeView(display hardware.Display, window image.Rectangle) View {
|
||||||
|
return View{
|
||||||
|
Display: display,
|
||||||
|
Window: window,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d View) Type() string {
|
||||||
|
return fmt.Sprintf("view:%s:%s", d.Display.Type(), d.Window)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d View) Size() image.Point {
|
||||||
|
return d.Window.Size()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d View) At(x, y int) color.Color {
|
||||||
|
if x < 0 || y < 0 || x >= d.Window.Dx() || y >= d.Window.Dy() {
|
||||||
|
return d.Display.ColorModel().Convert(color.Black)
|
||||||
|
}
|
||||||
|
x -= d.Window.Min.X
|
||||||
|
y -= d.Window.Min.Y
|
||||||
|
return d.Display.At(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d View) Set(x, y int, c color.Color) {
|
||||||
|
if x < 0 || y < 0 || x >= d.Window.Dx() || y >= d.Window.Dy() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
x -= d.Window.Min.X
|
||||||
|
y -= d.Window.Min.Y
|
||||||
|
d.Display.Set(x, y, c)
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package hardware
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type Input interface {
|
||||||
|
Events() <-chan InputEvent
|
||||||
|
}
|
||||||
|
|
||||||
|
type InputEvent interface {
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
RotaryEvent struct {
|
||||||
|
Time time.Time
|
||||||
|
Input Input
|
||||||
|
Delta int
|
||||||
|
}
|
||||||
|
|
||||||
|
RotaryPressEvent struct {
|
||||||
|
Time time.Time
|
||||||
|
Input Input
|
||||||
|
}
|
||||||
|
|
||||||
|
RotaryLongPressEvent struct {
|
||||||
|
Time time.Time
|
||||||
|
Input Input
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package input
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/config"
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"periph.io/x/conn/v3/gpio"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Encoder interface {
|
||||||
|
hardware.Driver
|
||||||
|
|
||||||
|
Events() (<-chan hardware.InputEvent, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEncoder(config config.Encoder) (Encoder, error) {
|
||||||
|
switch config.Type {
|
||||||
|
case "input":
|
||||||
|
return newDevInputEncoder(config.Switch)
|
||||||
|
|
||||||
|
case "gpio":
|
||||||
|
return newGPIOEncoder(config.CW, config.CCW, config.Switch)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported encoder type %q", config.Type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type gpioEncoder struct {
|
||||||
|
cw, ccw, click gpio.PinIn
|
||||||
|
}
|
||||||
|
|
||||||
|
func newGPIOEncoder(cw, ccw, click string) (enc Encoder, err error) {
|
||||||
|
e := new(gpioEncoder)
|
||||||
|
if e.cw, err = hardware.LookupPin(cw); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if e.ccw, err = hardware.LookupPin(ccw); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if e.click, err = hardware.LookupPin(click); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,270 @@
|
|||||||
|
package input
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"periph.io/x/conn/v3/gpio"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
devfsPath = "/dev"
|
||||||
|
procfsPath = "/proc"
|
||||||
|
procInputDevices = procfsPath + "/bus/input/devices"
|
||||||
|
)
|
||||||
|
|
||||||
|
type devInputEncoder struct {
|
||||||
|
path string
|
||||||
|
click gpio.PinIn
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDevInputEncoder(click string) (enc Encoder, err error) {
|
||||||
|
e := new(devInputEncoder)
|
||||||
|
if e.click, err = hardware.LookupPin(click); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var ps []*linuxPheripheral
|
||||||
|
if ps, err = linuxPheripherals(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range ps {
|
||||||
|
if strings.HasPrefix(p.name, "rotary@") {
|
||||||
|
e.path = p.path
|
||||||
|
return e, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errors.New("no rotary encoders found in " + procInputDevices)
|
||||||
|
}
|
||||||
|
|
||||||
|
type linuxPheripheral struct {
|
||||||
|
name string
|
||||||
|
bus string
|
||||||
|
vendor string
|
||||||
|
product string
|
||||||
|
version string
|
||||||
|
phys string
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
I: Bus=0019 Vendor=0001 Product=0001 Version=0100
|
||||||
|
N: Name="button@10"
|
||||||
|
P: Phys=gpio-keys/input0
|
||||||
|
S: Sysfs=/devices/platform/button@10/input/input0
|
||||||
|
U: Uniq=
|
||||||
|
H: Handlers=kbd event0
|
||||||
|
B: PROP=0
|
||||||
|
B: EV=3
|
||||||
|
B: KEY=20000 0 0 0
|
||||||
|
|
||||||
|
I: Bus=0019 Vendor=0000 Product=0000 Version=0000
|
||||||
|
N: Name="rotary@14"
|
||||||
|
P: Phys=
|
||||||
|
S: Sysfs=/devices/platform/rotary@14/input/input1
|
||||||
|
U: Uniq=
|
||||||
|
H: Handlers=event1
|
||||||
|
B: PROP=0
|
||||||
|
B: EV=5
|
||||||
|
B: REL=1
|
||||||
|
*/
|
||||||
|
func linuxPheripherals() (ps []*linuxPheripheral, err error) {
|
||||||
|
log := logrus.WithField("input", "linux")
|
||||||
|
log.Trace("detecting peripherals")
|
||||||
|
|
||||||
|
b, err := os.ReadFile(procInputDevices)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, segment := range strings.Split(string(b), "\n\n") {
|
||||||
|
lines := strings.Split(segment, "\n")
|
||||||
|
perip := new(linuxPheripheral)
|
||||||
|
for _, line := range lines {
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log.WithField("line", line).Trace("parsing line")
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(line, "I: "):
|
||||||
|
for _, kv := range strings.Split(strings.TrimPrefix(line, "I: "), " ") {
|
||||||
|
kv := strings.SplitN(kv, "=", 2)
|
||||||
|
switch kv[0] {
|
||||||
|
case "Bus":
|
||||||
|
case "Vendor":
|
||||||
|
perip.vendor = kv[1]
|
||||||
|
case "Product":
|
||||||
|
perip.product = kv[1]
|
||||||
|
case "Version":
|
||||||
|
perip.version = kv[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case strings.HasPrefix(line, "N: Name="):
|
||||||
|
perip.name = strings.TrimFunc(strings.TrimPrefix(line, "N: Name="), func(r rune) bool { return r == '"' || r == '@' })
|
||||||
|
case strings.HasPrefix(line, "P: Phys="):
|
||||||
|
perip.phys = strings.TrimPrefix(line, "P: Phys=")
|
||||||
|
//case strings.HasPrefix(line, "S: Sysfs="):
|
||||||
|
// perip.sysfs = filepath.Join(sysfsPath, strings.TrimPrefix(line, "S: Sysfs="), "device")
|
||||||
|
case strings.HasPrefix(line, "H: Handlers="):
|
||||||
|
for _, handler := range strings.Split(strings.TrimPrefix(line, "H: Handlers="), " ") {
|
||||||
|
if strings.HasPrefix(handler, "event") {
|
||||||
|
perip.path = filepath.Join(devfsPath, "input", handler)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if perip.path != "" {
|
||||||
|
log.WithFields(logrus.Fields{
|
||||||
|
"name": perip.name,
|
||||||
|
"bus": perip.bus,
|
||||||
|
"vendor": perip.vendor,
|
||||||
|
"product": perip.product,
|
||||||
|
"version": perip.version,
|
||||||
|
"phys": perip.phys,
|
||||||
|
"path": perip.path,
|
||||||
|
}).Trace("found peripheral")
|
||||||
|
ps = append(ps, perip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ps, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type linuxInputEvent struct {
|
||||||
|
Secs uint32
|
||||||
|
USecs uint32
|
||||||
|
Type uint16
|
||||||
|
Code uint16
|
||||||
|
Value int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e linuxInputEvent) Time() time.Time {
|
||||||
|
return time.Unix(int64(e.Secs), int64(e.USecs))
|
||||||
|
}
|
||||||
|
|
||||||
|
func readLinuxInputEvents(name string, cb func(linuxInputEvent) error) error {
|
||||||
|
f, err := os.Open(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var raw linuxInputEvent
|
||||||
|
for {
|
||||||
|
if err := binary.Read(f, binary.LittleEndian, &raw); err != nil {
|
||||||
|
_ = f.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := cb(raw); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type linuxButton struct {
|
||||||
|
p *linuxPheripheral
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLinuxButton(p *linuxPheripheral) *linuxButton {
|
||||||
|
return &linuxButton{p: p}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *linuxButton) Name() string {
|
||||||
|
return s.p.name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *linuxButton) Events() (<-chan Event, error) {
|
||||||
|
log := logrus.
|
||||||
|
WithField("input", "button").
|
||||||
|
WithField("path", s.p.path)
|
||||||
|
log.Debug("opening linux button source")
|
||||||
|
|
||||||
|
events := make(chan Event)
|
||||||
|
go s.readEvents(events)
|
||||||
|
return events, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *linuxButton) readEvents(events chan<- Event) {
|
||||||
|
defer close(events)
|
||||||
|
|
||||||
|
log := logrus.
|
||||||
|
WithField("input", "button").
|
||||||
|
WithField("path", s.p.path)
|
||||||
|
|
||||||
|
err := readLinuxInputEvents(s.p.path, func(ev linuxInputEvent) error {
|
||||||
|
log.WithField("data", ev).Debug("button event")
|
||||||
|
|
||||||
|
if ev.Code == 0 {
|
||||||
|
return nil // not sure what this is
|
||||||
|
}
|
||||||
|
|
||||||
|
var pressed bool
|
||||||
|
if ev.Value == 1 {
|
||||||
|
pressed = true
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case events <- NewButtonEvent(s, pressed):
|
||||||
|
default:
|
||||||
|
log.Warn("dropping event")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("failed to read events")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type linuxRotary struct {
|
||||||
|
p *linuxPheripheral
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLinuxRotary(p *linuxPheripheral) *linuxRotary {
|
||||||
|
return &linuxRotary{p: p}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *linuxRotary) Name() string {
|
||||||
|
return s.p.name
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *linuxRotary) Events() (<-chan Event, error) {
|
||||||
|
log := logrus.
|
||||||
|
WithField("input", "rotary").
|
||||||
|
WithField("path", s.p.path)
|
||||||
|
log.Debug("opening linux rotary source")
|
||||||
|
|
||||||
|
events := make(chan Event)
|
||||||
|
go s.readEvents(events)
|
||||||
|
return events, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *linuxRotary) readEvents(events chan<- Event) {
|
||||||
|
defer close(events)
|
||||||
|
|
||||||
|
log := logrus.
|
||||||
|
WithField("input", "rotary").
|
||||||
|
WithField("path", s.p.path)
|
||||||
|
|
||||||
|
err := readLinuxInputEvents(s.p.path, func(ev linuxInputEvent) error {
|
||||||
|
log.WithField("data", ev).Debug("rotary event")
|
||||||
|
|
||||||
|
select {
|
||||||
|
case events <- NewRotaryEvent(s, int(ev.Value), ev.Value == 0):
|
||||||
|
default:
|
||||||
|
log.Warn("dropping event")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("failed to read events")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package input
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
func newDevInputEncoder(string) (Encoder, error) {
|
||||||
|
return nil, errors.New("input encoders are only supported in Linux")
|
||||||
|
}
|
||||||
+22
-14
@@ -1,24 +1,32 @@
|
|||||||
display {
|
display {
|
||||||
fps = 15
|
fps = 20
|
||||||
|
|
||||||
|
#main {
|
||||||
|
# type = "ssd1322"
|
||||||
|
# size = "256x64"
|
||||||
|
#}
|
||||||
|
|
||||||
left {
|
left {
|
||||||
type = "ssd1306"
|
|
||||||
addr = "0x3d"
|
|
||||||
size = "128x64"
|
|
||||||
}
|
|
||||||
|
|
||||||
right {
|
|
||||||
type = "ssd1306"
|
type = "ssd1306"
|
||||||
addr = "0x3c"
|
addr = "0x3c"
|
||||||
size = "128x64"
|
size = "128x64"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
right {
|
||||||
|
type = "ssd1306"
|
||||||
|
addr = "0x3d"
|
||||||
|
size = "128x64"
|
||||||
|
}
|
||||||
|
|
||||||
color {
|
color {
|
||||||
type = "st7789"
|
#type = "st7789"
|
||||||
size = "240x240"
|
#size = "240x240"
|
||||||
reset = "GPIOx" # reset pin
|
type = "st7735"
|
||||||
dc = "GPIOx" # data control pin
|
size = "128x160"
|
||||||
bl = "GPIOx" # backlight pin
|
port = "" # SPI0.0
|
||||||
|
reset = "GPIO23" # reset pin
|
||||||
|
dc = "GPIO24" # data control pin
|
||||||
|
bl = "GPIO27" # backlight pin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,8 +62,8 @@ player {
|
|||||||
|
|
||||||
audio {
|
audio {
|
||||||
type = "fifo"
|
type = "fifo"
|
||||||
path = "/tmp/mpd.fifo"
|
path = "/tmp/harmon.fifo"
|
||||||
rate = 44100
|
rate = 8000
|
||||||
channels = 2
|
channels = 2
|
||||||
bits = 16
|
bits = 16
|
||||||
}
|
}
|
||||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,160 @@
|
|||||||
|
package calc
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
|
// Complex is a constraint that permits any complex numeric type.
|
||||||
|
type Complex interface {
|
||||||
|
~complex64 | ~complex128
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float is a constraint that permits any floating-point type.
|
||||||
|
type Float interface {
|
||||||
|
~float32 | ~float64
|
||||||
|
}
|
||||||
|
|
||||||
|
// Integer is a constraint that permits any integer type.
|
||||||
|
type Integer interface {
|
||||||
|
Signed | Unsigned
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signed is a constraint that permits any signed integer type.
|
||||||
|
type Signed interface {
|
||||||
|
~int | ~int8 | ~int16 | ~int32 | ~int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unsigned is a constraint that permits any unsigned integer type.
|
||||||
|
type Unsigned interface {
|
||||||
|
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
// Number are real valued number types.
|
||||||
|
type Number interface {
|
||||||
|
Integer | Float
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum of values.
|
||||||
|
func Sum[T Number](data []T) T {
|
||||||
|
if len(data) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var sum T
|
||||||
|
for _, v := range data {
|
||||||
|
sum += v
|
||||||
|
}
|
||||||
|
return sum
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mean of values.
|
||||||
|
func Mean[T Number](data []T) float64 {
|
||||||
|
if len(data) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// an algorithm that attempts to retain accuracy
|
||||||
|
// with widely different values.
|
||||||
|
var parts []float64
|
||||||
|
for _, v := range data {
|
||||||
|
var (
|
||||||
|
x = float64(v)
|
||||||
|
i int
|
||||||
|
)
|
||||||
|
for _, p := range parts {
|
||||||
|
sum := p + x
|
||||||
|
var err float64
|
||||||
|
switch ax, ap := math.Abs(x), math.Abs(p); {
|
||||||
|
case ax < ap:
|
||||||
|
err = x - (sum - p)
|
||||||
|
case ap < ax:
|
||||||
|
err = p - (sum - x)
|
||||||
|
}
|
||||||
|
if err != 0 {
|
||||||
|
parts[i] = err
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
x = sum
|
||||||
|
}
|
||||||
|
parts = append(parts[:i], x)
|
||||||
|
}
|
||||||
|
|
||||||
|
var sum float64
|
||||||
|
for _, x := range parts {
|
||||||
|
sum += x
|
||||||
|
}
|
||||||
|
return sum / float64(len(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MeanOffset is the mean of values every offset starting at start.
|
||||||
|
func MeanOffset[T Number](data []T, start, offset int) float64 {
|
||||||
|
if len(data)/offset == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// an algorithm that attempts to retain accuracy
|
||||||
|
// with widely different values.
|
||||||
|
var parts []float64
|
||||||
|
for j, l := start, len(data); j < l; j += offset {
|
||||||
|
var (
|
||||||
|
x = float64(data[j])
|
||||||
|
i int
|
||||||
|
)
|
||||||
|
for _, p := range parts {
|
||||||
|
sum := p + x
|
||||||
|
var err float64
|
||||||
|
switch ax, ap := math.Abs(x), math.Abs(p); {
|
||||||
|
case ax < ap:
|
||||||
|
err = x - (sum - p)
|
||||||
|
case ap < ax:
|
||||||
|
err = p - (sum - x)
|
||||||
|
}
|
||||||
|
if err != 0 {
|
||||||
|
parts[i] = err
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
x = sum
|
||||||
|
}
|
||||||
|
parts = append(parts[:i], x)
|
||||||
|
}
|
||||||
|
|
||||||
|
var sum float64
|
||||||
|
for _, x := range parts {
|
||||||
|
sum += x
|
||||||
|
}
|
||||||
|
return sum / float64(len(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RMS is the root mean square of values.
|
||||||
|
func RMS[T Number](data []T) float64 {
|
||||||
|
if len(data) == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var squares float64
|
||||||
|
for _, v := range data {
|
||||||
|
squares += float64(v) * float64(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return math.Sqrt(squares / float64(len(data)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// RMSOffset is the root mean square of values every offset.
|
||||||
|
func RMSOffset[T Number](data []T, start, offset int) float64 {
|
||||||
|
if len(data)/offset == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var squares float64
|
||||||
|
for i, l := start, len(data); i < l; i += offset {
|
||||||
|
squares += float64(data[i]) * float64(data[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
return math.Sqrt(squares / float64(len(data)/offset))
|
||||||
|
}
|
||||||
|
|
||||||
|
func Eq(a, b, epsilon float32) bool {
|
||||||
|
return math.Abs(float64(a-b)) < float64(epsilon)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AlmostEq(a, b float32) bool {
|
||||||
|
return Eq(a, b, 1e-20)
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package calc_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/internal/calc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMean(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
Test []float32
|
||||||
|
Want float64
|
||||||
|
}{
|
||||||
|
{nil, 0},
|
||||||
|
{[]float32{3, 1, 4, 1, 5, 9}, 3.8333333333333335},
|
||||||
|
{[]float32{1e20, 3, 1, 4, 1, 5, 9, -1e20}, 2.875},
|
||||||
|
{[]float32{10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, .11}, 3.674},
|
||||||
|
{[]float32{10, 20, 30, 40, 50, -100, 4.7, -11e2}, -130.66250002384186},
|
||||||
|
}
|
||||||
|
for _, test := range testCases {
|
||||||
|
if v := calc.Mean(test.Test); !almostEq(v, test.Want) {
|
||||||
|
t.Errorf("expected Mean(%v) to return %g, got %g", test.Test, test.Want, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRMS(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
Test []float32
|
||||||
|
Want float64
|
||||||
|
}{
|
||||||
|
{[]float32{3, 1, 4, 1, 5, 9}, 4.708148963941845},
|
||||||
|
{[]float32{1e20, 3, 1, 4, 1, 5, 9, -1e20}, 5.000000100204387e+19},
|
||||||
|
{[]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 6.2048368229954285},
|
||||||
|
}
|
||||||
|
for _, test := range testCases {
|
||||||
|
if v := calc.RMS(test.Test); !almostEq(v, test.Want) {
|
||||||
|
t.Errorf("expected RMS(%v) to return %g, got %g", test.Test, test.Want, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func almostEq(a, b float64) bool {
|
||||||
|
return math.Abs(a-b) < 1e-5
|
||||||
|
}
|
||||||
+171
-8
@@ -2,9 +2,54 @@ package pixel
|
|||||||
|
|
||||||
import "image/color"
|
import "image/color"
|
||||||
|
|
||||||
var (
|
// Pixel with a particular color, matching the underlying hardware of a
|
||||||
MonochromeModel color.Model = color.ModelFunc(monochromeModel)
|
// particular display. Each pixel is at least 1 byte in size.
|
||||||
)
|
// The color format is sRGB (or close to it) in all cases except for 1-bit.
|
||||||
|
type Color interface {
|
||||||
|
Monochrome | RGB444 | RGB565
|
||||||
|
|
||||||
|
BaseColor
|
||||||
|
}
|
||||||
|
|
||||||
|
// BaseColor contains all the methods needed in a color format. This can be used
|
||||||
|
// in display drivers that want to define their own Color type with just the
|
||||||
|
// pixel formats the display supports.
|
||||||
|
type BaseColor interface {
|
||||||
|
color.Color
|
||||||
|
|
||||||
|
// The number of bits when stored.
|
||||||
|
// This means for example that RGB555 (which is still stored as a 16-bit
|
||||||
|
// integer) returns 16, while RGB444 returns 12.
|
||||||
|
BitsPerPixel() int
|
||||||
|
|
||||||
|
// Return the given color in color.RGBA format, which is always sRGB. The
|
||||||
|
// alpha channel is always 255.
|
||||||
|
RGBAColor() color.RGBA
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewColor returns the given color based on the RGB values passed in the
|
||||||
|
// parameters. The input value is assumed to be in sRGB color space.
|
||||||
|
func NewColor[T Color](r, g, b uint8) T {
|
||||||
|
// Ugly cast from color.RGBA to T. The type switch and interface casts are
|
||||||
|
// trivially optimized away after instantiation.
|
||||||
|
var value T
|
||||||
|
switch any(value).(type) {
|
||||||
|
case Monochrome:
|
||||||
|
return any(NewMonochrome(r, g, b)).(T)
|
||||||
|
case RGB444:
|
||||||
|
return any(NewRGB444(r, g, b)).(T)
|
||||||
|
case RGB565:
|
||||||
|
return any(NewRGB565(r, g, b)).(T)
|
||||||
|
/*
|
||||||
|
case RGB555:
|
||||||
|
return any(NewRGB555(r, g, b)).(T)
|
||||||
|
case RGB888:
|
||||||
|
return any(NewRGB888(r, g, b)).(T)
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
panic("unknown color format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ToGrayBits converts a color to a n-bit grayscale color.
|
// ToGrayBits converts a color to a n-bit grayscale color.
|
||||||
func ToGrayBits(c color.Color, n uint8) uint16 {
|
func ToGrayBits(c color.Color, n uint8) uint16 {
|
||||||
@@ -39,6 +84,13 @@ const (
|
|||||||
On
|
On
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewMonochrome(r, g, b uint8) Monochrome {
|
||||||
|
if ToGrayBits(color.RGBA{r, g, b, 0xff}, 1) == 1 {
|
||||||
|
return On
|
||||||
|
}
|
||||||
|
return Off
|
||||||
|
}
|
||||||
|
|
||||||
func (c Monochrome) RGBA() (r, g, b, a uint32) {
|
func (c Monochrome) RGBA() (r, g, b, a uint32) {
|
||||||
if c == 0 {
|
if c == 0 {
|
||||||
return 0, 0, 0, 0
|
return 0, 0, 0, 0
|
||||||
@@ -46,13 +98,124 @@ func (c Monochrome) RGBA() (r, g, b, a uint32) {
|
|||||||
return 0xffff, 0xffff, 0xffff, 0xffff
|
return 0xffff, 0xffff, 0xffff, 0xffff
|
||||||
}
|
}
|
||||||
|
|
||||||
func monochromeModel(c color.Color) color.Color {
|
func IsOn(c color.Color) bool {
|
||||||
if _, ok := c.(Monochrome); ok {
|
if _, ok := c.(Monochrome); ok {
|
||||||
return c
|
return c == On
|
||||||
}
|
}
|
||||||
|
return ToGrayBits(c, 1) == 1
|
||||||
|
}
|
||||||
|
|
||||||
if ToGrayBits(c, 1) == 0 {
|
// Color format that is supported by the ST7789 for example.
|
||||||
return Off
|
// It may be a bit faster to use than RGB565BE on very slow SPI buses.
|
||||||
|
//
|
||||||
|
// The color format is native endian as a uint16 (0000rrrr_ggggbbbb), not big
|
||||||
|
// endian which you might expect. I tried swapping the bytes, but it didn't have
|
||||||
|
// much of a performance impact and made the code harder to read. It is stored
|
||||||
|
// as a 12-bit big endian value in Image[RGB444] though.
|
||||||
|
type RGB444 uint16
|
||||||
|
|
||||||
|
func NewRGB444(r, g, b uint8) RGB444 {
|
||||||
|
return RGB444(r>>4)<<8 | RGB444(g>>4)<<4 | RGB444(b>>4)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c RGB444) BitsPerPixel() int {
|
||||||
|
return 12
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c RGB444) RGBA() (r, g, b, a uint32) {
|
||||||
|
r = uint32(c>>8) & 0x0f
|
||||||
|
r |= (r << 4) | (r << 8) | (r << 12)
|
||||||
|
g = uint32(c>>4) & 0x0f
|
||||||
|
g |= (g << 4) | (g << 8) | (g << 12)
|
||||||
|
b = uint32(c>>0) & 0x0f
|
||||||
|
b |= (b << 4) | (b << 8) | (b << 12)
|
||||||
|
a |= 0xffff
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c RGB444) RGBAColor() color.RGBA {
|
||||||
|
color := color.RGBA{
|
||||||
|
R: uint8(c>>8) << 4,
|
||||||
|
G: uint8(c>>4) << 4,
|
||||||
|
B: uint8(c>>0) << 4,
|
||||||
|
A: 255,
|
||||||
|
}
|
||||||
|
// Correct color rounding, so that 0xff roundtrips back to 0xff.
|
||||||
|
color.R |= color.R >> 4
|
||||||
|
color.G |= color.G >> 4
|
||||||
|
color.B |= color.B >> 4
|
||||||
|
return color
|
||||||
|
}
|
||||||
|
|
||||||
|
// RGB565 color.
|
||||||
|
type RGB565 uint16
|
||||||
|
|
||||||
|
func NewRGB565(r, g, b uint8) RGB565 {
|
||||||
|
val := uint16(r&0xF8)<<8 +
|
||||||
|
uint16(g&0xFC)<<3 +
|
||||||
|
uint16(b&0xF8)>>3
|
||||||
|
// Swap endianness (make big endian).
|
||||||
|
// This is done using a single instruction on ARM (rev16).
|
||||||
|
// TODO: this should only be done on little endian systems, but TinyGo
|
||||||
|
// doesn't currently (2023) support big endian systems so it's difficult to
|
||||||
|
// test. Also, big endian systems don't seem fasionable these days.
|
||||||
|
//val = bits.ReverseBytes16(val)
|
||||||
|
return RGB565(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FromColor retusn the given color.
|
||||||
|
func FromColor[T Color](c color.Color) T {
|
||||||
|
var value T
|
||||||
|
switch any(value).(type) {
|
||||||
|
case Monochrome:
|
||||||
|
return monochromeModel(c).(T)
|
||||||
|
case RGB444:
|
||||||
|
return rgb444Model(c).(T)
|
||||||
|
case RGB565:
|
||||||
|
return rgb565Model(c).(T)
|
||||||
|
/*
|
||||||
|
case RGB555:
|
||||||
|
return rgb555Model(c).(T)
|
||||||
|
case RGB888:
|
||||||
|
return rgb888Model(c).(T)
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
panic("unknown color format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c RGB565) BitsPerPixel() int {
|
||||||
|
return 16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c RGB565) RGBA() (r, g, b, a uint32) {
|
||||||
|
r = uint32(uint8(c>>12) << 3)
|
||||||
|
r |= (r >> 5)
|
||||||
|
r |= (r << 8)
|
||||||
|
g = uint32(uint8(c>>5) << 2)
|
||||||
|
g |= (g >> 6)
|
||||||
|
g |= (g << 8)
|
||||||
|
b = uint32(uint8(c>>0) << 3)
|
||||||
|
b |= (b >> 5)
|
||||||
|
b |= (b << 8)
|
||||||
|
a = 0xffff
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c RGB565) RGBAColor() color.RGBA {
|
||||||
|
// Note: on ARM, the compiler uses a rev instruction instead of a rev16
|
||||||
|
// instruction. I wonder whether this can be optimized further to use rev16
|
||||||
|
// instead?
|
||||||
|
c = c<<8 | c>>8
|
||||||
|
color := color.RGBA{
|
||||||
|
R: uint8(c>>11) << 3,
|
||||||
|
G: uint8(c>>5) << 2,
|
||||||
|
B: uint8(c) << 3,
|
||||||
|
A: 255,
|
||||||
}
|
}
|
||||||
return On
|
// Correct color rounding, so that 0xff roundtrips back to 0xff.
|
||||||
|
color.R |= color.R >> 5
|
||||||
|
color.G |= color.G >> 6
|
||||||
|
color.B |= color.B >> 5
|
||||||
|
return color
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,376 @@ package pixel
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"image/draw"
|
||||||
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Image buffer, used for working with the native image format of various
|
||||||
|
// displays. It works a lot like a slice: it can be rescaled while reusing the
|
||||||
|
// underlying buffer and should be passed around by value.
|
||||||
|
type Image[T Color] struct {
|
||||||
|
width int16
|
||||||
|
height int16
|
||||||
|
data unsafe.Pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewImage creates a new image of the given size.
|
||||||
|
func NewImage[T Color](width, height int) Image[T] {
|
||||||
|
if width < 0 || height < 0 || int(int16(width)) != width || int(int16(height)) != height {
|
||||||
|
// The width/height are stored as 16-bit integers and should never be
|
||||||
|
// negative.
|
||||||
|
panic("NewImage: width/height out of bounds")
|
||||||
|
}
|
||||||
|
var zeroColor T
|
||||||
|
var data unsafe.Pointer
|
||||||
|
switch {
|
||||||
|
case zeroColor.BitsPerPixel()%8 == 0:
|
||||||
|
// Typical formats like RGB888 and RGB565.
|
||||||
|
// Each color starts at a whole byte offset from the start.
|
||||||
|
buf := make([]T, width*height)
|
||||||
|
data = unsafe.Pointer(&buf[0])
|
||||||
|
default:
|
||||||
|
// Formats like RGB444 that have 12 bits per pixel.
|
||||||
|
// We access these as bytes, so allocate the buffer as a byte slice.
|
||||||
|
bufBits := width * height * zeroColor.BitsPerPixel()
|
||||||
|
bufBytes := (bufBits + 7) / 8
|
||||||
|
buf := make([]byte, bufBytes)
|
||||||
|
data = unsafe.Pointer(&buf[0])
|
||||||
|
}
|
||||||
|
return Image[T]{
|
||||||
|
width: int16(width),
|
||||||
|
height: int16(height),
|
||||||
|
data: data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewImageFromBytes creates a new image of the given size using an existing data slice of bytes.
|
||||||
|
func NewImageFromBytes[T Color](width, height int, buf []byte) Image[T] {
|
||||||
|
if width < 0 || height < 0 || int(int16(width)) != width || int(int16(height)) != height {
|
||||||
|
// The width/height are stored as 16-bit integers and should never be
|
||||||
|
// negative.
|
||||||
|
panic("NewImageFromBytes: width/height out of bounds")
|
||||||
|
}
|
||||||
|
var zeroColor T
|
||||||
|
var data unsafe.Pointer
|
||||||
|
switch {
|
||||||
|
case zeroColor.BitsPerPixel()%8 == 0:
|
||||||
|
// Typical formats like RGB888 and RGB565.
|
||||||
|
// Each color starts at a whole byte offset from the start.
|
||||||
|
if len(buf) != width*height*int(unsafe.Sizeof(zeroColor)) {
|
||||||
|
panic("NewImageFromBytes: data slice size mismatch")
|
||||||
|
}
|
||||||
|
data = unsafe.Pointer(&buf[0])
|
||||||
|
default:
|
||||||
|
// Formats like RGB444 that have 12 bits per pixel.
|
||||||
|
// We access these as bytes, so allocate the buffer as a byte slice.
|
||||||
|
bufBits := width * height * zeroColor.BitsPerPixel()
|
||||||
|
bufBytes := (bufBits + 7) / 8
|
||||||
|
if len(buf) != bufBytes {
|
||||||
|
panic("NewImageFromBytes: data slice size mismatch")
|
||||||
|
}
|
||||||
|
data = unsafe.Pointer(&buf[0])
|
||||||
|
}
|
||||||
|
return Image[T]{
|
||||||
|
width: int16(width),
|
||||||
|
height: int16(height),
|
||||||
|
data: data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewImageFromImage creates a new image from the provided image.
|
||||||
|
func NewImageFromImage[T Color](src image.Image) Image[T] {
|
||||||
|
var (
|
||||||
|
r = src.Bounds()
|
||||||
|
width = r.Dx()
|
||||||
|
height = r.Dy()
|
||||||
|
dst = NewImage[T](width, height)
|
||||||
|
)
|
||||||
|
draw.Draw(dst, r, src, image.Point{}, draw.Src)
|
||||||
|
return dst
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rescale returns a new Image buffer based on the img buffer.
|
||||||
|
// The contents is undefined after the Rescale operation, and any modification
|
||||||
|
// to the returned image will overwrite the underlying image buffer in undefined
|
||||||
|
// ways. It will panic if width*height is larger than img.Len().
|
||||||
|
func (img Image[T]) Rescale(width, height int) Image[T] {
|
||||||
|
if width*height > img.Len() {
|
||||||
|
panic("Image.Rescale size out of bounds")
|
||||||
|
}
|
||||||
|
return Image[T]{
|
||||||
|
width: int16(width),
|
||||||
|
height: int16(height),
|
||||||
|
data: img.data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LimitHeight returns a subimage with the bottom part cut off, as specified by
|
||||||
|
// height.
|
||||||
|
func (img Image[T]) LimitHeight(height int) Image[T] {
|
||||||
|
if height < 0 || height > int(img.height) {
|
||||||
|
panic("Image.LimitHeight: out of bounds")
|
||||||
|
}
|
||||||
|
return Image[T]{
|
||||||
|
width: img.width,
|
||||||
|
height: int16(height),
|
||||||
|
data: img.data,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Len returns the number of pixels in this image buffer.
|
||||||
|
func (img Image[T]) Len() int {
|
||||||
|
return int(img.width) * int(img.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RawBuffer returns a byte slice that can be written directly to the screen
|
||||||
|
// using DrawRGBBitmap8.
|
||||||
|
func (img Image[T]) RawBuffer() []uint8 {
|
||||||
|
var zeroColor T
|
||||||
|
var numBytes int
|
||||||
|
switch {
|
||||||
|
case zeroColor.BitsPerPixel()%8 == 0:
|
||||||
|
// Each color starts at a whole byte offset.
|
||||||
|
numBytes = int(unsafe.Sizeof(zeroColor)) * int(img.width) * int(img.height)
|
||||||
|
default:
|
||||||
|
// Formats like RGB444 that aren't a whole number of bytes.
|
||||||
|
numBits := zeroColor.BitsPerPixel() * int(img.width) * int(img.height)
|
||||||
|
numBytes = (numBits + 7) / 8 // round up (see NewImage)
|
||||||
|
}
|
||||||
|
return unsafe.Slice((*byte)(img.data), numBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size returns the image size.
|
||||||
|
func (img Image[T]) Size() (int, int) {
|
||||||
|
return int(img.width), int(img.height)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (img Image[T]) setPixel(index int, c T) {
|
||||||
|
var zeroColor T
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case zeroColor.BitsPerPixel() == 1:
|
||||||
|
// Monochrome.
|
||||||
|
offset := index / 8
|
||||||
|
bits := index % 8
|
||||||
|
|
||||||
|
ptr := (*byte)(unsafe.Add(img.data, offset))
|
||||||
|
if c != zeroColor {
|
||||||
|
*((*byte)(ptr)) |= (1 << (7 - uint8(bits)))
|
||||||
|
} else {
|
||||||
|
*((*byte)(ptr)) &^= (1 << (7 - uint8(bits)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
case zeroColor.BitsPerPixel()%8 == 0:
|
||||||
|
// Each color starts at a whole byte offset.
|
||||||
|
// This is the easy case.
|
||||||
|
offset := index * int(unsafe.Sizeof(zeroColor))
|
||||||
|
ptr := unsafe.Add(img.data, offset)
|
||||||
|
*((*T)(ptr)) = c
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if c, ok := any(c).(RGB444); ok {
|
||||||
|
// Special case for RGB444.
|
||||||
|
bitIndex := index * zeroColor.BitsPerPixel()
|
||||||
|
if bitIndex%8 == 0 {
|
||||||
|
byteOffset := bitIndex / 8
|
||||||
|
ptr := (*[2]byte)(unsafe.Add(img.data, byteOffset))
|
||||||
|
ptr[0] = uint8(c >> 4)
|
||||||
|
ptr[1] = ptr[1]&0x0f | uint8(c)<<4 // change top bits
|
||||||
|
} else {
|
||||||
|
byteOffset := bitIndex / 8
|
||||||
|
ptr := (*[2]byte)(unsafe.Add(img.data, byteOffset))
|
||||||
|
ptr[0] = ptr[0]&0xf0 | uint8(c>>8) // change bottom bits
|
||||||
|
ptr[1] = uint8(c)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: the code for RGB444 should be generalized to support any bit size.
|
||||||
|
panic("todo: setPixel for odd bits per pixel")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set sets the pixel at x, y to the given color.
|
||||||
|
// Use FillSolidColor to efficiently fill the entire image buffer.
|
||||||
|
func (img Image[T]) SetPixel(x, y int, c T) {
|
||||||
|
if uint(x) >= uint(int(img.width)) || uint(y) >= uint(int(img.height)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
index := y*int(img.width) + x
|
||||||
|
img.setPixel(index, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns the color at the given index.
|
||||||
|
func (img Image[T]) GetPixel(x, y int) T {
|
||||||
|
var zeroColor T
|
||||||
|
if uint(x) >= uint(int(img.width)) || uint(y) >= uint(int(img.height)) {
|
||||||
|
return zeroColor
|
||||||
|
}
|
||||||
|
index := y*int(img.width) + x // index into img.data
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case zeroColor.BitsPerPixel() == 1:
|
||||||
|
// Monochrome.
|
||||||
|
var c Monochrome
|
||||||
|
offset := index / 8
|
||||||
|
bits := index % 8
|
||||||
|
ptr := (*byte)(unsafe.Add(img.data, offset))
|
||||||
|
c = Monochrome((*ptr >> (7 - uint8(bits))) & 0x1)
|
||||||
|
return any(c).(T)
|
||||||
|
case zeroColor.BitsPerPixel()%8 == 0:
|
||||||
|
// Colors like RGB565, RGB888, etc.
|
||||||
|
offset := index * int(unsafe.Sizeof(zeroColor))
|
||||||
|
ptr := unsafe.Add(img.data, offset)
|
||||||
|
return *((*T)(ptr))
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := any(zeroColor).(RGB444); ok {
|
||||||
|
// Special case for RGB444 that isn't stored in a neat byte multiple.
|
||||||
|
bitIndex := index * zeroColor.BitsPerPixel()
|
||||||
|
var c RGB444
|
||||||
|
if bitIndex%8 == 0 {
|
||||||
|
byteOffset := bitIndex / 8
|
||||||
|
ptr := (*[2]byte)(unsafe.Add(img.data, byteOffset))
|
||||||
|
c |= RGB444(ptr[0]) << 4
|
||||||
|
c |= RGB444(ptr[1] >> 4) // load top bits
|
||||||
|
} else {
|
||||||
|
byteOffset := bitIndex / 8
|
||||||
|
ptr := (*[2]byte)(unsafe.Add(img.data, byteOffset))
|
||||||
|
c |= RGB444(ptr[0]&0x0f) << 8 // load bottom bits
|
||||||
|
c |= RGB444(ptr[1])
|
||||||
|
}
|
||||||
|
return any(c).(T)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: generalize the above code.
|
||||||
|
panic("todo: Image.Get for odd bits per pixel")
|
||||||
|
}
|
||||||
|
|
||||||
|
// FillSolidColor fills the entire image with the given color.
|
||||||
|
// This may be faster than setting individual pixels.
|
||||||
|
func (img Image[T]) FillSolidColor(color T) {
|
||||||
|
var zeroColor T
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case zeroColor.BitsPerPixel() == 1:
|
||||||
|
// Monochrome.
|
||||||
|
var colorByte uint8
|
||||||
|
if color != zeroColor {
|
||||||
|
colorByte = 0xff
|
||||||
|
}
|
||||||
|
numBytes := int(img.width) * int(img.height) / 8
|
||||||
|
for i := 0; i < numBytes; i++ {
|
||||||
|
// TODO: this can be optimized a lot.
|
||||||
|
// - The store can be done as a 32-bit integer, after checking for
|
||||||
|
// alignment.
|
||||||
|
// - Perhaps the loop can be unrolled to improve copy performance.
|
||||||
|
ptr := (*byte)(unsafe.Add(img.data, i))
|
||||||
|
*((*byte)(ptr)) = colorByte
|
||||||
|
}
|
||||||
|
return
|
||||||
|
|
||||||
|
case zeroColor.BitsPerPixel()%8 == 0:
|
||||||
|
// Fast pass for colors of 8, 16, 24, etc bytes in size.
|
||||||
|
ptr := img.data
|
||||||
|
for i := 0; i < img.Len(); i++ {
|
||||||
|
// TODO: this can be optimized a lot.
|
||||||
|
// - The store can be done as a 32-bit integer, after checking for
|
||||||
|
// alignment.
|
||||||
|
// - Perhaps the loop can be unrolled to improve copy performance.
|
||||||
|
*(*T)(ptr) = color
|
||||||
|
ptr = unsafe.Add(ptr, unsafe.Sizeof(zeroColor))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special case for RGB444.
|
||||||
|
if c, ok := any(color).(RGB444); ok {
|
||||||
|
// RGB444 can be stored in a more optimized way, by storing two colors
|
||||||
|
// at a time instead of setting each color individually. This avoids
|
||||||
|
// loading and masking the old color bits for the half-bytes.
|
||||||
|
var buf [3]uint8
|
||||||
|
buf[0] = uint8(c >> 4)
|
||||||
|
buf[1] = uint8(c)<<4 | uint8(c>>8)
|
||||||
|
buf[2] = uint8(c)
|
||||||
|
rawBuf := unsafe.Slice((*[3]byte)(img.data), img.Len()/2)
|
||||||
|
for i := 0; i < len(rawBuf); i++ {
|
||||||
|
rawBuf[i] = buf
|
||||||
|
}
|
||||||
|
if img.Len()%2 != 0 {
|
||||||
|
// The image contains an uneven number of pixels.
|
||||||
|
// This is uncommon, but it can happen and we have to handle it.
|
||||||
|
img.setPixel(img.Len()-1, color)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback for other color formats.
|
||||||
|
for i := 0; i < img.Len(); i++ {
|
||||||
|
img.setPixel(i, color)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// At implements the draw.Image interface.
|
||||||
|
func (img Image[T]) At(x, y int) color.Color {
|
||||||
|
return img.GetPixel(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set implements the draw.Image interface.
|
||||||
|
func (img Image[T]) Set(x, y int, c color.Color) {
|
||||||
|
var value T
|
||||||
|
switch any(value).(type) {
|
||||||
|
case Monochrome:
|
||||||
|
img.SetPixel(x, y, monochromeModel(c).(T))
|
||||||
|
case RGB444:
|
||||||
|
img.SetPixel(x, y, rgb444Model(c).(T))
|
||||||
|
case RGB565:
|
||||||
|
img.SetPixel(x, y, rgb565Model(c).(T))
|
||||||
|
/*
|
||||||
|
case RGB888:
|
||||||
|
img.SetPixel(x, y, rgb888Model(c).(T))
|
||||||
|
case RGB555:
|
||||||
|
img.SetPixel(x, y, rgb555Model(c).(T))
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bounds returns the image bounding box.
|
||||||
|
func (img Image[T]) Bounds() image.Rectangle {
|
||||||
|
return image.Rect(0, 0, int(img.width), int(img.height))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ColorModel returns the image color model.
|
||||||
|
func (img Image[T]) ColorModel() color.Model {
|
||||||
|
// Ugly cast from color.RGBA to T. The type switch and interface casts are
|
||||||
|
// trivially optimized away after instantiation.
|
||||||
|
var value T
|
||||||
|
switch any(value).(type) {
|
||||||
|
case Monochrome:
|
||||||
|
return MonochromeModel
|
||||||
|
case RGB444:
|
||||||
|
return RGB444Model
|
||||||
|
case RGB565:
|
||||||
|
return RGB565Model
|
||||||
|
/*
|
||||||
|
case RGB888:
|
||||||
|
return RGB888Model
|
||||||
|
case RGB555:
|
||||||
|
return RGB555Model
|
||||||
|
*/
|
||||||
|
default:
|
||||||
|
panic("unknown color format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the image buffer.
|
||||||
|
func (img *Image[T]) Clear() {
|
||||||
|
var zeroColor T
|
||||||
|
img.FillSolidColor(zeroColor)
|
||||||
|
}
|
||||||
|
|
||||||
// VerticalLSB is a 1 bit (black and white) image.
|
// VerticalLSB is a 1 bit (black and white) image.
|
||||||
//
|
//
|
||||||
// Each byte is 8 vertical pixels. Each stride is a horizontal band of 8
|
// Each byte is 8 vertical pixels. Each stride is a horizontal band of 8
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package pixel
|
||||||
|
|
||||||
|
import "image/color"
|
||||||
|
|
||||||
|
var (
|
||||||
|
MonochromeModel color.Model = color.ModelFunc(monochromeModel)
|
||||||
|
RGB444Model color.Model = color.ModelFunc(rgb444Model)
|
||||||
|
RGB565Model color.Model = color.ModelFunc(rgb565Model)
|
||||||
|
)
|
||||||
|
|
||||||
|
func monochromeModel(c color.Color) color.Color {
|
||||||
|
if _, ok := c.(Monochrome); ok {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
r, g, b, _ := c.RGBA()
|
||||||
|
return NewMonochrome(uint8(r>>8), uint8(g>>8), uint8(b>>8))
|
||||||
|
}
|
||||||
|
|
||||||
|
func rgb444Model(c color.Color) color.Color {
|
||||||
|
if _, ok := c.(RGB444); ok {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
r, g, b, _ := c.RGBA()
|
||||||
|
return RGB444(r>>12)<<8 | RGB444(g>>12)<<4 | RGB444(b>>12)
|
||||||
|
}
|
||||||
|
|
||||||
|
func rgb565Model(c color.Color) color.Color {
|
||||||
|
if _, ok := c.(RGB565); ok {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
r, g, b, _ := c.RGBA()
|
||||||
|
return RGB565(uint16((r>>8)&0xF8)<<8 + uint16((g>>8)&0xFC)<<3 + uint16((b>>8)&0xF8)>>3)
|
||||||
|
}
|
||||||
@@ -0,0 +1,348 @@
|
|||||||
|
// Copyright 2021 the u-root Authors. All rights reserved
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Package spidev wraps the Linux spidev driver and performs low-level SPI
|
||||||
|
// operations.
|
||||||
|
package spidev
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
// See Linux "include/uapi/linux/spi/spidev.h" and
|
||||||
|
// "Documentation/spi/spidev.rst"
|
||||||
|
|
||||||
|
// Various ioctl numbers.
|
||||||
|
const (
|
||||||
|
iocRdMode = 0x80016b01
|
||||||
|
iocWrMode = 0x40016b01
|
||||||
|
iocRdLSBFirst = 0x80016b02
|
||||||
|
iocWrLSBFirst = 0x40016b02
|
||||||
|
iocRdBitsPerWord = 0x80016b03
|
||||||
|
iocWrBitsPerWord = 0x40016b03
|
||||||
|
iocRdMaxSpeedHz = 0x80046b04
|
||||||
|
iocWrMaxSpeedHz = 0x40046b04
|
||||||
|
iocRdMode32 = 0x80046b05
|
||||||
|
iocWrMode32 = 0x40046b05
|
||||||
|
)
|
||||||
|
|
||||||
|
// Constants used by iocMessage function.
|
||||||
|
const (
|
||||||
|
// iocMessage0 is the length of a message of 0 length. Use the
|
||||||
|
// iocMessage(n) function for an iocMessage of length n.
|
||||||
|
iocMessage0 = 0x40006b00
|
||||||
|
sizeBits = 14
|
||||||
|
sizeShift = 16
|
||||||
|
sizeMask = ((1 << sizeBits) - 1) << sizeShift
|
||||||
|
)
|
||||||
|
|
||||||
|
// maxTransferSize is the maximum size of a transfer. This is limited by the
|
||||||
|
// `length uint32` in the iocTransfer struct.
|
||||||
|
var maxTransferSize = math.MaxInt32
|
||||||
|
|
||||||
|
// iocMessage is an ioctl number for n Transfers. Since the ioctl number
|
||||||
|
// contains the size of the message, it is not a constant.
|
||||||
|
func iocMessage(n int) uint32 {
|
||||||
|
size := uint32(n * binary.Size(iocTransfer{}))
|
||||||
|
if n < 0 || size > (1<<sizeBits) {
|
||||||
|
return iocMessage(0)
|
||||||
|
}
|
||||||
|
return iocMessage0 | (size << sizeShift)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mode is a bitset of the current SPI mode bits.
|
||||||
|
type Mode uint32
|
||||||
|
|
||||||
|
const (
|
||||||
|
// CPHA determines clock phase sampling (1=trailing edge).
|
||||||
|
CPHA Mode = 1 << iota
|
||||||
|
// CPOL determines clock polarity (1=idle high).
|
||||||
|
CPOL
|
||||||
|
// CS_HIGH determines chip select polarity (1=idle high).
|
||||||
|
CS_HIGH
|
||||||
|
// LSB_FIRST determines whether least significant bit comes first in a
|
||||||
|
// word (1=LSB first).
|
||||||
|
LSB_FIRST
|
||||||
|
// THREE_WIRE determines whether the bus operates in three wire mode
|
||||||
|
// (1=three wire).
|
||||||
|
THREE_WIRE
|
||||||
|
// LOOP determines whether the device should loop (1=loop enabled).
|
||||||
|
LOOP
|
||||||
|
// NO_CS determines whether to disable chip select (1=no chip select).
|
||||||
|
NO_CS
|
||||||
|
// READY determins ready mode bit.
|
||||||
|
READY
|
||||||
|
// TX_DUAL determines whether to transmit in dual mode.
|
||||||
|
TX_DUAL
|
||||||
|
// TX_QUAD determines whether to transmit in quad mode.
|
||||||
|
TX_QUAD
|
||||||
|
// RX_DUAL determines whether to receive in dual mode.
|
||||||
|
RX_DUAL
|
||||||
|
// RX_QUAD determines whether to receive in quad mode.
|
||||||
|
RX_QUAD
|
||||||
|
)
|
||||||
|
|
||||||
|
// iocTransfer is the data type used by the iocMessage ioctl. Multiple such
|
||||||
|
// transfers may be chained together in a single ioctl call.
|
||||||
|
type iocTransfer struct {
|
||||||
|
// txBuf contains the userspace address of data to send. If this is 0,
|
||||||
|
// then zeros are shifted onto the SPI bus.
|
||||||
|
txBuf uint64
|
||||||
|
// rxBuf contains the userspace address of data to receive. If this is
|
||||||
|
// 0, data received is ignored.
|
||||||
|
rxBuf uint64
|
||||||
|
// length is the length of max{transfer, txBuf, rxBuf} in bytes.
|
||||||
|
length uint32
|
||||||
|
|
||||||
|
speedHz uint32
|
||||||
|
delayUSecs uint16
|
||||||
|
bitsPerWord uint8
|
||||||
|
csChange uint8
|
||||||
|
txNBits uint8
|
||||||
|
rxNBits uint8
|
||||||
|
wordDelayUSecs uint8
|
||||||
|
pad uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transfer is the data and options for a single SPI transfer. Note that a SPI
|
||||||
|
// transfer is full-duplex meaning data is shifted out of Tx and shifted into
|
||||||
|
// Rx on the same clock cycle.
|
||||||
|
type Transfer struct {
|
||||||
|
// Tx contains a slice sent over the SPI bus.
|
||||||
|
Tx []byte
|
||||||
|
// Rx contains a slice received from the SPI bus.
|
||||||
|
Rx []byte
|
||||||
|
|
||||||
|
// The following temporarily override the SPI mode. They only apply to
|
||||||
|
// the current transfer.
|
||||||
|
|
||||||
|
// SpeedHz sets speed in Hz (optional).
|
||||||
|
SpeedHz uint32
|
||||||
|
// DelayUSecs is how long to delay before the next transfer (optional).
|
||||||
|
DelayUSecs uint16
|
||||||
|
// BitsPerWord is the device's wordsize (optional).
|
||||||
|
BitsPerWord uint8
|
||||||
|
// CSChange controls whether the CS (Chip Select) signal will be
|
||||||
|
// de-asserted at the end of the transfer.
|
||||||
|
CSChange bool
|
||||||
|
// TxNbits controls single, dual or quad mode (optional).
|
||||||
|
TxNBits uint8
|
||||||
|
// RxNbits controls single, dual or quad mode (optional).
|
||||||
|
RxNBits uint8
|
||||||
|
// WordDelayUSecs is the delay between words (optional).
|
||||||
|
WordDelayUSecs uint8
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Transfer) String() string {
|
||||||
|
var x [8]byte
|
||||||
|
n, _ := io.ReadAtLeast(bytes.NewBuffer(t.Tx), x[:], len(x))
|
||||||
|
return fmt.Sprintf("%#02x...[:%d](%#02x)", x[:n], len(t.Tx), x[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrTxOverflow is returned if the Transfer buffer is too large.
|
||||||
|
type ErrTxOverflow struct {
|
||||||
|
TxLen, TxMax int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ErrTxOverflow) Error() string {
|
||||||
|
return fmt.Sprintf("SPI tx buffer overflow (%d > %d)", e.TxLen, e.TxMax)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrRxOverflow is returned if the Transfer buffer is too large.
|
||||||
|
type ErrRxOverflow struct {
|
||||||
|
RxLen, RxMax int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ErrRxOverflow) Error() string {
|
||||||
|
return fmt.Sprintf("SPI rx buffer overflow (%d > %d)", e.RxLen, e.RxMax)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ErrBufferMismatch is returned if the rx and tx buffers do not have equal
|
||||||
|
// length.
|
||||||
|
type ErrBufferMismatch struct {
|
||||||
|
TxLen, RxLen int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ErrBufferMismatch) Error() string {
|
||||||
|
return fmt.Sprintf("SPI tx and rx buffers of unequal length (%d != %d)", e.TxLen, e.RxLen)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SPI wraps the Linux device driver and provides low-level SPI operations.
|
||||||
|
type SPI struct {
|
||||||
|
f *os.File
|
||||||
|
// Used for mocking.
|
||||||
|
syscall func(trap, a1, a2 uintptr, a3 unsafe.Pointer) (r1, r2 uintptr, err unix.Errno)
|
||||||
|
// logger allows logging
|
||||||
|
logger func(string, ...any)
|
||||||
|
}
|
||||||
|
|
||||||
|
type opt func(s *SPI) error
|
||||||
|
|
||||||
|
// WithLogger returns an opt which can be used in Open to add
|
||||||
|
// a logger. A common usage would be:
|
||||||
|
// spidev.Open("/dev/spidev0.0", WithLogger(log.Printf))
|
||||||
|
func WithLogger(l func(string, ...any)) opt {
|
||||||
|
return func(s *SPI) error {
|
||||||
|
s.logger = l
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// safe tries to set "safe" settings for initial SPI operation.
|
||||||
|
// However, settings may not succeed, for $REASONS$.
|
||||||
|
// Hardware is highly variable.
|
||||||
|
// If there is an error, log it, and continue.
|
||||||
|
func (s *SPI) safe() {
|
||||||
|
if err := s.SetSpeedHz(500000); err != nil {
|
||||||
|
s.logger("warning only: set speed to %d HZ err %v", 500000, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open opens a new SPI device. dev is a filename such as "/dev/spidev0.0".
|
||||||
|
// Remember to call Close() once done.
|
||||||
|
func Open(dev string, opts ...opt) (*SPI, error) {
|
||||||
|
f, err := os.OpenFile(dev, os.O_RDWR, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
s := &SPI{
|
||||||
|
f: f,
|
||||||
|
logger: func(string, ...any) {}, // log.Printf,
|
||||||
|
//logger: log.Printf,
|
||||||
|
// a3 must be an unsafe.Pointer instead of a uintptr, otherwise
|
||||||
|
// we cannot mock out in the test without creating a race
|
||||||
|
// condition. See `go doc unsafe.Pointer`.
|
||||||
|
syscall: func(trap, a1, a2 uintptr, a3 unsafe.Pointer) (r1, r2 uintptr, err unix.Errno) {
|
||||||
|
return unix.Syscall(trap, a1, a2, uintptr(a3))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, o := range opts {
|
||||||
|
if err := o(s); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
s.safe()
|
||||||
|
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the SPI device.
|
||||||
|
func (s *SPI) Close() error {
|
||||||
|
return s.f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Transfer performs multiple SPI reads and/or writes in a single function.
|
||||||
|
// See the Transfer struct for details.
|
||||||
|
func (s *SPI) Transfer(transfers []Transfer) error {
|
||||||
|
// Convert []Transfer to []iocTransfer.
|
||||||
|
it := make([]iocTransfer, len(transfers))
|
||||||
|
for i, t := range transfers {
|
||||||
|
s.logger("%d:%s", i, t.String())
|
||||||
|
it[i] = iocTransfer{
|
||||||
|
speedHz: t.SpeedHz,
|
||||||
|
delayUSecs: t.DelayUSecs,
|
||||||
|
bitsPerWord: t.BitsPerWord,
|
||||||
|
txNBits: t.TxNBits,
|
||||||
|
rxNBits: t.RxNBits,
|
||||||
|
wordDelayUSecs: t.WordDelayUSecs,
|
||||||
|
}
|
||||||
|
if len(t.Tx) > maxTransferSize {
|
||||||
|
return ErrTxOverflow{len(t.Tx), maxTransferSize}
|
||||||
|
}
|
||||||
|
if len(t.Rx) > maxTransferSize {
|
||||||
|
return ErrRxOverflow{len(t.Rx), maxTransferSize}
|
||||||
|
}
|
||||||
|
if len(t.Tx) != 0 && len(t.Rx) != 0 && len(t.Tx) != len(t.Rx) {
|
||||||
|
return ErrBufferMismatch{len(t.Tx), len(t.Rx)}
|
||||||
|
}
|
||||||
|
if len(t.Tx) != 0 {
|
||||||
|
txBuf := &transfers[i].Tx[0]
|
||||||
|
it[i].txBuf = uint64(uintptr(unsafe.Pointer(txBuf)))
|
||||||
|
it[i].length = uint32(len(t.Tx))
|
||||||
|
// Defer garbage collection until after the syscall.
|
||||||
|
defer runtime.KeepAlive(txBuf)
|
||||||
|
}
|
||||||
|
if len(t.Rx) != 0 {
|
||||||
|
rxBuf := &transfers[i].Rx[0]
|
||||||
|
it[i].rxBuf = uint64(uintptr(unsafe.Pointer(rxBuf)))
|
||||||
|
it[i].length = uint32(len(t.Rx))
|
||||||
|
// Defer garbage collection until after the syscall.
|
||||||
|
defer runtime.KeepAlive(rxBuf)
|
||||||
|
}
|
||||||
|
if transfers[i].CSChange {
|
||||||
|
it[i].csChange = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), uintptr(iocMessage(len(transfers))), unsafe.Pointer(&it[0])); err != 0 {
|
||||||
|
return os.NewSyscallError("ioctl(SPI_IOC_MESSAGE)", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mode returns the Mode bitset.
|
||||||
|
func (s *SPI) Mode() (Mode, error) {
|
||||||
|
var m Mode
|
||||||
|
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocRdMode32, unsafe.Pointer(&m)); err != 0 {
|
||||||
|
return 0, os.NewSyscallError("ioctl(SPI_IOC_RD_MODE32)", err)
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMode sets the Mode bitset.
|
||||||
|
func (s *SPI) SetMode(m Mode) error {
|
||||||
|
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocWrMode32, unsafe.Pointer(&m)); err != 0 {
|
||||||
|
return os.NewSyscallError("ioctl(SPI_IOC_WR_MODE32)", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BitsPerWord sets the number of bits per word. Myy understanding is this is
|
||||||
|
// only useful if there is a word delay.
|
||||||
|
func (s *SPI) BitsPerWord() (uint8, error) {
|
||||||
|
var bpw uint8
|
||||||
|
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocRdBitsPerWord, unsafe.Pointer(&bpw)); err != 0 {
|
||||||
|
return bpw, os.NewSyscallError("ioctl(SPI_IOC_RD_BITS_PER_WORD)", err)
|
||||||
|
}
|
||||||
|
return bpw, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBitsPerWord sets the number of bits per word.
|
||||||
|
func (s *SPI) SetBitsPerWord(bpw uint8) error {
|
||||||
|
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocWrBitsPerWord, unsafe.Pointer(&bpw)); err != 0 {
|
||||||
|
return os.NewSyscallError("ioctl(SPI_IOC_WR_BITS_PER_WORD)", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SpeedHz gets the transfer speed.
|
||||||
|
func (s *SPI) SpeedHz() (uint32, error) {
|
||||||
|
var hz uint32
|
||||||
|
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocRdMaxSpeedHz, unsafe.Pointer(&hz)); err != 0 {
|
||||||
|
return hz, os.NewSyscallError("ioctl(SPI_IOC_RD_MAX_SPEED_HZ)", err)
|
||||||
|
}
|
||||||
|
return hz, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSpeedHz sets the transfer speed.
|
||||||
|
func (s *SPI) SetSpeedHz(hz uint32) error {
|
||||||
|
if _, _, err := s.syscall(unix.SYS_IOCTL, s.f.Fd(), iocWrMaxSpeedHz, unsafe.Pointer(&hz)); err != 0 {
|
||||||
|
return os.NewSyscallError("ioctl(SPI_IOC_WR_MAX_SPEED_HZ)", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package moode
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -49,6 +50,10 @@ func (Player) Pause() error { return nil }
|
|||||||
func (Player) Play() error { return nil }
|
func (Player) Play() error { return nil }
|
||||||
func (Player) Seek(time.Duration) error { return nil }
|
func (Player) Seek(time.Duration) error { return nil }
|
||||||
|
|
||||||
|
func (p *Player) AlbumArt(t *player.Track) (image.Image, bool) {
|
||||||
|
return p.mpd.AlbumArt(t)
|
||||||
|
}
|
||||||
|
|
||||||
func (Player) Status() *player.Status {
|
func (Player) Status() *player.Status {
|
||||||
s, _ := parseStatus(currentSongFile)
|
s, _ := parseStatus(currentSongFile)
|
||||||
return s
|
return s
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package mpd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/player"
|
||||||
|
)
|
||||||
|
|
||||||
|
type artRequest struct {
|
||||||
|
Path string
|
||||||
|
Art chan image.Image
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Player) AlbumArt(track *player.Track) (image.Image, bool) {
|
||||||
|
if track == nil || track.Path == "" {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
if cached, ok := d.artCache.Load(track.Path); ok {
|
||||||
|
return cached.(image.Image), true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not in cache, request artwork through the art connection.
|
||||||
|
art := make(chan image.Image)
|
||||||
|
d.artRequest <- &artRequest{Path: track.Path, Art: art}
|
||||||
|
|
||||||
|
// Respond with image.
|
||||||
|
if image := <-art; image != nil {
|
||||||
|
return image, true
|
||||||
|
}
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Player) artLoop(conn *clientConn) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case request := <-d.artRequest:
|
||||||
|
logrus.WithField("path", request.Path).Debug("requesting album art")
|
||||||
|
request.Art <- nil
|
||||||
|
|
||||||
|
case <-d.quit:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"net/textproto"
|
"net/textproto"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@@ -34,6 +35,8 @@ type Player struct {
|
|||||||
addr string
|
addr string
|
||||||
password string
|
password string
|
||||||
idleSubsystems []string
|
idleSubsystems []string
|
||||||
|
artCache sync.Map // map of path to image
|
||||||
|
artRequest chan *artRequest
|
||||||
commands chan *Command
|
commands chan *Command
|
||||||
errors chan error
|
errors chan error
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
@@ -96,6 +99,7 @@ func New(addr, password string) (*Player, error) {
|
|||||||
p := &Player{
|
p := &Player{
|
||||||
addr: addr,
|
addr: addr,
|
||||||
commands: make(chan *Command, 16),
|
commands: make(chan *Command, 16),
|
||||||
|
artRequest: make(chan *artRequest, 16),
|
||||||
errors: make(chan error, 1),
|
errors: make(chan error, 1),
|
||||||
quit: make(chan struct{}, 2),
|
quit: make(chan struct{}, 2),
|
||||||
}
|
}
|
||||||
@@ -301,6 +305,15 @@ func (p *Player) run(events chan player.Event) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
art, _, err := newConn(p.addr, p.password, "art", p.name)
|
||||||
|
if err != nil {
|
||||||
|
_ = idle.Close()
|
||||||
|
_ = main.Close()
|
||||||
|
log.WithError(err).Warn("connection failed; retrying")
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
p.commands = make(chan *Command)
|
p.commands = make(chan *Command)
|
||||||
p.errors = make(chan error)
|
p.errors = make(chan error)
|
||||||
p.quit = make(chan struct{}, 2)
|
p.quit = make(chan struct{}, 2)
|
||||||
@@ -308,6 +321,7 @@ func (p *Player) run(events chan player.Event) {
|
|||||||
events <- player.NewConnectedEvent(p)
|
events <- player.NewConnectedEvent(p)
|
||||||
|
|
||||||
go p.idleLoop(idle)
|
go p.idleLoop(idle)
|
||||||
|
go p.artLoop(art)
|
||||||
p.mainLoop(main, events)
|
p.mainLoop(main, events)
|
||||||
|
|
||||||
events <- player.NewDisconnectedEvent(p)
|
events <- player.NewDisconnectedEvent(p)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type Player interface {
|
|||||||
// Status of the player
|
// Status of the player
|
||||||
Status() *Status
|
Status() *Status
|
||||||
|
|
||||||
|
// Player controls
|
||||||
Play() error
|
Play() error
|
||||||
Pause() error
|
Pause() error
|
||||||
Next() error
|
Next() error
|
||||||
@@ -32,6 +33,10 @@ type Player interface {
|
|||||||
Seek(time.Duration) error
|
Seek(time.Duration) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AlbumArt interface {
|
||||||
|
AlbumArt(*Track) (image.Image, bool)
|
||||||
|
}
|
||||||
|
|
||||||
// AudioFormat is the audio format.
|
// AudioFormat is the audio format.
|
||||||
type AudioFormat struct {
|
type AudioFormat struct {
|
||||||
Encoding string
|
Encoding string
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package volumio
|
package volumio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.maze.io/harmon/config"
|
"go.maze.io/harmon/config"
|
||||||
@@ -47,3 +48,7 @@ func (p *Player) Seek(d time.Duration) error { return p.mpd.Seek(d) }
|
|||||||
func (p *Player) Events() (<-chan player.Event, error) {
|
func (p *Player) Events() (<-chan player.Event, error) {
|
||||||
return p.mpd.Events()
|
return p.mpd.Events()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Player) AlbumArt(t *player.Track) (image.Image, bool) {
|
||||||
|
return p.mpd.AlbumArt(t)
|
||||||
|
}
|
||||||
+20
-20
@@ -1,47 +1,47 @@
|
|||||||
package visual
|
package visual
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.maze.io/harmon/hardware"
|
"go.maze.io/harmon/hardware"
|
||||||
"go.maze.io/harmon/hardware/display"
|
"go.maze.io/harmon/hardware/display"
|
||||||
"go.maze.io/harmon/internal/pixel"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Offline struct {
|
type Offline struct {
|
||||||
since time.Time
|
since time.Time
|
||||||
l, r, c hardware.Display
|
l, r, c hardware.Display
|
||||||
|
x, y int
|
||||||
|
w, h int
|
||||||
|
dx, dy bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOffline(left, right, center hardware.Display) *Offline {
|
func NewOffline(left, right, center hardware.Display) *Offline {
|
||||||
|
size := left.Size()
|
||||||
return &Offline{
|
return &Offline{
|
||||||
since: time.Now(),
|
since: time.Now(),
|
||||||
l: left,
|
l: left,
|
||||||
r: right,
|
r: right,
|
||||||
c: center,
|
c: center,
|
||||||
|
w: size.X - 3,
|
||||||
|
h: size.Y - 3,
|
||||||
|
x: rand.Int() % (size.X - 3),
|
||||||
|
y: rand.Int() % (size.Y - 3),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Offline) Render() error {
|
func (v *Offline) Render() error {
|
||||||
i := pixel.NewVerticalLSB(v.l.Bounds())
|
// Left shows text
|
||||||
display.DrawText(i, 0, 32, "Offline!")
|
v.l.Clear()
|
||||||
|
display.DrawText(v.l, 1, 1, display.Font8x16, "Player offline!")
|
||||||
|
display.DrawText(v.l, 1, 3, display.Font7x13, "retrying...")
|
||||||
|
v.l.Refresh()
|
||||||
|
|
||||||
|
// Right shows time + date
|
||||||
|
v.r.Clear()
|
||||||
|
display.DrawText(v.r, 1, 1, display.Font8x16, time.Now().Format("01-02-06"))
|
||||||
|
display.DrawText(v.r, 1, 3, display.Font8x16, time.Now().Format("15:04:05"))
|
||||||
|
v.r.Refresh()
|
||||||
|
|
||||||
if err := v.l.Draw(i.Rect, i, image.Point{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := v.r.Draw(i.Rect, i, image.Point{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
//v.render(v.c)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *Offline) render(d hardware.Display) {
|
|
||||||
if d == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
display.DrawText(d, 0, 32, "Offline!")
|
|
||||||
d.Refresh()
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package screensaver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"image/color"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"go.maze.io/harmon/hardware/display"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Snake struct {
|
||||||
|
display hardware.Display
|
||||||
|
size image.Point
|
||||||
|
pos image.Point
|
||||||
|
count int
|
||||||
|
flip bool
|
||||||
|
tail []image.Point
|
||||||
|
tailLen int
|
||||||
|
pickups []image.Point
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSnake(d hardware.Display) *Snake {
|
||||||
|
logrus.WithField("size", d.Size()).Debug("snake screensaver setup")
|
||||||
|
s := &Snake{
|
||||||
|
display: d,
|
||||||
|
size: d.Size(),
|
||||||
|
tailLen: 10,
|
||||||
|
}
|
||||||
|
s.Reset()
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Snake) Reset() {
|
||||||
|
s.count = 0
|
||||||
|
s.tail = nil
|
||||||
|
s.tailLen = 10
|
||||||
|
s.pickups = make([]image.Point, 0, 7)
|
||||||
|
for i := 0; i < 7; i++ {
|
||||||
|
s.pickups = append(s.pickups, image.Pt(rand.Intn(s.size.X), rand.Intn(s.size.Y)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Snake) Refresh() error {
|
||||||
|
s.display.Clear()
|
||||||
|
|
||||||
|
if s.count%s.size.X == 0 {
|
||||||
|
s.flip = !s.flip
|
||||||
|
}
|
||||||
|
|
||||||
|
var x, y int
|
||||||
|
if s.flip {
|
||||||
|
x = s.count%s.size.X + 1
|
||||||
|
} else {
|
||||||
|
x = s.size.X - s.count%s.size.X
|
||||||
|
}
|
||||||
|
y = ^(s.count / s.size.X) * 3
|
||||||
|
|
||||||
|
s.tail = append(s.tail, image.Point{X: x, Y: y})
|
||||||
|
if len(s.tail) > s.tailLen {
|
||||||
|
s.tail = s.tail[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range s.tail {
|
||||||
|
display.DrawRectangle(s.display, t.X, t.Y-1, 2, 3, color.White)
|
||||||
|
}
|
||||||
|
|
||||||
|
d := -1
|
||||||
|
for i, p := range s.pickups {
|
||||||
|
if ((s.flip && x > -p.X) || (!s.flip && x <= p.X)) && y >= p.Y {
|
||||||
|
s.tailLen += 5
|
||||||
|
d = i
|
||||||
|
}
|
||||||
|
display.DrawRectangle(s.display, p.X, p.Y, 1, 1, color.White)
|
||||||
|
}
|
||||||
|
if d > -1 {
|
||||||
|
s.pickups = append(s.pickups[:d], s.pickups[d+1:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.count++
|
||||||
|
if y > s.size.Y {
|
||||||
|
s.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.display.Refresh()
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package screensaver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"go.maze.io/harmon/internal/pixel"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Stars struct {
|
||||||
|
display hardware.Display
|
||||||
|
points []image.Point
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStars(display hardware.Display, n int) *Stars {
|
||||||
|
s := &Stars{
|
||||||
|
display: display,
|
||||||
|
}
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
s.points = append(s.points, s.randomPoint(display.Size()))
|
||||||
|
}
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stars) randomPoint(p image.Point) image.Point {
|
||||||
|
return image.Point{X: rand.Intn(p.X), Y: rand.Intn(p.Y)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Stars) Refresh() error {
|
||||||
|
s.display.Clear()
|
||||||
|
for _, p := range s.points {
|
||||||
|
s.display.Set(p.X, p.Y, pixel.On)
|
||||||
|
}
|
||||||
|
copy(s.points[1:], s.points)
|
||||||
|
s.points[0] = s.randomPoint(s.display.Size())
|
||||||
|
return s.display.Refresh()
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
package visual
|
||||||
|
|
||||||
|
import (
|
||||||
|
"image"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"periph.io/x/conn/v3/physic"
|
||||||
|
|
||||||
|
"go.maze.io/harmon/audio"
|
||||||
|
"go.maze.io/harmon/hardware"
|
||||||
|
"go.maze.io/harmon/hardware/display"
|
||||||
|
"go.maze.io/harmon/internal/pixel"
|
||||||
|
)
|
||||||
|
|
||||||
|
type VUMeter struct {
|
||||||
|
display hardware.Display
|
||||||
|
rate physic.Frequency
|
||||||
|
channel int
|
||||||
|
channels int
|
||||||
|
level float32 // in dBFS
|
||||||
|
alpha float32 // smoothing factor
|
||||||
|
samples []float32
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVUMeter(display hardware.Display, rate physic.Frequency, channel, channels int) *VUMeter {
|
||||||
|
if channel < 0 {
|
||||||
|
channel = 0
|
||||||
|
} else if channel > 2 {
|
||||||
|
channel = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
if channels < 1 {
|
||||||
|
channels = 1
|
||||||
|
} else if channels > 2 {
|
||||||
|
channels = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
v := &VUMeter{
|
||||||
|
display: display,
|
||||||
|
rate: rate,
|
||||||
|
channel: channel,
|
||||||
|
channels: channels,
|
||||||
|
}
|
||||||
|
v.alpha = calculateAlpha(rate, 0.01)
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *VUMeter) Process(samples audio.Buffer) {
|
||||||
|
floats := samples.Samples()
|
||||||
|
if len(v.samples) != len(floats.Buf) {
|
||||||
|
v.samples = make([]float32, len(floats.Buf))
|
||||||
|
}
|
||||||
|
copy(v.samples, floats.Buf)
|
||||||
|
//audio.Normalize(v.samples) // [-1..+1]
|
||||||
|
//audio.Abs(v.samples) // [ 0..+1]
|
||||||
|
|
||||||
|
rms := audio.RMS(v.samples, v.channel, v.channels) // in [0..1]
|
||||||
|
//logrus.WithFields(logrus.Fields{"rms": rms, "dBFS": rms, "alpha": v.alpha}).Debug("got samples")
|
||||||
|
v.level = float32(rms) // smoothValue(v.level, float32(rms), v.alpha)
|
||||||
|
}
|
||||||
|
|
||||||
|
// smoothValue applies simple exponential smoothing to the signal
|
||||||
|
func smoothValue(previous, current, alpha float32) float32 {
|
||||||
|
return alpha*current + (1-alpha)*previous
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculateAlpha computes the smoothing factor based on sample rate and time constant
|
||||||
|
func calculateAlpha(rate physic.Frequency, timeConstant float64) float32 {
|
||||||
|
// Calculate the smoothing factor alpha
|
||||||
|
return float32(1 - math.Exp(-1/(float64(rate/physic.Hertz)*timeConstant)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v *VUMeter) Render() error {
|
||||||
|
// Clear buffer
|
||||||
|
v.display.Clear()
|
||||||
|
|
||||||
|
// Draw background
|
||||||
|
display.DrawSprite(v.display, 0, 0, vumeterBackground[0], pixel.On)
|
||||||
|
|
||||||
|
angle := uint8(float32(len(needleCoordinates)) * v.level)
|
||||||
|
//if v.channel == 1 {
|
||||||
|
// angle = 127 - angle
|
||||||
|
//}
|
||||||
|
point := needleCoordinates[angle]
|
||||||
|
display.DrawLine(v.display, point.X, point.Y, 64, 96, pixel.On)
|
||||||
|
|
||||||
|
return v.display.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
var needleCoordinates = [...]image.Point{
|
||||||
|
{0, 23},
|
||||||
|
{1, 23},
|
||||||
|
{2, 22},
|
||||||
|
{3, 21},
|
||||||
|
{3, 21},
|
||||||
|
{4, 20},
|
||||||
|
{5, 19},
|
||||||
|
{6, 19},
|
||||||
|
{7, 18},
|
||||||
|
{8, 17},
|
||||||
|
{9, 17},
|
||||||
|
{10, 16},
|
||||||
|
{10, 16},
|
||||||
|
{11, 15},
|
||||||
|
{12, 14},
|
||||||
|
{13, 14},
|
||||||
|
{14, 13},
|
||||||
|
{15, 13},
|
||||||
|
{16, 12},
|
||||||
|
{17, 12},
|
||||||
|
{18, 11},
|
||||||
|
{19, 11},
|
||||||
|
{20, 10},
|
||||||
|
{21, 10},
|
||||||
|
{22, 9},
|
||||||
|
{23, 9},
|
||||||
|
{24, 8},
|
||||||
|
{25, 8},
|
||||||
|
{26, 7},
|
||||||
|
{27, 7},
|
||||||
|
{28, 6},
|
||||||
|
{29, 6},
|
||||||
|
{30, 6},
|
||||||
|
{31, 5},
|
||||||
|
{32, 5},
|
||||||
|
{33, 5},
|
||||||
|
{34, 4},
|
||||||
|
{35, 4},
|
||||||
|
{36, 4},
|
||||||
|
{37, 3},
|
||||||
|
{38, 3},
|
||||||
|
{39, 3},
|
||||||
|
{40, 2},
|
||||||
|
{41, 2},
|
||||||
|
{42, 2},
|
||||||
|
{43, 2},
|
||||||
|
{45, 1},
|
||||||
|
{46, 1},
|
||||||
|
{47, 1},
|
||||||
|
{48, 1},
|
||||||
|
{49, 1},
|
||||||
|
{50, 0},
|
||||||
|
{51, 0},
|
||||||
|
{52, 0},
|
||||||
|
{53, 0},
|
||||||
|
{54, 0},
|
||||||
|
{55, 0},
|
||||||
|
{56, 0},
|
||||||
|
{57, 0},
|
||||||
|
{59, 0},
|
||||||
|
{60, 0},
|
||||||
|
{61, 0},
|
||||||
|
{62, 0},
|
||||||
|
{63, 0},
|
||||||
|
{64, 0},
|
||||||
|
{65, 0},
|
||||||
|
{66, 0},
|
||||||
|
{67, 0},
|
||||||
|
{68, 0},
|
||||||
|
{70, 0},
|
||||||
|
{71, 0},
|
||||||
|
{72, 0},
|
||||||
|
{73, 0},
|
||||||
|
{74, 0},
|
||||||
|
{75, 0},
|
||||||
|
{76, 0},
|
||||||
|
{77, 0},
|
||||||
|
{78, 1},
|
||||||
|
{79, 1},
|
||||||
|
{80, 1},
|
||||||
|
{81, 1},
|
||||||
|
{82, 1},
|
||||||
|
{84, 2},
|
||||||
|
{85, 2},
|
||||||
|
{86, 2},
|
||||||
|
{87, 2},
|
||||||
|
{88, 3},
|
||||||
|
{89, 3},
|
||||||
|
{90, 3},
|
||||||
|
{91, 4},
|
||||||
|
{92, 4},
|
||||||
|
{93, 4},
|
||||||
|
{94, 5},
|
||||||
|
{95, 5},
|
||||||
|
{96, 5},
|
||||||
|
{97, 6},
|
||||||
|
{98, 6},
|
||||||
|
{99, 6},
|
||||||
|
{100, 7},
|
||||||
|
{101, 7},
|
||||||
|
{102, 8},
|
||||||
|
{103, 8},
|
||||||
|
{104, 9},
|
||||||
|
{105, 9},
|
||||||
|
{106, 10},
|
||||||
|
{107, 10},
|
||||||
|
{108, 11},
|
||||||
|
{109, 11},
|
||||||
|
{110, 12},
|
||||||
|
{111, 12},
|
||||||
|
{112, 13},
|
||||||
|
{113, 13},
|
||||||
|
{114, 14},
|
||||||
|
{115, 14},
|
||||||
|
{116, 15},
|
||||||
|
{117, 16},
|
||||||
|
{117, 16},
|
||||||
|
{118, 17},
|
||||||
|
{119, 17},
|
||||||
|
{120, 18},
|
||||||
|
{121, 19},
|
||||||
|
{122, 19},
|
||||||
|
{123, 20},
|
||||||
|
{124, 21},
|
||||||
|
{124, 21},
|
||||||
|
{125, 22},
|
||||||
|
{126, 23},
|
||||||
|
{127, 23},
|
||||||
|
}
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
package audio
|
|
||||||
|
|
||||||
var vumeterBackground = [2][]uint8{{
|
|
||||||
0x80, /* = width */
|
|
||||||
0x40, /* = height */
|
|
||||||
0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x1f, 0x04, 0x04,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0xf0, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x50,
|
|
||||||
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x50, 0xf0,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x78, 0x41, 0x41, 0x41, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
||||||
0x41, 0x40, 0x79, 0x41, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x79,
|
|
||||||
0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x79, 0x01, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x79,
|
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x61, 0x79, 0x61, 0x60, 0x60,
|
|
||||||
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x61, 0x79, 0x01,
|
|
||||||
0xc0, 0x4e, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x42, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x02, 0x82, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0x42, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0xc2, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0xc2, 0x02, 0xc2, 0x42, 0xce, 0x00, 0xc0, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x05, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00,
|
|
||||||
0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x2f, 0x50, 0xa0, 0x50, 0x2f, 0x10, 0x0f, 0x00,
|
|
||||||
0x00, 0x3f, 0x40, 0xbf, 0xa0, 0xa0, 0xa0, 0xbf, 0x40, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x22, 0x22, 0x3e,
|
|
||||||
0x00, 0x7e, 0x52, 0x52, 0x42, 0x00, 0x7e, 0x12, 0x12, 0x7e, 0x00, 0x7e, 0x08, 0x08, 0x76, 0x00,
|
|
||||||
}, {
|
|
||||||
0x80, /* = width */
|
|
||||||
0x40, /* = height */
|
|
||||||
0x04, 0x04, 0x1f, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04,
|
|
||||||
0x50, 0x50, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,
|
|
||||||
0x50, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xf0, 0x10, 0xf0,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x01, 0x79, 0x61, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
|
||||||
0x60, 0x60, 0x61, 0x79, 0x61, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
|
||||||
0x79, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x01, 0x79, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41,
|
|
||||||
0x79, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x40, 0x79, 0x41, 0x41,
|
|
||||||
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
|
|
||||||
0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x78, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x40, 0xce, 0x02, 0xc2, 0x42, 0xc2, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0x42, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0xc2, 0x02, 0x82, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x42, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
|
||||||
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x4e, 0xc0,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x05, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x07,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00,
|
|
||||||
0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x2f, 0x50, 0xa0, 0x50, 0x2f, 0x10, 0x0f, 0x00,
|
|
||||||
0x00, 0x3f, 0x40, 0xbf, 0xa0, 0xa0, 0xa0, 0xbf, 0x40, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x7e, 0x22, 0x22, 0x3e, 0x00, 0x7e, 0x52, 0x52, 0x42, 0x00, 0x7e, 0x12, 0x12, 0x7e, 0x00,
|
|
||||||
0x7e, 0x08, 0x08, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
}}
|
|
||||||
@@ -0,0 +1,273 @@
|
|||||||
|
package visual
|
||||||
|
|
||||||
|
var vumeterBackground = [2][]uint8{{
|
||||||
|
0x80, /* = width */
|
||||||
|
0x40, /* = height */
|
||||||
|
0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x1f, 0x04, 0x04,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xa8, 0xb8, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xf8, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xa8,
|
||||||
|
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xa8, 0xb8, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xa8, 0xf8,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00,
|
||||||
|
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00,
|
||||||
|
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00, 0xe0, 0xe0, 0xe0,
|
||||||
|
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00,
|
||||||
|
0xc0, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x0f, 0x00,
|
||||||
|
0x0f, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0x04, 0x04,
|
||||||
|
0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x04, 0x04, 0xfc, 0x04, 0x04, 0x00,
|
||||||
|
0x00, 0xfc, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x04,
|
||||||
|
0x04, 0xfc, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x24,
|
||||||
|
0x24, 0x24, 0x00, 0x00, 0x3c, 0xc0, 0x00, 0xc0, 0x3c, 0x00, 0x00, 0xfc, 0x24, 0x24, 0x24, 0x00,
|
||||||
|
0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
|
||||||
|
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
|
||||||
|
0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x22, 0x22, 0x1c,
|
||||||
|
0x00, 0x7e, 0x4a, 0x4a, 0x42, 0x00, 0x7c, 0x12, 0x12, 0x7c, 0x00, 0x7e, 0x08, 0x08, 0x76, 0x00,
|
||||||
|
}, {
|
||||||
|
0x80, /* = width */
|
||||||
|
0x40, /* = height */
|
||||||
|
0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x1f, 0x04, 0x04,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xa8, 0xb8, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xf8, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xa8,
|
||||||
|
0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x88, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8, 0xa8, 0xb8, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa8, 0xa8, 0xf8,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00,
|
||||||
|
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xc0, 0xc0,
|
||||||
|
0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00,
|
||||||
|
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0x00, 0xe0, 0xe0, 0xe0,
|
||||||
|
0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xe0, 0xf0, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00,
|
||||||
|
0xc0, 0x40, 0x40, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x0f, 0x00,
|
||||||
|
0x0f, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0x04, 0x04,
|
||||||
|
0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x04, 0x04, 0xfc, 0x04, 0x04, 0x00,
|
||||||
|
0x00, 0xfc, 0x44, 0x44, 0x44, 0x38, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x04,
|
||||||
|
0x04, 0xfc, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x24,
|
||||||
|
0x24, 0x24, 0x00, 0x00, 0x3c, 0xc0, 0x00, 0xc0, 0x3c, 0x00, 0x00, 0xfc, 0x24, 0x24, 0x24, 0x00,
|
||||||
|
0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x01, 0x01,
|
||||||
|
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x00,
|
||||||
|
0x00, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x22, 0x22, 0x1c,
|
||||||
|
0x00, 0x7e, 0x4a, 0x4a, 0x42, 0x00, 0x7c, 0x12, 0x12, 0x7c, 0x00, 0x7e, 0x08, 0x08, 0x76, 0x00,
|
||||||
|
}}
|
||||||
|
|
||||||
|
var vumeterBackgroundVU = [2][]uint8{{
|
||||||
|
0x80, /* = width */
|
||||||
|
0x40, /* = height */
|
||||||
|
0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x1f, 0x04, 0x04,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xf0, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x50,
|
||||||
|
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x50, 0xf0,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x78, 0x41, 0x41, 0x41, 0x40, 0x40, 0x40,
|
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
|
||||||
|
0x41, 0x40, 0x79, 0x41, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40,
|
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x79,
|
||||||
|
0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40,
|
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x79, 0x01, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x79,
|
||||||
|
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x61, 0x79, 0x61, 0x60, 0x60,
|
||||||
|
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x61, 0x79, 0x01,
|
||||||
|
0xc0, 0x4e, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0x02, 0x42, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x02, 0x82, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0x42, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0xc2, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0xc2, 0x02, 0xc2, 0x42, 0xce, 0x00, 0xc0, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x05, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00,
|
||||||
|
0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x2f, 0x50, 0xa0, 0x50, 0x2f, 0x10, 0x0f, 0x00,
|
||||||
|
0x00, 0x3f, 0x40, 0xbf, 0xa0, 0xa0, 0xa0, 0xbf, 0x40, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x22, 0x22, 0x3e,
|
||||||
|
0x00, 0x7e, 0x52, 0x52, 0x42, 0x00, 0x7e, 0x12, 0x12, 0x7e, 0x00, 0x7e, 0x08, 0x08, 0x76, 0x00,
|
||||||
|
}, {
|
||||||
|
0x80, /* = width */
|
||||||
|
0x40, /* = height */
|
||||||
|
0x04, 0x04, 0x1f, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04,
|
||||||
|
0x50, 0x50, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,
|
||||||
|
0x50, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0xf0, 0x10, 0xf0,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0xd0, 0x50, 0x70, 0x00, 0xf0, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x01, 0x79, 0x61, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||||
|
0x60, 0x60, 0x61, 0x79, 0x61, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60,
|
||||||
|
0x79, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x01, 0x79, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40,
|
||||||
|
0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41,
|
||||||
|
0x79, 0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40,
|
||||||
|
0x40, 0x40, 0x40, 0x60, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x40, 0x79, 0x41, 0x41,
|
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
|
||||||
|
0x40, 0x40, 0x40, 0x41, 0x41, 0x41, 0x78, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0xc0, 0x40, 0xce, 0x02, 0xc2, 0x42, 0xc2, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0x02, 0xc2, 0x42, 0x42, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0x02, 0xc2, 0x02, 0x82, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0x02, 0x02, 0x42, 0x42, 0xc2, 0x06, 0xc2, 0x42, 0xc2, 0x02, 0x02, 0x02, 0x02,
|
||||||
|
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xc2, 0x4e, 0xc0,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x07, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x05, 0x05, 0x00, 0x07, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x04, 0x07,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00,
|
||||||
|
0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x2f, 0x50, 0xa0, 0x50, 0x2f, 0x10, 0x0f, 0x00,
|
||||||
|
0x00, 0x3f, 0x40, 0xbf, 0xa0, 0xa0, 0xa0, 0xbf, 0x40, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x7e, 0x22, 0x22, 0x3e, 0x00, 0x7e, 0x52, 0x52, 0x42, 0x00, 0x7e, 0x12, 0x12, 0x7e, 0x00,
|
||||||
|
0x7e, 0x08, 0x08, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
}}
|
||||||
Reference in new issue
Block a user