Skip to content

Commit

Permalink
jhd1313m1_driver: fix '\n' processing
Browse files Browse the repository at this point in the history
  • Loading branch information
toxeus committed Jul 10, 2015
1 parent d18d6cd commit cc9893d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions platforms/i2c/i2c.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
)

var (
ErrEncryptedBytes = errors.New("Encrypted bytes")
ErrNotEnoughBytes = errors.New("Not enough bytes read")
ErrNotReady = errors.New("Device is not ready")
ErrEncryptedBytes = errors.New("Encrypted bytes")
ErrNotEnoughBytes = errors.New("Not enough bytes read")
ErrNotReady = errors.New("Device is not ready")
ErrInvalidPosition = errors.New("Invalid position value")
)

const (
Expand Down
25 changes: 25 additions & 0 deletions platforms/i2c/jhd1313m1_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
LCD_MOVERIGHT = 0x04
LCD_MOVELEFT = 0x00
LCD_2LINE = 0x08

LCD_2NDLINEOFFSET = 0x40
)

var _ gobot.Driver = (*JHD1313M1Driver)(nil)
Expand Down Expand Up @@ -145,13 +147,36 @@ func (h *JHD1313M1Driver) Home() (err error) {

func (h *JHD1313M1Driver) Write(message string) (err error) {
for _, val := range message {
if val == '\n' {
if err = h.SetPosition(16); err != nil {
return
}
continue
}
if err = h.connection.I2cWrite(h.lcdAddress, []byte{0x40, byte(val)}); err != nil {
break
}
}
return
}

// SetPosition sets the cursor and the data display to pos.
// 0..15 are the positions in the first display line.
// 16..32 are the positions in the second display line.
func (h *JHD1313M1Driver) SetPosition(pos int) (err error) {
if pos < 0 || pos > 31 {
err = ErrInvalidPosition
return
}
offset := byte(pos)
if pos >= 16 {
offset -= 16
offset |= LCD_2NDLINEOFFSET
}
err = h.command([]byte{LCD_SETDDRAMADDR | offset})
return
}

func (h *JHD1313M1Driver) Halt() (errs []error) { return }

func (h *JHD1313M1Driver) command(buf []byte) (err error) {
Expand Down

0 comments on commit cc9893d

Please sign in to comment.