Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssd1306: Add function SetFlip and GetFlip #702

Merged
merged 2 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ssd1306/registers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ const (

EXTERNALVCC VccMode = 0x1
SWITCHCAPVCC VccMode = 0x2

NO_FLIP = false
FLIP = true
)
25 changes: 23 additions & 2 deletions ssd1306/ssd1306.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Device struct {
canReset bool
resetCol ResetValue
resetPage ResetValue
isFlip bool
}

// Config is the configuration for the display
Expand All @@ -48,6 +49,7 @@ type Config struct {
// If you're using a different size, you might need to set these values manually.
ResetCol ResetValue
ResetPage ResetValue
IsFlip bool
}

type I2CBus struct {
Expand Down Expand Up @@ -149,8 +151,8 @@ func (d *Device) Configure(cfg Config) {
}
d.Command(MEMORYMODE)
d.Command(0x00)
d.Command(SEGREMAP | 0x1)
d.Command(COMSCANDEC)

d.SetFlip(cfg.IsFlip)

if (d.width == 128 && d.height == 64) || (d.width == 64 && d.height == 48) { // 128x64 or 64x48
d.Command(SETCOMPINS)
Expand Down Expand Up @@ -383,3 +385,22 @@ func (d *Device) Sleep(sleepEnabled bool) error {
}
return nil
}

// GetFlip retrieves the current state of the display's flip orientation.
// Returns a boolean value indicating whether the display is flipped or not.
func (d *Device) GetFlip() bool {
return d.isFlip
}

// SetFlip sets the flip orientation of the display.
// It uses commands SEGREMAP and COMSCANINC to achieve this.
func (d *Device) SetFlip(flip bool) {
d.isFlip = flip
if d.isFlip {
d.Command(SEGREMAP | 0x1) // Reverse horizontal mapping
d.Command(COMSCANDEC) // Reverse vertical mapping
} else {
d.Command(SEGREMAP) // Normal horizontal mapping
d.Command(COMSCANINC) // Normal vertical mapping
}
}
Loading