Refactor display options in ssd1306.go (#77)

pull/80/head
czechbol 2 years ago committed by GitHub
parent f9d46888f5
commit 853aec60c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -84,11 +84,13 @@ const (
// DefaultOpts is the recommended default options.
var DefaultOpts = Opts{
W: 128,
H: 64,
Rotated: false,
Sequential: false,
SwapTopBottom: false,
W: 128,
H: 64,
Rotated: false,
MirrorVertical: false,
MirrorHorizontal: false,
Sequential: false,
SwapTopBottom: false,
}
// Opts defines the options for the device.
@ -96,11 +98,21 @@ type Opts struct {
W int
H int
// Rotated determines if the display is rotated by 180°.
//
// Deprecated: Use MirrorVertical and MirrorHorizontal instead.
Rotated bool
// Sequential corresponds to the Sequential/Alternative COM pin configuration
// in the OLED panel hardware. Try toggling this if half the rows appear to be
// missing on your display.
Sequential bool
// MirrorVertical corresponds to the COM remap configuration in the OLED panel
// hardware. Try toggling this if the display is flipped vertically.
// Overwrites Rotated.
MirrorVertical bool
// MirrorHorizontal corresponds to the SEG remap configuration in the OLED panel
// hardware. Try toggling this if the display is flipped horizontally.
// Overwrites Rotated.
MirrorHorizontal bool
// SwapTopBottom corresponds to the Left/Right remap COM pin configuration in
// the OLED panel hardware. Try toggling this if the top and bottom halves of
// your display are swapped.
@ -354,6 +366,12 @@ func getInitCmd(opts *Opts) []byte {
comScan = 0xC0
columnAddr = byte(0xA0)
}
if opts.MirrorVertical {
comScan = byte(0xC0)
}
if opts.MirrorHorizontal {
columnAddr = byte(0xA0)
}
// See page 40.
hwLayout := byte(0x02)
if !opts.Sequential {

@ -29,7 +29,7 @@ func TestNewI2C_fail(t *testing.T) {
if d, err := NewI2C(&bus, &Opts{W: 64}); d != nil || err == nil {
t.Fatal(d, err)
}
if d, err := NewI2C(&bus, &Opts{W: 64, H: 64, Rotated: true}); d != nil || err == nil {
if d, err := NewI2C(&bus, &Opts{W: 64, H: 64, MirrorVertical: true, MirrorHorizontal: true}); d != nil || err == nil {
t.Fatal(d, err)
}
if err := bus.Close(); err != nil {
@ -491,7 +491,7 @@ func TestSPI_3wire(t *testing.T) {
func TestSPI_4wire_String(t *testing.T) {
port := spitest.Playback{
Playback: conntest.Playback{
Ops: []conntest.IO{{W: getInitCmd(&Opts{W: 128, H: 64, Rotated: false})}},
Ops: []conntest.IO{{W: getInitCmd(&Opts{W: 128, H: 64, MirrorVertical: false, MirrorHorizontal: false})}},
},
}
dev, err := NewSPI(&port, &gpiotest.Pin{N: "pin1", Num: 42}, &DefaultOpts)
@ -516,7 +516,7 @@ func TestSPI_4wire_Write_differential(t *testing.T) {
port := spitest.Playback{
Playback: conntest.Playback{
Ops: []conntest.IO{
{W: getInitCmd(&Opts{W: 128, H: 64, Rotated: false})},
{W: getInitCmd(&Opts{W: 128, H: 64, MirrorVertical: false, MirrorHorizontal: false})},
// Page 1
{W: []byte{0xB0, 0x00, 0x10}},
@ -573,7 +573,7 @@ func TestSPI_4wire_Write_differential_fail(t *testing.T) {
port := spitest.Playback{
Playback: conntest.Playback{
Ops: []conntest.IO{
{W: getInitCmd(&Opts{W: 128, H: 64, Rotated: false})},
{W: getInitCmd(&Opts{W: 128, H: 64, MirrorVertical: false, MirrorHorizontal: false})},
// Page 1
{W: []byte{0xB0, 0x00, 0x10}},
{W: buf1},
@ -623,7 +623,7 @@ func TestSPI_4wire_Write_differential_fail(t *testing.T) {
func TestSPI_4wire_gpio_fail(t *testing.T) {
port := spitest.Playback{
Playback: conntest.Playback{
Ops: []conntest.IO{{W: getInitCmd(&Opts{W: 128, H: 64, Rotated: false})}},
Ops: []conntest.IO{{W: getInitCmd(&Opts{W: 128, H: 64, MirrorVertical: false, MirrorHorizontal: false})}},
},
}
pin := &failPin{fail: false}
@ -666,7 +666,7 @@ func TestInitCmd(t *testing.T) {
//
func initCmdI2C() []byte {
return append([]byte{0}, getInitCmd(&Opts{W: 128, H: 64, Rotated: false})...)
return append([]byte{0}, getInitCmd(&Opts{W: 128, H: 64, MirrorVertical: false, MirrorHorizontal: false})...)
}
func getI2CPlayback() *i2ctest.Playback {

@ -94,7 +94,11 @@ func (s *SmokeTest) Run(f *flag.FlagSet, args []string) (err error) {
if len(*dcName) != 0 {
dc = gpioreg.ByName(*dcName)
}
opts := ssd1306.Opts{W: *w, H: *h, Rotated: *rotated}
opts := ssd1306.Opts{W: *w, H: *h}
if *rotated {
opts.MirrorHorizontal = true
opts.MirrorVertical = true
}
if !*record {
return s.run(i2cBus, spiPort, dc, &opts)
}

Loading…
Cancel
Save