Exemplo n.º 1
0
// Open opens a connection the the RGB backlight display.
// Once display is no longer in-use, it should be closed by Close.
func Open(o driver.Opener) (*Device, error) {
	lcd, err := i2c.Open(o, lcdAddr)
	if err != nil {
		return nil, fmt.Errorf("cannot open LCD device: %v", err)
	}
	rgb, err := i2c.Open(o, rgbAddr)
	if err != nil {
		return nil, fmt.Errorf("cannot open RGB device: %v", err)
	}

	// two lines, regular 10 dots font.
	if err := lcd.Write([]byte{lcdFn, functionSet | displayOn | line2 | dots10}); err != nil {
		return nil, err
	}
	// direction: left to right
	if err := lcd.Write([]byte{lcdFn, displayControl | displayOn}); err != nil {
		return nil, err
	}
	// display on
	if err := lcd.Write([]byte{lcdFn, entryModeSet | entryLeft | entryShiftDecrement}); err != nil {
		return nil, err
	}

	return &Device{lcd: lcd, rgb: rgb}, nil
}
Exemplo n.º 2
0
// Open opens a new PiGlow. A PiGlow must be closed if no longer in use.
// If the PiGlow has not been powered down since last use, it will be opened
// with its last programmed state.
func Open(o driver.Opener) (*PiGlow, error) {
	conn, err := i2c.Open(o, addr)
	if err != nil {
		return nil, err
	}
	return &PiGlow{conn: conn}, nil
}
Exemplo n.º 3
0
Arquivo: rtc.go Projeto: rogpeppe/misc
// Open opens a new RTC. An RTC must be closed when no longer used.
func Open(o driver.Opener) (*RTC, error) {
	c, err := i2c.Open(o, addr)
	if err != nil {
		return nil, err
	}
	rtc := &RTC{conn: c}
	if err := rtc.setup(); err != nil {
		rtc.Close()
		return nil, fmt.Errorf("cannot set up: %v", err)
	}
	return rtc, nil
}