<commit_before>package devices

import (
	"bytes"
	"encoding/binary"
	"errors"
	"fmt"
	i2c "github.com/davecheney/i2c"
	"log"
)

const (
	regWhoAmI    = 0x00
	regSmplrtDiv = 0x15
	regDlpfFs    = 0x16
	regIntCfg    = 0x17
	regIntStatus = 0x1a
	regTempOutH  = 0x1b
	regTempOutL  = 0x1c
	regGyroXoutH = 0x1d
	regGyroXoutL = 0x1e
	regGyroYoutH = 0x1f
	regGyroYoutL = 0x20
	regGyroZoutH = 0x21
	regGyroZoutL = 0x22
	regPwrMgm    = 0x3e
)

const (
	dlpfCfg256Hz    byte = 0x00
	dlpfCfg188Hz    byte = 0x01
	dlpfCfg98Hz     byte = 0x02
	dlpfCfg42Hz     byte = 0x03
	dlpfCfg20Hz     byte = 0x04
	dlpfCfg10Hz     byte = 0x05
	dlpfCfg5Hz      byte = 0x06
	dlpfFsFullScale byte = 0x18
)

const (
	pwrMgmClkSelInternal        byte = 0x00
	pwrMgmClkSelXGyroRef        byte = 0x01
	pwrMgmClkSelYGyroRef        byte = 0x02
	pwrMgmClkSelZGyroRef        byte = 0x03
	pwrMgmClkSelExt32_768kHzRef byte = 0x04
	pwrMgmClkSelExt19_2kHzRef   byte = 0x05
	pwrMgmStbyZG                byte = 0x08
	pwrMgmStbyYG                byte = 0x10
	pwrMgmStbyXG                byte = 0x20
	pwrMgmSleep                 byte = 0x40
	pwrMgmHReset                byte = 0x80
)

const whoAmIMask = 0x7e

type Itg3200 struct {
	bus     *i2c.I2C
	device  int
	address uint8
}

func NewItg3200(address uint8, device int) (Device, error) {
	itg := Itg3200{
		device:  device,
		address: address,
	}

	bus, err := i2c.New(address, device)
	if err != nil {
		return nil, err
	}

	itg.bus = bus
	return &itg, nil
}

func (itg *Itg3200) Init() {
	if err := itg.checkWhoAmI(); err != nil {
		log.Fatal(err.Error())
	}

	itg.setRegister(regDlpfFs, dlpfFsFullScale|dlpfCfg10Hz)
	itg.setRegister(regPwrMgm, pwrMgmClkSelXGyroRef)
}

func (itg *Itg3200) Destroy() {
}
<commit_msg>Give itg some time to settle<commit_after>package devices

import (
	"bytes"
	"encoding/binary"
	"errors"
	"fmt"
	i2c "github.com/davecheney/i2c"
	"log"
	"time"
)

const (
	regWhoAmI    = 0x00
	regSmplrtDiv = 0x15
	regDlpfFs    = 0x16
	regIntCfg    = 0x17
	regIntStatus = 0x1a
	regTempOutH  = 0x1b
	regTempOutL  = 0x1c
	regGyroXoutH = 0x1d
	regGyroXoutL = 0x1e
	regGyroYoutH = 0x1f
	regGyroYoutL = 0x20
	regGyroZoutH = 0x21
	regGyroZoutL = 0x22
	regPwrMgm    = 0x3e
)

const (
	dlpfCfg256Hz    byte = 0x00
	dlpfCfg188Hz    byte = 0x01
	dlpfCfg98Hz     byte = 0x02
	dlpfCfg42Hz     byte = 0x03
	dlpfCfg20Hz     byte = 0x04
	dlpfCfg10Hz     byte = 0x05
	dlpfCfg5Hz      byte = 0x06
	dlpfFsFullScale byte = 0x18
)

const (
	pwrMgmClkSelInternal        byte = 0x00
	pwrMgmClkSelXGyroRef        byte = 0x01
	pwrMgmClkSelYGyroRef        byte = 0x02
	pwrMgmClkSelZGyroRef        byte = 0x03
	pwrMgmClkSelExt32_768kHzRef byte = 0x04
	pwrMgmClkSelExt19_2kHzRef   byte = 0x05
	pwrMgmStbyZG                byte = 0x08
	pwrMgmStbyYG                byte = 0x10
	pwrMgmStbyXG                byte = 0x20
	pwrMgmSleep                 byte = 0x40
	pwrMgmHReset                byte = 0x80
)

const whoAmIMask = 0x7e

type Itg3200 struct {
	bus     *i2c.I2C
	device  int
	address uint8
}

func NewItg3200(address uint8, device int) (Device, error) {
	itg := Itg3200{
		device:  device,
		address: address,
	}

	bus, err := i2c.New(address, device)
	if err != nil {
		return nil, err
	}

	itg.bus = bus
	return &itg, nil
}

func (itg *Itg3200) Init() {
	if err := itg.checkWhoAmI(); err != nil {
		log.Fatal(err.Error())
	}

	itg.setRegister(regPwrMgm, pwrMgmHReset)
	itg.setRegister(regDlpfFs, dlpfFsFullScale)
	time.Sleep(50 * time.Millisecond) /* Give gyro time to settle */

	itg.setRegister(regDlpfFs, dlpfFsFullScale|dlpfCfg10Hz)
	itg.setRegister(regPwrMgm, pwrMgmClkSelXGyroRef)
}

func (itg *Itg3200) Destroy() {
}

{'fraction_non_alphanumeric': 0.08018737944337283, 'fraction_numerical': 0.08101405345825297, 'mean_word_length': 2.8535031847133756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3664298', 'n_tokens_mistral': 1946, 'n_tokens_neox': 1675, 'n_words': 329}