repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
hybridgroup/gobot
drivers/i2c/sht3x_driver.go
SetHeater
func (s *SHT3xDriver) SetHeater(enabled bool) (err error) { out := []byte{0x30, 0x66} if true == enabled { out[1] = 0x6d } _, err = s.connection.Write(out) return }
go
func (s *SHT3xDriver) SetHeater(enabled bool) (err error) { out := []byte{0x30, 0x66} if true == enabled { out[1] = 0x6d } _, err = s.connection.Write(out) return }
[ "func", "(", "s", "*", "SHT3xDriver", ")", "SetHeater", "(", "enabled", "bool", ")", "(", "err", "error", ")", "{", "out", ":=", "[", "]", "byte", "{", "0x30", ",", "0x66", "}", "\n", "if", "true", "==", "enabled", "{", "out", "[", "1", "]", "=", "0x6d", "\n", "}", "\n", "_", ",", "err", "=", "s", ".", "connection", ".", "Write", "(", "out", ")", "\n", "return", "\n", "}" ]
// SetHeater enables or disables the heater on the device
[ "SetHeater", "enables", "or", "disables", "the", "heater", "on", "the", "device" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/sht3x_driver.go#L162-L169
train
hybridgroup/gobot
drivers/i2c/sht3x_driver.go
Sample
func (s *SHT3xDriver) Sample() (temp float32, rh float32, err error) { ret, err := s.sendCommandDelayGetResponse([]byte{0x24, s.accuracy}, &s.delay, 2) if nil != err { return } // From the datasheet: // RH = 100 * Srh / (2^16 - 1) rhSample := uint64(ret[1]) rh = float32((uint64(1000000)*rhSample)/uint64(0xffff)) / 10000.0 tempSample := uint64(ret[0]) switch s.Units { case "C": // From the datasheet: // T[C] = -45 + 175 * (St / (2^16 - 1)) temp = float32((uint64(1750000)*tempSample)/uint64(0xffff)-uint64(450000)) / 10000.0 case "F": // From the datasheet: // T[F] = -49 + 315 * (St / (2^16 - 1)) temp = float32((uint64(3150000)*tempSample)/uint64(0xffff)-uint64(490000)) / 10000.0 default: err = ErrInvalidTemp } return }
go
func (s *SHT3xDriver) Sample() (temp float32, rh float32, err error) { ret, err := s.sendCommandDelayGetResponse([]byte{0x24, s.accuracy}, &s.delay, 2) if nil != err { return } // From the datasheet: // RH = 100 * Srh / (2^16 - 1) rhSample := uint64(ret[1]) rh = float32((uint64(1000000)*rhSample)/uint64(0xffff)) / 10000.0 tempSample := uint64(ret[0]) switch s.Units { case "C": // From the datasheet: // T[C] = -45 + 175 * (St / (2^16 - 1)) temp = float32((uint64(1750000)*tempSample)/uint64(0xffff)-uint64(450000)) / 10000.0 case "F": // From the datasheet: // T[F] = -49 + 315 * (St / (2^16 - 1)) temp = float32((uint64(3150000)*tempSample)/uint64(0xffff)-uint64(490000)) / 10000.0 default: err = ErrInvalidTemp } return }
[ "func", "(", "s", "*", "SHT3xDriver", ")", "Sample", "(", ")", "(", "temp", "float32", ",", "rh", "float32", ",", "err", "error", ")", "{", "ret", ",", "err", ":=", "s", ".", "sendCommandDelayGetResponse", "(", "[", "]", "byte", "{", "0x24", ",", "s", ".", "accuracy", "}", ",", "&", "s", ".", "delay", ",", "2", ")", "\n", "if", "nil", "!=", "err", "{", "return", "\n", "}", "\n\n", "// From the datasheet:", "// RH = 100 * Srh / (2^16 - 1)", "rhSample", ":=", "uint64", "(", "ret", "[", "1", "]", ")", "\n", "rh", "=", "float32", "(", "(", "uint64", "(", "1000000", ")", "*", "rhSample", ")", "/", "uint64", "(", "0xffff", ")", ")", "/", "10000.0", "\n\n", "tempSample", ":=", "uint64", "(", "ret", "[", "0", "]", ")", "\n", "switch", "s", ".", "Units", "{", "case", "\"", "\"", ":", "// From the datasheet:", "// T[C] = -45 + 175 * (St / (2^16 - 1))", "temp", "=", "float32", "(", "(", "uint64", "(", "1750000", ")", "*", "tempSample", ")", "/", "uint64", "(", "0xffff", ")", "-", "uint64", "(", "450000", ")", ")", "/", "10000.0", "\n", "case", "\"", "\"", ":", "// From the datasheet:", "// T[F] = -49 + 315 * (St / (2^16 - 1))", "temp", "=", "float32", "(", "(", "uint64", "(", "3150000", ")", "*", "tempSample", ")", "/", "uint64", "(", "0xffff", ")", "-", "uint64", "(", "490000", ")", ")", "/", "10000.0", "\n", "default", ":", "err", "=", "ErrInvalidTemp", "\n", "}", "\n\n", "return", "\n", "}" ]
// Sample returns the temperature in celsius and relative humidity for one sample
[ "Sample", "returns", "the", "temperature", "in", "celsius", "and", "relative", "humidity", "for", "one", "sample" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/sht3x_driver.go#L172-L198
train
hybridgroup/gobot
drivers/i2c/sht3x_driver.go
getStatusRegister
func (s *SHT3xDriver) getStatusRegister() (status uint16, err error) { ret, err := s.sendCommandDelayGetResponse([]byte{0xf3, 0x2d}, nil, 1) if nil == err { status = ret[0] } return }
go
func (s *SHT3xDriver) getStatusRegister() (status uint16, err error) { ret, err := s.sendCommandDelayGetResponse([]byte{0xf3, 0x2d}, nil, 1) if nil == err { status = ret[0] } return }
[ "func", "(", "s", "*", "SHT3xDriver", ")", "getStatusRegister", "(", ")", "(", "status", "uint16", ",", "err", "error", ")", "{", "ret", ",", "err", ":=", "s", ".", "sendCommandDelayGetResponse", "(", "[", "]", "byte", "{", "0xf3", ",", "0x2d", "}", ",", "nil", ",", "1", ")", "\n", "if", "nil", "==", "err", "{", "status", "=", "ret", "[", "0", "]", "\n", "}", "\n", "return", "\n", "}" ]
// getStatusRegister returns the device status register
[ "getStatusRegister", "returns", "the", "device", "status", "register" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/sht3x_driver.go#L201-L207
train
hybridgroup/gobot
drivers/i2c/sht3x_driver.go
sendCommandDelayGetResponse
func (s *SHT3xDriver) sendCommandDelayGetResponse(send []byte, delay *time.Duration, expect int) (read []uint16, err error) { if _, err = s.connection.Write(send); err != nil { return } if nil != delay { time.Sleep(*delay) } buf := make([]byte, 3*expect) got, err := s.connection.Read(buf) if err != nil { return } if got != (3 * expect) { err = ErrNotEnoughBytes return } read = make([]uint16, expect) for i := 0; i < expect; i++ { crc := crc8.Checksum(buf[i*3:i*3+2], s.crcTable) if buf[i*3+2] != crc { err = ErrInvalidCrc return } read[i] = uint16(buf[i*3])<<8 | uint16(buf[i*3+1]) } return }
go
func (s *SHT3xDriver) sendCommandDelayGetResponse(send []byte, delay *time.Duration, expect int) (read []uint16, err error) { if _, err = s.connection.Write(send); err != nil { return } if nil != delay { time.Sleep(*delay) } buf := make([]byte, 3*expect) got, err := s.connection.Read(buf) if err != nil { return } if got != (3 * expect) { err = ErrNotEnoughBytes return } read = make([]uint16, expect) for i := 0; i < expect; i++ { crc := crc8.Checksum(buf[i*3:i*3+2], s.crcTable) if buf[i*3+2] != crc { err = ErrInvalidCrc return } read[i] = uint16(buf[i*3])<<8 | uint16(buf[i*3+1]) } return }
[ "func", "(", "s", "*", "SHT3xDriver", ")", "sendCommandDelayGetResponse", "(", "send", "[", "]", "byte", ",", "delay", "*", "time", ".", "Duration", ",", "expect", "int", ")", "(", "read", "[", "]", "uint16", ",", "err", "error", ")", "{", "if", "_", ",", "err", "=", "s", ".", "connection", ".", "Write", "(", "send", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "nil", "!=", "delay", "{", "time", ".", "Sleep", "(", "*", "delay", ")", "\n", "}", "\n\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "3", "*", "expect", ")", "\n", "got", ",", "err", ":=", "s", ".", "connection", ".", "Read", "(", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "got", "!=", "(", "3", "*", "expect", ")", "{", "err", "=", "ErrNotEnoughBytes", "\n", "return", "\n", "}", "\n\n", "read", "=", "make", "(", "[", "]", "uint16", ",", "expect", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "expect", ";", "i", "++", "{", "crc", ":=", "crc8", ".", "Checksum", "(", "buf", "[", "i", "*", "3", ":", "i", "*", "3", "+", "2", "]", ",", "s", ".", "crcTable", ")", "\n", "if", "buf", "[", "i", "*", "3", "+", "2", "]", "!=", "crc", "{", "err", "=", "ErrInvalidCrc", "\n", "return", "\n", "}", "\n", "read", "[", "i", "]", "=", "uint16", "(", "buf", "[", "i", "*", "3", "]", ")", "<<", "8", "|", "uint16", "(", "buf", "[", "i", "*", "3", "+", "1", "]", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// sendCommandDelayGetResponse is a helper function to reduce duplicated code
[ "sendCommandDelayGetResponse", "is", "a", "helper", "function", "to", "reduce", "duplicated", "code" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/sht3x_driver.go#L210-L240
train
hybridgroup/gobot
platforms/intel-iot/joule/joule_adaptor.go
NewAdaptor
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Joule"), connect: func(e *Adaptor) (err error) { return }, mutex: &sync.Mutex{}, } }
go
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Joule"), connect: func(e *Adaptor) (err error) { return }, mutex: &sync.Mutex{}, } }
[ "func", "NewAdaptor", "(", ")", "*", "Adaptor", "{", "return", "&", "Adaptor", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connect", ":", "func", "(", "e", "*", "Adaptor", ")", "(", "err", "error", ")", "{", "return", "\n", "}", ",", "mutex", ":", "&", "sync", ".", "Mutex", "{", "}", ",", "}", "\n", "}" ]
// NewAdaptor returns a new Joule Adaptor
[ "NewAdaptor", "returns", "a", "new", "Joule", "Adaptor" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/joule/joule_adaptor.go#L30-L38
train
hybridgroup/gobot
platforms/intel-iot/joule/joule_adaptor.go
Connect
func (e *Adaptor) Connect() (err error) { e.mutex.Lock() defer e.mutex.Unlock() e.digitalPins = make(map[int]*sysfs.DigitalPin) e.pwmPins = make(map[int]*sysfs.PWMPin) err = e.connect(e) return }
go
func (e *Adaptor) Connect() (err error) { e.mutex.Lock() defer e.mutex.Unlock() e.digitalPins = make(map[int]*sysfs.DigitalPin) e.pwmPins = make(map[int]*sysfs.PWMPin) err = e.connect(e) return }
[ "func", "(", "e", "*", "Adaptor", ")", "Connect", "(", ")", "(", "err", "error", ")", "{", "e", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "e", ".", "digitalPins", "=", "make", "(", "map", "[", "int", "]", "*", "sysfs", ".", "DigitalPin", ")", "\n", "e", ".", "pwmPins", "=", "make", "(", "map", "[", "int", "]", "*", "sysfs", ".", "PWMPin", ")", "\n", "err", "=", "e", ".", "connect", "(", "e", ")", "\n", "return", "\n", "}" ]
// Connect initializes the Joule for use with the Arduino beakout board
[ "Connect", "initializes", "the", "Joule", "for", "use", "with", "the", "Arduino", "beakout", "board" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/joule/joule_adaptor.go#L47-L55
train
hybridgroup/gobot
platforms/intel-iot/joule/joule_adaptor.go
DigitalPin
func (e *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) { e.mutex.Lock() defer e.mutex.Unlock() i := sysfsPinMap[pin] if e.digitalPins[i.pin] == nil { e.digitalPins[i.pin] = sysfs.NewDigitalPin(i.pin) if err = e.digitalPins[i.pin].Export(); err != nil { return } } if dir == "in" { if err = e.digitalPins[i.pin].Direction(sysfs.IN); err != nil { return } } else if dir == "out" { if err = e.digitalPins[i.pin].Direction(sysfs.OUT); err != nil { return } } return e.digitalPins[i.pin], nil }
go
func (e *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) { e.mutex.Lock() defer e.mutex.Unlock() i := sysfsPinMap[pin] if e.digitalPins[i.pin] == nil { e.digitalPins[i.pin] = sysfs.NewDigitalPin(i.pin) if err = e.digitalPins[i.pin].Export(); err != nil { return } } if dir == "in" { if err = e.digitalPins[i.pin].Direction(sysfs.IN); err != nil { return } } else if dir == "out" { if err = e.digitalPins[i.pin].Direction(sysfs.OUT); err != nil { return } } return e.digitalPins[i.pin], nil }
[ "func", "(", "e", "*", "Adaptor", ")", "DigitalPin", "(", "pin", "string", ",", "dir", "string", ")", "(", "sysfsPin", "sysfs", ".", "DigitalPinner", ",", "err", "error", ")", "{", "e", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "i", ":=", "sysfsPinMap", "[", "pin", "]", "\n", "if", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", "==", "nil", "{", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", "=", "sysfs", ".", "NewDigitalPin", "(", "i", ".", "pin", ")", "\n", "if", "err", "=", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", ".", "Export", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n\n", "if", "dir", "==", "\"", "\"", "{", "if", "err", "=", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", ".", "Direction", "(", "sysfs", ".", "IN", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "else", "if", "dir", "==", "\"", "\"", "{", "if", "err", "=", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", ".", "Direction", "(", "sysfs", ".", "OUT", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "return", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", ",", "nil", "\n", "}" ]
// digitalPin returns matched digitalPin for specified values
[ "digitalPin", "returns", "matched", "digitalPin", "for", "specified", "values" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/joule/joule_adaptor.go#L90-L112
train
hybridgroup/gobot
drivers/i2c/mpu6050_driver.go
Start
func (h *MPU6050Driver) Start() (err error) { if err := h.initialize(); err != nil { return err } return }
go
func (h *MPU6050Driver) Start() (err error) { if err := h.initialize(); err != nil { return err } return }
[ "func", "(", "h", "*", "MPU6050Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "h", ".", "initialize", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "\n", "}" ]
// Start writes initialization bytes to sensor
[ "Start", "writes", "initialization", "bytes", "to", "sensor" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mpu6050_driver.go#L83-L89
train
hybridgroup/gobot
drivers/i2c/mpu6050_driver.go
GetData
func (h *MPU6050Driver) GetData() (err error) { if _, err = h.connection.Write([]byte{MPU6050_RA_ACCEL_XOUT_H}); err != nil { return } data := make([]byte, 14) _, err = h.connection.Read(data) if err != nil { return } buf := bytes.NewBuffer(data) binary.Read(buf, binary.BigEndian, &h.Accelerometer) binary.Read(buf, binary.BigEndian, &h.Temperature) binary.Read(buf, binary.BigEndian, &h.Gyroscope) h.convertToCelsius() return }
go
func (h *MPU6050Driver) GetData() (err error) { if _, err = h.connection.Write([]byte{MPU6050_RA_ACCEL_XOUT_H}); err != nil { return } data := make([]byte, 14) _, err = h.connection.Read(data) if err != nil { return } buf := bytes.NewBuffer(data) binary.Read(buf, binary.BigEndian, &h.Accelerometer) binary.Read(buf, binary.BigEndian, &h.Temperature) binary.Read(buf, binary.BigEndian, &h.Gyroscope) h.convertToCelsius() return }
[ "func", "(", "h", "*", "MPU6050Driver", ")", "GetData", "(", ")", "(", "err", "error", ")", "{", "if", "_", ",", "err", "=", "h", ".", "connection", ".", "Write", "(", "[", "]", "byte", "{", "MPU6050_RA_ACCEL_XOUT_H", "}", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "data", ":=", "make", "(", "[", "]", "byte", ",", "14", ")", "\n", "_", ",", "err", "=", "h", ".", "connection", ".", "Read", "(", "data", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "data", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "h", ".", "Accelerometer", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "h", ".", "Temperature", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "h", ".", "Gyroscope", ")", "\n", "h", ".", "convertToCelsius", "(", ")", "\n", "return", "\n", "}" ]
// GetData fetches the latest data from the MPU6050
[ "GetData", "fetches", "the", "latest", "data", "from", "the", "MPU6050" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mpu6050_driver.go#L95-L112
train
hybridgroup/gobot
drivers/i2c/tsl2561_driver.go
WithTSL2561Gain1X
func WithTSL2561Gain1X(c Config) { d, ok := c.(*TSL2561Driver) if ok { d.gain = TSL2561Gain1X return } // TODO: return errors.New("Trying to set Gain for non-TSL2561Driver") }
go
func WithTSL2561Gain1X(c Config) { d, ok := c.(*TSL2561Driver) if ok { d.gain = TSL2561Gain1X return } // TODO: return errors.New("Trying to set Gain for non-TSL2561Driver") }
[ "func", "WithTSL2561Gain1X", "(", "c", "Config", ")", "{", "d", ",", "ok", ":=", "c", ".", "(", "*", "TSL2561Driver", ")", "\n", "if", "ok", "{", "d", ".", "gain", "=", "TSL2561Gain1X", "\n", "return", "\n", "}", "\n", "// TODO: return errors.New(\"Trying to set Gain for non-TSL2561Driver\")", "}" ]
// WithTSL2561Gain1X option sets the TSL2561Driver gain to 1X
[ "WithTSL2561Gain1X", "option", "sets", "the", "TSL2561Driver", "gain", "to", "1X" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/tsl2561_driver.go#L159-L166
train
hybridgroup/gobot
drivers/i2c/tsl2561_driver.go
WithTSL2561Gain16X
func WithTSL2561Gain16X(c Config) { d, ok := c.(*TSL2561Driver) if ok { d.gain = TSL2561Gain16X return } // TODO: return errors.New("Trying to set Gain for non-TSL2561Driver") }
go
func WithTSL2561Gain16X(c Config) { d, ok := c.(*TSL2561Driver) if ok { d.gain = TSL2561Gain16X return } // TODO: return errors.New("Trying to set Gain for non-TSL2561Driver") }
[ "func", "WithTSL2561Gain16X", "(", "c", "Config", ")", "{", "d", ",", "ok", ":=", "c", ".", "(", "*", "TSL2561Driver", ")", "\n", "if", "ok", "{", "d", ".", "gain", "=", "TSL2561Gain16X", "\n", "return", "\n", "}", "\n", "// TODO: return errors.New(\"Trying to set Gain for non-TSL2561Driver\")", "}" ]
// WithTSL2561Gain16X option sets the TSL2561Driver gain to 16X
[ "WithTSL2561Gain16X", "option", "sets", "the", "TSL2561Driver", "gain", "to", "16X" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/tsl2561_driver.go#L169-L176
train
hybridgroup/gobot
drivers/i2c/tsl2561_driver.go
WithTSL2561AutoGain
func WithTSL2561AutoGain(c Config) { d, ok := c.(*TSL2561Driver) if ok { d.autoGain = true return } // TODO: return errors.New("Trying to set Auto Gain for non-TSL2561Driver") }
go
func WithTSL2561AutoGain(c Config) { d, ok := c.(*TSL2561Driver) if ok { d.autoGain = true return } // TODO: return errors.New("Trying to set Auto Gain for non-TSL2561Driver") }
[ "func", "WithTSL2561AutoGain", "(", "c", "Config", ")", "{", "d", ",", "ok", ":=", "c", ".", "(", "*", "TSL2561Driver", ")", "\n", "if", "ok", "{", "d", ".", "autoGain", "=", "true", "\n", "return", "\n", "}", "\n", "// TODO: return errors.New(\"Trying to set Auto Gain for non-TSL2561Driver\")", "}" ]
// WithTSL2561AutoGain option turns on TSL2561Driver auto gain
[ "WithTSL2561AutoGain", "option", "turns", "on", "TSL2561Driver", "auto", "gain" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/tsl2561_driver.go#L179-L186
train
hybridgroup/gobot
drivers/i2c/tsl2561_driver.go
SetIntegrationTime
func (d *TSL2561Driver) SetIntegrationTime(time TSL2561IntegrationTime) error { if err := d.enable(); err != nil { return err } timeGainVal := uint8(time) | uint8(d.gain) if err := d.connection.WriteByteData(tsl2561CommandBit|tsl2561RegisterTiming, timeGainVal); err != nil { return err } d.integrationTime = time return d.disable() }
go
func (d *TSL2561Driver) SetIntegrationTime(time TSL2561IntegrationTime) error { if err := d.enable(); err != nil { return err } timeGainVal := uint8(time) | uint8(d.gain) if err := d.connection.WriteByteData(tsl2561CommandBit|tsl2561RegisterTiming, timeGainVal); err != nil { return err } d.integrationTime = time return d.disable() }
[ "func", "(", "d", "*", "TSL2561Driver", ")", "SetIntegrationTime", "(", "time", "TSL2561IntegrationTime", ")", "error", "{", "if", "err", ":=", "d", ".", "enable", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "timeGainVal", ":=", "uint8", "(", "time", ")", "|", "uint8", "(", "d", ".", "gain", ")", "\n", "if", "err", ":=", "d", ".", "connection", ".", "WriteByteData", "(", "tsl2561CommandBit", "|", "tsl2561RegisterTiming", ",", "timeGainVal", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "d", ".", "integrationTime", "=", "time", "\n\n", "return", "d", ".", "disable", "(", ")", "\n", "}" ]
// SetIntegrationTime sets integrations time for the TSL2561
[ "SetIntegrationTime", "sets", "integrations", "time", "for", "the", "TSL2561" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/tsl2561_driver.go#L273-L285
train
hybridgroup/gobot
drivers/i2c/tsl2561_driver.go
GetLuminocity
func (d *TSL2561Driver) GetLuminocity() (broadband uint16, ir uint16, err error) { // if auto gain disabled get a single reading and continue if !d.autoGain { broadband, ir, err = d.getData() return } agcCheck := false hi, lo := d.getHiLo() // Read data until we find a valid range valid := false for { broadband, ir, err = d.getData() if err != nil { return } // Run an auto-gain check if we haven't already done so if !agcCheck { if (broadband < lo) && (d.gain == TSL2561Gain1X) { // increase gain and try again err = d.SetGain(TSL2561Gain16X) if err != nil { return } agcCheck = true } else if (broadband > hi) && (d.gain == TSL2561Gain16X) { // drop gain and try again err = d.SetGain(TSL2561Gain1X) if err != nil { return } agcCheck = true } else { // Reading is either valid, or we're already at the chips // limits valid = true } } else { // If we've already adjusted the gain once, just return the new results. // This avoids endless loops where a value is at one extreme pre-gain, // and the the other extreme post-gain valid = true } if valid { break } } return }
go
func (d *TSL2561Driver) GetLuminocity() (broadband uint16, ir uint16, err error) { // if auto gain disabled get a single reading and continue if !d.autoGain { broadband, ir, err = d.getData() return } agcCheck := false hi, lo := d.getHiLo() // Read data until we find a valid range valid := false for { broadband, ir, err = d.getData() if err != nil { return } // Run an auto-gain check if we haven't already done so if !agcCheck { if (broadband < lo) && (d.gain == TSL2561Gain1X) { // increase gain and try again err = d.SetGain(TSL2561Gain16X) if err != nil { return } agcCheck = true } else if (broadband > hi) && (d.gain == TSL2561Gain16X) { // drop gain and try again err = d.SetGain(TSL2561Gain1X) if err != nil { return } agcCheck = true } else { // Reading is either valid, or we're already at the chips // limits valid = true } } else { // If we've already adjusted the gain once, just return the new results. // This avoids endless loops where a value is at one extreme pre-gain, // and the the other extreme post-gain valid = true } if valid { break } } return }
[ "func", "(", "d", "*", "TSL2561Driver", ")", "GetLuminocity", "(", ")", "(", "broadband", "uint16", ",", "ir", "uint16", ",", "err", "error", ")", "{", "// if auto gain disabled get a single reading and continue", "if", "!", "d", ".", "autoGain", "{", "broadband", ",", "ir", ",", "err", "=", "d", ".", "getData", "(", ")", "\n", "return", "\n", "}", "\n\n", "agcCheck", ":=", "false", "\n", "hi", ",", "lo", ":=", "d", ".", "getHiLo", "(", ")", "\n\n", "// Read data until we find a valid range", "valid", ":=", "false", "\n", "for", "{", "broadband", ",", "ir", ",", "err", "=", "d", ".", "getData", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "// Run an auto-gain check if we haven't already done so", "if", "!", "agcCheck", "{", "if", "(", "broadband", "<", "lo", ")", "&&", "(", "d", ".", "gain", "==", "TSL2561Gain1X", ")", "{", "// increase gain and try again", "err", "=", "d", ".", "SetGain", "(", "TSL2561Gain16X", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "agcCheck", "=", "true", "\n", "}", "else", "if", "(", "broadband", ">", "hi", ")", "&&", "(", "d", ".", "gain", "==", "TSL2561Gain16X", ")", "{", "// drop gain and try again", "err", "=", "d", ".", "SetGain", "(", "TSL2561Gain1X", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "agcCheck", "=", "true", "\n", "}", "else", "{", "// Reading is either valid, or we're already at the chips", "// limits", "valid", "=", "true", "\n", "}", "\n", "}", "else", "{", "// If we've already adjusted the gain once, just return the new results.", "// This avoids endless loops where a value is at one extreme pre-gain,", "// and the the other extreme post-gain", "valid", "=", "true", "\n", "}", "\n\n", "if", "valid", "{", "break", "\n", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// GetLuminocity gets the broadband and IR only values from the TSL2561, // adjusting gain if auto-gain is enabled
[ "GetLuminocity", "gets", "the", "broadband", "and", "IR", "only", "values", "from", "the", "TSL2561", "adjusting", "gain", "if", "auto", "-", "gain", "is", "enabled" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/tsl2561_driver.go#L304-L356
train
hybridgroup/gobot
drivers/i2c/tsl2561_driver.go
CalculateLux
func (d *TSL2561Driver) CalculateLux(broadband uint16, ir uint16) (lux uint32) { var channel1 uint32 var channel0 uint32 // Set cliplevel and scaling based on integration time clipThreshold, chScale := d.getClipScaling() // Saturated sensor if (broadband > clipThreshold) || (ir > clipThreshold) { return 65536 } // Adjust scale for gain if d.gain == TSL2561Gain1X { chScale = chScale * 16 } channel0 = (uint32(broadband) * chScale) >> tsl2561LuxChScale channel1 = (uint32(ir) * chScale) >> tsl2561LuxChScale // Find the ratio of the channel values (channel1 / channel0) var ratio1 uint32 if channel0 != 0 { ratio1 = (channel1 << (tsl2561LuxRatioScale + 1)) / channel0 } // Round the ratio value ratio := (ratio1 + 1) / 2 b, m := d.getBM(ratio) temp := (channel0 * b) - (channel1 * m) // Negative lux not allowed if temp < 0 { temp = 0 } // Round lsb (2^(LUX_SCALE+1)) temp += (1 << (tsl2561LuxLuxScale - 1)) // Strip off fractional portion lux = temp >> tsl2561LuxLuxScale return lux }
go
func (d *TSL2561Driver) CalculateLux(broadband uint16, ir uint16) (lux uint32) { var channel1 uint32 var channel0 uint32 // Set cliplevel and scaling based on integration time clipThreshold, chScale := d.getClipScaling() // Saturated sensor if (broadband > clipThreshold) || (ir > clipThreshold) { return 65536 } // Adjust scale for gain if d.gain == TSL2561Gain1X { chScale = chScale * 16 } channel0 = (uint32(broadband) * chScale) >> tsl2561LuxChScale channel1 = (uint32(ir) * chScale) >> tsl2561LuxChScale // Find the ratio of the channel values (channel1 / channel0) var ratio1 uint32 if channel0 != 0 { ratio1 = (channel1 << (tsl2561LuxRatioScale + 1)) / channel0 } // Round the ratio value ratio := (ratio1 + 1) / 2 b, m := d.getBM(ratio) temp := (channel0 * b) - (channel1 * m) // Negative lux not allowed if temp < 0 { temp = 0 } // Round lsb (2^(LUX_SCALE+1)) temp += (1 << (tsl2561LuxLuxScale - 1)) // Strip off fractional portion lux = temp >> tsl2561LuxLuxScale return lux }
[ "func", "(", "d", "*", "TSL2561Driver", ")", "CalculateLux", "(", "broadband", "uint16", ",", "ir", "uint16", ")", "(", "lux", "uint32", ")", "{", "var", "channel1", "uint32", "\n", "var", "channel0", "uint32", "\n\n", "// Set cliplevel and scaling based on integration time", "clipThreshold", ",", "chScale", ":=", "d", ".", "getClipScaling", "(", ")", "\n\n", "// Saturated sensor", "if", "(", "broadband", ">", "clipThreshold", ")", "||", "(", "ir", ">", "clipThreshold", ")", "{", "return", "65536", "\n", "}", "\n\n", "// Adjust scale for gain", "if", "d", ".", "gain", "==", "TSL2561Gain1X", "{", "chScale", "=", "chScale", "*", "16", "\n", "}", "\n\n", "channel0", "=", "(", "uint32", "(", "broadband", ")", "*", "chScale", ")", ">>", "tsl2561LuxChScale", "\n", "channel1", "=", "(", "uint32", "(", "ir", ")", "*", "chScale", ")", ">>", "tsl2561LuxChScale", "\n\n", "// Find the ratio of the channel values (channel1 / channel0)", "var", "ratio1", "uint32", "\n", "if", "channel0", "!=", "0", "{", "ratio1", "=", "(", "channel1", "<<", "(", "tsl2561LuxRatioScale", "+", "1", ")", ")", "/", "channel0", "\n", "}", "\n\n", "// Round the ratio value", "ratio", ":=", "(", "ratio1", "+", "1", ")", "/", "2", "\n\n", "b", ",", "m", ":=", "d", ".", "getBM", "(", "ratio", ")", "\n", "temp", ":=", "(", "channel0", "*", "b", ")", "-", "(", "channel1", "*", "m", ")", "\n\n", "// Negative lux not allowed", "if", "temp", "<", "0", "{", "temp", "=", "0", "\n", "}", "\n\n", "// Round lsb (2^(LUX_SCALE+1))", "temp", "+=", "(", "1", "<<", "(", "tsl2561LuxLuxScale", "-", "1", ")", ")", "\n\n", "// Strip off fractional portion", "lux", "=", "temp", ">>", "tsl2561LuxLuxScale", "\n\n", "return", "lux", "\n", "}" ]
// CalculateLux converts raw sensor values to the standard SI Lux equivalent. // Returns 65536 if the sensor is saturated.
[ "CalculateLux", "converts", "raw", "sensor", "values", "to", "the", "standard", "SI", "Lux", "equivalent", ".", "Returns", "65536", "if", "the", "sensor", "is", "saturated", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/tsl2561_driver.go#L360-L404
train
hybridgroup/gobot
platforms/opencv/utils.go
loadCascadeClassifier
func loadCascadeClassifier(haar string) *gocv.CascadeClassifier { if classifier != nil { return classifier } c := gocv.NewCascadeClassifier() c.Load(haar) classifier = &c return classifier }
go
func loadCascadeClassifier(haar string) *gocv.CascadeClassifier { if classifier != nil { return classifier } c := gocv.NewCascadeClassifier() c.Load(haar) classifier = &c return classifier }
[ "func", "loadCascadeClassifier", "(", "haar", "string", ")", "*", "gocv", ".", "CascadeClassifier", "{", "if", "classifier", "!=", "nil", "{", "return", "classifier", "\n", "}", "\n\n", "c", ":=", "gocv", ".", "NewCascadeClassifier", "(", ")", "\n", "c", ".", "Load", "(", "haar", ")", "\n", "classifier", "=", "&", "c", "\n", "return", "classifier", "\n", "}" ]
// loadHaarClassifierCascade returns open cv HaarCascade loaded
[ "loadHaarClassifierCascade", "returns", "open", "cv", "HaarCascade", "loaded" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/opencv/utils.go#L13-L22
train
hybridgroup/gobot
platforms/opencv/utils.go
DetectObjects
func DetectObjects(haar string, img gocv.Mat) []image.Rectangle { return loadCascadeClassifier(haar).DetectMultiScale(img) }
go
func DetectObjects(haar string, img gocv.Mat) []image.Rectangle { return loadCascadeClassifier(haar).DetectMultiScale(img) }
[ "func", "DetectObjects", "(", "haar", "string", ",", "img", "gocv", ".", "Mat", ")", "[", "]", "image", ".", "Rectangle", "{", "return", "loadCascadeClassifier", "(", "haar", ")", ".", "DetectMultiScale", "(", "img", ")", "\n", "}" ]
// DetectObjects loads Haar cascade to detect face objects in image
[ "DetectObjects", "loads", "Haar", "cascade", "to", "detect", "face", "objects", "in", "image" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/opencv/utils.go#L25-L27
train
hybridgroup/gobot
platforms/opencv/utils.go
DrawRectangles
func DrawRectangles(img gocv.Mat, rects []image.Rectangle, r int, g int, b int, thickness int) { for _, rect := range rects { gocv.Rectangle(&img, rect, color.RGBA{uint8(r), uint8(g), uint8(b), 0}, thickness) } return }
go
func DrawRectangles(img gocv.Mat, rects []image.Rectangle, r int, g int, b int, thickness int) { for _, rect := range rects { gocv.Rectangle(&img, rect, color.RGBA{uint8(r), uint8(g), uint8(b), 0}, thickness) } return }
[ "func", "DrawRectangles", "(", "img", "gocv", ".", "Mat", ",", "rects", "[", "]", "image", ".", "Rectangle", ",", "r", "int", ",", "g", "int", ",", "b", "int", ",", "thickness", "int", ")", "{", "for", "_", ",", "rect", ":=", "range", "rects", "{", "gocv", ".", "Rectangle", "(", "&", "img", ",", "rect", ",", "color", ".", "RGBA", "{", "uint8", "(", "r", ")", ",", "uint8", "(", "g", ")", ",", "uint8", "(", "b", ")", ",", "0", "}", ",", "thickness", ")", "\n", "}", "\n", "return", "\n", "}" ]
// DrawRectangles uses Rect array values to return image with rectangles drawn.
[ "DrawRectangles", "uses", "Rect", "array", "values", "to", "return", "image", "with", "rectangles", "drawn", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/opencv/utils.go#L30-L35
train
hybridgroup/gobot
device.go
NewJSONDevice
func NewJSONDevice(device Device) *JSONDevice { jsonDevice := &JSONDevice{ Name: device.Name(), Driver: reflect.TypeOf(device).String(), Commands: []string{}, Connection: "", } if device.Connection() != nil { jsonDevice.Connection = device.Connection().Name() } if commander, ok := device.(Commander); ok { for command := range commander.Commands() { jsonDevice.Commands = append(jsonDevice.Commands, command) } } return jsonDevice }
go
func NewJSONDevice(device Device) *JSONDevice { jsonDevice := &JSONDevice{ Name: device.Name(), Driver: reflect.TypeOf(device).String(), Commands: []string{}, Connection: "", } if device.Connection() != nil { jsonDevice.Connection = device.Connection().Name() } if commander, ok := device.(Commander); ok { for command := range commander.Commands() { jsonDevice.Commands = append(jsonDevice.Commands, command) } } return jsonDevice }
[ "func", "NewJSONDevice", "(", "device", "Device", ")", "*", "JSONDevice", "{", "jsonDevice", ":=", "&", "JSONDevice", "{", "Name", ":", "device", ".", "Name", "(", ")", ",", "Driver", ":", "reflect", ".", "TypeOf", "(", "device", ")", ".", "String", "(", ")", ",", "Commands", ":", "[", "]", "string", "{", "}", ",", "Connection", ":", "\"", "\"", ",", "}", "\n", "if", "device", ".", "Connection", "(", ")", "!=", "nil", "{", "jsonDevice", ".", "Connection", "=", "device", ".", "Connection", "(", ")", ".", "Name", "(", ")", "\n", "}", "\n", "if", "commander", ",", "ok", ":=", "device", ".", "(", "Commander", ")", ";", "ok", "{", "for", "command", ":=", "range", "commander", ".", "Commands", "(", ")", "{", "jsonDevice", ".", "Commands", "=", "append", "(", "jsonDevice", ".", "Commands", ",", "command", ")", "\n", "}", "\n", "}", "\n", "return", "jsonDevice", "\n", "}" ]
// NewJSONDevice returns a JSONDevice given a Device.
[ "NewJSONDevice", "returns", "a", "JSONDevice", "given", "a", "Device", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/device.go#L19-L35
train
hybridgroup/gobot
device.go
Each
func (d *Devices) Each(f func(Device)) { for _, device := range *d { f(device) } }
go
func (d *Devices) Each(f func(Device)) { for _, device := range *d { f(device) } }
[ "func", "(", "d", "*", "Devices", ")", "Each", "(", "f", "func", "(", "Device", ")", ")", "{", "for", "_", ",", "device", ":=", "range", "*", "d", "{", "f", "(", "device", ")", "\n", "}", "\n", "}" ]
// Each enumerates through the Devices and calls specified callback function.
[ "Each", "enumerates", "through", "the", "Devices", "and", "calls", "specified", "callback", "function", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/device.go#L49-L53
train
hybridgroup/gobot
device.go
Start
func (d *Devices) Start() (err error) { log.Println("Starting devices...") for _, device := range *d { info := "Starting device " + device.Name() if pinner, ok := device.(Pinner); ok { info = info + " on pin " + pinner.Pin() } log.Println(info + "...") if derr := device.Start(); derr != nil { err = multierror.Append(err, derr) } } return err }
go
func (d *Devices) Start() (err error) { log.Println("Starting devices...") for _, device := range *d { info := "Starting device " + device.Name() if pinner, ok := device.(Pinner); ok { info = info + " on pin " + pinner.Pin() } log.Println(info + "...") if derr := device.Start(); derr != nil { err = multierror.Append(err, derr) } } return err }
[ "func", "(", "d", "*", "Devices", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "log", ".", "Println", "(", "\"", "\"", ")", "\n", "for", "_", ",", "device", ":=", "range", "*", "d", "{", "info", ":=", "\"", "\"", "+", "device", ".", "Name", "(", ")", "\n\n", "if", "pinner", ",", "ok", ":=", "device", ".", "(", "Pinner", ")", ";", "ok", "{", "info", "=", "info", "+", "\"", "\"", "+", "pinner", ".", "Pin", "(", ")", "\n", "}", "\n\n", "log", ".", "Println", "(", "info", "+", "\"", "\"", ")", "\n", "if", "derr", ":=", "device", ".", "Start", "(", ")", ";", "derr", "!=", "nil", "{", "err", "=", "multierror", ".", "Append", "(", "err", ",", "derr", ")", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Start calls Start on each Device in d
[ "Start", "calls", "Start", "on", "each", "Device", "in", "d" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/device.go#L56-L71
train
hybridgroup/gobot
device.go
Halt
func (d *Devices) Halt() (err error) { for _, device := range *d { if derr := device.Halt(); derr != nil { err = multierror.Append(err, derr) } } return err }
go
func (d *Devices) Halt() (err error) { for _, device := range *d { if derr := device.Halt(); derr != nil { err = multierror.Append(err, derr) } } return err }
[ "func", "(", "d", "*", "Devices", ")", "Halt", "(", ")", "(", "err", "error", ")", "{", "for", "_", ",", "device", ":=", "range", "*", "d", "{", "if", "derr", ":=", "device", ".", "Halt", "(", ")", ";", "derr", "!=", "nil", "{", "err", "=", "multierror", ".", "Append", "(", "err", ",", "derr", ")", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Halt calls Halt on each Device in d
[ "Halt", "calls", "Halt", "on", "each", "Device", "in", "d" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/device.go#L74-L81
train
hybridgroup/gobot
sysfs/digital_pin.go
NewDigitalPin
func NewDigitalPin(pin int, v ...string) *DigitalPin { d := &DigitalPin{pin: strconv.Itoa(pin)} if len(v) > 0 { d.label = v[0] } else { d.label = "gpio" + d.pin } return d }
go
func NewDigitalPin(pin int, v ...string) *DigitalPin { d := &DigitalPin{pin: strconv.Itoa(pin)} if len(v) > 0 { d.label = v[0] } else { d.label = "gpio" + d.pin } return d }
[ "func", "NewDigitalPin", "(", "pin", "int", ",", "v", "...", "string", ")", "*", "DigitalPin", "{", "d", ":=", "&", "DigitalPin", "{", "pin", ":", "strconv", ".", "Itoa", "(", "pin", ")", "}", "\n", "if", "len", "(", "v", ")", ">", "0", "{", "d", ".", "label", "=", "v", "[", "0", "]", "\n", "}", "else", "{", "d", ".", "label", "=", "\"", "\"", "+", "d", ".", "pin", "\n", "}", "\n\n", "return", "d", "\n", "}" ]
// NewDigitalPin returns a DigitalPin given the pin number and an optional sysfs pin label. // If no label is supplied the default label will prepend "gpio" to the pin number, // eg. a pin number of 10 will have a label of "gpio10"
[ "NewDigitalPin", "returns", "a", "DigitalPin", "given", "the", "pin", "number", "and", "an", "optional", "sysfs", "pin", "label", ".", "If", "no", "label", "is", "supplied", "the", "default", "label", "will", "prepend", "gpio", "to", "the", "pin", "number", "eg", ".", "a", "pin", "number", "of", "10", "will", "have", "a", "label", "of", "gpio10" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/digital_pin.go#L58-L67
train
hybridgroup/gobot
drivers/i2c/bme280_driver.go
Humidity
func (d *BME280Driver) Humidity() (humidity float32, err error) { var rawH uint32 if rawH, err = d.rawHumidity(); err != nil { return 0.0, err } humidity = d.calculateHumidity(rawH) return }
go
func (d *BME280Driver) Humidity() (humidity float32, err error) { var rawH uint32 if rawH, err = d.rawHumidity(); err != nil { return 0.0, err } humidity = d.calculateHumidity(rawH) return }
[ "func", "(", "d", "*", "BME280Driver", ")", "Humidity", "(", ")", "(", "humidity", "float32", ",", "err", "error", ")", "{", "var", "rawH", "uint32", "\n", "if", "rawH", ",", "err", "=", "d", ".", "rawHumidity", "(", ")", ";", "err", "!=", "nil", "{", "return", "0.0", ",", "err", "\n", "}", "\n", "humidity", "=", "d", ".", "calculateHumidity", "(", "rawH", ")", "\n", "return", "\n", "}" ]
// Humidity returns the current humidity in percentage of relative humidity
[ "Humidity", "returns", "the", "current", "humidity", "in", "percentage", "of", "relative", "humidity" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bme280_driver.go#L77-L84
train
hybridgroup/gobot
drivers/i2c/bme280_driver.go
initHumidity
func (d *BME280Driver) initHumidity() (err error) { var coefficients []byte if coefficients, err = d.read(bme280RegisterCalibDigH1, 1); err != nil { return err } buf := bytes.NewBuffer(coefficients) binary.Read(buf, binary.BigEndian, &d.hc.h1) if coefficients, err = d.read(bme280RegisterCalibDigH2LSB, 7); err != nil { return err } buf = bytes.NewBuffer(coefficients) // H4 and H5 laid out strangely on the bme280 var addrE4 byte var addrE5 byte var addrE6 byte binary.Read(buf, binary.LittleEndian, &d.hc.h2) // E1 ... binary.Read(buf, binary.BigEndian, &d.hc.h3) // E3 binary.Read(buf, binary.BigEndian, &addrE4) // E4 binary.Read(buf, binary.BigEndian, &addrE5) // E5 binary.Read(buf, binary.BigEndian, &addrE6) // E6 binary.Read(buf, binary.BigEndian, &d.hc.h6) // ... E7 d.hc.h4 = 0 + (int16(addrE4) << 4) | (int16(addrE5 & 0x0F)) d.hc.h5 = 0 + (int16(addrE6) << 4) | (int16(addrE5) >> 4) d.connection.WriteByteData(bme280RegisterControlHumidity, 0x3F) // The 'ctrl_hum' register sets the humidity data acquisition options of // the device. Changes to this register only become effective after a write // operation to 'ctrl_meas'. Read the current value in, then write it back var cmr uint8 cmr, err = d.connection.ReadByteData(bmp280RegisterControl) if err == nil { err = d.connection.WriteByteData(bmp280RegisterControl, cmr) } return err }
go
func (d *BME280Driver) initHumidity() (err error) { var coefficients []byte if coefficients, err = d.read(bme280RegisterCalibDigH1, 1); err != nil { return err } buf := bytes.NewBuffer(coefficients) binary.Read(buf, binary.BigEndian, &d.hc.h1) if coefficients, err = d.read(bme280RegisterCalibDigH2LSB, 7); err != nil { return err } buf = bytes.NewBuffer(coefficients) // H4 and H5 laid out strangely on the bme280 var addrE4 byte var addrE5 byte var addrE6 byte binary.Read(buf, binary.LittleEndian, &d.hc.h2) // E1 ... binary.Read(buf, binary.BigEndian, &d.hc.h3) // E3 binary.Read(buf, binary.BigEndian, &addrE4) // E4 binary.Read(buf, binary.BigEndian, &addrE5) // E5 binary.Read(buf, binary.BigEndian, &addrE6) // E6 binary.Read(buf, binary.BigEndian, &d.hc.h6) // ... E7 d.hc.h4 = 0 + (int16(addrE4) << 4) | (int16(addrE5 & 0x0F)) d.hc.h5 = 0 + (int16(addrE6) << 4) | (int16(addrE5) >> 4) d.connection.WriteByteData(bme280RegisterControlHumidity, 0x3F) // The 'ctrl_hum' register sets the humidity data acquisition options of // the device. Changes to this register only become effective after a write // operation to 'ctrl_meas'. Read the current value in, then write it back var cmr uint8 cmr, err = d.connection.ReadByteData(bmp280RegisterControl) if err == nil { err = d.connection.WriteByteData(bmp280RegisterControl, cmr) } return err }
[ "func", "(", "d", "*", "BME280Driver", ")", "initHumidity", "(", ")", "(", "err", "error", ")", "{", "var", "coefficients", "[", "]", "byte", "\n", "if", "coefficients", ",", "err", "=", "d", ".", "read", "(", "bme280RegisterCalibDigH1", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "coefficients", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "d", ".", "hc", ".", "h1", ")", "\n\n", "if", "coefficients", ",", "err", "=", "d", ".", "read", "(", "bme280RegisterCalibDigH2LSB", ",", "7", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "buf", "=", "bytes", ".", "NewBuffer", "(", "coefficients", ")", "\n\n", "// H4 and H5 laid out strangely on the bme280", "var", "addrE4", "byte", "\n", "var", "addrE5", "byte", "\n", "var", "addrE6", "byte", "\n\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "hc", ".", "h2", ")", "// E1 ...", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "d", ".", "hc", ".", "h3", ")", "// E3", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "addrE4", ")", "// E4", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "addrE5", ")", "// E5", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "addrE6", ")", "// E6", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "BigEndian", ",", "&", "d", ".", "hc", ".", "h6", ")", "// ... E7", "\n\n", "d", ".", "hc", ".", "h4", "=", "0", "+", "(", "int16", "(", "addrE4", ")", "<<", "4", ")", "|", "(", "int16", "(", "addrE5", "&", "0x0F", ")", ")", "\n", "d", ".", "hc", ".", "h5", "=", "0", "+", "(", "int16", "(", "addrE6", ")", "<<", "4", ")", "|", "(", "int16", "(", "addrE5", ")", ">>", "4", ")", "\n\n", "d", ".", "connection", ".", "WriteByteData", "(", "bme280RegisterControlHumidity", ",", "0x3F", ")", "\n\n", "// The 'ctrl_hum' register sets the humidity data acquisition options of", "// the device. Changes to this register only become effective after a write", "// operation to 'ctrl_meas'. Read the current value in, then write it back", "var", "cmr", "uint8", "\n", "cmr", ",", "err", "=", "d", ".", "connection", ".", "ReadByteData", "(", "bmp280RegisterControl", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "d", ".", "connection", ".", "WriteByteData", "(", "bmp280RegisterControl", ",", "cmr", ")", "\n", "}", "\n", "return", "err", "\n", "}" ]
// read the humidity calibration coefficients.
[ "read", "the", "humidity", "calibration", "coefficients", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bme280_driver.go#L87-L126
train
hybridgroup/gobot
platforms/chip/chip_adaptor.go
SetBoard
func (c *Adaptor) SetBoard(n string) (err error) { if n == "chip" || n == "pro" { c.board = n c.setPins() return } return errors.New("Invalid board type") }
go
func (c *Adaptor) SetBoard(n string) (err error) { if n == "chip" || n == "pro" { c.board = n c.setPins() return } return errors.New("Invalid board type") }
[ "func", "(", "c", "*", "Adaptor", ")", "SetBoard", "(", "n", "string", ")", "(", "err", "error", ")", "{", "if", "n", "==", "\"", "\"", "||", "n", "==", "\"", "\"", "{", "c", ".", "board", "=", "n", "\n", "c", ".", "setPins", "(", ")", "\n", "return", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// SetBoard sets the name of the type of board
[ "SetBoard", "sets", "the", "name", "of", "the", "type", "of", "board" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/chip/chip_adaptor.go#L238-L245
train
hybridgroup/gobot
drivers/gpio/led_driver.go
On
func (l *LedDriver) On() (err error) { if err = l.connection.DigitalWrite(l.Pin(), 1); err != nil { return } l.high = true return }
go
func (l *LedDriver) On() (err error) { if err = l.connection.DigitalWrite(l.Pin(), 1); err != nil { return } l.high = true return }
[ "func", "(", "l", "*", "LedDriver", ")", "On", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "l", ".", "connection", ".", "DigitalWrite", "(", "l", ".", "Pin", "(", ")", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "l", ".", "high", "=", "true", "\n", "return", "\n", "}" ]
// On sets the led to a high state.
[ "On", "sets", "the", "led", "to", "a", "high", "state", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/led_driver.go#L76-L82
train
hybridgroup/gobot
drivers/gpio/led_driver.go
Off
func (l *LedDriver) Off() (err error) { if err = l.connection.DigitalWrite(l.Pin(), 0); err != nil { return } l.high = false return }
go
func (l *LedDriver) Off() (err error) { if err = l.connection.DigitalWrite(l.Pin(), 0); err != nil { return } l.high = false return }
[ "func", "(", "l", "*", "LedDriver", ")", "Off", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "l", ".", "connection", ".", "DigitalWrite", "(", "l", ".", "Pin", "(", ")", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "l", ".", "high", "=", "false", "\n", "return", "\n", "}" ]
// Off sets the led to a low state.
[ "Off", "sets", "the", "led", "to", "a", "low", "state", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/led_driver.go#L85-L91
train
hybridgroup/gobot
drivers/gpio/led_driver.go
Brightness
func (l *LedDriver) Brightness(level byte) (err error) { if writer, ok := l.connection.(PwmWriter); ok { return writer.PwmWrite(l.Pin(), level) } return ErrPwmWriteUnsupported }
go
func (l *LedDriver) Brightness(level byte) (err error) { if writer, ok := l.connection.(PwmWriter); ok { return writer.PwmWrite(l.Pin(), level) } return ErrPwmWriteUnsupported }
[ "func", "(", "l", "*", "LedDriver", ")", "Brightness", "(", "level", "byte", ")", "(", "err", "error", ")", "{", "if", "writer", ",", "ok", ":=", "l", ".", "connection", ".", "(", "PwmWriter", ")", ";", "ok", "{", "return", "writer", ".", "PwmWrite", "(", "l", ".", "Pin", "(", ")", ",", "level", ")", "\n", "}", "\n", "return", "ErrPwmWriteUnsupported", "\n", "}" ]
// Brightness sets the led to the specified level of brightness
[ "Brightness", "sets", "the", "led", "to", "the", "specified", "level", "of", "brightness" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/led_driver.go#L104-L109
train
hybridgroup/gobot
platforms/digispark/digispark_adaptor.go
NewAdaptor
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Digispark"), connect: func(d *Adaptor) (err error) { d.littleWire = littleWireConnect() if d.littleWire.(*littleWire).lwHandle == nil { return ErrConnection } return }, } }
go
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Digispark"), connect: func(d *Adaptor) (err error) { d.littleWire = littleWireConnect() if d.littleWire.(*littleWire).lwHandle == nil { return ErrConnection } return }, } }
[ "func", "NewAdaptor", "(", ")", "*", "Adaptor", "{", "return", "&", "Adaptor", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connect", ":", "func", "(", "d", "*", "Adaptor", ")", "(", "err", "error", ")", "{", "d", ".", "littleWire", "=", "littleWireConnect", "(", ")", "\n", "if", "d", ".", "littleWire", ".", "(", "*", "littleWire", ")", ".", "lwHandle", "==", "nil", "{", "return", "ErrConnection", "\n", "}", "\n", "return", "\n", "}", ",", "}", "\n", "}" ]
// NewAdaptor returns a new Digispark Adaptor
[ "NewAdaptor", "returns", "a", "new", "Digispark", "Adaptor" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/digispark/digispark_adaptor.go#L26-L37
train
hybridgroup/gobot
platforms/digispark/digispark_adaptor.go
ServoWrite
func (d *Adaptor) ServoWrite(pin string, angle uint8) (err error) { if !d.servo { if err = d.littleWire.servoInit(); err != nil { return } d.servo = true } return d.littleWire.servoUpdateLocation(angle, angle) }
go
func (d *Adaptor) ServoWrite(pin string, angle uint8) (err error) { if !d.servo { if err = d.littleWire.servoInit(); err != nil { return } d.servo = true } return d.littleWire.servoUpdateLocation(angle, angle) }
[ "func", "(", "d", "*", "Adaptor", ")", "ServoWrite", "(", "pin", "string", ",", "angle", "uint8", ")", "(", "err", "error", ")", "{", "if", "!", "d", ".", "servo", "{", "if", "err", "=", "d", ".", "littleWire", ".", "servoInit", "(", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "d", ".", "servo", "=", "true", "\n", "}", "\n", "return", "d", ".", "littleWire", ".", "servoUpdateLocation", "(", "angle", ",", "angle", ")", "\n", "}" ]
// ServoWrite writes the 0-180 degree val to the specified pin.
[ "ServoWrite", "writes", "the", "0", "-", "180", "degree", "val", "to", "the", "specified", "pin", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/digispark/digispark_adaptor.go#L86-L94
train
hybridgroup/gobot
platforms/joystick/joystick_adaptor.go
NewAdaptor
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Joystick"), connect: func(j *Adaptor) (err error) { sdl.Init(sdl.INIT_JOYSTICK) if sdl.NumJoysticks() > 0 { j.joystick = sdl.JoystickOpen(0) return } return errors.New("No joystick available") }, } }
go
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Joystick"), connect: func(j *Adaptor) (err error) { sdl.Init(sdl.INIT_JOYSTICK) if sdl.NumJoysticks() > 0 { j.joystick = sdl.JoystickOpen(0) return } return errors.New("No joystick available") }, } }
[ "func", "NewAdaptor", "(", ")", "*", "Adaptor", "{", "return", "&", "Adaptor", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connect", ":", "func", "(", "j", "*", "Adaptor", ")", "(", "err", "error", ")", "{", "sdl", ".", "Init", "(", "sdl", ".", "INIT_JOYSTICK", ")", "\n", "if", "sdl", ".", "NumJoysticks", "(", ")", ">", "0", "{", "j", ".", "joystick", "=", "sdl", ".", "JoystickOpen", "(", "0", ")", "\n", "return", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", ",", "}", "\n", "}" ]
// NewAdaptor returns a new Joystick Adaptor.
[ "NewAdaptor", "returns", "a", "new", "Joystick", "Adaptor", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/joystick/joystick_adaptor.go#L24-L36
train
hybridgroup/gobot
drivers/i2c/mma7660_driver.go
Start
func (h *MMA7660Driver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) address := h.GetAddressOrDefault(mma7660Address) h.connection, err = h.connector.GetConnection(address, bus) if err != nil { return err } if _, err := h.connection.Write([]byte{MMA7660_MODE, MMA7660_STAND_BY}); err != nil { return err } if _, err := h.connection.Write([]byte{MMA7660_SR, MMA7660_AUTO_SLEEP_32}); err != nil { return err } if _, err := h.connection.Write([]byte{MMA7660_MODE, MMA7660_ACTIVE}); err != nil { return err } return }
go
func (h *MMA7660Driver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) address := h.GetAddressOrDefault(mma7660Address) h.connection, err = h.connector.GetConnection(address, bus) if err != nil { return err } if _, err := h.connection.Write([]byte{MMA7660_MODE, MMA7660_STAND_BY}); err != nil { return err } if _, err := h.connection.Write([]byte{MMA7660_SR, MMA7660_AUTO_SLEEP_32}); err != nil { return err } if _, err := h.connection.Write([]byte{MMA7660_MODE, MMA7660_ACTIVE}); err != nil { return err } return }
[ "func", "(", "h", "*", "MMA7660Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "h", ".", "GetBusOrDefault", "(", "h", ".", "connector", ".", "GetDefaultBus", "(", ")", ")", "\n", "address", ":=", "h", ".", "GetAddressOrDefault", "(", "mma7660Address", ")", "\n\n", "h", ".", "connection", ",", "err", "=", "h", ".", "connector", ".", "GetConnection", "(", "address", ",", "bus", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "h", ".", "connection", ".", "Write", "(", "[", "]", "byte", "{", "MMA7660_MODE", ",", "MMA7660_STAND_BY", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "h", ".", "connection", ".", "Write", "(", "[", "]", "byte", "{", "MMA7660_SR", ",", "MMA7660_AUTO_SLEEP_32", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "h", ".", "connection", ".", "Write", "(", "[", "]", "byte", "{", "MMA7660_MODE", ",", "MMA7660_ACTIVE", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "\n", "}" ]
// Start initialized the mma7660
[ "Start", "initialized", "the", "mma7660" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mma7660_driver.go#L73-L95
train
hybridgroup/gobot
drivers/i2c/mma7660_driver.go
Acceleration
func (h *MMA7660Driver) Acceleration(x, y, z float64) (ax, ay, az float64) { return x / 21.0, y / 21.0, z / 21.0 }
go
func (h *MMA7660Driver) Acceleration(x, y, z float64) (ax, ay, az float64) { return x / 21.0, y / 21.0, z / 21.0 }
[ "func", "(", "h", "*", "MMA7660Driver", ")", "Acceleration", "(", "x", ",", "y", ",", "z", "float64", ")", "(", "ax", ",", "ay", ",", "az", "float64", ")", "{", "return", "x", "/", "21.0", ",", "y", "/", "21.0", ",", "z", "/", "21.0", "\n", "}" ]
// Acceleration returns the acceleration of the provided x, y, z
[ "Acceleration", "returns", "the", "acceleration", "of", "the", "provided", "x", "y", "z" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mma7660_driver.go#L101-L103
train
hybridgroup/gobot
drivers/i2c/mma7660_driver.go
XYZ
func (h *MMA7660Driver) XYZ() (x float64, y float64, z float64, err error) { buf := []byte{0, 0, 0} bytesRead, err := h.connection.Read(buf) if err != nil { return } if bytesRead != 3 { err = ErrNotEnoughBytes return } for _, val := range buf { if ((val >> 6) & 0x01) == 1 { err = ErrNotReady return } } x = float64((int8(buf[0]) << 2)) / 4.0 y = float64((int8(buf[1]) << 2)) / 4.0 z = float64((int8(buf[2]) << 2)) / 4.0 return }
go
func (h *MMA7660Driver) XYZ() (x float64, y float64, z float64, err error) { buf := []byte{0, 0, 0} bytesRead, err := h.connection.Read(buf) if err != nil { return } if bytesRead != 3 { err = ErrNotEnoughBytes return } for _, val := range buf { if ((val >> 6) & 0x01) == 1 { err = ErrNotReady return } } x = float64((int8(buf[0]) << 2)) / 4.0 y = float64((int8(buf[1]) << 2)) / 4.0 z = float64((int8(buf[2]) << 2)) / 4.0 return }
[ "func", "(", "h", "*", "MMA7660Driver", ")", "XYZ", "(", ")", "(", "x", "float64", ",", "y", "float64", ",", "z", "float64", ",", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0", ",", "0", ",", "0", "}", "\n", "bytesRead", ",", "err", ":=", "h", ".", "connection", ".", "Read", "(", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "bytesRead", "!=", "3", "{", "err", "=", "ErrNotEnoughBytes", "\n", "return", "\n", "}", "\n\n", "for", "_", ",", "val", ":=", "range", "buf", "{", "if", "(", "(", "val", ">>", "6", ")", "&", "0x01", ")", "==", "1", "{", "err", "=", "ErrNotReady", "\n", "return", "\n", "}", "\n", "}", "\n\n", "x", "=", "float64", "(", "(", "int8", "(", "buf", "[", "0", "]", ")", "<<", "2", ")", ")", "/", "4.0", "\n", "y", "=", "float64", "(", "(", "int8", "(", "buf", "[", "1", "]", ")", "<<", "2", ")", ")", "/", "4.0", "\n", "z", "=", "float64", "(", "(", "int8", "(", "buf", "[", "2", "]", ")", "<<", "2", ")", ")", "/", "4.0", "\n\n", "return", "\n", "}" ]
// XYZ returns the raw x,y and z axis from the mma7660
[ "XYZ", "returns", "the", "raw", "x", "y", "and", "z", "axis", "from", "the", "mma7660" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mma7660_driver.go#L106-L130
train
hybridgroup/gobot
drivers/i2c/ina3221_driver.go
Start
func (i *INA3221Driver) Start() error { var err error bus := i.GetBusOrDefault(i.connector.GetDefaultBus()) address := i.GetAddressOrDefault(int(ina3221Address)) if i.connection, err = i.connector.GetConnection(address, bus); err != nil { return err } if err := i.initialize(); err != nil { return err } return nil }
go
func (i *INA3221Driver) Start() error { var err error bus := i.GetBusOrDefault(i.connector.GetDefaultBus()) address := i.GetAddressOrDefault(int(ina3221Address)) if i.connection, err = i.connector.GetConnection(address, bus); err != nil { return err } if err := i.initialize(); err != nil { return err } return nil }
[ "func", "(", "i", "*", "INA3221Driver", ")", "Start", "(", ")", "error", "{", "var", "err", "error", "\n", "bus", ":=", "i", ".", "GetBusOrDefault", "(", "i", ".", "connector", ".", "GetDefaultBus", "(", ")", ")", "\n", "address", ":=", "i", ".", "GetAddressOrDefault", "(", "int", "(", "ina3221Address", ")", ")", "\n\n", "if", "i", ".", "connection", ",", "err", "=", "i", ".", "connector", ".", "GetConnection", "(", "address", ",", "bus", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "i", ".", "initialize", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Start initializes the INA3221
[ "Start", "initializes", "the", "INA3221" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ina3221_driver.go#L92-L106
train
hybridgroup/gobot
drivers/i2c/ina3221_driver.go
GetBusVoltage
func (i *INA3221Driver) GetBusVoltage(channel INA3221Channel) (float64, error) { value, err := i.getBusVoltageRaw(channel) if err != nil { return 0, err } return float64(value) * .001, nil }
go
func (i *INA3221Driver) GetBusVoltage(channel INA3221Channel) (float64, error) { value, err := i.getBusVoltageRaw(channel) if err != nil { return 0, err } return float64(value) * .001, nil }
[ "func", "(", "i", "*", "INA3221Driver", ")", "GetBusVoltage", "(", "channel", "INA3221Channel", ")", "(", "float64", ",", "error", ")", "{", "value", ",", "err", ":=", "i", ".", "getBusVoltageRaw", "(", "channel", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "float64", "(", "value", ")", "*", ".001", ",", "nil", "\n", "}" ]
// GetBusVoltage gets the bus voltage in Volts
[ "GetBusVoltage", "gets", "the", "bus", "voltage", "in", "Volts" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ina3221_driver.go#L114-L121
train
hybridgroup/gobot
drivers/i2c/ina3221_driver.go
GetShuntVoltage
func (i *INA3221Driver) GetShuntVoltage(channel INA3221Channel) (float64, error) { value, err := i.getShuntVoltageRaw(channel) if err != nil { return 0, err } return float64(value) * float64(.005), nil }
go
func (i *INA3221Driver) GetShuntVoltage(channel INA3221Channel) (float64, error) { value, err := i.getShuntVoltageRaw(channel) if err != nil { return 0, err } return float64(value) * float64(.005), nil }
[ "func", "(", "i", "*", "INA3221Driver", ")", "GetShuntVoltage", "(", "channel", "INA3221Channel", ")", "(", "float64", ",", "error", ")", "{", "value", ",", "err", ":=", "i", ".", "getShuntVoltageRaw", "(", "channel", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "float64", "(", "value", ")", "*", "float64", "(", ".005", ")", ",", "nil", "\n", "}" ]
// GetShuntVoltage Gets the shunt voltage in mV
[ "GetShuntVoltage", "Gets", "the", "shunt", "voltage", "in", "mV" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ina3221_driver.go#L124-L131
train
hybridgroup/gobot
drivers/i2c/ina3221_driver.go
GetCurrent
func (i *INA3221Driver) GetCurrent(channel INA3221Channel) (float64, error) { value, err := i.GetShuntVoltage(channel) if err != nil { return 0, err } ma := value / ina3221ShuntResistorValue return ma, nil }
go
func (i *INA3221Driver) GetCurrent(channel INA3221Channel) (float64, error) { value, err := i.GetShuntVoltage(channel) if err != nil { return 0, err } ma := value / ina3221ShuntResistorValue return ma, nil }
[ "func", "(", "i", "*", "INA3221Driver", ")", "GetCurrent", "(", "channel", "INA3221Channel", ")", "(", "float64", ",", "error", ")", "{", "value", ",", "err", ":=", "i", ".", "GetShuntVoltage", "(", "channel", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "ma", ":=", "value", "/", "ina3221ShuntResistorValue", "\n", "return", "ma", ",", "nil", "\n", "}" ]
// GetCurrent gets the current value in mA, taking into account the config settings and current LSB
[ "GetCurrent", "gets", "the", "current", "value", "in", "mA", "taking", "into", "account", "the", "config", "settings", "and", "current", "LSB" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ina3221_driver.go#L134-L142
train
hybridgroup/gobot
drivers/i2c/ina3221_driver.go
GetLoadVoltage
func (i *INA3221Driver) GetLoadVoltage(channel INA3221Channel) (float64, error) { bv, err := i.GetBusVoltage(channel) if err != nil { return 0, err } sv, err := i.GetShuntVoltage(channel) if err != nil { return 0, err } return bv + (sv / 1000.0), nil }
go
func (i *INA3221Driver) GetLoadVoltage(channel INA3221Channel) (float64, error) { bv, err := i.GetBusVoltage(channel) if err != nil { return 0, err } sv, err := i.GetShuntVoltage(channel) if err != nil { return 0, err } return bv + (sv / 1000.0), nil }
[ "func", "(", "i", "*", "INA3221Driver", ")", "GetLoadVoltage", "(", "channel", "INA3221Channel", ")", "(", "float64", ",", "error", ")", "{", "bv", ",", "err", ":=", "i", ".", "GetBusVoltage", "(", "channel", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "sv", ",", "err", ":=", "i", ".", "GetShuntVoltage", "(", "channel", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "bv", "+", "(", "sv", "/", "1000.0", ")", ",", "nil", "\n", "}" ]
// GetLoadVoltage gets the load voltage in mV
[ "GetLoadVoltage", "gets", "the", "load", "voltage", "in", "mV" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ina3221_driver.go#L145-L157
train
hybridgroup/gobot
drivers/i2c/ina3221_driver.go
readWordFromRegister
func (i *INA3221Driver) readWordFromRegister(reg uint8) (uint16, error) { val, err := i.connection.ReadWordData(reg) if err != nil { return 0, err } return uint16(((val & 0x00FF) << 8) | ((val & 0xFF00) >> 8)), nil }
go
func (i *INA3221Driver) readWordFromRegister(reg uint8) (uint16, error) { val, err := i.connection.ReadWordData(reg) if err != nil { return 0, err } return uint16(((val & 0x00FF) << 8) | ((val & 0xFF00) >> 8)), nil }
[ "func", "(", "i", "*", "INA3221Driver", ")", "readWordFromRegister", "(", "reg", "uint8", ")", "(", "uint16", ",", "error", ")", "{", "val", ",", "err", ":=", "i", ".", "connection", ".", "ReadWordData", "(", "reg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n\n", "return", "uint16", "(", "(", "(", "val", "&", "0x00FF", ")", "<<", "8", ")", "|", "(", "(", "val", "&", "0xFF00", ")", ">>", "8", ")", ")", ",", "nil", "\n", "}" ]
// reads word from supplied register address
[ "reads", "word", "from", "supplied", "register", "address" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ina3221_driver.go#L190-L197
train
hybridgroup/gobot
drivers/i2c/ina3221_driver.go
initialize
func (i *INA3221Driver) initialize() error { config := ina3221ConfigEnableChan1 | ina3221ConfigEnableChan2 | ina3221ConfigEnableChan3 | ina3221ConfigAvg1 | ina3221ConfigVBusCT2 | ina3221ConfigVShCT2 | ina3221ConfigMode2 | ina3221ConfigMode1 | ina3221ConfigMode0 return i.connection.WriteBlockData(ina3221RegConfig, []byte{byte(config >> 8), byte(config & 0x00FF)}) }
go
func (i *INA3221Driver) initialize() error { config := ina3221ConfigEnableChan1 | ina3221ConfigEnableChan2 | ina3221ConfigEnableChan3 | ina3221ConfigAvg1 | ina3221ConfigVBusCT2 | ina3221ConfigVShCT2 | ina3221ConfigMode2 | ina3221ConfigMode1 | ina3221ConfigMode0 return i.connection.WriteBlockData(ina3221RegConfig, []byte{byte(config >> 8), byte(config & 0x00FF)}) }
[ "func", "(", "i", "*", "INA3221Driver", ")", "initialize", "(", ")", "error", "{", "config", ":=", "ina3221ConfigEnableChan1", "|", "ina3221ConfigEnableChan2", "|", "ina3221ConfigEnableChan3", "|", "ina3221ConfigAvg1", "|", "ina3221ConfigVBusCT2", "|", "ina3221ConfigVShCT2", "|", "ina3221ConfigMode2", "|", "ina3221ConfigMode1", "|", "ina3221ConfigMode0", "\n\n", "return", "i", ".", "connection", ".", "WriteBlockData", "(", "ina3221RegConfig", ",", "[", "]", "byte", "{", "byte", "(", "config", ">>", "8", ")", ",", "byte", "(", "config", "&", "0x00FF", ")", "}", ")", "\n", "}" ]
// initialize initializes the INA3221 device
[ "initialize", "initializes", "the", "INA3221", "device" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ina3221_driver.go#L200-L212
train
hybridgroup/gobot
platforms/nats/nats_adaptor.go
NewAdaptor
func NewAdaptor(host string, clientID int, options ...nats.Option) *Adaptor { hosts, err := processHostString(host) return &Adaptor{ name: gobot.DefaultName("NATS"), Host: hosts, clientID: clientID, connect: func() (*nats.Conn, error) { if err != nil { return nil, err } return nats.Connect(hosts, options...) }, } }
go
func NewAdaptor(host string, clientID int, options ...nats.Option) *Adaptor { hosts, err := processHostString(host) return &Adaptor{ name: gobot.DefaultName("NATS"), Host: hosts, clientID: clientID, connect: func() (*nats.Conn, error) { if err != nil { return nil, err } return nats.Connect(hosts, options...) }, } }
[ "func", "NewAdaptor", "(", "host", "string", ",", "clientID", "int", ",", "options", "...", "nats", ".", "Option", ")", "*", "Adaptor", "{", "hosts", ",", "err", ":=", "processHostString", "(", "host", ")", "\n\n", "return", "&", "Adaptor", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "Host", ":", "hosts", ",", "clientID", ":", "clientID", ",", "connect", ":", "func", "(", ")", "(", "*", "nats", ".", "Conn", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "nats", ".", "Connect", "(", "hosts", ",", "options", "...", ")", "\n", "}", ",", "}", "\n", "}" ]
// NewAdaptor populates a new NATS Adaptor.
[ "NewAdaptor", "populates", "a", "new", "NATS", "Adaptor", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/nats/nats_adaptor.go#L28-L42
train
hybridgroup/gobot
platforms/nats/nats_adaptor.go
NewAdaptorWithAuth
func NewAdaptorWithAuth(host string, clientID int, username string, password string, options ...nats.Option) *Adaptor { hosts, err := processHostString(host) return &Adaptor{ Host: hosts, clientID: clientID, username: username, password: password, connect: func() (*nats.Conn, error) { if err != nil { return nil, err } return nats.Connect(hosts, append(options, nats.UserInfo(username, password))...) }, } }
go
func NewAdaptorWithAuth(host string, clientID int, username string, password string, options ...nats.Option) *Adaptor { hosts, err := processHostString(host) return &Adaptor{ Host: hosts, clientID: clientID, username: username, password: password, connect: func() (*nats.Conn, error) { if err != nil { return nil, err } return nats.Connect(hosts, append(options, nats.UserInfo(username, password))...) }, } }
[ "func", "NewAdaptorWithAuth", "(", "host", "string", ",", "clientID", "int", ",", "username", "string", ",", "password", "string", ",", "options", "...", "nats", ".", "Option", ")", "*", "Adaptor", "{", "hosts", ",", "err", ":=", "processHostString", "(", "host", ")", "\n\n", "return", "&", "Adaptor", "{", "Host", ":", "hosts", ",", "clientID", ":", "clientID", ",", "username", ":", "username", ",", "password", ":", "password", ",", "connect", ":", "func", "(", ")", "(", "*", "nats", ".", "Conn", ",", "error", ")", "{", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "nats", ".", "Connect", "(", "hosts", ",", "append", "(", "options", ",", "nats", ".", "UserInfo", "(", "username", ",", "password", ")", ")", "...", ")", "\n", "}", ",", "}", "\n", "}" ]
// NewAdaptorWithAuth populates a NATS Adaptor including username and password.
[ "NewAdaptorWithAuth", "populates", "a", "NATS", "Adaptor", "including", "username", "and", "password", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/nats/nats_adaptor.go#L45-L60
train
hybridgroup/gobot
platforms/nats/nats_adaptor.go
Connect
func (a *Adaptor) Connect() (err error) { a.client, err = a.connect() return }
go
func (a *Adaptor) Connect() (err error) { a.client, err = a.connect() return }
[ "func", "(", "a", "*", "Adaptor", ")", "Connect", "(", ")", "(", "err", "error", ")", "{", "a", ".", "client", ",", "err", "=", "a", ".", "connect", "(", ")", "\n", "return", "\n", "}" ]
// Connect makes a connection to the Nats server.
[ "Connect", "makes", "a", "connection", "to", "the", "Nats", "server", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/nats/nats_adaptor.go#L88-L91
train
hybridgroup/gobot
platforms/nats/nats_adaptor.go
Publish
func (a *Adaptor) Publish(topic string, message []byte) bool { if a.client == nil { return false } a.client.Publish(topic, message) return true }
go
func (a *Adaptor) Publish(topic string, message []byte) bool { if a.client == nil { return false } a.client.Publish(topic, message) return true }
[ "func", "(", "a", "*", "Adaptor", ")", "Publish", "(", "topic", "string", ",", "message", "[", "]", "byte", ")", "bool", "{", "if", "a", ".", "client", "==", "nil", "{", "return", "false", "\n", "}", "\n", "a", ".", "client", ".", "Publish", "(", "topic", ",", "message", ")", "\n", "return", "true", "\n", "}" ]
// Publish sends a message with the particular topic to the nats server.
[ "Publish", "sends", "a", "message", "with", "the", "particular", "topic", "to", "the", "nats", "server", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/nats/nats_adaptor.go#L108-L114
train
hybridgroup/gobot
drivers/i2c/bmp180_driver.go
Pressure
func (d *BMP180Driver) Pressure() (pressure float32, err error) { var rawTemp int16 var rawPressure int32 if rawTemp, err = d.rawTemp(); err != nil { return 0, err } if rawPressure, err = d.rawPressure(d.Mode); err != nil { return 0, err } return d.calculatePressure(rawTemp, rawPressure, d.Mode), nil }
go
func (d *BMP180Driver) Pressure() (pressure float32, err error) { var rawTemp int16 var rawPressure int32 if rawTemp, err = d.rawTemp(); err != nil { return 0, err } if rawPressure, err = d.rawPressure(d.Mode); err != nil { return 0, err } return d.calculatePressure(rawTemp, rawPressure, d.Mode), nil }
[ "func", "(", "d", "*", "BMP180Driver", ")", "Pressure", "(", ")", "(", "pressure", "float32", ",", "err", "error", ")", "{", "var", "rawTemp", "int16", "\n", "var", "rawPressure", "int32", "\n", "if", "rawTemp", ",", "err", "=", "d", ".", "rawTemp", "(", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "if", "rawPressure", ",", "err", "=", "d", ".", "rawPressure", "(", "d", ".", "Mode", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "err", "\n", "}", "\n", "return", "d", ".", "calculatePressure", "(", "rawTemp", ",", "rawPressure", ",", "d", ".", "Mode", ")", ",", "nil", "\n", "}" ]
// Pressure returns the current pressure, in pascals.
[ "Pressure", "returns", "the", "current", "pressure", "in", "pascals", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bmp180_driver.go#L151-L161
train
hybridgroup/gobot
drivers/gpio/max7219_driver.go
NewMAX7219Driver
func NewMAX7219Driver(a gobot.Connection, clockPin string, dataPin string, csPin string, count uint) *MAX7219Driver { t := &MAX7219Driver{ name: gobot.DefaultName("MAX7219Driver"), pinClock: NewDirectPinDriver(a, clockPin), pinData: NewDirectPinDriver(a, dataPin), pinCS: NewDirectPinDriver(a, csPin), count: count, connection: a, Commander: gobot.NewCommander(), } /* TODO : Add commands */ return t }
go
func NewMAX7219Driver(a gobot.Connection, clockPin string, dataPin string, csPin string, count uint) *MAX7219Driver { t := &MAX7219Driver{ name: gobot.DefaultName("MAX7219Driver"), pinClock: NewDirectPinDriver(a, clockPin), pinData: NewDirectPinDriver(a, dataPin), pinCS: NewDirectPinDriver(a, csPin), count: count, connection: a, Commander: gobot.NewCommander(), } /* TODO : Add commands */ return t }
[ "func", "NewMAX7219Driver", "(", "a", "gobot", ".", "Connection", ",", "clockPin", "string", ",", "dataPin", "string", ",", "csPin", "string", ",", "count", "uint", ")", "*", "MAX7219Driver", "{", "t", ":=", "&", "MAX7219Driver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "pinClock", ":", "NewDirectPinDriver", "(", "a", ",", "clockPin", ")", ",", "pinData", ":", "NewDirectPinDriver", "(", "a", ",", "dataPin", ")", ",", "pinCS", ":", "NewDirectPinDriver", "(", "a", ",", "csPin", ")", ",", "count", ":", "count", ",", "connection", ":", "a", ",", "Commander", ":", "gobot", ".", "NewCommander", "(", ")", ",", "}", "\n\n", "/* TODO : Add commands */", "return", "t", "\n", "}" ]
// NewMAX7219Driver return a new MAX7219Driver given a gobot.Connection, pins and how many chips are chained
[ "NewMAX7219Driver", "return", "a", "new", "MAX7219Driver", "given", "a", "gobot", ".", "Connection", "pins", "and", "how", "many", "chips", "are", "chained" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/max7219_driver.go#L38-L52
train
hybridgroup/gobot
drivers/gpio/max7219_driver.go
Start
func (a *MAX7219Driver) Start() (err error) { a.pinData.On() a.pinClock.On() a.pinCS.On() a.All(MAX7219ScanLimit, 0x07) a.All(MAX7219DecodeMode, 0x00) a.All(MAX7219Shutdown, 0x01) a.All(MAX7219DisplayTest, 0x00) a.ClearAll() a.All(MAX7219Intensity, 0x0f&0x0f) return }
go
func (a *MAX7219Driver) Start() (err error) { a.pinData.On() a.pinClock.On() a.pinCS.On() a.All(MAX7219ScanLimit, 0x07) a.All(MAX7219DecodeMode, 0x00) a.All(MAX7219Shutdown, 0x01) a.All(MAX7219DisplayTest, 0x00) a.ClearAll() a.All(MAX7219Intensity, 0x0f&0x0f) return }
[ "func", "(", "a", "*", "MAX7219Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "a", ".", "pinData", ".", "On", "(", ")", "\n", "a", ".", "pinClock", ".", "On", "(", ")", "\n", "a", ".", "pinCS", ".", "On", "(", ")", "\n\n", "a", ".", "All", "(", "MAX7219ScanLimit", ",", "0x07", ")", "\n", "a", ".", "All", "(", "MAX7219DecodeMode", ",", "0x00", ")", "\n", "a", ".", "All", "(", "MAX7219Shutdown", ",", "0x01", ")", "\n", "a", ".", "All", "(", "MAX7219DisplayTest", ",", "0x00", ")", "\n", "a", ".", "ClearAll", "(", ")", "\n", "a", ".", "All", "(", "MAX7219Intensity", ",", "0x0f", "&", "0x0f", ")", "\n\n", "return", "\n", "}" ]
// Start initializes the max7219, it uses a SPI-like communication protocol
[ "Start", "initializes", "the", "max7219", "it", "uses", "a", "SPI", "-", "like", "communication", "protocol" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/max7219_driver.go#L55-L68
train
hybridgroup/gobot
drivers/gpio/max7219_driver.go
ClearAll
func (a *MAX7219Driver) ClearAll() { for i := 1; i <= 8; i++ { a.All(byte(i), 0) } }
go
func (a *MAX7219Driver) ClearAll() { for i := 1; i <= 8; i++ { a.All(byte(i), 0) } }
[ "func", "(", "a", "*", "MAX7219Driver", ")", "ClearAll", "(", ")", "{", "for", "i", ":=", "1", ";", "i", "<=", "8", ";", "i", "++", "{", "a", ".", "All", "(", "byte", "(", "i", ")", ",", "0", ")", "\n", "}", "\n", "}" ]
// ClearAll turns off all LEDs of all modules
[ "ClearAll", "turns", "off", "all", "LEDs", "of", "all", "modules" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/max7219_driver.go#L93-L97
train
hybridgroup/gobot
drivers/gpio/max7219_driver.go
ClearOne
func (a *MAX7219Driver) ClearOne(which uint) { for i := 1; i <= 8; i++ { a.One(which, byte(i), 0) } }
go
func (a *MAX7219Driver) ClearOne(which uint) { for i := 1; i <= 8; i++ { a.One(which, byte(i), 0) } }
[ "func", "(", "a", "*", "MAX7219Driver", ")", "ClearOne", "(", "which", "uint", ")", "{", "for", "i", ":=", "1", ";", "i", "<=", "8", ";", "i", "++", "{", "a", ".", "One", "(", "which", ",", "byte", "(", "i", ")", ",", "0", ")", "\n", "}", "\n", "}" ]
// ClearAll turns off all LEDs of the given module
[ "ClearAll", "turns", "off", "all", "LEDs", "of", "the", "given", "module" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/max7219_driver.go#L100-L104
train
hybridgroup/gobot
drivers/gpio/max7219_driver.go
sendData
func (a *MAX7219Driver) sendData(address byte, data byte) { a.pinCS.Off() a.send(address) a.send(data) a.pinCS.On() }
go
func (a *MAX7219Driver) sendData(address byte, data byte) { a.pinCS.Off() a.send(address) a.send(data) a.pinCS.On() }
[ "func", "(", "a", "*", "MAX7219Driver", ")", "sendData", "(", "address", "byte", ",", "data", "byte", ")", "{", "a", ".", "pinCS", ".", "Off", "(", ")", "\n", "a", ".", "send", "(", "address", ")", "\n", "a", ".", "send", "(", "data", ")", "\n", "a", ".", "pinCS", ".", "On", "(", ")", "\n", "}" ]
// sendData is an auxiliary function to send data to the MAX7219Driver module
[ "sendData", "is", "an", "auxiliary", "function", "to", "send", "data", "to", "the", "MAX7219Driver", "module" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/max7219_driver.go#L107-L112
train
hybridgroup/gobot
drivers/gpio/max7219_driver.go
All
func (a *MAX7219Driver) All(address byte, data byte) { a.pinCS.Off() var c uint for c = 0; c < a.count; c++ { a.send(address) a.send(data) } a.pinCS.On() }
go
func (a *MAX7219Driver) All(address byte, data byte) { a.pinCS.Off() var c uint for c = 0; c < a.count; c++ { a.send(address) a.send(data) } a.pinCS.On() }
[ "func", "(", "a", "*", "MAX7219Driver", ")", "All", "(", "address", "byte", ",", "data", "byte", ")", "{", "a", ".", "pinCS", ".", "Off", "(", ")", "\n", "var", "c", "uint", "\n", "for", "c", "=", "0", ";", "c", "<", "a", ".", "count", ";", "c", "++", "{", "a", ".", "send", "(", "address", ")", "\n", "a", ".", "send", "(", "data", ")", "\n", "}", "\n", "a", ".", "pinCS", ".", "On", "(", ")", "\n", "}" ]
// All sends the same data to all the modules
[ "All", "sends", "the", "same", "data", "to", "all", "the", "modules" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/max7219_driver.go#L131-L139
train
hybridgroup/gobot
platforms/megapi/megapi_adaptor.go
NewAdaptor
func NewAdaptor(device string) *Adaptor { c := &serial.Mode{BaudRate: 115200} return &Adaptor{ name: "MegaPi", connection: nil, port: device, serialMode: c, writeBytesChannel: make(chan []byte), finalizeChannel: make(chan struct{}), } }
go
func NewAdaptor(device string) *Adaptor { c := &serial.Mode{BaudRate: 115200} return &Adaptor{ name: "MegaPi", connection: nil, port: device, serialMode: c, writeBytesChannel: make(chan []byte), finalizeChannel: make(chan struct{}), } }
[ "func", "NewAdaptor", "(", "device", "string", ")", "*", "Adaptor", "{", "c", ":=", "&", "serial", ".", "Mode", "{", "BaudRate", ":", "115200", "}", "\n", "return", "&", "Adaptor", "{", "name", ":", "\"", "\"", ",", "connection", ":", "nil", ",", "port", ":", "device", ",", "serialMode", ":", "c", ",", "writeBytesChannel", ":", "make", "(", "chan", "[", "]", "byte", ")", ",", "finalizeChannel", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n", "}" ]
// NewAdaptor returns a new MegaPi Adaptor with specified serial port used to talk to the MegaPi with a baud rate of 115200
[ "NewAdaptor", "returns", "a", "new", "MegaPi", "Adaptor", "with", "specified", "serial", "port", "used", "to", "talk", "to", "the", "MegaPi", "with", "a", "baud", "rate", "of", "115200" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/megapi_adaptor.go#L24-L34
train
hybridgroup/gobot
platforms/megapi/megapi_adaptor.go
Connect
func (megaPi *Adaptor) Connect() error { if megaPi.connection == nil { sp, err := serial.Open(megaPi.port, megaPi.serialMode) if err != nil { return err } // sleeping is required to give the board a chance to reset time.Sleep(2 * time.Second) megaPi.connection = sp } // kick off thread to send bytes to the board go func() { for { select { case bytes := <-megaPi.writeBytesChannel: megaPi.connection.Write(bytes) time.Sleep(10 * time.Millisecond) case <-megaPi.finalizeChannel: megaPi.finalizeChannel <- struct{}{} return default: time.Sleep(10 * time.Millisecond) } } }() return nil }
go
func (megaPi *Adaptor) Connect() error { if megaPi.connection == nil { sp, err := serial.Open(megaPi.port, megaPi.serialMode) if err != nil { return err } // sleeping is required to give the board a chance to reset time.Sleep(2 * time.Second) megaPi.connection = sp } // kick off thread to send bytes to the board go func() { for { select { case bytes := <-megaPi.writeBytesChannel: megaPi.connection.Write(bytes) time.Sleep(10 * time.Millisecond) case <-megaPi.finalizeChannel: megaPi.finalizeChannel <- struct{}{} return default: time.Sleep(10 * time.Millisecond) } } }() return nil }
[ "func", "(", "megaPi", "*", "Adaptor", ")", "Connect", "(", ")", "error", "{", "if", "megaPi", ".", "connection", "==", "nil", "{", "sp", ",", "err", ":=", "serial", ".", "Open", "(", "megaPi", ".", "port", ",", "megaPi", ".", "serialMode", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// sleeping is required to give the board a chance to reset", "time", ".", "Sleep", "(", "2", "*", "time", ".", "Second", ")", "\n", "megaPi", ".", "connection", "=", "sp", "\n", "}", "\n\n", "// kick off thread to send bytes to the board", "go", "func", "(", ")", "{", "for", "{", "select", "{", "case", "bytes", ":=", "<-", "megaPi", ".", "writeBytesChannel", ":", "megaPi", ".", "connection", ".", "Write", "(", "bytes", ")", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "case", "<-", "megaPi", ".", "finalizeChannel", ":", "megaPi", ".", "finalizeChannel", "<-", "struct", "{", "}", "{", "}", "\n", "return", "\n", "default", ":", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Connect starts a connection to the board
[ "Connect", "starts", "a", "connection", "to", "the", "board" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/megapi_adaptor.go#L47-L75
train
hybridgroup/gobot
platforms/megapi/megapi_adaptor.go
Finalize
func (megaPi *Adaptor) Finalize() error { megaPi.finalizeChannel <- struct{}{} <-megaPi.finalizeChannel if err := megaPi.connection.Close(); err != nil { return err } return nil }
go
func (megaPi *Adaptor) Finalize() error { megaPi.finalizeChannel <- struct{}{} <-megaPi.finalizeChannel if err := megaPi.connection.Close(); err != nil { return err } return nil }
[ "func", "(", "megaPi", "*", "Adaptor", ")", "Finalize", "(", ")", "error", "{", "megaPi", ".", "finalizeChannel", "<-", "struct", "{", "}", "{", "}", "\n", "<-", "megaPi", ".", "finalizeChannel", "\n", "if", "err", ":=", "megaPi", ".", "connection", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Finalize terminates the connection to the board
[ "Finalize", "terminates", "the", "connection", "to", "the", "board" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/megapi_adaptor.go#L78-L85
train
hybridgroup/gobot
platforms/mavlink/common/mavlink.go
ReadMAVLinkPacket
func ReadMAVLinkPacket(r io.Reader) (*MAVLinkPacket, error) { for { header, err := read(r, 1) if err != nil { return nil, err } if header[0] == 254 { length, err := read(r, 1) if err != nil { return nil, err } else if length[0] > 250 { continue } m := &MAVLinkPacket{} data, err := read(r, int(length[0])+7) if err != nil { return nil, err } data = append([]byte{header[0], length[0]}, data...) m.Decode(data) return m, nil } } }
go
func ReadMAVLinkPacket(r io.Reader) (*MAVLinkPacket, error) { for { header, err := read(r, 1) if err != nil { return nil, err } if header[0] == 254 { length, err := read(r, 1) if err != nil { return nil, err } else if length[0] > 250 { continue } m := &MAVLinkPacket{} data, err := read(r, int(length[0])+7) if err != nil { return nil, err } data = append([]byte{header[0], length[0]}, data...) m.Decode(data) return m, nil } } }
[ "func", "ReadMAVLinkPacket", "(", "r", "io", ".", "Reader", ")", "(", "*", "MAVLinkPacket", ",", "error", ")", "{", "for", "{", "header", ",", "err", ":=", "read", "(", "r", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "header", "[", "0", "]", "==", "254", "{", "length", ",", "err", ":=", "read", "(", "r", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "else", "if", "length", "[", "0", "]", ">", "250", "{", "continue", "\n", "}", "\n", "m", ":=", "&", "MAVLinkPacket", "{", "}", "\n", "data", ",", "err", ":=", "read", "(", "r", ",", "int", "(", "length", "[", "0", "]", ")", "+", "7", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "data", "=", "append", "(", "[", "]", "byte", "{", "header", "[", "0", "]", ",", "length", "[", "0", "]", "}", ",", "data", "...", ")", "\n", "m", ".", "Decode", "(", "data", ")", "\n", "return", "m", ",", "nil", "\n", "}", "\n", "}", "\n", "}" ]
// ReadMAVLinkPacket reads an io.Reader for a new packet and returns a new MAVLink packet // or returns the error received by the io.Reader
[ "ReadMAVLinkPacket", "reads", "an", "io", ".", "Reader", "for", "a", "new", "packet", "and", "returns", "a", "new", "MAVLink", "packet", "or", "returns", "the", "error", "received", "by", "the", "io", ".", "Reader" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/common/mavlink.go#L57-L80
train
hybridgroup/gobot
platforms/mavlink/common/mavlink.go
CraftMAVLinkPacket
func CraftMAVLinkPacket(SystemID uint8, ComponentID uint8, Message MAVLinkMessage) *MAVLinkPacket { return NewMAVLinkPacket( 0xFE, Message.Len(), generateSequence(), SystemID, ComponentID, Message.Id(), Message.Pack(), ) }
go
func CraftMAVLinkPacket(SystemID uint8, ComponentID uint8, Message MAVLinkMessage) *MAVLinkPacket { return NewMAVLinkPacket( 0xFE, Message.Len(), generateSequence(), SystemID, ComponentID, Message.Id(), Message.Pack(), ) }
[ "func", "CraftMAVLinkPacket", "(", "SystemID", "uint8", ",", "ComponentID", "uint8", ",", "Message", "MAVLinkMessage", ")", "*", "MAVLinkPacket", "{", "return", "NewMAVLinkPacket", "(", "0xFE", ",", "Message", ".", "Len", "(", ")", ",", "generateSequence", "(", ")", ",", "SystemID", ",", "ComponentID", ",", "Message", ".", "Id", "(", ")", ",", "Message", ".", "Pack", "(", ")", ",", ")", "\n", "}" ]
// CraftMAVLinkPacket returns a new MAVLinkPacket from a MAVLinkMessage
[ "CraftMAVLinkPacket", "returns", "a", "new", "MAVLinkPacket", "from", "a", "MAVLinkMessage" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/common/mavlink.go#L83-L93
train
hybridgroup/gobot
platforms/mavlink/common/mavlink.go
NewMAVLinkPacket
func NewMAVLinkPacket(Protocol uint8, Length uint8, Sequence uint8, SystemID uint8, ComponentID uint8, MessageID uint8, Data []uint8) *MAVLinkPacket { m := &MAVLinkPacket{ Protocol: Protocol, Length: Length, Sequence: Sequence, SystemID: SystemID, ComponentID: ComponentID, MessageID: MessageID, Data: Data, } m.Checksum = crcCalculate(m) return m }
go
func NewMAVLinkPacket(Protocol uint8, Length uint8, Sequence uint8, SystemID uint8, ComponentID uint8, MessageID uint8, Data []uint8) *MAVLinkPacket { m := &MAVLinkPacket{ Protocol: Protocol, Length: Length, Sequence: Sequence, SystemID: SystemID, ComponentID: ComponentID, MessageID: MessageID, Data: Data, } m.Checksum = crcCalculate(m) return m }
[ "func", "NewMAVLinkPacket", "(", "Protocol", "uint8", ",", "Length", "uint8", ",", "Sequence", "uint8", ",", "SystemID", "uint8", ",", "ComponentID", "uint8", ",", "MessageID", "uint8", ",", "Data", "[", "]", "uint8", ")", "*", "MAVLinkPacket", "{", "m", ":=", "&", "MAVLinkPacket", "{", "Protocol", ":", "Protocol", ",", "Length", ":", "Length", ",", "Sequence", ":", "Sequence", ",", "SystemID", ":", "SystemID", ",", "ComponentID", ":", "ComponentID", ",", "MessageID", ":", "MessageID", ",", "Data", ":", "Data", ",", "}", "\n", "m", ".", "Checksum", "=", "crcCalculate", "(", "m", ")", "\n", "return", "m", "\n", "}" ]
// NewMAVLinkPacket returns a new MAVLinkPacket
[ "NewMAVLinkPacket", "returns", "a", "new", "MAVLinkPacket" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/common/mavlink.go#L96-L108
train
hybridgroup/gobot
platforms/mavlink/common/mavlink.go
MAVLinkMessage
func (m *MAVLinkPacket) MAVLinkMessage() (MAVLinkMessage, error) { return NewMAVLinkMessage(m.MessageID, m.Data) }
go
func (m *MAVLinkPacket) MAVLinkMessage() (MAVLinkMessage, error) { return NewMAVLinkMessage(m.MessageID, m.Data) }
[ "func", "(", "m", "*", "MAVLinkPacket", ")", "MAVLinkMessage", "(", ")", "(", "MAVLinkMessage", ",", "error", ")", "{", "return", "NewMAVLinkMessage", "(", "m", ".", "MessageID", ",", "m", ".", "Data", ")", "\n", "}" ]
// MAVLinkMessage returns the decoded MAVLinkMessage from the MAVLinkPacket // or returns an error generated from the MAVLinkMessage
[ "MAVLinkMessage", "returns", "the", "decoded", "MAVLinkMessage", "from", "the", "MAVLinkPacket", "or", "returns", "an", "error", "generated", "from", "the", "MAVLinkMessage" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/common/mavlink.go#L112-L114
train
hybridgroup/gobot
platforms/mavlink/common/mavlink.go
Pack
func (m *MAVLinkPacket) Pack() []byte { data := new(bytes.Buffer) binary.Write(data, binary.LittleEndian, m.Protocol) binary.Write(data, binary.LittleEndian, m.Length) binary.Write(data, binary.LittleEndian, m.Sequence) binary.Write(data, binary.LittleEndian, m.SystemID) binary.Write(data, binary.LittleEndian, m.ComponentID) binary.Write(data, binary.LittleEndian, m.MessageID) data.Write(m.Data) binary.Write(data, binary.LittleEndian, m.Checksum) return data.Bytes() }
go
func (m *MAVLinkPacket) Pack() []byte { data := new(bytes.Buffer) binary.Write(data, binary.LittleEndian, m.Protocol) binary.Write(data, binary.LittleEndian, m.Length) binary.Write(data, binary.LittleEndian, m.Sequence) binary.Write(data, binary.LittleEndian, m.SystemID) binary.Write(data, binary.LittleEndian, m.ComponentID) binary.Write(data, binary.LittleEndian, m.MessageID) data.Write(m.Data) binary.Write(data, binary.LittleEndian, m.Checksum) return data.Bytes() }
[ "func", "(", "m", "*", "MAVLinkPacket", ")", "Pack", "(", ")", "[", "]", "byte", "{", "data", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "binary", ".", "Write", "(", "data", ",", "binary", ".", "LittleEndian", ",", "m", ".", "Protocol", ")", "\n", "binary", ".", "Write", "(", "data", ",", "binary", ".", "LittleEndian", ",", "m", ".", "Length", ")", "\n", "binary", ".", "Write", "(", "data", ",", "binary", ".", "LittleEndian", ",", "m", ".", "Sequence", ")", "\n", "binary", ".", "Write", "(", "data", ",", "binary", ".", "LittleEndian", ",", "m", ".", "SystemID", ")", "\n", "binary", ".", "Write", "(", "data", ",", "binary", ".", "LittleEndian", ",", "m", ".", "ComponentID", ")", "\n", "binary", ".", "Write", "(", "data", ",", "binary", ".", "LittleEndian", ",", "m", ".", "MessageID", ")", "\n", "data", ".", "Write", "(", "m", ".", "Data", ")", "\n", "binary", ".", "Write", "(", "data", ",", "binary", ".", "LittleEndian", ",", "m", ".", "Checksum", ")", "\n", "return", "data", ".", "Bytes", "(", ")", "\n", "}" ]
// Pack returns a packed byte array which represents the MAVLinkPacket
[ "Pack", "returns", "a", "packed", "byte", "array", "which", "represents", "the", "MAVLinkPacket" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/common/mavlink.go#L117-L128
train
hybridgroup/gobot
platforms/mavlink/common/mavlink.go
Decode
func (m *MAVLinkPacket) Decode(buf []byte) { m.Protocol = buf[0] m.Length = buf[1] m.Sequence = buf[2] m.SystemID = buf[3] m.ComponentID = buf[4] m.MessageID = buf[5] m.Data = buf[6 : 6+int(m.Length)] checksum := buf[7+int(m.Length):] m.Checksum = uint16(checksum[1])<<8 | uint16(checksum[0]) }
go
func (m *MAVLinkPacket) Decode(buf []byte) { m.Protocol = buf[0] m.Length = buf[1] m.Sequence = buf[2] m.SystemID = buf[3] m.ComponentID = buf[4] m.MessageID = buf[5] m.Data = buf[6 : 6+int(m.Length)] checksum := buf[7+int(m.Length):] m.Checksum = uint16(checksum[1])<<8 | uint16(checksum[0]) }
[ "func", "(", "m", "*", "MAVLinkPacket", ")", "Decode", "(", "buf", "[", "]", "byte", ")", "{", "m", ".", "Protocol", "=", "buf", "[", "0", "]", "\n", "m", ".", "Length", "=", "buf", "[", "1", "]", "\n", "m", ".", "Sequence", "=", "buf", "[", "2", "]", "\n", "m", ".", "SystemID", "=", "buf", "[", "3", "]", "\n", "m", ".", "ComponentID", "=", "buf", "[", "4", "]", "\n", "m", ".", "MessageID", "=", "buf", "[", "5", "]", "\n", "m", ".", "Data", "=", "buf", "[", "6", ":", "6", "+", "int", "(", "m", ".", "Length", ")", "]", "\n", "checksum", ":=", "buf", "[", "7", "+", "int", "(", "m", ".", "Length", ")", ":", "]", "\n", "m", ".", "Checksum", "=", "uint16", "(", "checksum", "[", "1", "]", ")", "<<", "8", "|", "uint16", "(", "checksum", "[", "0", "]", ")", "\n", "}" ]
// Decode accepts a packed byte array and populates the fields of the MAVLinkPacket
[ "Decode", "accepts", "a", "packed", "byte", "array", "and", "populates", "the", "fields", "of", "the", "MAVLinkPacket" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/common/mavlink.go#L131-L141
train
hybridgroup/gobot
platforms/mavlink/common/mavlink.go
crcCalculate
func crcCalculate(m *MAVLinkPacket) uint16 { crc := crcInit() for _, v := range m.Pack()[1 : m.Length+6] { crc = crcAccumulate(v, crc) } message, _ := m.MAVLinkMessage() crc = crcAccumulate(message.Crc(), crc) return crc }
go
func crcCalculate(m *MAVLinkPacket) uint16 { crc := crcInit() for _, v := range m.Pack()[1 : m.Length+6] { crc = crcAccumulate(v, crc) } message, _ := m.MAVLinkMessage() crc = crcAccumulate(message.Crc(), crc) return crc }
[ "func", "crcCalculate", "(", "m", "*", "MAVLinkPacket", ")", "uint16", "{", "crc", ":=", "crcInit", "(", ")", "\n\n", "for", "_", ",", "v", ":=", "range", "m", ".", "Pack", "(", ")", "[", "1", ":", "m", ".", "Length", "+", "6", "]", "{", "crc", "=", "crcAccumulate", "(", "v", ",", "crc", ")", "\n", "}", "\n", "message", ",", "_", ":=", "m", ".", "MAVLinkMessage", "(", ")", "\n", "crc", "=", "crcAccumulate", "(", "message", ".", "Crc", "(", ")", ",", "crc", ")", "\n", "return", "crc", "\n", "}" ]
// // Calculates the X.25 checksum on a byte buffer // // return the checksum over the buffer bytes //
[ "Calculates", "the", "X", ".", "25", "checksum", "on", "a", "byte", "buffer", "return", "the", "checksum", "over", "the", "buffer", "bytes" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/common/mavlink.go#L194-L203
train
hybridgroup/gobot
platforms/beaglebone/pocketbeagle_adaptor.go
NewPocketBeagleAdaptor
func NewPocketBeagleAdaptor() *PocketBeagleAdaptor { a := NewAdaptor() a.SetName(gobot.DefaultName("PocketBeagle")) a.pinMap = pocketBeaglePinMap a.pwmPinMap = pocketBeaglePwmPinMap a.analogPinMap = pocketBeagleAnalogPinMap return &PocketBeagleAdaptor{ Adaptor: a, } }
go
func NewPocketBeagleAdaptor() *PocketBeagleAdaptor { a := NewAdaptor() a.SetName(gobot.DefaultName("PocketBeagle")) a.pinMap = pocketBeaglePinMap a.pwmPinMap = pocketBeaglePwmPinMap a.analogPinMap = pocketBeagleAnalogPinMap return &PocketBeagleAdaptor{ Adaptor: a, } }
[ "func", "NewPocketBeagleAdaptor", "(", ")", "*", "PocketBeagleAdaptor", "{", "a", ":=", "NewAdaptor", "(", ")", "\n", "a", ".", "SetName", "(", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ")", "\n", "a", ".", "pinMap", "=", "pocketBeaglePinMap", "\n", "a", ".", "pwmPinMap", "=", "pocketBeaglePwmPinMap", "\n", "a", ".", "analogPinMap", "=", "pocketBeagleAnalogPinMap", "\n\n", "return", "&", "PocketBeagleAdaptor", "{", "Adaptor", ":", "a", ",", "}", "\n", "}" ]
// NewPocketBeagleAdaptor creates a new Adaptor for the PocketBeagle
[ "NewPocketBeagleAdaptor", "creates", "a", "new", "Adaptor", "for", "the", "PocketBeagle" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/beaglebone/pocketbeagle_adaptor.go#L14-L24
train
hybridgroup/gobot
platforms/sphero/bb8/bb8_driver.go
NewDriver
func NewDriver(a ble.BLEConnector) *BB8Driver { d := ollie.NewDriver(a) d.SetName(gobot.DefaultName("BB8")) return &BB8Driver{ Driver: d, } }
go
func NewDriver(a ble.BLEConnector) *BB8Driver { d := ollie.NewDriver(a) d.SetName(gobot.DefaultName("BB8")) return &BB8Driver{ Driver: d, } }
[ "func", "NewDriver", "(", "a", "ble", ".", "BLEConnector", ")", "*", "BB8Driver", "{", "d", ":=", "ollie", ".", "NewDriver", "(", "a", ")", "\n", "d", ".", "SetName", "(", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ")", "\n\n", "return", "&", "BB8Driver", "{", "Driver", ":", "d", ",", "}", "\n", "}" ]
// NewDriver creates a Driver for a Sphero BB-8
[ "NewDriver", "creates", "a", "Driver", "for", "a", "Sphero", "BB", "-", "8" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/bb8/bb8_driver.go#L15-L22
train
hybridgroup/gobot
eventer.go
NewEventer
func NewEventer() Eventer { evtr := &eventer{ eventnames: make(map[string]string), in: make(eventChannel, eventChanBufferSize), outs: make(map[eventChannel]eventChannel), } // goroutine to cascade "in" events to all "out" event channels go func() { for { select { case evt := <-evtr.in: evtr.eventsMutex.Lock() for _, out := range evtr.outs { out <- evt } evtr.eventsMutex.Unlock() } } }() return evtr }
go
func NewEventer() Eventer { evtr := &eventer{ eventnames: make(map[string]string), in: make(eventChannel, eventChanBufferSize), outs: make(map[eventChannel]eventChannel), } // goroutine to cascade "in" events to all "out" event channels go func() { for { select { case evt := <-evtr.in: evtr.eventsMutex.Lock() for _, out := range evtr.outs { out <- evt } evtr.eventsMutex.Unlock() } } }() return evtr }
[ "func", "NewEventer", "(", ")", "Eventer", "{", "evtr", ":=", "&", "eventer", "{", "eventnames", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "in", ":", "make", "(", "eventChannel", ",", "eventChanBufferSize", ")", ",", "outs", ":", "make", "(", "map", "[", "eventChannel", "]", "eventChannel", ")", ",", "}", "\n\n", "// goroutine to cascade \"in\" events to all \"out\" event channels", "go", "func", "(", ")", "{", "for", "{", "select", "{", "case", "evt", ":=", "<-", "evtr", ".", "in", ":", "evtr", ".", "eventsMutex", ".", "Lock", "(", ")", "\n", "for", "_", ",", "out", ":=", "range", "evtr", ".", "outs", "{", "out", "<-", "evt", "\n", "}", "\n", "evtr", ".", "eventsMutex", ".", "Unlock", "(", ")", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "evtr", "\n", "}" ]
// NewEventer returns a new Eventer.
[ "NewEventer", "returns", "a", "new", "Eventer", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/eventer.go#L56-L78
train
hybridgroup/gobot
eventer.go
Publish
func (e *eventer) Publish(name string, data interface{}) { evt := NewEvent(name, data) e.in <- evt }
go
func (e *eventer) Publish(name string, data interface{}) { evt := NewEvent(name, data) e.in <- evt }
[ "func", "(", "e", "*", "eventer", ")", "Publish", "(", "name", "string", ",", "data", "interface", "{", "}", ")", "{", "evt", ":=", "NewEvent", "(", "name", ",", "data", ")", "\n", "e", ".", "in", "<-", "evt", "\n", "}" ]
// Publish new events to anyone that is subscribed
[ "Publish", "new", "events", "to", "anyone", "that", "is", "subscribed" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/eventer.go#L102-L105
train
hybridgroup/gobot
eventer.go
Subscribe
func (e *eventer) Subscribe() eventChannel { e.eventsMutex.Lock() defer e.eventsMutex.Unlock() out := make(eventChannel, eventChanBufferSize) e.outs[out] = out return out }
go
func (e *eventer) Subscribe() eventChannel { e.eventsMutex.Lock() defer e.eventsMutex.Unlock() out := make(eventChannel, eventChanBufferSize) e.outs[out] = out return out }
[ "func", "(", "e", "*", "eventer", ")", "Subscribe", "(", ")", "eventChannel", "{", "e", ".", "eventsMutex", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "eventsMutex", ".", "Unlock", "(", ")", "\n", "out", ":=", "make", "(", "eventChannel", ",", "eventChanBufferSize", ")", "\n", "e", ".", "outs", "[", "out", "]", "=", "out", "\n", "return", "out", "\n", "}" ]
// Subscribe to any events from this eventer
[ "Subscribe", "to", "any", "events", "from", "this", "eventer" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/eventer.go#L108-L114
train
hybridgroup/gobot
eventer.go
Unsubscribe
func (e *eventer) Unsubscribe(events eventChannel) { e.eventsMutex.Lock() defer e.eventsMutex.Unlock() delete(e.outs, events) }
go
func (e *eventer) Unsubscribe(events eventChannel) { e.eventsMutex.Lock() defer e.eventsMutex.Unlock() delete(e.outs, events) }
[ "func", "(", "e", "*", "eventer", ")", "Unsubscribe", "(", "events", "eventChannel", ")", "{", "e", ".", "eventsMutex", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "eventsMutex", ".", "Unlock", "(", ")", "\n", "delete", "(", "e", ".", "outs", ",", "events", ")", "\n", "}" ]
// Unsubscribe from the event channel
[ "Unsubscribe", "from", "the", "event", "channel" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/eventer.go#L117-L121
train
hybridgroup/gobot
eventer.go
On
func (e *eventer) On(n string, f func(s interface{})) (err error) { out := e.Subscribe() go func() { for { select { case evt := <-out: if evt.Name == n { f(evt.Data) } } } }() return }
go
func (e *eventer) On(n string, f func(s interface{})) (err error) { out := e.Subscribe() go func() { for { select { case evt := <-out: if evt.Name == n { f(evt.Data) } } } }() return }
[ "func", "(", "e", "*", "eventer", ")", "On", "(", "n", "string", ",", "f", "func", "(", "s", "interface", "{", "}", ")", ")", "(", "err", "error", ")", "{", "out", ":=", "e", ".", "Subscribe", "(", ")", "\n", "go", "func", "(", ")", "{", "for", "{", "select", "{", "case", "evt", ":=", "<-", "out", ":", "if", "evt", ".", "Name", "==", "n", "{", "f", "(", "evt", ".", "Data", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "\n", "}" ]
// On executes the event handler f when e is Published to.
[ "On", "executes", "the", "event", "handler", "f", "when", "e", "is", "Published", "to", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/eventer.go#L124-L138
train
hybridgroup/gobot
eventer.go
Once
func (e *eventer) Once(n string, f func(s interface{})) (err error) { out := e.Subscribe() go func() { ProcessEvents: for evt := range out { if evt.Name == n { f(evt.Data) e.Unsubscribe(out) break ProcessEvents } } }() return }
go
func (e *eventer) Once(n string, f func(s interface{})) (err error) { out := e.Subscribe() go func() { ProcessEvents: for evt := range out { if evt.Name == n { f(evt.Data) e.Unsubscribe(out) break ProcessEvents } } }() return }
[ "func", "(", "e", "*", "eventer", ")", "Once", "(", "n", "string", ",", "f", "func", "(", "s", "interface", "{", "}", ")", ")", "(", "err", "error", ")", "{", "out", ":=", "e", ".", "Subscribe", "(", ")", "\n", "go", "func", "(", ")", "{", "ProcessEvents", ":", "for", "evt", ":=", "range", "out", "{", "if", "evt", ".", "Name", "==", "n", "{", "f", "(", "evt", ".", "Data", ")", "\n", "e", ".", "Unsubscribe", "(", "out", ")", "\n", "break", "ProcessEvents", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "\n", "}" ]
// Once is similar to On except that it only executes f one time.
[ "Once", "is", "similar", "to", "On", "except", "that", "it", "only", "executes", "f", "one", "time", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/eventer.go#L141-L155
train
hybridgroup/gobot
drivers/gpio/tm1638_driver.go
NewTM1638Driver
func NewTM1638Driver(a gobot.Connection, clockPin string, dataPin string, strobePin string) *TM1638Driver { t := &TM1638Driver{ name: gobot.DefaultName("TM1638"), pinClock: NewDirectPinDriver(a, clockPin), pinData: NewDirectPinDriver(a, dataPin), pinStrobe: NewDirectPinDriver(a, strobePin), fonts: NewTM1638Fonts(), connection: a, Commander: gobot.NewCommander(), } /* TODO : Add commands */ return t }
go
func NewTM1638Driver(a gobot.Connection, clockPin string, dataPin string, strobePin string) *TM1638Driver { t := &TM1638Driver{ name: gobot.DefaultName("TM1638"), pinClock: NewDirectPinDriver(a, clockPin), pinData: NewDirectPinDriver(a, dataPin), pinStrobe: NewDirectPinDriver(a, strobePin), fonts: NewTM1638Fonts(), connection: a, Commander: gobot.NewCommander(), } /* TODO : Add commands */ return t }
[ "func", "NewTM1638Driver", "(", "a", "gobot", ".", "Connection", ",", "clockPin", "string", ",", "dataPin", "string", ",", "strobePin", "string", ")", "*", "TM1638Driver", "{", "t", ":=", "&", "TM1638Driver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "pinClock", ":", "NewDirectPinDriver", "(", "a", ",", "clockPin", ")", ",", "pinData", ":", "NewDirectPinDriver", "(", "a", ",", "dataPin", ")", ",", "pinStrobe", ":", "NewDirectPinDriver", "(", "a", ",", "strobePin", ")", ",", "fonts", ":", "NewTM1638Fonts", "(", ")", ",", "connection", ":", "a", ",", "Commander", ":", "gobot", ".", "NewCommander", "(", ")", ",", "}", "\n\n", "/* TODO : Add commands */", "return", "t", "\n", "}" ]
// NewTM1638Driver return a new TM1638Driver given a gobot.Connection and the clock, data and strobe pins
[ "NewTM1638Driver", "return", "a", "new", "TM1638Driver", "given", "a", "gobot", ".", "Connection", "and", "the", "clock", "data", "and", "strobe", "pins" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/tm1638_driver.go#L46-L60
train
hybridgroup/gobot
drivers/gpio/tm1638_driver.go
sendCommand
func (t *TM1638Driver) sendCommand(cmd byte) { t.pinStrobe.Off() t.send(cmd) t.pinStrobe.On() }
go
func (t *TM1638Driver) sendCommand(cmd byte) { t.pinStrobe.Off() t.send(cmd) t.pinStrobe.On() }
[ "func", "(", "t", "*", "TM1638Driver", ")", "sendCommand", "(", "cmd", "byte", ")", "{", "t", ".", "pinStrobe", ".", "Off", "(", ")", "\n", "t", ".", "send", "(", "cmd", ")", "\n", "t", ".", "pinStrobe", ".", "On", "(", ")", "\n", "}" ]
// sendCommand is an auxiliary function to send commands to the TM1638 module
[ "sendCommand", "is", "an", "auxiliary", "function", "to", "send", "commands", "to", "the", "TM1638", "module" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/tm1638_driver.go#L96-L100
train
hybridgroup/gobot
drivers/gpio/tm1638_driver.go
sendData
func (t *TM1638Driver) sendData(address byte, data byte) { t.sendCommand(TM1638DataCmd | TM1638FixedAddr) t.pinStrobe.Off() t.send(TM1638AddrCmd | address) t.send(data) t.pinStrobe.On() }
go
func (t *TM1638Driver) sendData(address byte, data byte) { t.sendCommand(TM1638DataCmd | TM1638FixedAddr) t.pinStrobe.Off() t.send(TM1638AddrCmd | address) t.send(data) t.pinStrobe.On() }
[ "func", "(", "t", "*", "TM1638Driver", ")", "sendData", "(", "address", "byte", ",", "data", "byte", ")", "{", "t", ".", "sendCommand", "(", "TM1638DataCmd", "|", "TM1638FixedAddr", ")", "\n", "t", ".", "pinStrobe", ".", "Off", "(", ")", "\n", "t", ".", "send", "(", "TM1638AddrCmd", "|", "address", ")", "\n", "t", ".", "send", "(", "data", ")", "\n", "t", ".", "pinStrobe", ".", "On", "(", ")", "\n", "}" ]
// sendData is an auxiliary function to send data to the TM1638 module
[ "sendData", "is", "an", "auxiliary", "function", "to", "send", "data", "to", "the", "TM1638", "module" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/tm1638_driver.go#L119-L125
train
hybridgroup/gobot
drivers/gpio/tm1638_driver.go
SendChar
func (t *TM1638Driver) SendChar(pos byte, data byte, dot bool) { if pos > 7 { return } var dotData byte if dot { dotData = TM1638DispCtrl } t.sendData(pos<<1, data|(dotData)) }
go
func (t *TM1638Driver) SendChar(pos byte, data byte, dot bool) { if pos > 7 { return } var dotData byte if dot { dotData = TM1638DispCtrl } t.sendData(pos<<1, data|(dotData)) }
[ "func", "(", "t", "*", "TM1638Driver", ")", "SendChar", "(", "pos", "byte", ",", "data", "byte", ",", "dot", "bool", ")", "{", "if", "pos", ">", "7", "{", "return", "\n", "}", "\n", "var", "dotData", "byte", "\n", "if", "dot", "{", "dotData", "=", "TM1638DispCtrl", "\n", "}", "\n", "t", ".", "sendData", "(", "pos", "<<", "1", ",", "data", "|", "(", "dotData", ")", ")", "\n", "}" ]
// SendChar sends one byte to the specific position in the display
[ "SendChar", "sends", "one", "byte", "to", "the", "specific", "position", "in", "the", "display" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/tm1638_driver.go#L153-L162
train
hybridgroup/gobot
drivers/gpio/tm1638_driver.go
fromStringToByteArray
func (t *TM1638Driver) fromStringToByteArray(str string) []byte { chars := strings.Split(str, "") data := make([]byte, len(chars)) for index, char := range chars { if val, ok := t.fonts[char]; ok { data[index] = val } } return data }
go
func (t *TM1638Driver) fromStringToByteArray(str string) []byte { chars := strings.Split(str, "") data := make([]byte, len(chars)) for index, char := range chars { if val, ok := t.fonts[char]; ok { data[index] = val } } return data }
[ "func", "(", "t", "*", "TM1638Driver", ")", "fromStringToByteArray", "(", "str", "string", ")", "[", "]", "byte", "{", "chars", ":=", "strings", ".", "Split", "(", "str", ",", "\"", "\"", ")", "\n", "data", ":=", "make", "(", "[", "]", "byte", ",", "len", "(", "chars", ")", ")", "\n\n", "for", "index", ",", "char", ":=", "range", "chars", "{", "if", "val", ",", "ok", ":=", "t", ".", "fonts", "[", "char", "]", ";", "ok", "{", "data", "[", "index", "]", "=", "val", "\n", "}", "\n", "}", "\n", "return", "data", "\n", "}" ]
// fromStringToByteArray translates a string to a byte array with the corresponding representation for the 7-segment LCD, return and empty character if the font is not available
[ "fromStringToByteArray", "translates", "a", "string", "to", "a", "byte", "array", "with", "the", "corresponding", "representation", "for", "the", "7", "-", "segment", "LCD", "return", "and", "empty", "character", "if", "the", "font", "is", "not", "available" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/tm1638_driver.go#L165-L175
train
hybridgroup/gobot
drivers/gpio/tm1638_driver.go
AddFonts
func (t *TM1638Driver) AddFonts(fonts map[string]byte) { for k, v := range fonts { t.fonts[k] = v } }
go
func (t *TM1638Driver) AddFonts(fonts map[string]byte) { for k, v := range fonts { t.fonts[k] = v } }
[ "func", "(", "t", "*", "TM1638Driver", ")", "AddFonts", "(", "fonts", "map", "[", "string", "]", "byte", ")", "{", "for", "k", ",", "v", ":=", "range", "fonts", "{", "t", ".", "fonts", "[", "k", "]", "=", "v", "\n", "}", "\n", "}" ]
// AddFonts adds new custom fonts or modify the representation of existing ones
[ "AddFonts", "adds", "new", "custom", "fonts", "or", "modify", "the", "representation", "of", "existing", "ones" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/tm1638_driver.go#L178-L182
train
cayleygraph/cayley
voc/voc.go
Register
func (p *Namespaces) Register(ns Namespace) { if !p.Safe { p.mu.Lock() defer p.mu.Unlock() } if p.prefixes == nil { p.prefixes = make(map[string]string) } p.prefixes[ns.Prefix] = ns.Full }
go
func (p *Namespaces) Register(ns Namespace) { if !p.Safe { p.mu.Lock() defer p.mu.Unlock() } if p.prefixes == nil { p.prefixes = make(map[string]string) } p.prefixes[ns.Prefix] = ns.Full }
[ "func", "(", "p", "*", "Namespaces", ")", "Register", "(", "ns", "Namespace", ")", "{", "if", "!", "p", ".", "Safe", "{", "p", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "mu", ".", "Unlock", "(", ")", "\n", "}", "\n", "if", "p", ".", "prefixes", "==", "nil", "{", "p", ".", "prefixes", "=", "make", "(", "map", "[", "string", "]", "string", ")", "\n", "}", "\n", "p", ".", "prefixes", "[", "ns", ".", "Prefix", "]", "=", "ns", ".", "Full", "\n", "}" ]
// Register adds namespace to registered list.
[ "Register", "adds", "namespace", "to", "registered", "list", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/voc/voc.go#L29-L38
train
cayleygraph/cayley
voc/voc.go
List
func (p *Namespaces) List() (out []Namespace) { if !p.Safe { p.mu.RLock() defer p.mu.RUnlock() } out = make([]Namespace, 0, len(p.prefixes)) for pref, ns := range p.prefixes { out = append(out, Namespace{Prefix: pref, Full: ns}) } return }
go
func (p *Namespaces) List() (out []Namespace) { if !p.Safe { p.mu.RLock() defer p.mu.RUnlock() } out = make([]Namespace, 0, len(p.prefixes)) for pref, ns := range p.prefixes { out = append(out, Namespace{Prefix: pref, Full: ns}) } return }
[ "func", "(", "p", "*", "Namespaces", ")", "List", "(", ")", "(", "out", "[", "]", "Namespace", ")", "{", "if", "!", "p", ".", "Safe", "{", "p", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mu", ".", "RUnlock", "(", ")", "\n", "}", "\n", "out", "=", "make", "(", "[", "]", "Namespace", ",", "0", ",", "len", "(", "p", ".", "prefixes", ")", ")", "\n", "for", "pref", ",", "ns", ":=", "range", "p", ".", "prefixes", "{", "out", "=", "append", "(", "out", ",", "Namespace", "{", "Prefix", ":", "pref", ",", "Full", ":", "ns", "}", ")", "\n", "}", "\n", "return", "\n", "}" ]
// List enumerates all registered namespace pairs.
[ "List", "enumerates", "all", "registered", "namespace", "pairs", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/voc/voc.go#L73-L83
train
cayleygraph/cayley
voc/voc.go
Clone
func (p *Namespaces) Clone() *Namespaces { if !p.Safe { p.mu.RLock() defer p.mu.RUnlock() } p2 := Namespaces{ prefixes: make(map[string]string, len(p.prefixes)), } for pref, ns := range p.prefixes { p2.prefixes[pref] = ns } return &p2 }
go
func (p *Namespaces) Clone() *Namespaces { if !p.Safe { p.mu.RLock() defer p.mu.RUnlock() } p2 := Namespaces{ prefixes: make(map[string]string, len(p.prefixes)), } for pref, ns := range p.prefixes { p2.prefixes[pref] = ns } return &p2 }
[ "func", "(", "p", "*", "Namespaces", ")", "Clone", "(", ")", "*", "Namespaces", "{", "if", "!", "p", ".", "Safe", "{", "p", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mu", ".", "RUnlock", "(", ")", "\n", "}", "\n", "p2", ":=", "Namespaces", "{", "prefixes", ":", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "p", ".", "prefixes", ")", ")", ",", "}", "\n", "for", "pref", ",", "ns", ":=", "range", "p", ".", "prefixes", "{", "p2", ".", "prefixes", "[", "pref", "]", "=", "ns", "\n", "}", "\n", "return", "&", "p2", "\n", "}" ]
// Clone makes a copy of namespaces list.
[ "Clone", "makes", "a", "copy", "of", "namespaces", "list", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/voc/voc.go#L86-L98
train
cayleygraph/cayley
voc/voc.go
CloneTo
func (p *Namespaces) CloneTo(p2 *Namespaces) { if p == p2 { return } if !p.Safe { p.mu.RLock() defer p.mu.RUnlock() } if !p2.Safe { p2.mu.Lock() defer p2.mu.Unlock() } if p2.prefixes == nil { p2.prefixes = make(map[string]string, len(p.prefixes)) } for pref, ns := range p.prefixes { p2.prefixes[pref] = ns } }
go
func (p *Namespaces) CloneTo(p2 *Namespaces) { if p == p2 { return } if !p.Safe { p.mu.RLock() defer p.mu.RUnlock() } if !p2.Safe { p2.mu.Lock() defer p2.mu.Unlock() } if p2.prefixes == nil { p2.prefixes = make(map[string]string, len(p.prefixes)) } for pref, ns := range p.prefixes { p2.prefixes[pref] = ns } }
[ "func", "(", "p", "*", "Namespaces", ")", "CloneTo", "(", "p2", "*", "Namespaces", ")", "{", "if", "p", "==", "p2", "{", "return", "\n", "}", "\n", "if", "!", "p", ".", "Safe", "{", "p", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "mu", ".", "RUnlock", "(", ")", "\n", "}", "\n", "if", "!", "p2", ".", "Safe", "{", "p2", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "p2", ".", "mu", ".", "Unlock", "(", ")", "\n", "}", "\n", "if", "p2", ".", "prefixes", "==", "nil", "{", "p2", ".", "prefixes", "=", "make", "(", "map", "[", "string", "]", "string", ",", "len", "(", "p", ".", "prefixes", ")", ")", "\n", "}", "\n", "for", "pref", ",", "ns", ":=", "range", "p", ".", "prefixes", "{", "p2", ".", "prefixes", "[", "pref", "]", "=", "ns", "\n", "}", "\n", "}" ]
// CloneTo adds registered namespaces to a given list.
[ "CloneTo", "adds", "registered", "namespaces", "to", "a", "given", "list", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/voc/voc.go#L101-L119
train
cayleygraph/cayley
voc/voc.go
RegisterPrefix
func RegisterPrefix(pref string, ns string) { Register(Namespace{Prefix: pref, Full: ns}) }
go
func RegisterPrefix(pref string, ns string) { Register(Namespace{Prefix: pref, Full: ns}) }
[ "func", "RegisterPrefix", "(", "pref", "string", ",", "ns", "string", ")", "{", "Register", "(", "Namespace", "{", "Prefix", ":", "pref", ",", "Full", ":", "ns", "}", ")", "\n", "}" ]
// RegisterPrefix globally associates a given prefix with a base vocabulary IRI.
[ "RegisterPrefix", "globally", "associates", "a", "given", "prefix", "with", "a", "base", "vocabulary", "IRI", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/voc/voc.go#L129-L131
train
cayleygraph/cayley
graph/iterator/limit.go
Next
func (it *Limit) Next(ctx context.Context) bool { graph.NextLogIn(it) if it.limit > 0 && it.count >= it.limit { return graph.NextLogOut(it, false) } if it.primaryIt.Next(ctx) { it.count++ return graph.NextLogOut(it, true) } return graph.NextLogOut(it, false) }
go
func (it *Limit) Next(ctx context.Context) bool { graph.NextLogIn(it) if it.limit > 0 && it.count >= it.limit { return graph.NextLogOut(it, false) } if it.primaryIt.Next(ctx) { it.count++ return graph.NextLogOut(it, true) } return graph.NextLogOut(it, false) }
[ "func", "(", "it", "*", "Limit", ")", "Next", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "graph", ".", "NextLogIn", "(", "it", ")", "\n", "if", "it", ".", "limit", ">", "0", "&&", "it", ".", "count", ">=", "it", ".", "limit", "{", "return", "graph", ".", "NextLogOut", "(", "it", ",", "false", ")", "\n", "}", "\n", "if", "it", ".", "primaryIt", ".", "Next", "(", "ctx", ")", "{", "it", ".", "count", "++", "\n", "return", "graph", ".", "NextLogOut", "(", "it", ",", "true", ")", "\n", "}", "\n", "return", "graph", ".", "NextLogOut", "(", "it", ",", "false", ")", "\n", "}" ]
// Next advances the Limit iterator. It will stop iteration if limit was reached.
[ "Next", "advances", "the", "Limit", "iterator", ".", "It", "will", "stop", "iteration", "if", "limit", "was", "reached", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/limit.go#L57-L67
train
cayleygraph/cayley
graph/iterator/limit.go
NextPath
func (it *Limit) NextPath(ctx context.Context) bool { if it.limit > 0 && it.count >= it.limit { return false } if it.primaryIt.NextPath(ctx) { it.count++ return true } return false }
go
func (it *Limit) NextPath(ctx context.Context) bool { if it.limit > 0 && it.count >= it.limit { return false } if it.primaryIt.NextPath(ctx) { it.count++ return true } return false }
[ "func", "(", "it", "*", "Limit", ")", "NextPath", "(", "ctx", "context", ".", "Context", ")", "bool", "{", "if", "it", ".", "limit", ">", "0", "&&", "it", ".", "count", ">=", "it", ".", "limit", "{", "return", "false", "\n", "}", "\n", "if", "it", ".", "primaryIt", ".", "NextPath", "(", "ctx", ")", "{", "it", ".", "count", "++", "\n", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// NextPath checks whether there is another path. Will call primary iterator // if limit is not reached yet.
[ "NextPath", "checks", "whether", "there", "is", "another", "path", ".", "Will", "call", "primary", "iterator", "if", "limit", "is", "not", "reached", "yet", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/iterator/limit.go#L83-L92
train
cayleygraph/cayley
graph/shape/path.go
Predicates
func Predicates(from Shape, in bool) Shape { dir := quad.Subject if in { dir = quad.Object } return Unique{NodesFrom{ Quads: Quads{ {Dir: dir, Values: from}, }, Dir: quad.Predicate, }} }
go
func Predicates(from Shape, in bool) Shape { dir := quad.Subject if in { dir = quad.Object } return Unique{NodesFrom{ Quads: Quads{ {Dir: dir, Values: from}, }, Dir: quad.Predicate, }} }
[ "func", "Predicates", "(", "from", "Shape", ",", "in", "bool", ")", "Shape", "{", "dir", ":=", "quad", ".", "Subject", "\n", "if", "in", "{", "dir", "=", "quad", ".", "Object", "\n", "}", "\n", "return", "Unique", "{", "NodesFrom", "{", "Quads", ":", "Quads", "{", "{", "Dir", ":", "dir", ",", "Values", ":", "from", "}", ",", "}", ",", "Dir", ":", "quad", ".", "Predicate", ",", "}", "}", "\n", "}" ]
// InWithTags, OutWithTags, Both, BothWithTags
[ "InWithTags", "OutWithTags", "Both", "BothWithTags" ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/path.go#L99-L110
train
cayleygraph/cayley
graph/shape/shape.go
Optimize
func Optimize(s Shape, qs graph.QuadStore) (Shape, bool) { if s == nil { return nil, false } qs = graph.Unwrap(qs) var opt bool if qs != nil { // resolve all lookups earlier s, opt = s.Optimize(resolveValues{qs: qs}) } if s == nil { return Null{}, true } // generic optimizations var opt1 bool s, opt1 = s.Optimize(nil) if s == nil { return Null{}, true } opt = opt || opt1 // apply quadstore-specific optimizations if so, ok := qs.(Optimizer); ok && s != nil { var opt2 bool s, opt2 = s.Optimize(so) opt = opt || opt2 } if s == nil { return Null{}, true } return s, opt }
go
func Optimize(s Shape, qs graph.QuadStore) (Shape, bool) { if s == nil { return nil, false } qs = graph.Unwrap(qs) var opt bool if qs != nil { // resolve all lookups earlier s, opt = s.Optimize(resolveValues{qs: qs}) } if s == nil { return Null{}, true } // generic optimizations var opt1 bool s, opt1 = s.Optimize(nil) if s == nil { return Null{}, true } opt = opt || opt1 // apply quadstore-specific optimizations if so, ok := qs.(Optimizer); ok && s != nil { var opt2 bool s, opt2 = s.Optimize(so) opt = opt || opt2 } if s == nil { return Null{}, true } return s, opt }
[ "func", "Optimize", "(", "s", "Shape", ",", "qs", "graph", ".", "QuadStore", ")", "(", "Shape", ",", "bool", ")", "{", "if", "s", "==", "nil", "{", "return", "nil", ",", "false", "\n", "}", "\n", "qs", "=", "graph", ".", "Unwrap", "(", "qs", ")", "\n", "var", "opt", "bool", "\n", "if", "qs", "!=", "nil", "{", "// resolve all lookups earlier", "s", ",", "opt", "=", "s", ".", "Optimize", "(", "resolveValues", "{", "qs", ":", "qs", "}", ")", "\n", "}", "\n", "if", "s", "==", "nil", "{", "return", "Null", "{", "}", ",", "true", "\n", "}", "\n", "// generic optimizations", "var", "opt1", "bool", "\n", "s", ",", "opt1", "=", "s", ".", "Optimize", "(", "nil", ")", "\n", "if", "s", "==", "nil", "{", "return", "Null", "{", "}", ",", "true", "\n", "}", "\n", "opt", "=", "opt", "||", "opt1", "\n", "// apply quadstore-specific optimizations", "if", "so", ",", "ok", ":=", "qs", ".", "(", "Optimizer", ")", ";", "ok", "&&", "s", "!=", "nil", "{", "var", "opt2", "bool", "\n", "s", ",", "opt2", "=", "s", ".", "Optimize", "(", "so", ")", "\n", "opt", "=", "opt", "||", "opt2", "\n", "}", "\n", "if", "s", "==", "nil", "{", "return", "Null", "{", "}", ",", "true", "\n", "}", "\n", "return", "s", ",", "opt", "\n", "}" ]
// Optimize applies generic optimizations for the tree. // If quad store is specified it will also resolve Lookups and apply any specific optimizations. // Should not be used with Simplify - it will fold query to a compact form again.
[ "Optimize", "applies", "generic", "optimizations", "for", "the", "tree", ".", "If", "quad", "store", "is", "specified", "it", "will", "also", "resolve", "Lookups", "and", "apply", "any", "specific", "optimizations", ".", "Should", "not", "be", "used", "with", "Simplify", "-", "it", "will", "fold", "query", "to", "a", "compact", "form", "again", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/shape.go#L60-L90
train
cayleygraph/cayley
graph/shape/shape.go
Walk
func Walk(s Shape, fnc WalkFunc) { if s == nil { return } if !fnc(s) { return } walkReflect(reflect.ValueOf(s), fnc) }
go
func Walk(s Shape, fnc WalkFunc) { if s == nil { return } if !fnc(s) { return } walkReflect(reflect.ValueOf(s), fnc) }
[ "func", "Walk", "(", "s", "Shape", ",", "fnc", "WalkFunc", ")", "{", "if", "s", "==", "nil", "{", "return", "\n", "}", "\n", "if", "!", "fnc", "(", "s", ")", "{", "return", "\n", "}", "\n", "walkReflect", "(", "reflect", ".", "ValueOf", "(", "s", ")", ",", "fnc", ")", "\n", "}" ]
// Walk calls provided function for each shape in the tree.
[ "Walk", "calls", "provided", "function", "for", "each", "shape", "in", "the", "tree", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/shape.go#L95-L103
train
cayleygraph/cayley
graph/shape/shape.go
Get
func (q InternalQuad) Get(d quad.Direction) graph.Value { switch d { case quad.Subject: return q.Subject case quad.Predicate: return q.Predicate case quad.Object: return q.Object case quad.Label: return q.Label default: return nil } }
go
func (q InternalQuad) Get(d quad.Direction) graph.Value { switch d { case quad.Subject: return q.Subject case quad.Predicate: return q.Predicate case quad.Object: return q.Object case quad.Label: return q.Label default: return nil } }
[ "func", "(", "q", "InternalQuad", ")", "Get", "(", "d", "quad", ".", "Direction", ")", "graph", ".", "Value", "{", "switch", "d", "{", "case", "quad", ".", "Subject", ":", "return", "q", ".", "Subject", "\n", "case", "quad", ".", "Predicate", ":", "return", "q", ".", "Predicate", "\n", "case", "quad", ".", "Object", ":", "return", "q", ".", "Object", "\n", "case", "quad", ".", "Label", ":", "return", "q", ".", "Label", "\n", "default", ":", "return", "nil", "\n", "}", "\n", "}" ]
// Get returns a specified direction of the quad.
[ "Get", "returns", "a", "specified", "direction", "of", "the", "quad", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/shape.go#L158-L171
train
cayleygraph/cayley
graph/shape/shape.go
Set
func (q InternalQuad) Set(d quad.Direction, v graph.Value) { switch d { case quad.Subject: q.Subject = v case quad.Predicate: q.Predicate = v case quad.Object: q.Object = v case quad.Label: q.Label = v default: panic(d) } }
go
func (q InternalQuad) Set(d quad.Direction, v graph.Value) { switch d { case quad.Subject: q.Subject = v case quad.Predicate: q.Predicate = v case quad.Object: q.Object = v case quad.Label: q.Label = v default: panic(d) } }
[ "func", "(", "q", "InternalQuad", ")", "Set", "(", "d", "quad", ".", "Direction", ",", "v", "graph", ".", "Value", ")", "{", "switch", "d", "{", "case", "quad", ".", "Subject", ":", "q", ".", "Subject", "=", "v", "\n", "case", "quad", ".", "Predicate", ":", "q", ".", "Predicate", "=", "v", "\n", "case", "quad", ".", "Object", ":", "q", ".", "Object", "=", "v", "\n", "case", "quad", ".", "Label", ":", "q", ".", "Label", "=", "v", "\n", "default", ":", "panic", "(", "d", ")", "\n", "}", "\n", "}" ]
// Set assigns a specified direction of the quad to a given value.
[ "Set", "assigns", "a", "specified", "direction", "of", "the", "quad", "to", "a", "given", "value", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/shape.go#L174-L187
train
cayleygraph/cayley
graph/shape/shape.go
IsNull
func IsNull(s Shape) bool { _, ok := s.(Null) return s == nil || ok }
go
func IsNull(s Shape) bool { _, ok := s.(Null) return s == nil || ok }
[ "func", "IsNull", "(", "s", "Shape", ")", "bool", "{", "_", ",", "ok", ":=", "s", ".", "(", "Null", ")", "\n", "return", "s", "==", "nil", "||", "ok", "\n", "}" ]
// IsNull safely checks if shape represents an empty set. It accounts for both Null and nil.
[ "IsNull", "safely", "checks", "if", "shape", "represents", "an", "empty", "set", ".", "It", "accounts", "for", "both", "Null", "and", "nil", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/shape.go#L201-L204
train
cayleygraph/cayley
graph/shape/shape.go
BuildIterator
func BuildIterator(qs graph.QuadStore, s Shape) graph.Iterator { qs = graph.Unwrap(qs) if s != nil { if debugShapes || clog.V(2) { clog.Infof("shape: %#v", s) } s, _ = Optimize(s, qs) if debugOptimizer || clog.V(2) { clog.Infof("optimized: %#v", s) } } if IsNull(s) { return iterator.NewNull() } return s.BuildIterator(qs) }
go
func BuildIterator(qs graph.QuadStore, s Shape) graph.Iterator { qs = graph.Unwrap(qs) if s != nil { if debugShapes || clog.V(2) { clog.Infof("shape: %#v", s) } s, _ = Optimize(s, qs) if debugOptimizer || clog.V(2) { clog.Infof("optimized: %#v", s) } } if IsNull(s) { return iterator.NewNull() } return s.BuildIterator(qs) }
[ "func", "BuildIterator", "(", "qs", "graph", ".", "QuadStore", ",", "s", "Shape", ")", "graph", ".", "Iterator", "{", "qs", "=", "graph", ".", "Unwrap", "(", "qs", ")", "\n", "if", "s", "!=", "nil", "{", "if", "debugShapes", "||", "clog", ".", "V", "(", "2", ")", "{", "clog", ".", "Infof", "(", "\"", "\"", ",", "s", ")", "\n", "}", "\n", "s", ",", "_", "=", "Optimize", "(", "s", ",", "qs", ")", "\n", "if", "debugOptimizer", "||", "clog", ".", "V", "(", "2", ")", "{", "clog", ".", "Infof", "(", "\"", "\"", ",", "s", ")", "\n", "}", "\n", "}", "\n", "if", "IsNull", "(", "s", ")", "{", "return", "iterator", ".", "NewNull", "(", ")", "\n", "}", "\n", "return", "s", ".", "BuildIterator", "(", "qs", ")", "\n", "}" ]
// BuildIterator optimizes the shape and builds a corresponding iterator tree.
[ "BuildIterator", "optimizes", "the", "shape", "and", "builds", "a", "corresponding", "iterator", "tree", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/shape.go#L207-L222
train
cayleygraph/cayley
graph/shape/shape.go
buildIterator
func (s QuadFilter) buildIterator(qs graph.QuadStore) graph.Iterator { if s.Values == nil { return iterator.NewNull() } else if v, ok := One(s.Values); ok { return qs.QuadIterator(s.Dir, v) } if s.Dir == quad.Any { panic("direction is not set") } sub := s.Values.BuildIterator(qs) return iterator.NewLinksTo(qs, sub, s.Dir) }
go
func (s QuadFilter) buildIterator(qs graph.QuadStore) graph.Iterator { if s.Values == nil { return iterator.NewNull() } else if v, ok := One(s.Values); ok { return qs.QuadIterator(s.Dir, v) } if s.Dir == quad.Any { panic("direction is not set") } sub := s.Values.BuildIterator(qs) return iterator.NewLinksTo(qs, sub, s.Dir) }
[ "func", "(", "s", "QuadFilter", ")", "buildIterator", "(", "qs", "graph", ".", "QuadStore", ")", "graph", ".", "Iterator", "{", "if", "s", ".", "Values", "==", "nil", "{", "return", "iterator", ".", "NewNull", "(", ")", "\n", "}", "else", "if", "v", ",", "ok", ":=", "One", "(", "s", ".", "Values", ")", ";", "ok", "{", "return", "qs", ".", "QuadIterator", "(", "s", ".", "Dir", ",", "v", ")", "\n", "}", "\n", "if", "s", ".", "Dir", "==", "quad", ".", "Any", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "sub", ":=", "s", ".", "Values", ".", "BuildIterator", "(", "qs", ")", "\n", "return", "iterator", ".", "NewLinksTo", "(", "qs", ",", "sub", ",", "s", ".", "Dir", ")", "\n", "}" ]
// buildIterator is not exposed to force to use Quads and group filters together.
[ "buildIterator", "is", "not", "exposed", "to", "force", "to", "use", "Quads", "and", "group", "filters", "together", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/shape.go#L443-L454
train
cayleygraph/cayley
graph/shape/shape.go
One
func One(s Shape) (graph.Value, bool) { switch s := s.(type) { case Fixed: if len(s) == 1 { return s[0], true } } return nil, false }
go
func One(s Shape) (graph.Value, bool) { switch s := s.(type) { case Fixed: if len(s) == 1 { return s[0], true } } return nil, false }
[ "func", "One", "(", "s", "Shape", ")", "(", "graph", ".", "Value", ",", "bool", ")", "{", "switch", "s", ":=", "s", ".", "(", "type", ")", "{", "case", "Fixed", ":", "if", "len", "(", "s", ")", "==", "1", "{", "return", "s", "[", "0", "]", ",", "true", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// One checks if Shape represents a single fixed value and returns it.
[ "One", "checks", "if", "Shape", "represents", "a", "single", "fixed", "value", "and", "returns", "it", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/shape/shape.go#L720-L728
train
cayleygraph/cayley
quad/pquads/pquads.go
NewWriter
func NewWriter(w io.Writer, opts *Options) *Writer { // Write file magic and version buf := make([]byte, 8) copy(buf[:4], magic[:]) binary.LittleEndian.PutUint32(buf[4:], currentVersion) if _, err := w.Write(buf); err != nil { return &Writer{err: err} } pw := pio.NewWriter(w) if opts == nil { opts = &Options{} } // Write options header _, err := pw.WriteMsg(&Header{ Full: opts.Full, NotStrict: !opts.Strict, }) return &Writer{pw: pw, err: err, opts: *opts} }
go
func NewWriter(w io.Writer, opts *Options) *Writer { // Write file magic and version buf := make([]byte, 8) copy(buf[:4], magic[:]) binary.LittleEndian.PutUint32(buf[4:], currentVersion) if _, err := w.Write(buf); err != nil { return &Writer{err: err} } pw := pio.NewWriter(w) if opts == nil { opts = &Options{} } // Write options header _, err := pw.WriteMsg(&Header{ Full: opts.Full, NotStrict: !opts.Strict, }) return &Writer{pw: pw, err: err, opts: *opts} }
[ "func", "NewWriter", "(", "w", "io", ".", "Writer", ",", "opts", "*", "Options", ")", "*", "Writer", "{", "// Write file magic and version", "buf", ":=", "make", "(", "[", "]", "byte", ",", "8", ")", "\n", "copy", "(", "buf", "[", ":", "4", "]", ",", "magic", "[", ":", "]", ")", "\n", "binary", ".", "LittleEndian", ".", "PutUint32", "(", "buf", "[", "4", ":", "]", ",", "currentVersion", ")", "\n", "if", "_", ",", "err", ":=", "w", ".", "Write", "(", "buf", ")", ";", "err", "!=", "nil", "{", "return", "&", "Writer", "{", "err", ":", "err", "}", "\n", "}", "\n", "pw", ":=", "pio", ".", "NewWriter", "(", "w", ")", "\n", "if", "opts", "==", "nil", "{", "opts", "=", "&", "Options", "{", "}", "\n", "}", "\n", "// Write options header", "_", ",", "err", ":=", "pw", ".", "WriteMsg", "(", "&", "Header", "{", "Full", ":", "opts", ".", "Full", ",", "NotStrict", ":", "!", "opts", ".", "Strict", ",", "}", ")", "\n", "return", "&", "Writer", "{", "pw", ":", "pw", ",", "err", ":", "err", ",", "opts", ":", "*", "opts", "}", "\n", "}" ]
// NewWriter creates protobuf quads encoder.
[ "NewWriter", "creates", "protobuf", "quads", "encoder", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/pquads/pquads.go#L55-L73
train
cayleygraph/cayley
quad/pquads/pquads.go
NewReader
func NewReader(r io.Reader, maxSize int) *Reader { if maxSize <= 0 { maxSize = DefaultMaxSize } qr := &Reader{} buf := make([]byte, 8) if _, err := io.ReadFull(r, buf); err != nil { qr.err = err return qr } else if bytes.Compare(magic[:], buf[:4]) != 0 { qr.err = fmt.Errorf("not a pquads file") return qr } vers := binary.LittleEndian.Uint32(buf[4:]) if vers != currentVersion { qr.err = fmt.Errorf("unsupported pquads version: %d", vers) return qr } qr.pr = pio.NewReader(r, maxSize) var h Header if err := qr.pr.ReadMsg(&h); err != nil { qr.err = err } qr.opts = Options{ Full: h.Full, Strict: !h.NotStrict, } return qr }
go
func NewReader(r io.Reader, maxSize int) *Reader { if maxSize <= 0 { maxSize = DefaultMaxSize } qr := &Reader{} buf := make([]byte, 8) if _, err := io.ReadFull(r, buf); err != nil { qr.err = err return qr } else if bytes.Compare(magic[:], buf[:4]) != 0 { qr.err = fmt.Errorf("not a pquads file") return qr } vers := binary.LittleEndian.Uint32(buf[4:]) if vers != currentVersion { qr.err = fmt.Errorf("unsupported pquads version: %d", vers) return qr } qr.pr = pio.NewReader(r, maxSize) var h Header if err := qr.pr.ReadMsg(&h); err != nil { qr.err = err } qr.opts = Options{ Full: h.Full, Strict: !h.NotStrict, } return qr }
[ "func", "NewReader", "(", "r", "io", ".", "Reader", ",", "maxSize", "int", ")", "*", "Reader", "{", "if", "maxSize", "<=", "0", "{", "maxSize", "=", "DefaultMaxSize", "\n", "}", "\n", "qr", ":=", "&", "Reader", "{", "}", "\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "8", ")", "\n", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "r", ",", "buf", ")", ";", "err", "!=", "nil", "{", "qr", ".", "err", "=", "err", "\n", "return", "qr", "\n", "}", "else", "if", "bytes", ".", "Compare", "(", "magic", "[", ":", "]", ",", "buf", "[", ":", "4", "]", ")", "!=", "0", "{", "qr", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "qr", "\n", "}", "\n", "vers", ":=", "binary", ".", "LittleEndian", ".", "Uint32", "(", "buf", "[", "4", ":", "]", ")", "\n", "if", "vers", "!=", "currentVersion", "{", "qr", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "vers", ")", "\n", "return", "qr", "\n", "}", "\n\n", "qr", ".", "pr", "=", "pio", ".", "NewReader", "(", "r", ",", "maxSize", ")", "\n", "var", "h", "Header", "\n", "if", "err", ":=", "qr", ".", "pr", ".", "ReadMsg", "(", "&", "h", ")", ";", "err", "!=", "nil", "{", "qr", ".", "err", "=", "err", "\n", "}", "\n", "qr", ".", "opts", "=", "Options", "{", "Full", ":", "h", ".", "Full", ",", "Strict", ":", "!", "h", ".", "NotStrict", ",", "}", "\n", "return", "qr", "\n", "}" ]
// NewReader creates protobuf quads decoder. // // MaxSize argument limits maximal size of the buffer used to read quads.
[ "NewReader", "creates", "protobuf", "quads", "decoder", ".", "MaxSize", "argument", "limits", "maximal", "size", "of", "the", "buffer", "used", "to", "read", "quads", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/quad/pquads/pquads.go#L143-L172
train
cayleygraph/cayley
graph/nosql/nosql.go
KeyFrom
func KeyFrom(fields []string, doc Document) Key { key := make(Key, 0, len(fields)) for _, f := range fields { if s, ok := doc[f].(String); ok { key = append(key, string(s)) } } return key }
go
func KeyFrom(fields []string, doc Document) Key { key := make(Key, 0, len(fields)) for _, f := range fields { if s, ok := doc[f].(String); ok { key = append(key, string(s)) } } return key }
[ "func", "KeyFrom", "(", "fields", "[", "]", "string", ",", "doc", "Document", ")", "Key", "{", "key", ":=", "make", "(", "Key", ",", "0", ",", "len", "(", "fields", ")", ")", "\n", "for", "_", ",", "f", ":=", "range", "fields", "{", "if", "s", ",", "ok", ":=", "doc", "[", "f", "]", ".", "(", "String", ")", ";", "ok", "{", "key", "=", "append", "(", "key", ",", "string", "(", "s", ")", ")", "\n", "}", "\n", "}", "\n", "return", "key", "\n", "}" ]
// KeyFrom extracts a set of fields as a Key from Document.
[ "KeyFrom", "extracts", "a", "set", "of", "fields", "as", "a", "Key", "from", "Document", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/nosql/nosql.go#L30-L38
train
cayleygraph/cayley
graph/nosql/nosql.go
BatchInsert
func BatchInsert(db Database, col string) DocWriter { if bi, ok := db.(BatchInserter); ok { return bi.BatchInsert(col) } return &seqInsert{db: db, col: col} }
go
func BatchInsert(db Database, col string) DocWriter { if bi, ok := db.(BatchInserter); ok { return bi.BatchInsert(col) } return &seqInsert{db: db, col: col} }
[ "func", "BatchInsert", "(", "db", "Database", ",", "col", "string", ")", "DocWriter", "{", "if", "bi", ",", "ok", ":=", "db", ".", "(", "BatchInserter", ")", ";", "ok", "{", "return", "bi", ".", "BatchInsert", "(", "col", ")", "\n", "}", "\n", "return", "&", "seqInsert", "{", "db", ":", "db", ",", "col", ":", "col", "}", "\n", "}" ]
// BatchInsert returns a streaming writer for database or emulates it if database has no support for batch inserts.
[ "BatchInsert", "returns", "a", "streaming", "writer", "for", "database", "or", "emulates", "it", "if", "database", "has", "no", "support", "for", "batch", "inserts", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/graph/nosql/nosql.go#L218-L223
train
cayleygraph/cayley
internal/load.go
Load
func Load(qw graph.QuadWriter, batch int, path, typ string) error { return DecompressAndLoad(qw, batch, path, typ, nil) }
go
func Load(qw graph.QuadWriter, batch int, path, typ string) error { return DecompressAndLoad(qw, batch, path, typ, nil) }
[ "func", "Load", "(", "qw", "graph", ".", "QuadWriter", ",", "batch", "int", ",", "path", ",", "typ", "string", ")", "error", "{", "return", "DecompressAndLoad", "(", "qw", ",", "batch", ",", "path", ",", "typ", ",", "nil", ")", "\n", "}" ]
// Load loads a graph from the given path and write it to qw. See // DecompressAndLoad for more information.
[ "Load", "loads", "a", "graph", "from", "the", "given", "path", "and", "write", "it", "to", "qw", ".", "See", "DecompressAndLoad", "for", "more", "information", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/internal/load.go#L21-L23
train
cayleygraph/cayley
internal/load.go
DecompressAndLoad
func DecompressAndLoad(qw graph.QuadWriter, batch int, path, typ string, writerFunc func(graph.QuadWriter) graph.BatchWriter) error { if path == "" { return nil } qr, err := QuadReaderFor(path, typ) if err != nil { return err } defer qr.Close() if writerFunc == nil { writerFunc = graph.NewWriter } dest := writerFunc(qw) _, err = quad.CopyBatch(&batchLogger{BatchWriter: dest}, qr, batch) if err != nil { return fmt.Errorf("db: failed to load data: %v", err) } return dest.Close() }
go
func DecompressAndLoad(qw graph.QuadWriter, batch int, path, typ string, writerFunc func(graph.QuadWriter) graph.BatchWriter) error { if path == "" { return nil } qr, err := QuadReaderFor(path, typ) if err != nil { return err } defer qr.Close() if writerFunc == nil { writerFunc = graph.NewWriter } dest := writerFunc(qw) _, err = quad.CopyBatch(&batchLogger{BatchWriter: dest}, qr, batch) if err != nil { return fmt.Errorf("db: failed to load data: %v", err) } return dest.Close() }
[ "func", "DecompressAndLoad", "(", "qw", "graph", ".", "QuadWriter", ",", "batch", "int", ",", "path", ",", "typ", "string", ",", "writerFunc", "func", "(", "graph", ".", "QuadWriter", ")", "graph", ".", "BatchWriter", ")", "error", "{", "if", "path", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "qr", ",", "err", ":=", "QuadReaderFor", "(", "path", ",", "typ", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "qr", ".", "Close", "(", ")", "\n\n", "if", "writerFunc", "==", "nil", "{", "writerFunc", "=", "graph", ".", "NewWriter", "\n", "}", "\n", "dest", ":=", "writerFunc", "(", "qw", ")", "\n\n", "_", ",", "err", "=", "quad", ".", "CopyBatch", "(", "&", "batchLogger", "{", "BatchWriter", ":", "dest", "}", ",", "qr", ",", "batch", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "dest", ".", "Close", "(", ")", "\n", "}" ]
// DecompressAndLoad will load or fetch a graph from the given path, decompress // it, and then call the given load function to process the decompressed graph. // If no loadFn is provided, db.Load is called.
[ "DecompressAndLoad", "will", "load", "or", "fetch", "a", "graph", "from", "the", "given", "path", "decompress", "it", "and", "then", "call", "the", "given", "load", "function", "to", "process", "the", "decompressed", "graph", ".", "If", "no", "loadFn", "is", "provided", "db", ".", "Load", "is", "called", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/internal/load.go#L124-L144
train
cayleygraph/cayley
query/session.go
NewSession
func NewSession(qs graph.QuadStore, lang string) Session { if l := languages[lang]; l.Session != nil { return l.Session(qs) } return nil }
go
func NewSession(qs graph.QuadStore, lang string) Session { if l := languages[lang]; l.Session != nil { return l.Session(qs) } return nil }
[ "func", "NewSession", "(", "qs", "graph", ".", "QuadStore", ",", "lang", "string", ")", "Session", "{", "if", "l", ":=", "languages", "[", "lang", "]", ";", "l", ".", "Session", "!=", "nil", "{", "return", "l", ".", "Session", "(", "qs", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// NewSession creates a new session for specified query language. // It returns nil if language was not registered.
[ "NewSession", "creates", "a", "new", "session", "for", "specified", "query", "language", ".", "It", "returns", "nil", "if", "language", "was", "not", "registered", "." ]
5318a818e947b20ef36a274f643e577f036bca7c
https://github.com/cayleygraph/cayley/blob/5318a818e947b20ef36a274f643e577f036bca7c/query/session.go#L104-L109
train