|
|
|
@ -179,8 +179,8 @@ func (d *Dev) ChannelSelect(ch int) error {
|
|
|
|
var err error = nil
|
|
|
|
var err error = nil
|
|
|
|
switch d.isDS248x {
|
|
|
|
switch d.isDS248x {
|
|
|
|
case isDS2482x100:
|
|
|
|
case isDS2482x100:
|
|
|
|
err = errors.New("unsupported (ds2482-100 has only channel 0)")
|
|
|
|
// err = errors.New("unsupported (ds2482-100 has only channel 0)")
|
|
|
|
return fmt.Errorf("ds2482-100: error while selecting channel: %s", err)
|
|
|
|
// return fmt.Errorf("ds2482-100: error while selecting channel: %s", err)
|
|
|
|
case isDS2482x800:
|
|
|
|
case isDS2482x800:
|
|
|
|
if ch < 0 || ch > 7 {
|
|
|
|
if ch < 0 || ch > 7 {
|
|
|
|
err = errors.New("channel out of range 0...7")
|
|
|
|
err = errors.New("channel out of range 0...7")
|
|
|
|
@ -191,8 +191,8 @@ func (d *Dev) ChannelSelect(ch int) error {
|
|
|
|
return fmt.Errorf("ds2482-800: error while selecting channel: %s", err)
|
|
|
|
return fmt.Errorf("ds2482-800: error while selecting channel: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case isDS2483:
|
|
|
|
case isDS2483:
|
|
|
|
err = errors.New("unsupported (ds2483 has only channel 0)")
|
|
|
|
// err = errors.New("unsupported (ds2483 has only channel 0)")
|
|
|
|
return fmt.Errorf("ds2483: error while selecting channel: %s", err)
|
|
|
|
// return fmt.Errorf("ds2483: error while selecting channel: %s", err)
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
err = errors.New("wrong chip")
|
|
|
|
err = errors.New("wrong chip")
|
|
|
|
return fmt.Errorf("ds248x: error while selecting channel: %s", err)
|
|
|
|
return fmt.Errorf("ds248x: error while selecting channel: %s", err)
|
|
|
|
@ -214,7 +214,7 @@ func (d *Dev) SelectedChannel() int {
|
|
|
|
if err := d.i2c.Tx([]byte{cmdSetReadPtr, regCSR}, sch[:]); err != nil {
|
|
|
|
if err := d.i2c.Tx([]byte{cmdSetReadPtr, regCSR}, sch[:]); err != nil {
|
|
|
|
return 255
|
|
|
|
return 255
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ch = bytes.Index(cscr, []byte{sch[0]})
|
|
|
|
ch = bytes.Index(cscr[:], sch[:])
|
|
|
|
if ch < 0 {
|
|
|
|
if ch < 0 {
|
|
|
|
return 255
|
|
|
|
return 255
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -349,7 +349,7 @@ func (d *Dev) makeDev(opts *Opts) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set the read ptr to the port configuration register to determine whether we have a
|
|
|
|
// Set the read ptr to the port configuration register to determine whether we have a
|
|
|
|
// ds2483 vs ds2482-100 or ds2482-800. This will fail on devices that do not have a port
|
|
|
|
// ds2483 vs ds2482-100 or ds2482-800. This will fail on devices that do not have a port
|
|
|
|
// configuration register, such as the ds2482-100 or ds2482-800.
|
|
|
|
// configuration register, such as the ds2482-100 or ds2482-800.
|
|
|
|
if d.i2c.Tx([]byte{cmdSetReadPtr, regPCR}, nil) == nil {
|
|
|
|
if d.i2c.Tx([]byte{cmdSetReadPtr, regPCR}, nil) == nil {
|
|
|
|
d.isDS248x = isDS2483
|
|
|
|
d.isDS248x = isDS2483
|
|
|
|
@ -365,7 +365,7 @@ func (d *Dev) makeDev(opts *Opts) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Set the read ptr to the channel selection register to determine whether we have a
|
|
|
|
// Set the read ptr to the channel selection register to determine whether we have a
|
|
|
|
// ds2482-800 vs ds2482-100. This will fail on devices that do not have a channel
|
|
|
|
// ds2482-800 vs ds2482-100. This will fail on devices that do not have a channel
|
|
|
|
// selection register, such as the ds2482-100.
|
|
|
|
// selection register, such as the ds2482-100.
|
|
|
|
if d.i2c.Tx([]byte{cmdSetReadPtr, regCSR}, nil) == nil {
|
|
|
|
if d.i2c.Tx([]byte{cmdSetReadPtr, regCSR}, nil) == nil {
|
|
|
|
d.isDS248x = isDS2482x800
|
|
|
|
d.isDS248x = isDS2482x800
|
|
|
|
@ -435,4 +435,4 @@ const (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var cscw = [...]byte{cscIO0w, cscIO1w, cscIO2w, cscIO3w, cscIO4w, cscIO5w, cscIO6w, cscIO7w}
|
|
|
|
var cscw = [...]byte{cscIO0w, cscIO1w, cscIO2w, cscIO3w, cscIO4w, cscIO5w, cscIO6w, cscIO7w}
|
|
|
|
var cscr = []byte{cscIO0r, cscIO1r, cscIO2r, cscIO3r, cscIO4r, cscIO5r, cscIO6r, cscIO7r}
|
|
|
|
var cscr = [...]byte{cscIO0r, cscIO1r, cscIO2r, cscIO3r, cscIO4r, cscIO5r, cscIO6r, cscIO7r}
|
|
|
|
|