Skip to content

Commit

Permalink
ssd1306: Add SetDisplayStartLine (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzky authored May 8, 2021
1 parent 765957c commit 8249b95
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ssd1306/ssd1306.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ func (d *Dev) SetContrast(level byte) error {
return d.sendCommand([]byte{0x81, level})
}

// SetDisplayStartLine causes the display to start from startLine, effectively
// scrolling the screen to that position.
//
// startLine must be between 0 and 63.
func (d *Dev) SetDisplayStartLine(startLine byte) error {
if startLine > 63 {
return fmt.Errorf("ssd1306: invalid startLine %d", startLine)
}
return d.sendCommand([]byte{_SETSTARTLINE | startLine})
}

// Halt turns off the display.
//
// Sending any other command afterward reenables the display.
Expand Down
31 changes: 31 additions & 0 deletions ssd1306/ssd1306_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,37 @@ func TestI2C_SetContrast(t *testing.T) {
}
}

func TestI2C_SetDisplayStartLine(t *testing.T) {
bus := i2ctest.Playback{
Ops: []i2ctest.IO{
{Addr: 0x3c, W: initCmdI2C()},
{Addr: 0x3c, W: []byte{0x0, 0x40}},
{Addr: 0x3c, W: []byte{0x0, 0x45}},
{Addr: 0x3c, W: []byte{0x0, 0x60}},
{Addr: 0x3c, W: []byte{0x0, 0x7F}},
},
}
dev, err := NewI2C(&bus, &DefaultOpts)
if err != nil {
t.Fatal(err)
}
if err := dev.SetDisplayStartLine(0); err != nil {
t.Fatal(err)
}
if err := dev.SetDisplayStartLine(5); err != nil {
t.Fatal(err)
}
if err := dev.SetDisplayStartLine(32); err != nil {
t.Fatal(err)
}
if err := dev.SetDisplayStartLine(63); err != nil {
t.Fatal(err)
}
if err := bus.Close(); err != nil {
t.Fatal(err)
}
}

func TestI2C_Invert_Halt_resume(t *testing.T) {
bus := i2ctest.Playback{
Ops: []i2ctest.IO{
Expand Down

0 comments on commit 8249b95

Please sign in to comment.