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 | platforms/particle/adaptor.go | ServoWrite | func (s *Adaptor) ServoWrite(pin string, angle byte) (err error) {
if _, present := s.servoPins[pin]; !present {
err = s.servoPinOpen(pin)
if err != nil {
return
}
}
params := url.Values{
"params": {fmt.Sprintf("%v,%v", pin, angle)},
"access_token": {s.AccessToken},
}
url := fmt.Sprintf("%v/servoSet", s.deviceURL())
_, err = s.request("POST", url, params)
return err
} | go | func (s *Adaptor) ServoWrite(pin string, angle byte) (err error) {
if _, present := s.servoPins[pin]; !present {
err = s.servoPinOpen(pin)
if err != nil {
return
}
}
params := url.Values{
"params": {fmt.Sprintf("%v,%v", pin, angle)},
"access_token": {s.AccessToken},
}
url := fmt.Sprintf("%v/servoSet", s.deviceURL())
_, err = s.request("POST", url, params)
return err
} | [
"func",
"(",
"s",
"*",
"Adaptor",
")",
"ServoWrite",
"(",
"pin",
"string",
",",
"angle",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"_",
",",
"present",
":=",
"s",
".",
"servoPins",
"[",
"pin",
"]",
";",
"!",
"present",
"{",
"err",
"=",
"s",
".",
"servoPinOpen",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"params",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pin",
",",
"angle",
")",
"}",
",",
"\"",
"\"",
":",
"{",
"s",
".",
"AccessToken",
"}",
",",
"}",
"\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"deviceURL",
"(",
")",
")",
"\n",
"_",
",",
"err",
"=",
"s",
".",
"request",
"(",
"\"",
"\"",
",",
"url",
",",
"params",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ServoWrite writes the 0-180 degree angle to the specified pin.
// To use it requires installing the "tinker-servo" sketch on your
// Particle device. not just the default "tinker". | [
"ServoWrite",
"writes",
"the",
"0",
"-",
"180",
"degree",
"angle",
"to",
"the",
"specified",
"pin",
".",
"To",
"use",
"it",
"requires",
"installing",
"the",
"tinker",
"-",
"servo",
"sketch",
"on",
"your",
"Particle",
"device",
".",
"not",
"just",
"the",
"default",
"tinker",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L133-L148 | train |
hybridgroup/gobot | platforms/particle/adaptor.go | Variable | func (s *Adaptor) Variable(name string) (result string, err error) {
url := fmt.Sprintf("%v/%s?access_token=%s", s.deviceURL(), name, s.AccessToken)
resp, err := s.request("GET", url, nil)
if err != nil {
return
}
val := resp["result"]
switch val.(type) {
case bool:
result = strconv.FormatBool(val.(bool))
case float64:
result = strconv.FormatFloat(val.(float64), 'f', -1, 64)
case string:
result = val.(string)
}
return
} | go | func (s *Adaptor) Variable(name string) (result string, err error) {
url := fmt.Sprintf("%v/%s?access_token=%s", s.deviceURL(), name, s.AccessToken)
resp, err := s.request("GET", url, nil)
if err != nil {
return
}
val := resp["result"]
switch val.(type) {
case bool:
result = strconv.FormatBool(val.(bool))
case float64:
result = strconv.FormatFloat(val.(float64), 'f', -1, 64)
case string:
result = val.(string)
}
return
} | [
"func",
"(",
"s",
"*",
"Adaptor",
")",
"Variable",
"(",
"name",
"string",
")",
"(",
"result",
"string",
",",
"err",
"error",
")",
"{",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"deviceURL",
"(",
")",
",",
"name",
",",
"s",
".",
"AccessToken",
")",
"\n",
"resp",
",",
"err",
":=",
"s",
".",
"request",
"(",
"\"",
"\"",
",",
"url",
",",
"nil",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"val",
":=",
"resp",
"[",
"\"",
"\"",
"]",
"\n",
"switch",
"val",
".",
"(",
"type",
")",
"{",
"case",
"bool",
":",
"result",
"=",
"strconv",
".",
"FormatBool",
"(",
"val",
".",
"(",
"bool",
")",
")",
"\n",
"case",
"float64",
":",
"result",
"=",
"strconv",
".",
"FormatFloat",
"(",
"val",
".",
"(",
"float64",
")",
",",
"'f'",
",",
"-",
"1",
",",
"64",
")",
"\n",
"case",
"string",
":",
"result",
"=",
"val",
".",
"(",
"string",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Variable returns a core variable value as a string | [
"Variable",
"returns",
"a",
"core",
"variable",
"value",
"as",
"a",
"string"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L190-L209 | train |
hybridgroup/gobot | platforms/particle/adaptor.go | Function | func (s *Adaptor) Function(name string, args string) (val int, err error) {
params := url.Values{
"args": {args},
"access_token": {s.AccessToken},
}
url := fmt.Sprintf("%s/%s", s.deviceURL(), name)
resp, err := s.request("POST", url, params)
if err != nil {
return -1, err
}
val = int(resp["return_value"].(float64))
return
} | go | func (s *Adaptor) Function(name string, args string) (val int, err error) {
params := url.Values{
"args": {args},
"access_token": {s.AccessToken},
}
url := fmt.Sprintf("%s/%s", s.deviceURL(), name)
resp, err := s.request("POST", url, params)
if err != nil {
return -1, err
}
val = int(resp["return_value"].(float64))
return
} | [
"func",
"(",
"s",
"*",
"Adaptor",
")",
"Function",
"(",
"name",
"string",
",",
"args",
"string",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"params",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"{",
"args",
"}",
",",
"\"",
"\"",
":",
"{",
"s",
".",
"AccessToken",
"}",
",",
"}",
"\n\n",
"url",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"deviceURL",
"(",
")",
",",
"name",
")",
"\n",
"resp",
",",
"err",
":=",
"s",
".",
"request",
"(",
"\"",
"\"",
",",
"url",
",",
"params",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"val",
"=",
"int",
"(",
"resp",
"[",
"\"",
"\"",
"]",
".",
"(",
"float64",
")",
")",
"\n",
"return",
"\n",
"}"
] | // Function executes a core function and
// returns value from request.
// Takes a String as the only argument and returns an Int.
// If function is not defined in core, it will time out | [
"Function",
"executes",
"a",
"core",
"function",
"and",
"returns",
"value",
"from",
"request",
".",
"Takes",
"a",
"String",
"as",
"the",
"only",
"argument",
"and",
"returns",
"an",
"Int",
".",
"If",
"function",
"is",
"not",
"defined",
"in",
"core",
"it",
"will",
"time",
"out"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L215-L230 | train |
hybridgroup/gobot | platforms/particle/adaptor.go | deviceURL | func (s *Adaptor) deviceURL() string {
if len(s.APIServer) <= 0 {
s.setAPIServer("https://api.particle.io")
}
return fmt.Sprintf("%v/v1/devices/%v", s.APIServer, s.DeviceID)
} | go | func (s *Adaptor) deviceURL() string {
if len(s.APIServer) <= 0 {
s.setAPIServer("https://api.particle.io")
}
return fmt.Sprintf("%v/v1/devices/%v", s.APIServer, s.DeviceID)
} | [
"func",
"(",
"s",
"*",
"Adaptor",
")",
"deviceURL",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"s",
".",
"APIServer",
")",
"<=",
"0",
"{",
"s",
".",
"setAPIServer",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"APIServer",
",",
"s",
".",
"DeviceID",
")",
"\n",
"}"
] | // deviceURL constructs device url to make requests from Particle cloud api | [
"deviceURL",
"constructs",
"device",
"url",
"to",
"make",
"requests",
"from",
"Particle",
"cloud",
"api"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L238-L243 | train |
hybridgroup/gobot | platforms/particle/adaptor.go | request | func (s *Adaptor) request(method string, url string, params url.Values) (m map[string]interface{}, err error) {
var resp *http.Response
if method == "POST" {
resp, err = http.PostForm(url, params)
} else if method == "GET" {
resp, err = http.Get(url)
}
if err != nil {
return
}
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
json.Unmarshal(buf, &m)
if resp.Status != "200 OK" {
err = fmt.Errorf("%v: error communicating to the Particle cloud", resp.Status)
} else if _, ok := m["error"]; ok {
err = errors.New(m["error"].(string))
}
return
} | go | func (s *Adaptor) request(method string, url string, params url.Values) (m map[string]interface{}, err error) {
var resp *http.Response
if method == "POST" {
resp, err = http.PostForm(url, params)
} else if method == "GET" {
resp, err = http.Get(url)
}
if err != nil {
return
}
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
json.Unmarshal(buf, &m)
if resp.Status != "200 OK" {
err = fmt.Errorf("%v: error communicating to the Particle cloud", resp.Status)
} else if _, ok := m["error"]; ok {
err = errors.New(m["error"].(string))
}
return
} | [
"func",
"(",
"s",
"*",
"Adaptor",
")",
"request",
"(",
"method",
"string",
",",
"url",
"string",
",",
"params",
"url",
".",
"Values",
")",
"(",
"m",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"var",
"resp",
"*",
"http",
".",
"Response",
"\n\n",
"if",
"method",
"==",
"\"",
"\"",
"{",
"resp",
",",
"err",
"=",
"http",
".",
"PostForm",
"(",
"url",
",",
"params",
")",
"\n",
"}",
"else",
"if",
"method",
"==",
"\"",
"\"",
"{",
"resp",
",",
"err",
"=",
"http",
".",
"Get",
"(",
"url",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"json",
".",
"Unmarshal",
"(",
"buf",
",",
"&",
"m",
")",
"\n\n",
"if",
"resp",
".",
"Status",
"!=",
"\"",
"\"",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resp",
".",
"Status",
")",
"\n",
"}",
"else",
"if",
"_",
",",
"ok",
":=",
"m",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"m",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // request makes request to Particle cloud server, return err != nil if there is
// any issue with the request. | [
"request",
"makes",
"request",
"to",
"Particle",
"cloud",
"server",
"return",
"err",
"!",
"=",
"nil",
"if",
"there",
"is",
"any",
"issue",
"with",
"the",
"request",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L255-L283 | train |
hybridgroup/gobot | platforms/intel-iot/curie/imu_driver.go | NewIMUDriver | func NewIMUDriver(a *firmata.Adaptor) *IMUDriver {
imu := &IMUDriver{
name: gobot.DefaultName("CurieIMU"),
connection: a,
Eventer: gobot.NewEventer(),
}
return imu
} | go | func NewIMUDriver(a *firmata.Adaptor) *IMUDriver {
imu := &IMUDriver{
name: gobot.DefaultName("CurieIMU"),
connection: a,
Eventer: gobot.NewEventer(),
}
return imu
} | [
"func",
"NewIMUDriver",
"(",
"a",
"*",
"firmata",
".",
"Adaptor",
")",
"*",
"IMUDriver",
"{",
"imu",
":=",
"&",
"IMUDriver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"connection",
":",
"a",
",",
"Eventer",
":",
"gobot",
".",
"NewEventer",
"(",
")",
",",
"}",
"\n\n",
"return",
"imu",
"\n",
"}"
] | // NewIMUDriver returns a new IMUDriver | [
"NewIMUDriver",
"returns",
"a",
"new",
"IMUDriver"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/curie/imu_driver.go#L65-L73 | train |
hybridgroup/gobot | platforms/intel-iot/curie/imu_driver.go | Start | func (imu *IMUDriver) Start() (err error) {
imu.connection.On("SysexResponse", func(res interface{}) {
data := res.([]byte)
imu.handleEvent(data)
})
return
} | go | func (imu *IMUDriver) Start() (err error) {
imu.connection.On("SysexResponse", func(res interface{}) {
data := res.([]byte)
imu.handleEvent(data)
})
return
} | [
"func",
"(",
"imu",
"*",
"IMUDriver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"imu",
".",
"connection",
".",
"On",
"(",
"\"",
"\"",
",",
"func",
"(",
"res",
"interface",
"{",
"}",
")",
"{",
"data",
":=",
"res",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"imu",
".",
"handleEvent",
"(",
"data",
")",
"\n",
"}",
")",
"\n",
"return",
"\n",
"}"
] | // Start starts up the IMUDriver | [
"Start",
"starts",
"up",
"the",
"IMUDriver"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/curie/imu_driver.go#L76-L82 | train |
hybridgroup/gobot | platforms/intel-iot/curie/imu_driver.go | ReadAccelerometer | func (imu *IMUDriver) ReadAccelerometer() error {
return imu.connection.WriteSysex([]byte{CURIE_IMU, CURIE_IMU_READ_ACCEL})
} | go | func (imu *IMUDriver) ReadAccelerometer() error {
return imu.connection.WriteSysex([]byte{CURIE_IMU, CURIE_IMU_READ_ACCEL})
} | [
"func",
"(",
"imu",
"*",
"IMUDriver",
")",
"ReadAccelerometer",
"(",
")",
"error",
"{",
"return",
"imu",
".",
"connection",
".",
"WriteSysex",
"(",
"[",
"]",
"byte",
"{",
"CURIE_IMU",
",",
"CURIE_IMU_READ_ACCEL",
"}",
")",
"\n",
"}"
] | // ReadAccelerometer calls the Curie's built-in accelerometer. The result will
// be returned by the Sysex response message | [
"ReadAccelerometer",
"calls",
"the",
"Curie",
"s",
"built",
"-",
"in",
"accelerometer",
".",
"The",
"result",
"will",
"be",
"returned",
"by",
"the",
"Sysex",
"response",
"message"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/curie/imu_driver.go#L100-L102 | train |
hybridgroup/gobot | platforms/intel-iot/curie/imu_driver.go | ReadGyroscope | func (imu *IMUDriver) ReadGyroscope() error {
return imu.connection.WriteSysex([]byte{CURIE_IMU, CURIE_IMU_READ_GYRO})
} | go | func (imu *IMUDriver) ReadGyroscope() error {
return imu.connection.WriteSysex([]byte{CURIE_IMU, CURIE_IMU_READ_GYRO})
} | [
"func",
"(",
"imu",
"*",
"IMUDriver",
")",
"ReadGyroscope",
"(",
")",
"error",
"{",
"return",
"imu",
".",
"connection",
".",
"WriteSysex",
"(",
"[",
"]",
"byte",
"{",
"CURIE_IMU",
",",
"CURIE_IMU_READ_GYRO",
"}",
")",
"\n",
"}"
] | // ReadGyroscope calls the Curie's built-in gyroscope. The result will
// be returned by the Sysex response message | [
"ReadGyroscope",
"calls",
"the",
"Curie",
"s",
"built",
"-",
"in",
"gyroscope",
".",
"The",
"result",
"will",
"be",
"returned",
"by",
"the",
"Sysex",
"response",
"message"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/curie/imu_driver.go#L106-L108 | train |
hybridgroup/gobot | platforms/intel-iot/curie/imu_driver.go | ReadTemperature | func (imu *IMUDriver) ReadTemperature() error {
return imu.connection.WriteSysex([]byte{CURIE_IMU, CURIE_IMU_READ_TEMP})
} | go | func (imu *IMUDriver) ReadTemperature() error {
return imu.connection.WriteSysex([]byte{CURIE_IMU, CURIE_IMU_READ_TEMP})
} | [
"func",
"(",
"imu",
"*",
"IMUDriver",
")",
"ReadTemperature",
"(",
")",
"error",
"{",
"return",
"imu",
".",
"connection",
".",
"WriteSysex",
"(",
"[",
"]",
"byte",
"{",
"CURIE_IMU",
",",
"CURIE_IMU_READ_TEMP",
"}",
")",
"\n",
"}"
] | // ReadTemperature calls the Curie's built-in temperature sensor.
// The result will be returned by the Sysex response message | [
"ReadTemperature",
"calls",
"the",
"Curie",
"s",
"built",
"-",
"in",
"temperature",
"sensor",
".",
"The",
"result",
"will",
"be",
"returned",
"by",
"the",
"Sysex",
"response",
"message"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/curie/imu_driver.go#L112-L114 | train |
hybridgroup/gobot | platforms/intel-iot/curie/imu_driver.go | ReadMotion | func (imu *IMUDriver) ReadMotion() error {
return imu.connection.WriteSysex([]byte{CURIE_IMU, CURIE_IMU_READ_MOTION})
} | go | func (imu *IMUDriver) ReadMotion() error {
return imu.connection.WriteSysex([]byte{CURIE_IMU, CURIE_IMU_READ_MOTION})
} | [
"func",
"(",
"imu",
"*",
"IMUDriver",
")",
"ReadMotion",
"(",
")",
"error",
"{",
"return",
"imu",
".",
"connection",
".",
"WriteSysex",
"(",
"[",
"]",
"byte",
"{",
"CURIE_IMU",
",",
"CURIE_IMU_READ_MOTION",
"}",
")",
"\n",
"}"
] | // ReadMotion calls the Curie's built-in accelerometer & gyroscope.
// The result will be returned by the Sysex response message | [
"ReadMotion",
"calls",
"the",
"Curie",
"s",
"built",
"-",
"in",
"accelerometer",
"&",
"gyroscope",
".",
"The",
"result",
"will",
"be",
"returned",
"by",
"the",
"Sysex",
"response",
"message"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/curie/imu_driver.go#L148-L150 | train |
hybridgroup/gobot | platforms/leap/parser.go | ParseFrame | func (l *Driver) ParseFrame(data []byte) Frame {
var frame Frame
json.Unmarshal(data, &frame)
return frame
} | go | func (l *Driver) ParseFrame(data []byte) Frame {
var frame Frame
json.Unmarshal(data, &frame)
return frame
} | [
"func",
"(",
"l",
"*",
"Driver",
")",
"ParseFrame",
"(",
"data",
"[",
"]",
"byte",
")",
"Frame",
"{",
"var",
"frame",
"Frame",
"\n",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"frame",
")",
"\n",
"return",
"frame",
"\n",
"}"
] | // ParseFrame converts json data to a Frame | [
"ParseFrame",
"converts",
"json",
"data",
"to",
"a",
"Frame"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/leap/parser.go#L88-L92 | train |
hybridgroup/gobot | drivers/gpio/rgb_led_driver.go | On | func (l *RgbLedDriver) On() (err error) {
if err = l.SetLevel(l.pinRed, l.redColor); err != nil {
return
}
if err = l.SetLevel(l.pinGreen, l.greenColor); err != nil {
return
}
if err = l.SetLevel(l.pinBlue, l.blueColor); err != nil {
return
}
l.high = true
return
} | go | func (l *RgbLedDriver) On() (err error) {
if err = l.SetLevel(l.pinRed, l.redColor); err != nil {
return
}
if err = l.SetLevel(l.pinGreen, l.greenColor); err != nil {
return
}
if err = l.SetLevel(l.pinBlue, l.blueColor); err != nil {
return
}
l.high = true
return
} | [
"func",
"(",
"l",
"*",
"RgbLedDriver",
")",
"On",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"l",
".",
"SetLevel",
"(",
"l",
".",
"pinRed",
",",
"l",
".",
"redColor",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"l",
".",
"SetLevel",
"(",
"l",
".",
"pinGreen",
",",
"l",
".",
"greenColor",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"l",
".",
"SetLevel",
"(",
"l",
".",
"pinBlue",
",",
"l",
".",
"blueColor",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"l",
".",
"high",
"=",
"true",
"\n",
"return",
"\n",
"}"
] | // On sets the led's pins to their various states | [
"On",
"sets",
"the",
"led",
"s",
"pins",
"to",
"their",
"various",
"states"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/rgb_led_driver.go#L95-L110 | train |
hybridgroup/gobot | drivers/gpio/rgb_led_driver.go | Off | func (l *RgbLedDriver) Off() (err error) {
if err = l.SetLevel(l.pinRed, 0); err != nil {
return
}
if err = l.SetLevel(l.pinGreen, 0); err != nil {
return
}
if err = l.SetLevel(l.pinBlue, 0); err != nil {
return
}
l.high = false
return
} | go | func (l *RgbLedDriver) Off() (err error) {
if err = l.SetLevel(l.pinRed, 0); err != nil {
return
}
if err = l.SetLevel(l.pinGreen, 0); err != nil {
return
}
if err = l.SetLevel(l.pinBlue, 0); err != nil {
return
}
l.high = false
return
} | [
"func",
"(",
"l",
"*",
"RgbLedDriver",
")",
"Off",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"l",
".",
"SetLevel",
"(",
"l",
".",
"pinRed",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"l",
".",
"SetLevel",
"(",
"l",
".",
"pinGreen",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"l",
".",
"SetLevel",
"(",
"l",
".",
"pinBlue",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"l",
".",
"high",
"=",
"false",
"\n",
"return",
"\n",
"}"
] | // Off sets the led to black. | [
"Off",
"sets",
"the",
"led",
"to",
"black",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/rgb_led_driver.go#L113-L128 | train |
hybridgroup/gobot | drivers/gpio/rgb_led_driver.go | SetLevel | func (l *RgbLedDriver) SetLevel(pin string, level byte) (err error) {
if writer, ok := l.connection.(PwmWriter); ok {
return writer.PwmWrite(pin, level)
}
return ErrPwmWriteUnsupported
} | go | func (l *RgbLedDriver) SetLevel(pin string, level byte) (err error) {
if writer, ok := l.connection.(PwmWriter); ok {
return writer.PwmWrite(pin, level)
}
return ErrPwmWriteUnsupported
} | [
"func",
"(",
"l",
"*",
"RgbLedDriver",
")",
"SetLevel",
"(",
"pin",
"string",
",",
"level",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"writer",
",",
"ok",
":=",
"l",
".",
"connection",
".",
"(",
"PwmWriter",
")",
";",
"ok",
"{",
"return",
"writer",
".",
"PwmWrite",
"(",
"pin",
",",
"level",
")",
"\n",
"}",
"\n",
"return",
"ErrPwmWriteUnsupported",
"\n",
"}"
] | // SetLevel sets the led to the specified color level | [
"SetLevel",
"sets",
"the",
"led",
"to",
"the",
"specified",
"color",
"level"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/rgb_led_driver.go#L141-L146 | train |
hybridgroup/gobot | drivers/gpio/rgb_led_driver.go | SetRGB | func (l *RgbLedDriver) SetRGB(r, g, b byte) error {
l.redColor = r
l.greenColor = g
l.blueColor = b
return l.On()
} | go | func (l *RgbLedDriver) SetRGB(r, g, b byte) error {
l.redColor = r
l.greenColor = g
l.blueColor = b
return l.On()
} | [
"func",
"(",
"l",
"*",
"RgbLedDriver",
")",
"SetRGB",
"(",
"r",
",",
"g",
",",
"b",
"byte",
")",
"error",
"{",
"l",
".",
"redColor",
"=",
"r",
"\n",
"l",
".",
"greenColor",
"=",
"g",
"\n",
"l",
".",
"blueColor",
"=",
"b",
"\n\n",
"return",
"l",
".",
"On",
"(",
")",
"\n",
"}"
] | // SetRGB sets the Red Green Blue value of the LED. | [
"SetRGB",
"sets",
"the",
"Red",
"Green",
"Blue",
"value",
"of",
"the",
"LED",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/rgb_led_driver.go#L149-L155 | train |
hybridgroup/gobot | platforms/ble/ble_client_adaptor.go | NewClientAdaptor | func NewClientAdaptor(address string) *ClientAdaptor {
return &ClientAdaptor{
name: gobot.DefaultName("BLEClient"),
address: address,
DeviceName: "default",
connected: false,
withoutResponses: false,
}
} | go | func NewClientAdaptor(address string) *ClientAdaptor {
return &ClientAdaptor{
name: gobot.DefaultName("BLEClient"),
address: address,
DeviceName: "default",
connected: false,
withoutResponses: false,
}
} | [
"func",
"NewClientAdaptor",
"(",
"address",
"string",
")",
"*",
"ClientAdaptor",
"{",
"return",
"&",
"ClientAdaptor",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"address",
":",
"address",
",",
"DeviceName",
":",
"\"",
"\"",
",",
"connected",
":",
"false",
",",
"withoutResponses",
":",
"false",
",",
"}",
"\n",
"}"
] | // NewClientAdaptor returns a new ClientAdaptor given an address or peripheral name | [
"NewClientAdaptor",
"returns",
"a",
"new",
"ClientAdaptor",
"given",
"an",
"address",
"or",
"peripheral",
"name"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/ble_client_adaptor.go#L51-L59 | train |
hybridgroup/gobot | platforms/ble/ble_client_adaptor.go | Connect | func (b *ClientAdaptor) Connect() (err error) {
bleMutex.Lock()
defer bleMutex.Unlock()
b.device, err = getBLEDevice(b.DeviceName)
if err != nil {
return errors.Wrap(err, "can't connect to device "+b.DeviceName)
}
var cln blelib.Client
cln, err = blelib.Connect(context.Background(), filter(b.Address()))
if err != nil {
return errors.Wrap(err, "can't connect to peripheral "+b.Address())
}
b.addr = cln.Addr()
b.address = cln.Addr().String()
b.SetName(cln.Name())
b.client = cln
p, err := b.client.DiscoverProfile(true)
if err != nil {
return errors.Wrap(err, "can't discover profile")
}
b.profile = p
b.connected = true
return
} | go | func (b *ClientAdaptor) Connect() (err error) {
bleMutex.Lock()
defer bleMutex.Unlock()
b.device, err = getBLEDevice(b.DeviceName)
if err != nil {
return errors.Wrap(err, "can't connect to device "+b.DeviceName)
}
var cln blelib.Client
cln, err = blelib.Connect(context.Background(), filter(b.Address()))
if err != nil {
return errors.Wrap(err, "can't connect to peripheral "+b.Address())
}
b.addr = cln.Addr()
b.address = cln.Addr().String()
b.SetName(cln.Name())
b.client = cln
p, err := b.client.DiscoverProfile(true)
if err != nil {
return errors.Wrap(err, "can't discover profile")
}
b.profile = p
b.connected = true
return
} | [
"func",
"(",
"b",
"*",
"ClientAdaptor",
")",
"Connect",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bleMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"bleMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"b",
".",
"device",
",",
"err",
"=",
"getBLEDevice",
"(",
"b",
".",
"DeviceName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
"+",
"b",
".",
"DeviceName",
")",
"\n",
"}",
"\n\n",
"var",
"cln",
"blelib",
".",
"Client",
"\n\n",
"cln",
",",
"err",
"=",
"blelib",
".",
"Connect",
"(",
"context",
".",
"Background",
"(",
")",
",",
"filter",
"(",
"b",
".",
"Address",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
"+",
"b",
".",
"Address",
"(",
")",
")",
"\n",
"}",
"\n\n",
"b",
".",
"addr",
"=",
"cln",
".",
"Addr",
"(",
")",
"\n",
"b",
".",
"address",
"=",
"cln",
".",
"Addr",
"(",
")",
".",
"String",
"(",
")",
"\n",
"b",
".",
"SetName",
"(",
"cln",
".",
"Name",
"(",
")",
")",
"\n",
"b",
".",
"client",
"=",
"cln",
"\n\n",
"p",
",",
"err",
":=",
"b",
".",
"client",
".",
"DiscoverProfile",
"(",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"b",
".",
"profile",
"=",
"p",
"\n",
"b",
".",
"connected",
"=",
"true",
"\n",
"return",
"\n",
"}"
] | // Connect initiates a connection to the BLE peripheral. Returns true on successful connection. | [
"Connect",
"initiates",
"a",
"connection",
"to",
"the",
"BLE",
"peripheral",
".",
"Returns",
"true",
"on",
"successful",
"connection",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/ble_client_adaptor.go#L75-L104 | train |
hybridgroup/gobot | platforms/ble/ble_client_adaptor.go | Reconnect | func (b *ClientAdaptor) Reconnect() (err error) {
if b.connected {
b.Disconnect()
}
return b.Connect()
} | go | func (b *ClientAdaptor) Reconnect() (err error) {
if b.connected {
b.Disconnect()
}
return b.Connect()
} | [
"func",
"(",
"b",
"*",
"ClientAdaptor",
")",
"Reconnect",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"b",
".",
"connected",
"{",
"b",
".",
"Disconnect",
"(",
")",
"\n",
"}",
"\n",
"return",
"b",
".",
"Connect",
"(",
")",
"\n",
"}"
] | // Reconnect attempts to reconnect to the BLE peripheral. If it has an active connection
// it will first close that connection and then establish a new connection.
// Returns true on Successful reconnection | [
"Reconnect",
"attempts",
"to",
"reconnect",
"to",
"the",
"BLE",
"peripheral",
".",
"If",
"it",
"has",
"an",
"active",
"connection",
"it",
"will",
"first",
"close",
"that",
"connection",
"and",
"then",
"establish",
"a",
"new",
"connection",
".",
"Returns",
"true",
"on",
"Successful",
"reconnection"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/ble_client_adaptor.go#L109-L114 | train |
hybridgroup/gobot | platforms/ble/ble_client_adaptor.go | ReadCharacteristic | func (b *ClientAdaptor) ReadCharacteristic(cUUID string) (data []byte, err error) {
if !b.connected {
log.Fatalf("Cannot read from BLE device until connected")
return
}
uuid, _ := blelib.Parse(cUUID)
if u := b.profile.Find(blelib.NewCharacteristic(uuid)); u != nil {
data, err = b.client.ReadCharacteristic(u.(*blelib.Characteristic))
}
return
} | go | func (b *ClientAdaptor) ReadCharacteristic(cUUID string) (data []byte, err error) {
if !b.connected {
log.Fatalf("Cannot read from BLE device until connected")
return
}
uuid, _ := blelib.Parse(cUUID)
if u := b.profile.Find(blelib.NewCharacteristic(uuid)); u != nil {
data, err = b.client.ReadCharacteristic(u.(*blelib.Characteristic))
}
return
} | [
"func",
"(",
"b",
"*",
"ClientAdaptor",
")",
"ReadCharacteristic",
"(",
"cUUID",
"string",
")",
"(",
"data",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"if",
"!",
"b",
".",
"connected",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"uuid",
",",
"_",
":=",
"blelib",
".",
"Parse",
"(",
"cUUID",
")",
"\n\n",
"if",
"u",
":=",
"b",
".",
"profile",
".",
"Find",
"(",
"blelib",
".",
"NewCharacteristic",
"(",
"uuid",
")",
")",
";",
"u",
"!=",
"nil",
"{",
"data",
",",
"err",
"=",
"b",
".",
"client",
".",
"ReadCharacteristic",
"(",
"u",
".",
"(",
"*",
"blelib",
".",
"Characteristic",
")",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // ReadCharacteristic returns bytes from the BLE device for the
// requested characteristic uuid | [
"ReadCharacteristic",
"returns",
"bytes",
"from",
"the",
"BLE",
"device",
"for",
"the",
"requested",
"characteristic",
"uuid"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/ble_client_adaptor.go#L129-L142 | train |
hybridgroup/gobot | platforms/ble/ble_client_adaptor.go | Subscribe | func (b *ClientAdaptor) Subscribe(cUUID string, f func([]byte, error)) (err error) {
if !b.connected {
log.Fatalf("Cannot subscribe to BLE device until connected")
return
}
uuid, _ := blelib.Parse(cUUID)
if u := b.profile.Find(blelib.NewCharacteristic(uuid)); u != nil {
h := func(req []byte) { f(req, nil) }
err = b.client.Subscribe(u.(*blelib.Characteristic), false, h)
if err != nil {
return err
}
return nil
}
return
} | go | func (b *ClientAdaptor) Subscribe(cUUID string, f func([]byte, error)) (err error) {
if !b.connected {
log.Fatalf("Cannot subscribe to BLE device until connected")
return
}
uuid, _ := blelib.Parse(cUUID)
if u := b.profile.Find(blelib.NewCharacteristic(uuid)); u != nil {
h := func(req []byte) { f(req, nil) }
err = b.client.Subscribe(u.(*blelib.Characteristic), false, h)
if err != nil {
return err
}
return nil
}
return
} | [
"func",
"(",
"b",
"*",
"ClientAdaptor",
")",
"Subscribe",
"(",
"cUUID",
"string",
",",
"f",
"func",
"(",
"[",
"]",
"byte",
",",
"error",
")",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"b",
".",
"connected",
"{",
"log",
".",
"Fatalf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"uuid",
",",
"_",
":=",
"blelib",
".",
"Parse",
"(",
"cUUID",
")",
"\n\n",
"if",
"u",
":=",
"b",
".",
"profile",
".",
"Find",
"(",
"blelib",
".",
"NewCharacteristic",
"(",
"uuid",
")",
")",
";",
"u",
"!=",
"nil",
"{",
"h",
":=",
"func",
"(",
"req",
"[",
"]",
"byte",
")",
"{",
"f",
"(",
"req",
",",
"nil",
")",
"}",
"\n",
"err",
"=",
"b",
".",
"client",
".",
"Subscribe",
"(",
"u",
".",
"(",
"*",
"blelib",
".",
"Characteristic",
")",
",",
"false",
",",
"h",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Subscribe subscribes to notifications from the BLE device for the
// requested service and characteristic | [
"Subscribe",
"subscribes",
"to",
"notifications",
"from",
"the",
"BLE",
"device",
"for",
"the",
"requested",
"service",
"and",
"characteristic"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/ble_client_adaptor.go#L163-L181 | train |
hybridgroup/gobot | platforms/ble/ble_client_adaptor.go | getBLEDevice | func getBLEDevice(impl string) (d *blelib.Device, err error) {
if currentDevice != nil {
return currentDevice, nil
}
dev, e := defaultDevice(impl)
if e != nil {
return nil, errors.Wrap(e, "can't get device")
}
blelib.SetDefaultDevice(dev)
currentDevice = &dev
d = &dev
return
} | go | func getBLEDevice(impl string) (d *blelib.Device, err error) {
if currentDevice != nil {
return currentDevice, nil
}
dev, e := defaultDevice(impl)
if e != nil {
return nil, errors.Wrap(e, "can't get device")
}
blelib.SetDefaultDevice(dev)
currentDevice = &dev
d = &dev
return
} | [
"func",
"getBLEDevice",
"(",
"impl",
"string",
")",
"(",
"d",
"*",
"blelib",
".",
"Device",
",",
"err",
"error",
")",
"{",
"if",
"currentDevice",
"!=",
"nil",
"{",
"return",
"currentDevice",
",",
"nil",
"\n",
"}",
"\n\n",
"dev",
",",
"e",
":=",
"defaultDevice",
"(",
"impl",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"e",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"blelib",
".",
"SetDefaultDevice",
"(",
"dev",
")",
"\n\n",
"currentDevice",
"=",
"&",
"dev",
"\n",
"d",
"=",
"&",
"dev",
"\n",
"return",
"\n",
"}"
] | // getBLEDevice is singleton for blelib HCI device connection | [
"getBLEDevice",
"is",
"singleton",
"for",
"blelib",
"HCI",
"device",
"connection"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/ble_client_adaptor.go#L184-L198 | train |
hybridgroup/gobot | platforms/leap/leap_motion_adaptor.go | NewAdaptor | func NewAdaptor(port string) *Adaptor {
return &Adaptor{
name: gobot.DefaultName("LeapMotion"),
port: port,
connect: func(host string) (io.ReadWriteCloser, error) {
return websocket.Dial("ws://"+host+"/v3.json", "", "http://"+host)
},
}
} | go | func NewAdaptor(port string) *Adaptor {
return &Adaptor{
name: gobot.DefaultName("LeapMotion"),
port: port,
connect: func(host string) (io.ReadWriteCloser, error) {
return websocket.Dial("ws://"+host+"/v3.json", "", "http://"+host)
},
}
} | [
"func",
"NewAdaptor",
"(",
"port",
"string",
")",
"*",
"Adaptor",
"{",
"return",
"&",
"Adaptor",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"port",
":",
"port",
",",
"connect",
":",
"func",
"(",
"host",
"string",
")",
"(",
"io",
".",
"ReadWriteCloser",
",",
"error",
")",
"{",
"return",
"websocket",
".",
"Dial",
"(",
"\"",
"\"",
"+",
"host",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"host",
")",
"\n",
"}",
",",
"}",
"\n",
"}"
] | // NewAdaptor creates a new leap motion adaptor using specified port,
// which is this case is the host IP or name of the Leap Motion daemon | [
"NewAdaptor",
"creates",
"a",
"new",
"leap",
"motion",
"adaptor",
"using",
"specified",
"port",
"which",
"is",
"this",
"case",
"is",
"the",
"host",
"IP",
"or",
"name",
"of",
"the",
"Leap",
"Motion",
"daemon"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/leap/leap_motion_adaptor.go#L21-L29 | train |
hybridgroup/gobot | platforms/leap/leap_motion_adaptor.go | Connect | func (l *Adaptor) Connect() (err error) {
ws, e := l.connect(l.Port())
if e != nil {
return e
}
l.ws = ws
return
} | go | func (l *Adaptor) Connect() (err error) {
ws, e := l.connect(l.Port())
if e != nil {
return e
}
l.ws = ws
return
} | [
"func",
"(",
"l",
"*",
"Adaptor",
")",
"Connect",
"(",
")",
"(",
"err",
"error",
")",
"{",
"ws",
",",
"e",
":=",
"l",
".",
"connect",
"(",
"l",
".",
"Port",
"(",
")",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n\n",
"l",
".",
"ws",
"=",
"ws",
"\n",
"return",
"\n",
"}"
] | // Connect returns true if connection to leap motion is established successfully | [
"Connect",
"returns",
"true",
"if",
"connection",
"to",
"leap",
"motion",
"is",
"established",
"successfully"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/leap/leap_motion_adaptor.go#L41-L49 | train |
hybridgroup/gobot | drivers/i2c/mpl115a2_driver.go | Start | func (h *MPL115A2Driver) Start() (err error) {
if err := h.initialization(); err != nil {
return err
}
return
} | go | func (h *MPL115A2Driver) Start() (err error) {
if err := h.initialization(); err != nil {
return err
}
return
} | [
"func",
"(",
"h",
"*",
"MPL115A2Driver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
":=",
"h",
".",
"initialization",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Start writes initialization bytes and reads from adaptor
// using specified interval to accelerometer andtemperature data | [
"Start",
"writes",
"initialization",
"bytes",
"and",
"reads",
"from",
"adaptor",
"using",
"specified",
"interval",
"to",
"accelerometer",
"andtemperature",
"data"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mpl115a2_driver.go#L79-L85 | train |
hybridgroup/gobot | drivers/i2c/mpl115a2_driver.go | Pressure | func (h *MPL115A2Driver) Pressure() (p float32, err error) {
p, _, err = h.getData()
return
} | go | func (h *MPL115A2Driver) Pressure() (p float32, err error) {
p, _, err = h.getData()
return
} | [
"func",
"(",
"h",
"*",
"MPL115A2Driver",
")",
"Pressure",
"(",
")",
"(",
"p",
"float32",
",",
"err",
"error",
")",
"{",
"p",
",",
"_",
",",
"err",
"=",
"h",
".",
"getData",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // Pressure fetches the latest data from the MPL115A2, and returns the pressure | [
"Pressure",
"fetches",
"the",
"latest",
"data",
"from",
"the",
"MPL115A2",
"and",
"returns",
"the",
"pressure"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mpl115a2_driver.go#L91-L94 | train |
hybridgroup/gobot | drivers/i2c/mpl115a2_driver.go | Temperature | func (h *MPL115A2Driver) Temperature() (t float32, err error) {
_, t, err = h.getData()
return
} | go | func (h *MPL115A2Driver) Temperature() (t float32, err error) {
_, t, err = h.getData()
return
} | [
"func",
"(",
"h",
"*",
"MPL115A2Driver",
")",
"Temperature",
"(",
")",
"(",
"t",
"float32",
",",
"err",
"error",
")",
"{",
"_",
",",
"t",
",",
"err",
"=",
"h",
".",
"getData",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // Temperature fetches the latest data from the MPL115A2, and returns the temperature | [
"Temperature",
"fetches",
"the",
"latest",
"data",
"from",
"the",
"MPL115A2",
"and",
"returns",
"the",
"temperature"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mpl115a2_driver.go#L97-L100 | train |
hybridgroup/gobot | drivers/i2c/mpl115a2_driver.go | getData | func (h *MPL115A2Driver) getData() (p, t float32, err error) {
var temperature uint16
var pressure uint16
var pressureComp float32
if _, err = h.connection.Write([]byte{MPL115A2_REGISTER_STARTCONVERSION, 0}); err != nil {
return
}
time.Sleep(5 * time.Millisecond)
if _, err = h.connection.Write([]byte{MPL115A2_REGISTER_PRESSURE_MSB}); err != nil {
return
}
data := []byte{0, 0, 0, 0}
bytesRead, err1 := h.connection.Read(data)
if err1 != nil {
err = err1
return
}
if bytesRead == 4 {
buf := bytes.NewBuffer(data)
binary.Read(buf, binary.BigEndian, &pressure)
binary.Read(buf, binary.BigEndian, &temperature)
temperature = temperature >> 6
pressure = pressure >> 6
pressureComp = float32(h.A0) + (float32(h.B1)+float32(h.C12)*float32(temperature))*float32(pressure) + float32(h.B2)*float32(temperature)
p = (65.0/1023.0)*pressureComp + 50.0
t = ((float32(temperature) - 498.0) / -5.35) + 25.0
}
return
} | go | func (h *MPL115A2Driver) getData() (p, t float32, err error) {
var temperature uint16
var pressure uint16
var pressureComp float32
if _, err = h.connection.Write([]byte{MPL115A2_REGISTER_STARTCONVERSION, 0}); err != nil {
return
}
time.Sleep(5 * time.Millisecond)
if _, err = h.connection.Write([]byte{MPL115A2_REGISTER_PRESSURE_MSB}); err != nil {
return
}
data := []byte{0, 0, 0, 0}
bytesRead, err1 := h.connection.Read(data)
if err1 != nil {
err = err1
return
}
if bytesRead == 4 {
buf := bytes.NewBuffer(data)
binary.Read(buf, binary.BigEndian, &pressure)
binary.Read(buf, binary.BigEndian, &temperature)
temperature = temperature >> 6
pressure = pressure >> 6
pressureComp = float32(h.A0) + (float32(h.B1)+float32(h.C12)*float32(temperature))*float32(pressure) + float32(h.B2)*float32(temperature)
p = (65.0/1023.0)*pressureComp + 50.0
t = ((float32(temperature) - 498.0) / -5.35) + 25.0
}
return
} | [
"func",
"(",
"h",
"*",
"MPL115A2Driver",
")",
"getData",
"(",
")",
"(",
"p",
",",
"t",
"float32",
",",
"err",
"error",
")",
"{",
"var",
"temperature",
"uint16",
"\n",
"var",
"pressure",
"uint16",
"\n",
"var",
"pressureComp",
"float32",
"\n\n",
"if",
"_",
",",
"err",
"=",
"h",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"MPL115A2_REGISTER_STARTCONVERSION",
",",
"0",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"5",
"*",
"time",
".",
"Millisecond",
")",
"\n\n",
"if",
"_",
",",
"err",
"=",
"h",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"MPL115A2_REGISTER_PRESSURE_MSB",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"data",
":=",
"[",
"]",
"byte",
"{",
"0",
",",
"0",
",",
"0",
",",
"0",
"}",
"\n",
"bytesRead",
",",
"err1",
":=",
"h",
".",
"connection",
".",
"Read",
"(",
"data",
")",
"\n",
"if",
"err1",
"!=",
"nil",
"{",
"err",
"=",
"err1",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"bytesRead",
"==",
"4",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"data",
")",
"\n",
"binary",
".",
"Read",
"(",
"buf",
",",
"binary",
".",
"BigEndian",
",",
"&",
"pressure",
")",
"\n",
"binary",
".",
"Read",
"(",
"buf",
",",
"binary",
".",
"BigEndian",
",",
"&",
"temperature",
")",
"\n\n",
"temperature",
"=",
"temperature",
">>",
"6",
"\n",
"pressure",
"=",
"pressure",
">>",
"6",
"\n\n",
"pressureComp",
"=",
"float32",
"(",
"h",
".",
"A0",
")",
"+",
"(",
"float32",
"(",
"h",
".",
"B1",
")",
"+",
"float32",
"(",
"h",
".",
"C12",
")",
"*",
"float32",
"(",
"temperature",
")",
")",
"*",
"float32",
"(",
"pressure",
")",
"+",
"float32",
"(",
"h",
".",
"B2",
")",
"*",
"float32",
"(",
"temperature",
")",
"\n",
"p",
"=",
"(",
"65.0",
"/",
"1023.0",
")",
"*",
"pressureComp",
"+",
"50.0",
"\n",
"t",
"=",
"(",
"(",
"float32",
"(",
"temperature",
")",
"-",
"498.0",
")",
"/",
"-",
"5.35",
")",
"+",
"25.0",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // getData fetches the latest data from the MPL115A2 | [
"getData",
"fetches",
"the",
"latest",
"data",
"from",
"the",
"MPL115A2"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mpl115a2_driver.go#L142-L177 | train |
hybridgroup/gobot | drivers/i2c/adxl345_driver.go | Start | func (h *ADXL345Driver) Start() (err error) {
bus := h.GetBusOrDefault(h.connector.GetDefaultBus())
address := h.GetAddressOrDefault(ADXL345AddressLow)
h.connection, err = h.connector.GetConnection(address, bus)
if err != nil {
return err
}
if _, err := h.connection.Write([]byte{ADXL345_REG_BW_RATE, h.bwRate.toByte()}); err != nil {
return err
}
if _, err := h.connection.Write([]byte{ADXL345_REG_POWER_CTL, h.powerCtl.toByte()}); err != nil {
return err
}
if _, err := h.connection.Write([]byte{ADXL345_REG_DATA_FORMAT, h.dataFormat.toByte()}); err != nil {
return err
}
return
} | go | func (h *ADXL345Driver) Start() (err error) {
bus := h.GetBusOrDefault(h.connector.GetDefaultBus())
address := h.GetAddressOrDefault(ADXL345AddressLow)
h.connection, err = h.connector.GetConnection(address, bus)
if err != nil {
return err
}
if _, err := h.connection.Write([]byte{ADXL345_REG_BW_RATE, h.bwRate.toByte()}); err != nil {
return err
}
if _, err := h.connection.Write([]byte{ADXL345_REG_POWER_CTL, h.powerCtl.toByte()}); err != nil {
return err
}
if _, err := h.connection.Write([]byte{ADXL345_REG_DATA_FORMAT, h.dataFormat.toByte()}); err != nil {
return err
}
return
} | [
"func",
"(",
"h",
"*",
"ADXL345Driver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bus",
":=",
"h",
".",
"GetBusOrDefault",
"(",
"h",
".",
"connector",
".",
"GetDefaultBus",
"(",
")",
")",
"\n",
"address",
":=",
"h",
".",
"GetAddressOrDefault",
"(",
"ADXL345AddressLow",
")",
"\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",
"{",
"ADXL345_REG_BW_RATE",
",",
"h",
".",
"bwRate",
".",
"toByte",
"(",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"h",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"ADXL345_REG_POWER_CTL",
",",
"h",
".",
"powerCtl",
".",
"toByte",
"(",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"h",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"ADXL345_REG_DATA_FORMAT",
",",
"h",
".",
"dataFormat",
".",
"toByte",
"(",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Start initialized the adxl345 | [
"Start",
"initialized",
"the",
"adxl345"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adxl345_driver.go#L159-L181 | train |
hybridgroup/gobot | drivers/i2c/adxl345_driver.go | XYZ | func (h *ADXL345Driver) XYZ() (float64, float64, float64, error) {
err := h.update()
return h.x, h.y, h.z, err
} | go | func (h *ADXL345Driver) XYZ() (float64, float64, float64, error) {
err := h.update()
return h.x, h.y, h.z, err
} | [
"func",
"(",
"h",
"*",
"ADXL345Driver",
")",
"XYZ",
"(",
")",
"(",
"float64",
",",
"float64",
",",
"float64",
",",
"error",
")",
"{",
"err",
":=",
"h",
".",
"update",
"(",
")",
"\n",
"return",
"h",
".",
"x",
",",
"h",
".",
"y",
",",
"h",
".",
"z",
",",
"err",
"\n",
"}"
] | // XYZ returns the adjusted x, y and z axis from the adxl345 | [
"XYZ",
"returns",
"the",
"adjusted",
"x",
"y",
"and",
"z",
"axis",
"from",
"the",
"adxl345"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adxl345_driver.go#L203-L206 | train |
hybridgroup/gobot | drivers/i2c/adxl345_driver.go | RawXYZ | func (h *ADXL345Driver) RawXYZ() (int16, int16, int16, error) {
err := h.update()
return h.rawX, h.rawY, h.rawZ, err
} | go | func (h *ADXL345Driver) RawXYZ() (int16, int16, int16, error) {
err := h.update()
return h.rawX, h.rawY, h.rawZ, err
} | [
"func",
"(",
"h",
"*",
"ADXL345Driver",
")",
"RawXYZ",
"(",
")",
"(",
"int16",
",",
"int16",
",",
"int16",
",",
"error",
")",
"{",
"err",
":=",
"h",
".",
"update",
"(",
")",
"\n",
"return",
"h",
".",
"rawX",
",",
"h",
".",
"rawY",
",",
"h",
".",
"rawZ",
",",
"err",
"\n",
"}"
] | // XYZ returns the raw x,y and z axis from the adxl345 | [
"XYZ",
"returns",
"the",
"raw",
"x",
"y",
"and",
"z",
"axis",
"from",
"the",
"adxl345"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adxl345_driver.go#L209-L212 | train |
hybridgroup/gobot | drivers/i2c/adxl345_driver.go | SetRange | func (h *ADXL345Driver) SetRange(sensorRange byte) (err error) {
if sensorRange != ADXL345_RANGE_2G &&
sensorRange != ADXL345_RANGE_4G &&
sensorRange != ADXL345_RANGE_8G &&
sensorRange != ADXL345_RANGE_16G {
return errors.New("not a valid range")
}
h.dataFormat.sensorRange = sensorRange & 0x03
if _, err := h.connection.Write([]byte{ADXL345_REG_DATA_FORMAT, h.dataFormat.toByte()}); err != nil {
return err
}
return
} | go | func (h *ADXL345Driver) SetRange(sensorRange byte) (err error) {
if sensorRange != ADXL345_RANGE_2G &&
sensorRange != ADXL345_RANGE_4G &&
sensorRange != ADXL345_RANGE_8G &&
sensorRange != ADXL345_RANGE_16G {
return errors.New("not a valid range")
}
h.dataFormat.sensorRange = sensorRange & 0x03
if _, err := h.connection.Write([]byte{ADXL345_REG_DATA_FORMAT, h.dataFormat.toByte()}); err != nil {
return err
}
return
} | [
"func",
"(",
"h",
"*",
"ADXL345Driver",
")",
"SetRange",
"(",
"sensorRange",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"sensorRange",
"!=",
"ADXL345_RANGE_2G",
"&&",
"sensorRange",
"!=",
"ADXL345_RANGE_4G",
"&&",
"sensorRange",
"!=",
"ADXL345_RANGE_8G",
"&&",
"sensorRange",
"!=",
"ADXL345_RANGE_16G",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"h",
".",
"dataFormat",
".",
"sensorRange",
"=",
"sensorRange",
"&",
"0x03",
"\n",
"if",
"_",
",",
"err",
":=",
"h",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"ADXL345_REG_DATA_FORMAT",
",",
"h",
".",
"dataFormat",
".",
"toByte",
"(",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // SetRange change the current range of the sensor | [
"SetRange",
"change",
"the",
"current",
"range",
"of",
"the",
"sensor"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adxl345_driver.go#L266-L278 | train |
hybridgroup/gobot | drivers/i2c/adxl345_driver.go | ConvertToSI | func (d *adxl345DataFormat) ConvertToSI(rawValue int16) float64 {
switch d.sensorRange {
case ADXL345_RANGE_2G:
return float64(rawValue) * 2 / 512
case ADXL345_RANGE_4G:
return float64(rawValue) * 4 / 512
case ADXL345_RANGE_8G:
return float64(rawValue) * 8 / 512
case ADXL345_RANGE_16G:
return float64(rawValue) * 16 / 512
default:
return 0
}
} | go | func (d *adxl345DataFormat) ConvertToSI(rawValue int16) float64 {
switch d.sensorRange {
case ADXL345_RANGE_2G:
return float64(rawValue) * 2 / 512
case ADXL345_RANGE_4G:
return float64(rawValue) * 4 / 512
case ADXL345_RANGE_8G:
return float64(rawValue) * 8 / 512
case ADXL345_RANGE_16G:
return float64(rawValue) * 16 / 512
default:
return 0
}
} | [
"func",
"(",
"d",
"*",
"adxl345DataFormat",
")",
"ConvertToSI",
"(",
"rawValue",
"int16",
")",
"float64",
"{",
"switch",
"d",
".",
"sensorRange",
"{",
"case",
"ADXL345_RANGE_2G",
":",
"return",
"float64",
"(",
"rawValue",
")",
"*",
"2",
"/",
"512",
"\n",
"case",
"ADXL345_RANGE_4G",
":",
"return",
"float64",
"(",
"rawValue",
")",
"*",
"4",
"/",
"512",
"\n",
"case",
"ADXL345_RANGE_8G",
":",
"return",
"float64",
"(",
"rawValue",
")",
"*",
"8",
"/",
"512",
"\n",
"case",
"ADXL345_RANGE_16G",
":",
"return",
"float64",
"(",
"rawValue",
")",
"*",
"16",
"/",
"512",
"\n",
"default",
":",
"return",
"0",
"\n",
"}",
"\n",
"}"
] | // ConvertToSI adjusts the raw values from the adxl345 with the range configuration | [
"ConvertToSI",
"adjusts",
"the",
"raw",
"values",
"from",
"the",
"adxl345",
"with",
"the",
"range",
"configuration"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adxl345_driver.go#L281-L294 | train |
hybridgroup/gobot | drivers/i2c/adxl345_driver.go | toByte | func (p *adxl345PowerCtl) toByte() (bits uint8) {
bits = 0x00
bits = bits | (p.link << 5)
bits = bits | (p.autoSleep << 4)
bits = bits | (p.measure << 3)
bits = bits | (p.sleep << 2)
bits = bits | p.wakeUp
return bits
} | go | func (p *adxl345PowerCtl) toByte() (bits uint8) {
bits = 0x00
bits = bits | (p.link << 5)
bits = bits | (p.autoSleep << 4)
bits = bits | (p.measure << 3)
bits = bits | (p.sleep << 2)
bits = bits | p.wakeUp
return bits
} | [
"func",
"(",
"p",
"*",
"adxl345PowerCtl",
")",
"toByte",
"(",
")",
"(",
"bits",
"uint8",
")",
"{",
"bits",
"=",
"0x00",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"p",
".",
"link",
"<<",
"5",
")",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"p",
".",
"autoSleep",
"<<",
"4",
")",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"p",
".",
"measure",
"<<",
"3",
")",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"p",
".",
"sleep",
"<<",
"2",
")",
"\n",
"bits",
"=",
"bits",
"|",
"p",
".",
"wakeUp",
"\n\n",
"return",
"bits",
"\n",
"}"
] | // toByte returns a byte from the powerCtl configuration | [
"toByte",
"returns",
"a",
"byte",
"from",
"the",
"powerCtl",
"configuration"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adxl345_driver.go#L297-L306 | train |
hybridgroup/gobot | drivers/i2c/adxl345_driver.go | toByte | func (d *adxl345DataFormat) toByte() (bits uint8) {
bits = 0x00
bits = bits | (d.selfTest << 7)
bits = bits | (d.spi << 6)
bits = bits | (d.intInvert << 5)
bits = bits | (d.fullRes << 3)
bits = bits | (d.justify << 2)
bits = bits | d.sensorRange
return bits
} | go | func (d *adxl345DataFormat) toByte() (bits uint8) {
bits = 0x00
bits = bits | (d.selfTest << 7)
bits = bits | (d.spi << 6)
bits = bits | (d.intInvert << 5)
bits = bits | (d.fullRes << 3)
bits = bits | (d.justify << 2)
bits = bits | d.sensorRange
return bits
} | [
"func",
"(",
"d",
"*",
"adxl345DataFormat",
")",
"toByte",
"(",
")",
"(",
"bits",
"uint8",
")",
"{",
"bits",
"=",
"0x00",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"d",
".",
"selfTest",
"<<",
"7",
")",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"d",
".",
"spi",
"<<",
"6",
")",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"d",
".",
"intInvert",
"<<",
"5",
")",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"d",
".",
"fullRes",
"<<",
"3",
")",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"d",
".",
"justify",
"<<",
"2",
")",
"\n",
"bits",
"=",
"bits",
"|",
"d",
".",
"sensorRange",
"\n\n",
"return",
"bits",
"\n",
"}"
] | // toByte returns a byte from the dataFormat configuration | [
"toByte",
"returns",
"a",
"byte",
"from",
"the",
"dataFormat",
"configuration"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adxl345_driver.go#L309-L319 | train |
hybridgroup/gobot | drivers/i2c/adxl345_driver.go | toByte | func (b *adxl345BwRate) toByte() (bits uint8) {
bits = 0x00
bits = bits | (b.lowPower << 4)
bits = bits | b.rate
return bits
} | go | func (b *adxl345BwRate) toByte() (bits uint8) {
bits = 0x00
bits = bits | (b.lowPower << 4)
bits = bits | b.rate
return bits
} | [
"func",
"(",
"b",
"*",
"adxl345BwRate",
")",
"toByte",
"(",
")",
"(",
"bits",
"uint8",
")",
"{",
"bits",
"=",
"0x00",
"\n",
"bits",
"=",
"bits",
"|",
"(",
"b",
".",
"lowPower",
"<<",
"4",
")",
"\n",
"bits",
"=",
"bits",
"|",
"b",
".",
"rate",
"\n\n",
"return",
"bits",
"\n",
"}"
] | // toByte returns a byte from the bwRate configuration | [
"toByte",
"returns",
"a",
"byte",
"from",
"the",
"bwRate",
"configuration"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adxl345_driver.go#L322-L328 | train |
hybridgroup/gobot | drivers/i2c/pca9685_driver.go | Start | func (p *PCA9685Driver) Start() (err error) {
bus := p.GetBusOrDefault(p.connector.GetDefaultBus())
address := p.GetAddressOrDefault(pca9685Address)
p.connection, err = p.connector.GetConnection(address, bus)
if err != nil {
return err
}
if _, err := p.connection.Write([]byte{PCA9685_MODE1, 0x00}); err != nil {
return err
}
if _, err := p.connection.Write([]byte{PCA9685_ALLLED_OFF_H, 0x10}); err != nil {
return err
}
return
} | go | func (p *PCA9685Driver) Start() (err error) {
bus := p.GetBusOrDefault(p.connector.GetDefaultBus())
address := p.GetAddressOrDefault(pca9685Address)
p.connection, err = p.connector.GetConnection(address, bus)
if err != nil {
return err
}
if _, err := p.connection.Write([]byte{PCA9685_MODE1, 0x00}); err != nil {
return err
}
if _, err := p.connection.Write([]byte{PCA9685_ALLLED_OFF_H, 0x10}); err != nil {
return err
}
return
} | [
"func",
"(",
"p",
"*",
"PCA9685Driver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bus",
":=",
"p",
".",
"GetBusOrDefault",
"(",
"p",
".",
"connector",
".",
"GetDefaultBus",
"(",
")",
")",
"\n",
"address",
":=",
"p",
".",
"GetAddressOrDefault",
"(",
"pca9685Address",
")",
"\n\n",
"p",
".",
"connection",
",",
"err",
"=",
"p",
".",
"connector",
".",
"GetConnection",
"(",
"address",
",",
"bus",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"p",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"PCA9685_MODE1",
",",
"0x00",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"p",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"PCA9685_ALLLED_OFF_H",
",",
"0x10",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Start initializes the pca9685 | [
"Start",
"initializes",
"the",
"pca9685"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/pca9685_driver.go#L95-L113 | train |
hybridgroup/gobot | drivers/i2c/pca9685_driver.go | Halt | func (p *PCA9685Driver) Halt() (err error) {
_, err = p.connection.Write([]byte{PCA9685_ALLLED_OFF_H, 0x10})
return
} | go | func (p *PCA9685Driver) Halt() (err error) {
_, err = p.connection.Write([]byte{PCA9685_ALLLED_OFF_H, 0x10})
return
} | [
"func",
"(",
"p",
"*",
"PCA9685Driver",
")",
"Halt",
"(",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"p",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"PCA9685_ALLLED_OFF_H",
",",
"0x10",
"}",
")",
"\n",
"return",
"\n",
"}"
] | // Halt stops the device | [
"Halt",
"stops",
"the",
"device"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/pca9685_driver.go#L116-L119 | train |
hybridgroup/gobot | drivers/i2c/pca9685_driver.go | SetPWMFreq | func (p *PCA9685Driver) SetPWMFreq(freq float32) error {
// IC oscillator frequency is 25 MHz
var prescalevel float32 = 25000000
// Find frequency of PWM waveform
prescalevel /= 4096
// Ratio between desired frequency and maximum
prescalevel /= freq
prescalevel -= 1
// Round value to nearest whole
prescale := byte(prescalevel + 0.5)
if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1)}); err != nil {
return err
}
data := make([]byte, 1)
oldmode, err := p.connection.Read(data)
if err != nil {
return err
}
// Put oscillator in sleep mode, clear bit 7 here to avoid overwriting
// previous setting
newmode := (oldmode & 0x7F) | 0x10
if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(newmode)}); err != nil {
return err
}
// Write prescaler value
if _, err := p.connection.Write([]byte{byte(PCA9685_PRESCALE), prescale}); err != nil {
return err
}
// Put back to old settings
if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(oldmode)}); err != nil {
return err
}
time.Sleep(100 * time.Millisecond)
// Enable response to All Call address, enable auto-increment, clear restart
if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(oldmode | 0xa1)}); err != nil {
return err
}
return nil
} | go | func (p *PCA9685Driver) SetPWMFreq(freq float32) error {
// IC oscillator frequency is 25 MHz
var prescalevel float32 = 25000000
// Find frequency of PWM waveform
prescalevel /= 4096
// Ratio between desired frequency and maximum
prescalevel /= freq
prescalevel -= 1
// Round value to nearest whole
prescale := byte(prescalevel + 0.5)
if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1)}); err != nil {
return err
}
data := make([]byte, 1)
oldmode, err := p.connection.Read(data)
if err != nil {
return err
}
// Put oscillator in sleep mode, clear bit 7 here to avoid overwriting
// previous setting
newmode := (oldmode & 0x7F) | 0x10
if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(newmode)}); err != nil {
return err
}
// Write prescaler value
if _, err := p.connection.Write([]byte{byte(PCA9685_PRESCALE), prescale}); err != nil {
return err
}
// Put back to old settings
if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(oldmode)}); err != nil {
return err
}
time.Sleep(100 * time.Millisecond)
// Enable response to All Call address, enable auto-increment, clear restart
if _, err := p.connection.Write([]byte{byte(PCA9685_MODE1), byte(oldmode | 0xa1)}); err != nil {
return err
}
return nil
} | [
"func",
"(",
"p",
"*",
"PCA9685Driver",
")",
"SetPWMFreq",
"(",
"freq",
"float32",
")",
"error",
"{",
"// IC oscillator frequency is 25 MHz",
"var",
"prescalevel",
"float32",
"=",
"25000000",
"\n",
"// Find frequency of PWM waveform",
"prescalevel",
"/=",
"4096",
"\n",
"// Ratio between desired frequency and maximum",
"prescalevel",
"/=",
"freq",
"\n",
"prescalevel",
"-=",
"1",
"\n",
"// Round value to nearest whole",
"prescale",
":=",
"byte",
"(",
"prescalevel",
"+",
"0.5",
")",
"\n\n",
"if",
"_",
",",
"err",
":=",
"p",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"byte",
"(",
"PCA9685_MODE1",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1",
")",
"\n",
"oldmode",
",",
"err",
":=",
"p",
".",
"connection",
".",
"Read",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Put oscillator in sleep mode, clear bit 7 here to avoid overwriting",
"// previous setting",
"newmode",
":=",
"(",
"oldmode",
"&",
"0x7F",
")",
"|",
"0x10",
"\n",
"if",
"_",
",",
"err",
":=",
"p",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"byte",
"(",
"PCA9685_MODE1",
")",
",",
"byte",
"(",
"newmode",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Write prescaler value",
"if",
"_",
",",
"err",
":=",
"p",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"byte",
"(",
"PCA9685_PRESCALE",
")",
",",
"prescale",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Put back to old settings",
"if",
"_",
",",
"err",
":=",
"p",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"byte",
"(",
"PCA9685_MODE1",
")",
",",
"byte",
"(",
"oldmode",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"100",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"// Enable response to All Call address, enable auto-increment, clear restart",
"if",
"_",
",",
"err",
":=",
"p",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"byte",
"(",
"PCA9685_MODE1",
")",
",",
"byte",
"(",
"oldmode",
"|",
"0xa1",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // SetPWMFreq sets the PWM frequency in Hz | [
"SetPWMFreq",
"sets",
"the",
"PWM",
"frequency",
"in",
"Hz"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/pca9685_driver.go#L138-L180 | train |
hybridgroup/gobot | platforms/pebble/pebble_driver.go | PublishEvent | func (d *Driver) PublishEvent(name string, data string) {
d.Publish(d.Event(name), data)
} | go | func (d *Driver) PublishEvent(name string, data string) {
d.Publish(d.Event(name), data)
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"PublishEvent",
"(",
"name",
"string",
",",
"data",
"string",
")",
"{",
"d",
".",
"Publish",
"(",
"d",
".",
"Event",
"(",
"name",
")",
",",
"data",
")",
"\n",
"}"
] | // PublishEvent publishes event with specified name and data in gobot | [
"PublishEvent",
"publishes",
"event",
"with",
"specified",
"name",
"and",
"data",
"in",
"gobot"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/pebble/pebble_driver.go#L64-L66 | train |
hybridgroup/gobot | platforms/pebble/pebble_driver.go | SendNotification | func (d *Driver) SendNotification(message string) string {
d.Messages = append(d.Messages, message)
return message
} | go | func (d *Driver) SendNotification(message string) string {
d.Messages = append(d.Messages, message)
return message
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"SendNotification",
"(",
"message",
"string",
")",
"string",
"{",
"d",
".",
"Messages",
"=",
"append",
"(",
"d",
".",
"Messages",
",",
"message",
")",
"\n",
"return",
"message",
"\n",
"}"
] | // SendNotification appends message to list of notifications to be sent to watch | [
"SendNotification",
"appends",
"message",
"to",
"list",
"of",
"notifications",
"to",
"be",
"sent",
"to",
"watch"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/pebble/pebble_driver.go#L69-L72 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | Start | func (a *AdafruitMotorHatDriver) Start() (err error) {
bus := a.GetBusOrDefault(a.connector.GetDefaultBus())
if a.servoHatConnection, err = a.connector.GetConnection(servoHatAddress, bus); err != nil {
return
}
if err = a.startDriver(a.servoHatConnection); err != nil {
return
}
if a.motorHatConnection, err = a.connector.GetConnection(motorHatAddress, bus); err != nil {
return
}
if err = a.startDriver(a.motorHatConnection); err != nil {
return
}
return
} | go | func (a *AdafruitMotorHatDriver) Start() (err error) {
bus := a.GetBusOrDefault(a.connector.GetDefaultBus())
if a.servoHatConnection, err = a.connector.GetConnection(servoHatAddress, bus); err != nil {
return
}
if err = a.startDriver(a.servoHatConnection); err != nil {
return
}
if a.motorHatConnection, err = a.connector.GetConnection(motorHatAddress, bus); err != nil {
return
}
if err = a.startDriver(a.motorHatConnection); err != nil {
return
}
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bus",
":=",
"a",
".",
"GetBusOrDefault",
"(",
"a",
".",
"connector",
".",
"GetDefaultBus",
"(",
")",
")",
"\n\n",
"if",
"a",
".",
"servoHatConnection",
",",
"err",
"=",
"a",
".",
"connector",
".",
"GetConnection",
"(",
"servoHatAddress",
",",
"bus",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"a",
".",
"startDriver",
"(",
"a",
".",
"servoHatConnection",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"a",
".",
"motorHatConnection",
",",
"err",
"=",
"a",
".",
"connector",
".",
"GetConnection",
"(",
"motorHatAddress",
",",
"bus",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"a",
".",
"startDriver",
"(",
"a",
".",
"motorHatConnection",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Start initializes both I2C-addressable Adafruit Motor HAT drivers | [
"Start",
"initializes",
"both",
"I2C",
"-",
"addressable",
"Adafruit",
"Motor",
"HAT",
"drivers"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L201-L221 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | SetServoMotorFreq | func (a *AdafruitMotorHatDriver) SetServoMotorFreq(freq float64) (err error) {
if err = a.setPWMFreq(a.servoHatConnection, freq); err != nil {
return
}
return
} | go | func (a *AdafruitMotorHatDriver) SetServoMotorFreq(freq float64) (err error) {
if err = a.setPWMFreq(a.servoHatConnection, freq); err != nil {
return
}
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"SetServoMotorFreq",
"(",
"freq",
"float64",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"a",
".",
"setPWMFreq",
"(",
"a",
".",
"servoHatConnection",
",",
"freq",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // SetServoMotorFreq sets the frequency for the currently addressed PWM Servo HAT. | [
"SetServoMotorFreq",
"sets",
"the",
"frequency",
"for",
"the",
"currently",
"addressed",
"PWM",
"Servo",
"HAT",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L244-L249 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | SetServoMotorPulse | func (a *AdafruitMotorHatDriver) SetServoMotorPulse(channel byte, on, off int32) (err error) {
if err = a.setPWM(a.servoHatConnection, channel, on, off); err != nil {
return
}
return
} | go | func (a *AdafruitMotorHatDriver) SetServoMotorPulse(channel byte, on, off int32) (err error) {
if err = a.setPWM(a.servoHatConnection, channel, on, off); err != nil {
return
}
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"SetServoMotorPulse",
"(",
"channel",
"byte",
",",
"on",
",",
"off",
"int32",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"a",
".",
"setPWM",
"(",
"a",
".",
"servoHatConnection",
",",
"channel",
",",
"on",
",",
"off",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // SetServoMotorPulse is a convenience function to specify the 'tick' value,
// between 0-4095, when the signal will turn on, and when it will turn off. | [
"SetServoMotorPulse",
"is",
"a",
"convenience",
"function",
"to",
"specify",
"the",
"tick",
"value",
"between",
"0",
"-",
"4095",
"when",
"the",
"signal",
"will",
"turn",
"on",
"and",
"when",
"it",
"will",
"turn",
"off",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L253-L258 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | setPWMFreq | func (a *AdafruitMotorHatDriver) setPWMFreq(conn Connection, freq float64) (err error) {
// 25MHz
preScaleVal := 25000000.0
// 12-bit
preScaleVal /= 4096.0
preScaleVal /= freq
preScaleVal -= 1.0
preScale := math.Floor(preScaleVal + 0.5)
if adafruitDebug {
log.Printf("Setting PWM frequency to: %.2f Hz", freq)
log.Printf("Estimated pre-scale: %.2f", preScaleVal)
log.Printf("Final pre-scale: %.2f", preScale)
}
// default (and only) reads register 0
oldMode := []byte{0}
_, err = conn.Read(oldMode)
if err != nil {
return
}
// sleep?
if len(oldMode) > 0 {
newMode := (oldMode[0] & 0x7F) | 0x10
reg := byte(_Mode1)
if _, err = conn.Write([]byte{reg, newMode}); err != nil {
return
}
reg = byte(_Prescale)
val := byte(math.Floor(preScale))
if _, err = conn.Write([]byte{reg, val}); err != nil {
return
}
reg = byte(_Mode1)
if _, err = conn.Write([]byte{reg, oldMode[0]}); err != nil {
return
}
time.Sleep(5 * time.Millisecond)
if _, err = conn.Write([]byte{reg, (oldMode[0] | 0x80)}); err != nil {
return
}
}
return
} | go | func (a *AdafruitMotorHatDriver) setPWMFreq(conn Connection, freq float64) (err error) {
// 25MHz
preScaleVal := 25000000.0
// 12-bit
preScaleVal /= 4096.0
preScaleVal /= freq
preScaleVal -= 1.0
preScale := math.Floor(preScaleVal + 0.5)
if adafruitDebug {
log.Printf("Setting PWM frequency to: %.2f Hz", freq)
log.Printf("Estimated pre-scale: %.2f", preScaleVal)
log.Printf("Final pre-scale: %.2f", preScale)
}
// default (and only) reads register 0
oldMode := []byte{0}
_, err = conn.Read(oldMode)
if err != nil {
return
}
// sleep?
if len(oldMode) > 0 {
newMode := (oldMode[0] & 0x7F) | 0x10
reg := byte(_Mode1)
if _, err = conn.Write([]byte{reg, newMode}); err != nil {
return
}
reg = byte(_Prescale)
val := byte(math.Floor(preScale))
if _, err = conn.Write([]byte{reg, val}); err != nil {
return
}
reg = byte(_Mode1)
if _, err = conn.Write([]byte{reg, oldMode[0]}); err != nil {
return
}
time.Sleep(5 * time.Millisecond)
if _, err = conn.Write([]byte{reg, (oldMode[0] | 0x80)}); err != nil {
return
}
}
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"setPWMFreq",
"(",
"conn",
"Connection",
",",
"freq",
"float64",
")",
"(",
"err",
"error",
")",
"{",
"// 25MHz",
"preScaleVal",
":=",
"25000000.0",
"\n",
"// 12-bit",
"preScaleVal",
"/=",
"4096.0",
"\n",
"preScaleVal",
"/=",
"freq",
"\n",
"preScaleVal",
"-=",
"1.0",
"\n",
"preScale",
":=",
"math",
".",
"Floor",
"(",
"preScaleVal",
"+",
"0.5",
")",
"\n",
"if",
"adafruitDebug",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"freq",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"preScaleVal",
")",
"\n",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"preScale",
")",
"\n",
"}",
"\n",
"// default (and only) reads register 0",
"oldMode",
":=",
"[",
"]",
"byte",
"{",
"0",
"}",
"\n",
"_",
",",
"err",
"=",
"conn",
".",
"Read",
"(",
"oldMode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// sleep?",
"if",
"len",
"(",
"oldMode",
")",
">",
"0",
"{",
"newMode",
":=",
"(",
"oldMode",
"[",
"0",
"]",
"&",
"0x7F",
")",
"|",
"0x10",
"\n",
"reg",
":=",
"byte",
"(",
"_Mode1",
")",
"\n",
"if",
"_",
",",
"err",
"=",
"conn",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"reg",
",",
"newMode",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"reg",
"=",
"byte",
"(",
"_Prescale",
")",
"\n",
"val",
":=",
"byte",
"(",
"math",
".",
"Floor",
"(",
"preScale",
")",
")",
"\n",
"if",
"_",
",",
"err",
"=",
"conn",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"reg",
",",
"val",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"reg",
"=",
"byte",
"(",
"_Mode1",
")",
"\n",
"if",
"_",
",",
"err",
"=",
"conn",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"reg",
",",
"oldMode",
"[",
"0",
"]",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"5",
"*",
"time",
".",
"Millisecond",
")",
"\n",
"if",
"_",
",",
"err",
"=",
"conn",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"reg",
",",
"(",
"oldMode",
"[",
"0",
"]",
"|",
"0x80",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // setPWMFreq adjusts the PWM frequency which determines how many full
// pulses per second are generated by the integrated circuit. The frequency
// determines how "long" each pulse is in duration from start to finish,
// taking into account the high and low segments of the pulse. | [
"setPWMFreq",
"adjusts",
"the",
"PWM",
"frequency",
"which",
"determines",
"how",
"many",
"full",
"pulses",
"per",
"second",
"are",
"generated",
"by",
"the",
"integrated",
"circuit",
".",
"The",
"frequency",
"determines",
"how",
"long",
"each",
"pulse",
"is",
"in",
"duration",
"from",
"start",
"to",
"finish",
"taking",
"into",
"account",
"the",
"high",
"and",
"low",
"segments",
"of",
"the",
"pulse",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L264-L305 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | setAllPWM | func (a *AdafruitMotorHatDriver) setAllPWM(conn Connection, on, off int32) (err error) {
// register and values to be written to that register
regVals := make(map[int][]byte)
regVals[0] = []byte{byte(_AllLedOnL), byte(on & 0xff)}
regVals[1] = []byte{byte(_AllLedOnH), byte(on >> 8)}
regVals[2] = []byte{byte(_AllLedOffL), byte(off & 0xFF)}
regVals[3] = []byte{byte(_AllLedOffH), byte(off >> 8)}
for i := 0; i < len(regVals); i++ {
if _, err = conn.Write(regVals[i]); err != nil {
return
}
}
return
} | go | func (a *AdafruitMotorHatDriver) setAllPWM(conn Connection, on, off int32) (err error) {
// register and values to be written to that register
regVals := make(map[int][]byte)
regVals[0] = []byte{byte(_AllLedOnL), byte(on & 0xff)}
regVals[1] = []byte{byte(_AllLedOnH), byte(on >> 8)}
regVals[2] = []byte{byte(_AllLedOffL), byte(off & 0xFF)}
regVals[3] = []byte{byte(_AllLedOffH), byte(off >> 8)}
for i := 0; i < len(regVals); i++ {
if _, err = conn.Write(regVals[i]); err != nil {
return
}
}
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"setAllPWM",
"(",
"conn",
"Connection",
",",
"on",
",",
"off",
"int32",
")",
"(",
"err",
"error",
")",
"{",
"// register and values to be written to that register",
"regVals",
":=",
"make",
"(",
"map",
"[",
"int",
"]",
"[",
"]",
"byte",
")",
"\n",
"regVals",
"[",
"0",
"]",
"=",
"[",
"]",
"byte",
"{",
"byte",
"(",
"_AllLedOnL",
")",
",",
"byte",
"(",
"on",
"&",
"0xff",
")",
"}",
"\n",
"regVals",
"[",
"1",
"]",
"=",
"[",
"]",
"byte",
"{",
"byte",
"(",
"_AllLedOnH",
")",
",",
"byte",
"(",
"on",
">>",
"8",
")",
"}",
"\n",
"regVals",
"[",
"2",
"]",
"=",
"[",
"]",
"byte",
"{",
"byte",
"(",
"_AllLedOffL",
")",
",",
"byte",
"(",
"off",
"&",
"0xFF",
")",
"}",
"\n",
"regVals",
"[",
"3",
"]",
"=",
"[",
"]",
"byte",
"{",
"byte",
"(",
"_AllLedOffH",
")",
",",
"byte",
"(",
"off",
">>",
"8",
")",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"regVals",
")",
";",
"i",
"++",
"{",
"if",
"_",
",",
"err",
"=",
"conn",
".",
"Write",
"(",
"regVals",
"[",
"i",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // setAllPWM sets all PWM channels for the given address | [
"setAllPWM",
"sets",
"all",
"PWM",
"channels",
"for",
"the",
"given",
"address"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L308-L321 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | SetDCMotorSpeed | func (a *AdafruitMotorHatDriver) SetDCMotorSpeed(dcMotor int, speed int32) (err error) {
if err = a.setPWM(a.motorHatConnection, a.dcMotors[dcMotor].pwmPin, 0, speed*16); err != nil {
return
}
return
} | go | func (a *AdafruitMotorHatDriver) SetDCMotorSpeed(dcMotor int, speed int32) (err error) {
if err = a.setPWM(a.motorHatConnection, a.dcMotors[dcMotor].pwmPin, 0, speed*16); err != nil {
return
}
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"SetDCMotorSpeed",
"(",
"dcMotor",
"int",
",",
"speed",
"int32",
")",
"(",
"err",
"error",
")",
"{",
"if",
"err",
"=",
"a",
".",
"setPWM",
"(",
"a",
".",
"motorHatConnection",
",",
"a",
".",
"dcMotors",
"[",
"dcMotor",
"]",
".",
"pwmPin",
",",
"0",
",",
"speed",
"*",
"16",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // SetDCMotorSpeed will set the appropriate pins to run the specified DC motor
// for the given speed. | [
"SetDCMotorSpeed",
"will",
"set",
"the",
"appropriate",
"pins",
"to",
"run",
"the",
"specified",
"DC",
"motor",
"for",
"the",
"given",
"speed",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L335-L340 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | RunDCMotor | func (a *AdafruitMotorHatDriver) RunDCMotor(dcMotor int, dir AdafruitDirection) (err error) {
switch {
case dir == AdafruitForward:
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in2Pin, 0); err != nil {
return
}
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in1Pin, 1); err != nil {
return
}
case dir == AdafruitBackward:
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in1Pin, 0); err != nil {
return
}
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in2Pin, 1); err != nil {
return
}
case dir == AdafruitRelease:
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in1Pin, 0); err != nil {
return
}
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in2Pin, 0); err != nil {
return
}
}
return
} | go | func (a *AdafruitMotorHatDriver) RunDCMotor(dcMotor int, dir AdafruitDirection) (err error) {
switch {
case dir == AdafruitForward:
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in2Pin, 0); err != nil {
return
}
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in1Pin, 1); err != nil {
return
}
case dir == AdafruitBackward:
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in1Pin, 0); err != nil {
return
}
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in2Pin, 1); err != nil {
return
}
case dir == AdafruitRelease:
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in1Pin, 0); err != nil {
return
}
if err = a.setPin(a.motorHatConnection, a.dcMotors[dcMotor].in2Pin, 0); err != nil {
return
}
}
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"RunDCMotor",
"(",
"dcMotor",
"int",
",",
"dir",
"AdafruitDirection",
")",
"(",
"err",
"error",
")",
"{",
"switch",
"{",
"case",
"dir",
"==",
"AdafruitForward",
":",
"if",
"err",
"=",
"a",
".",
"setPin",
"(",
"a",
".",
"motorHatConnection",
",",
"a",
".",
"dcMotors",
"[",
"dcMotor",
"]",
".",
"in2Pin",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"a",
".",
"setPin",
"(",
"a",
".",
"motorHatConnection",
",",
"a",
".",
"dcMotors",
"[",
"dcMotor",
"]",
".",
"in1Pin",
",",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"case",
"dir",
"==",
"AdafruitBackward",
":",
"if",
"err",
"=",
"a",
".",
"setPin",
"(",
"a",
".",
"motorHatConnection",
",",
"a",
".",
"dcMotors",
"[",
"dcMotor",
"]",
".",
"in1Pin",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"a",
".",
"setPin",
"(",
"a",
".",
"motorHatConnection",
",",
"a",
".",
"dcMotors",
"[",
"dcMotor",
"]",
".",
"in2Pin",
",",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"case",
"dir",
"==",
"AdafruitRelease",
":",
"if",
"err",
"=",
"a",
".",
"setPin",
"(",
"a",
".",
"motorHatConnection",
",",
"a",
".",
"dcMotors",
"[",
"dcMotor",
"]",
".",
"in1Pin",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"err",
"=",
"a",
".",
"setPin",
"(",
"a",
".",
"motorHatConnection",
",",
"a",
".",
"dcMotors",
"[",
"dcMotor",
"]",
".",
"in2Pin",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // RunDCMotor will set the appropriate pins to run the specified DC motor for
// the given direction | [
"RunDCMotor",
"will",
"set",
"the",
"appropriate",
"pins",
"to",
"run",
"the",
"specified",
"DC",
"motor",
"for",
"the",
"given",
"direction"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L344-L370 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | SetStepperMotorSpeed | func (a *AdafruitMotorHatDriver) SetStepperMotorSpeed(stepperMotor int, rpm int) (err error) {
revSteps := a.stepperMotors[stepperMotor].revSteps
a.stepperMotors[stepperMotor].secPerStep = 60.0 / float64(revSteps*rpm)
a.stepperMotors[stepperMotor].stepCounter = 0
return
} | go | func (a *AdafruitMotorHatDriver) SetStepperMotorSpeed(stepperMotor int, rpm int) (err error) {
revSteps := a.stepperMotors[stepperMotor].revSteps
a.stepperMotors[stepperMotor].secPerStep = 60.0 / float64(revSteps*rpm)
a.stepperMotors[stepperMotor].stepCounter = 0
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"SetStepperMotorSpeed",
"(",
"stepperMotor",
"int",
",",
"rpm",
"int",
")",
"(",
"err",
"error",
")",
"{",
"revSteps",
":=",
"a",
".",
"stepperMotors",
"[",
"stepperMotor",
"]",
".",
"revSteps",
"\n",
"a",
".",
"stepperMotors",
"[",
"stepperMotor",
"]",
".",
"secPerStep",
"=",
"60.0",
"/",
"float64",
"(",
"revSteps",
"*",
"rpm",
")",
"\n",
"a",
".",
"stepperMotors",
"[",
"stepperMotor",
"]",
".",
"stepCounter",
"=",
"0",
"\n",
"return",
"\n",
"}"
] | // SetStepperMotorSpeed sets the seconds-per-step for the given Stepper Motor. | [
"SetStepperMotorSpeed",
"sets",
"the",
"seconds",
"-",
"per",
"-",
"step",
"for",
"the",
"given",
"Stepper",
"Motor",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L493-L498 | train |
hybridgroup/gobot | drivers/i2c/adafruit_driver.go | Step | func (a *AdafruitMotorHatDriver) Step(motor, steps int, dir AdafruitDirection, style AdafruitStepStyle) (err error) {
secPerStep := a.stepperMotors[motor].secPerStep
latestStep := 0
if style == AdafruitInterleave {
secPerStep = secPerStep / 2.0
}
if style == AdafruitMicrostep {
secPerStep /= float64(stepperMicrosteps)
steps *= stepperMicrosteps
}
if adafruitDebug {
log.Printf("[adafruit_driver] %f seconds per step", secPerStep)
}
for i := 0; i < steps; i++ {
if latestStep, err = a.oneStep(motor, dir, style); err != nil {
return
}
time.Sleep(time.Duration(secPerStep) * time.Second)
}
// As documented in the Adafruit python driver:
// This is an edge case, if we are in between full steps, keep going to end on a full step
if style == AdafruitMicrostep {
for latestStep != 0 && latestStep != stepperMicrosteps {
if latestStep, err = a.oneStep(motor, dir, style); err != nil {
return
}
time.Sleep(time.Duration(secPerStep) * time.Second)
}
}
return
} | go | func (a *AdafruitMotorHatDriver) Step(motor, steps int, dir AdafruitDirection, style AdafruitStepStyle) (err error) {
secPerStep := a.stepperMotors[motor].secPerStep
latestStep := 0
if style == AdafruitInterleave {
secPerStep = secPerStep / 2.0
}
if style == AdafruitMicrostep {
secPerStep /= float64(stepperMicrosteps)
steps *= stepperMicrosteps
}
if adafruitDebug {
log.Printf("[adafruit_driver] %f seconds per step", secPerStep)
}
for i := 0; i < steps; i++ {
if latestStep, err = a.oneStep(motor, dir, style); err != nil {
return
}
time.Sleep(time.Duration(secPerStep) * time.Second)
}
// As documented in the Adafruit python driver:
// This is an edge case, if we are in between full steps, keep going to end on a full step
if style == AdafruitMicrostep {
for latestStep != 0 && latestStep != stepperMicrosteps {
if latestStep, err = a.oneStep(motor, dir, style); err != nil {
return
}
time.Sleep(time.Duration(secPerStep) * time.Second)
}
}
return
} | [
"func",
"(",
"a",
"*",
"AdafruitMotorHatDriver",
")",
"Step",
"(",
"motor",
",",
"steps",
"int",
",",
"dir",
"AdafruitDirection",
",",
"style",
"AdafruitStepStyle",
")",
"(",
"err",
"error",
")",
"{",
"secPerStep",
":=",
"a",
".",
"stepperMotors",
"[",
"motor",
"]",
".",
"secPerStep",
"\n",
"latestStep",
":=",
"0",
"\n",
"if",
"style",
"==",
"AdafruitInterleave",
"{",
"secPerStep",
"=",
"secPerStep",
"/",
"2.0",
"\n",
"}",
"\n",
"if",
"style",
"==",
"AdafruitMicrostep",
"{",
"secPerStep",
"/=",
"float64",
"(",
"stepperMicrosteps",
")",
"\n",
"steps",
"*=",
"stepperMicrosteps",
"\n",
"}",
"\n",
"if",
"adafruitDebug",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"secPerStep",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"steps",
";",
"i",
"++",
"{",
"if",
"latestStep",
",",
"err",
"=",
"a",
".",
"oneStep",
"(",
"motor",
",",
"dir",
",",
"style",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Duration",
"(",
"secPerStep",
")",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"// As documented in the Adafruit python driver:",
"// This is an edge case, if we are in between full steps, keep going to end on a full step",
"if",
"style",
"==",
"AdafruitMicrostep",
"{",
"for",
"latestStep",
"!=",
"0",
"&&",
"latestStep",
"!=",
"stepperMicrosteps",
"{",
"if",
"latestStep",
",",
"err",
"=",
"a",
".",
"oneStep",
"(",
"motor",
",",
"dir",
",",
"style",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Duration",
"(",
"secPerStep",
")",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Step will rotate the stepper motor the given number of steps, in the given direction and step style. | [
"Step",
"will",
"rotate",
"the",
"stepper",
"motor",
"the",
"given",
"number",
"of",
"steps",
"in",
"the",
"given",
"direction",
"and",
"step",
"style",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/adafruit_driver.go#L501-L531 | train |
hybridgroup/gobot | platforms/digispark/digispark_i2c.go | NewDigisparkI2cConnection | func NewDigisparkI2cConnection(adaptor *Adaptor, address uint8) (connection *digisparkI2cConnection) {
return &digisparkI2cConnection{adaptor: adaptor, address: address}
} | go | func NewDigisparkI2cConnection(adaptor *Adaptor, address uint8) (connection *digisparkI2cConnection) {
return &digisparkI2cConnection{adaptor: adaptor, address: address}
} | [
"func",
"NewDigisparkI2cConnection",
"(",
"adaptor",
"*",
"Adaptor",
",",
"address",
"uint8",
")",
"(",
"connection",
"*",
"digisparkI2cConnection",
")",
"{",
"return",
"&",
"digisparkI2cConnection",
"{",
"adaptor",
":",
"adaptor",
",",
"address",
":",
"address",
"}",
"\n",
"}"
] | // NewDigisparkI2cConnection creates an i2c connection to an i2c device at
// the specified address | [
"NewDigisparkI2cConnection",
"creates",
"an",
"i2c",
"connection",
"to",
"an",
"i2c",
"device",
"at",
"the",
"specified",
"address"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/digispark/digispark_i2c.go#L14-L16 | train |
hybridgroup/gobot | platforms/digispark/digispark_i2c.go | Init | func (c *digisparkI2cConnection) Init() (err error) {
if !c.adaptor.i2c {
if err = c.adaptor.littleWire.i2cInit(); err != nil {
return
}
c.adaptor.i2c = true
}
return
} | go | func (c *digisparkI2cConnection) Init() (err error) {
if !c.adaptor.i2c {
if err = c.adaptor.littleWire.i2cInit(); err != nil {
return
}
c.adaptor.i2c = true
}
return
} | [
"func",
"(",
"c",
"*",
"digisparkI2cConnection",
")",
"Init",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"!",
"c",
".",
"adaptor",
".",
"i2c",
"{",
"if",
"err",
"=",
"c",
".",
"adaptor",
".",
"littleWire",
".",
"i2cInit",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"c",
".",
"adaptor",
".",
"i2c",
"=",
"true",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Init makes sure that the i2c device is already initialized | [
"Init",
"makes",
"sure",
"that",
"the",
"i2c",
"device",
"is",
"already",
"initialized"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/digispark/digispark_i2c.go#L19-L27 | train |
hybridgroup/gobot | platforms/digispark/digispark_i2c.go | UpdateDelay | func (c *digisparkI2cConnection) UpdateDelay(duration uint) error {
if !c.adaptor.i2c {
return errors.New("Digispark i2c not initialized")
}
return c.adaptor.littleWire.i2cUpdateDelay(duration)
} | go | func (c *digisparkI2cConnection) UpdateDelay(duration uint) error {
if !c.adaptor.i2c {
return errors.New("Digispark i2c not initialized")
}
return c.adaptor.littleWire.i2cUpdateDelay(duration)
} | [
"func",
"(",
"c",
"*",
"digisparkI2cConnection",
")",
"UpdateDelay",
"(",
"duration",
"uint",
")",
"error",
"{",
"if",
"!",
"c",
".",
"adaptor",
".",
"i2c",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"adaptor",
".",
"littleWire",
".",
"i2cUpdateDelay",
"(",
"duration",
")",
"\n",
"}"
] | // UpdateDelay updates i2c signal delay amount; tune if neccessary to fit your requirements | [
"UpdateDelay",
"updates",
"i2c",
"signal",
"delay",
"amount",
";",
"tune",
"if",
"neccessary",
"to",
"fit",
"your",
"requirements"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/digispark/digispark_i2c.go#L38-L43 | train |
hybridgroup/gobot | platforms/microbit/button_driver.go | NewButtonDriver | func NewButtonDriver(a ble.BLEConnector) *ButtonDriver {
n := &ButtonDriver{
name: gobot.DefaultName("Microbit Button"),
connection: a,
Eventer: gobot.NewEventer(),
}
n.AddEvent(ButtonA)
n.AddEvent(ButtonB)
return n
} | go | func NewButtonDriver(a ble.BLEConnector) *ButtonDriver {
n := &ButtonDriver{
name: gobot.DefaultName("Microbit Button"),
connection: a,
Eventer: gobot.NewEventer(),
}
n.AddEvent(ButtonA)
n.AddEvent(ButtonB)
return n
} | [
"func",
"NewButtonDriver",
"(",
"a",
"ble",
".",
"BLEConnector",
")",
"*",
"ButtonDriver",
"{",
"n",
":=",
"&",
"ButtonDriver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"connection",
":",
"a",
",",
"Eventer",
":",
"gobot",
".",
"NewEventer",
"(",
")",
",",
"}",
"\n\n",
"n",
".",
"AddEvent",
"(",
"ButtonA",
")",
"\n",
"n",
".",
"AddEvent",
"(",
"ButtonB",
")",
"\n\n",
"return",
"n",
"\n",
"}"
] | // NewButtonDriver creates a Microbit ButtonDriver | [
"NewButtonDriver",
"creates",
"a",
"Microbit",
"ButtonDriver"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/button_driver.go#L31-L42 | train |
hybridgroup/gobot | platforms/microbit/temperature_driver.go | NewTemperatureDriver | func NewTemperatureDriver(a ble.BLEConnector) *TemperatureDriver {
n := &TemperatureDriver{
name: gobot.DefaultName("Microbit Temperature"),
connection: a,
Eventer: gobot.NewEventer(),
}
n.AddEvent(Temperature)
return n
} | go | func NewTemperatureDriver(a ble.BLEConnector) *TemperatureDriver {
n := &TemperatureDriver{
name: gobot.DefaultName("Microbit Temperature"),
connection: a,
Eventer: gobot.NewEventer(),
}
n.AddEvent(Temperature)
return n
} | [
"func",
"NewTemperatureDriver",
"(",
"a",
"ble",
".",
"BLEConnector",
")",
"*",
"TemperatureDriver",
"{",
"n",
":=",
"&",
"TemperatureDriver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"connection",
":",
"a",
",",
"Eventer",
":",
"gobot",
".",
"NewEventer",
"(",
")",
",",
"}",
"\n\n",
"n",
".",
"AddEvent",
"(",
"Temperature",
")",
"\n\n",
"return",
"n",
"\n",
"}"
] | // NewTemperatureDriver creates a Microbit TemperatureDriver | [
"NewTemperatureDriver",
"creates",
"a",
"Microbit",
"TemperatureDriver"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/temperature_driver.go#L29-L39 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | TakeOff | func (a *Driver) TakeOff() {
a.Publish(a.Event("flying"), a.adaptor().drone.TakeOff())
} | go | func (a *Driver) TakeOff() {
a.Publish(a.Event("flying"), a.adaptor().drone.TakeOff())
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"TakeOff",
"(",
")",
"{",
"a",
".",
"Publish",
"(",
"a",
".",
"Event",
"(",
"\"",
"\"",
")",
",",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"TakeOff",
"(",
")",
")",
"\n",
"}"
] | // TakeOff makes the drone start flying | [
"TakeOff",
"makes",
"the",
"drone",
"start",
"flying"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L55-L57 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | Up | func (a *Driver) Up(speed int) {
a.adaptor().drone.Up(speed)
} | go | func (a *Driver) Up(speed int) {
a.adaptor().drone.Up(speed)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Up",
"(",
"speed",
"int",
")",
"{",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"Up",
"(",
"speed",
")",
"\n",
"}"
] | // Up makes the drone gain altitude.
// speed can be a value from `0` to `100`. | [
"Up",
"makes",
"the",
"drone",
"gain",
"altitude",
".",
"speed",
"can",
"be",
"a",
"value",
"from",
"0",
"to",
"100",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L66-L68 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | Down | func (a *Driver) Down(speed int) {
a.adaptor().drone.Down(speed)
} | go | func (a *Driver) Down(speed int) {
a.adaptor().drone.Down(speed)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Down",
"(",
"speed",
"int",
")",
"{",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"Down",
"(",
"speed",
")",
"\n",
"}"
] | // Down makes the drone reduce altitude.
// speed can be a value from `0` to `100`. | [
"Down",
"makes",
"the",
"drone",
"reduce",
"altitude",
".",
"speed",
"can",
"be",
"a",
"value",
"from",
"0",
"to",
"100",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L72-L74 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | Left | func (a *Driver) Left(speed int) {
a.adaptor().drone.Left(speed)
} | go | func (a *Driver) Left(speed int) {
a.adaptor().drone.Left(speed)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Left",
"(",
"speed",
"int",
")",
"{",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"Left",
"(",
"speed",
")",
"\n",
"}"
] | // Left causes the drone to bank to the left, controls the roll, which is
// a horizontal movement using the camera as a reference point.
// speed can be a value from `0` to `100`. | [
"Left",
"causes",
"the",
"drone",
"to",
"bank",
"to",
"the",
"left",
"controls",
"the",
"roll",
"which",
"is",
"a",
"horizontal",
"movement",
"using",
"the",
"camera",
"as",
"a",
"reference",
"point",
".",
"speed",
"can",
"be",
"a",
"value",
"from",
"0",
"to",
"100",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L79-L81 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | Right | func (a *Driver) Right(speed int) {
a.adaptor().drone.Right(speed)
} | go | func (a *Driver) Right(speed int) {
a.adaptor().drone.Right(speed)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Right",
"(",
"speed",
"int",
")",
"{",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"Right",
"(",
"speed",
")",
"\n",
"}"
] | // Right causes the drone to bank to the right, controls the roll, which is
// a horizontal movement using the camera as a reference point.
// speed can be a value from `0` to `100`. | [
"Right",
"causes",
"the",
"drone",
"to",
"bank",
"to",
"the",
"right",
"controls",
"the",
"roll",
"which",
"is",
"a",
"horizontal",
"movement",
"using",
"the",
"camera",
"as",
"a",
"reference",
"point",
".",
"speed",
"can",
"be",
"a",
"value",
"from",
"0",
"to",
"100",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L86-L88 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | Forward | func (a *Driver) Forward(speed int) {
a.adaptor().drone.Forward(speed)
} | go | func (a *Driver) Forward(speed int) {
a.adaptor().drone.Forward(speed)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Forward",
"(",
"speed",
"int",
")",
"{",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"Forward",
"(",
"speed",
")",
"\n",
"}"
] | // Forward causes the drone go forward, controls the pitch.
// speed can be a value from `0` to `100`. | [
"Forward",
"causes",
"the",
"drone",
"go",
"forward",
"controls",
"the",
"pitch",
".",
"speed",
"can",
"be",
"a",
"value",
"from",
"0",
"to",
"100",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L92-L94 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | Backward | func (a *Driver) Backward(speed int) {
a.adaptor().drone.Backward(speed)
} | go | func (a *Driver) Backward(speed int) {
a.adaptor().drone.Backward(speed)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Backward",
"(",
"speed",
"int",
")",
"{",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"Backward",
"(",
"speed",
")",
"\n",
"}"
] | // Backward causes the drone go forward, controls the pitch.
// speed can be a value from `0` to `100`. | [
"Backward",
"causes",
"the",
"drone",
"go",
"forward",
"controls",
"the",
"pitch",
".",
"speed",
"can",
"be",
"a",
"value",
"from",
"0",
"to",
"100",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L98-L100 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | Clockwise | func (a *Driver) Clockwise(speed int) {
a.adaptor().drone.Clockwise(speed)
} | go | func (a *Driver) Clockwise(speed int) {
a.adaptor().drone.Clockwise(speed)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Clockwise",
"(",
"speed",
"int",
")",
"{",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"Clockwise",
"(",
"speed",
")",
"\n",
"}"
] | // Clockwise causes the drone to spin in clockwise direction
// speed can be a value from `0` to `100`. | [
"Clockwise",
"causes",
"the",
"drone",
"to",
"spin",
"in",
"clockwise",
"direction",
"speed",
"can",
"be",
"a",
"value",
"from",
"0",
"to",
"100",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L104-L106 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | CounterClockwise | func (a *Driver) CounterClockwise(speed int) {
a.adaptor().drone.CounterClockwise(speed)
} | go | func (a *Driver) CounterClockwise(speed int) {
a.adaptor().drone.CounterClockwise(speed)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"CounterClockwise",
"(",
"speed",
"int",
")",
"{",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"CounterClockwise",
"(",
"speed",
")",
"\n",
"}"
] | // CounterClockwise the drone to spin in counter clockwise direction
// speed can be a value from `0` to `100`. | [
"CounterClockwise",
"the",
"drone",
"to",
"spin",
"in",
"counter",
"clockwise",
"direction",
"speed",
"can",
"be",
"a",
"value",
"from",
"0",
"to",
"100",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L110-L112 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | Outdoor | func (a *Driver) Outdoor(outdoor bool) error {
return a.adaptor().drone.Outdoor(outdoor)
} | go | func (a *Driver) Outdoor(outdoor bool) error {
return a.adaptor().drone.Outdoor(outdoor)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"Outdoor",
"(",
"outdoor",
"bool",
")",
"error",
"{",
"return",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"Outdoor",
"(",
"outdoor",
")",
"\n",
"}"
] | // Outdoor tells the drone if flying Outdoor or not. This is needed to adjust flight characteristics of the Bebop. | [
"Outdoor",
"tells",
"the",
"drone",
"if",
"flying",
"Outdoor",
"or",
"not",
".",
"This",
"is",
"needed",
"to",
"adjust",
"flight",
"characteristics",
"of",
"the",
"Bebop",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L140-L142 | train |
hybridgroup/gobot | platforms/parrot/bebop/bebop_driver.go | VideoStreamMode | func (a *Driver) VideoStreamMode(mode int8) error {
return a.adaptor().drone.VideoStreamMode(mode)
} | go | func (a *Driver) VideoStreamMode(mode int8) error {
return a.adaptor().drone.VideoStreamMode(mode)
} | [
"func",
"(",
"a",
"*",
"Driver",
")",
"VideoStreamMode",
"(",
"mode",
"int8",
")",
"error",
"{",
"return",
"a",
".",
"adaptor",
"(",
")",
".",
"drone",
".",
"VideoStreamMode",
"(",
"mode",
")",
"\n",
"}"
] | // VideoStreamMode tells the drone what mode to use for streaming video | [
"VideoStreamMode",
"tells",
"the",
"drone",
"what",
"mode",
"to",
"use",
"for",
"streaming",
"video"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_driver.go#L150-L152 | train |
hybridgroup/gobot | api/cors.go | AllowRequestsFrom | func AllowRequestsFrom(allowedOrigins ...string) http.HandlerFunc {
c := &CORS{
AllowOrigins: allowedOrigins,
AllowMethods: []string{"GET", "POST"},
AllowHeaders: []string{"Origin", "Content-Type"},
ContentType: "application/json; charset=utf-8",
}
c.generatePatterns()
return func(w http.ResponseWriter, req *http.Request) {
origin := req.Header.Get("Origin")
if c.isOriginAllowed(origin) {
w.Header().Set("Access-Control-Allow-Origin", origin)
w.Header().Set("Access-Control-Allow-Headers", c.AllowedHeaders())
w.Header().Set("Access-Control-Allow-Methods", c.AllowedMethods())
w.Header().Set("Content-Type", c.ContentType)
}
}
} | go | func AllowRequestsFrom(allowedOrigins ...string) http.HandlerFunc {
c := &CORS{
AllowOrigins: allowedOrigins,
AllowMethods: []string{"GET", "POST"},
AllowHeaders: []string{"Origin", "Content-Type"},
ContentType: "application/json; charset=utf-8",
}
c.generatePatterns()
return func(w http.ResponseWriter, req *http.Request) {
origin := req.Header.Get("Origin")
if c.isOriginAllowed(origin) {
w.Header().Set("Access-Control-Allow-Origin", origin)
w.Header().Set("Access-Control-Allow-Headers", c.AllowedHeaders())
w.Header().Set("Access-Control-Allow-Methods", c.AllowedMethods())
w.Header().Set("Content-Type", c.ContentType)
}
}
} | [
"func",
"AllowRequestsFrom",
"(",
"allowedOrigins",
"...",
"string",
")",
"http",
".",
"HandlerFunc",
"{",
"c",
":=",
"&",
"CORS",
"{",
"AllowOrigins",
":",
"allowedOrigins",
",",
"AllowMethods",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"AllowHeaders",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"ContentType",
":",
"\"",
"\"",
",",
"}",
"\n\n",
"c",
".",
"generatePatterns",
"(",
")",
"\n\n",
"return",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"origin",
":=",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"if",
"c",
".",
"isOriginAllowed",
"(",
"origin",
")",
"{",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"origin",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"c",
".",
"AllowedHeaders",
"(",
")",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"c",
".",
"AllowedMethods",
"(",
")",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"c",
".",
"ContentType",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // AllowRequestsFrom returns handler to verify that requests come from allowedOrigins | [
"AllowRequestsFrom",
"returns",
"handler",
"to",
"verify",
"that",
"requests",
"come",
"from",
"allowedOrigins"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/cors.go#L19-L38 | train |
hybridgroup/gobot | api/cors.go | isOriginAllowed | func (c *CORS) isOriginAllowed(origin string) (allowed bool) {
for _, allowedOriginPattern := range c.allowOriginPatterns {
allowed, _ = regexp.MatchString(allowedOriginPattern, origin)
if allowed {
return
}
}
return
} | go | func (c *CORS) isOriginAllowed(origin string) (allowed bool) {
for _, allowedOriginPattern := range c.allowOriginPatterns {
allowed, _ = regexp.MatchString(allowedOriginPattern, origin)
if allowed {
return
}
}
return
} | [
"func",
"(",
"c",
"*",
"CORS",
")",
"isOriginAllowed",
"(",
"origin",
"string",
")",
"(",
"allowed",
"bool",
")",
"{",
"for",
"_",
",",
"allowedOriginPattern",
":=",
"range",
"c",
".",
"allowOriginPatterns",
"{",
"allowed",
",",
"_",
"=",
"regexp",
".",
"MatchString",
"(",
"allowedOriginPattern",
",",
"origin",
")",
"\n",
"if",
"allowed",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // isOriginAllowed returns true if origin matches an allowed origin pattern. | [
"isOriginAllowed",
"returns",
"true",
"if",
"origin",
"matches",
"an",
"allowed",
"origin",
"pattern",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/cors.go#L41-L49 | train |
hybridgroup/gobot | api/cors.go | generatePatterns | func (c *CORS) generatePatterns() {
if c.AllowOrigins != nil {
for _, origin := range c.AllowOrigins {
pattern := regexp.QuoteMeta(origin)
pattern = strings.Replace(pattern, "\\*", ".*", -1)
pattern = strings.Replace(pattern, "\\?", ".", -1)
c.allowOriginPatterns = append(c.allowOriginPatterns, "^"+pattern+"$")
}
}
} | go | func (c *CORS) generatePatterns() {
if c.AllowOrigins != nil {
for _, origin := range c.AllowOrigins {
pattern := regexp.QuoteMeta(origin)
pattern = strings.Replace(pattern, "\\*", ".*", -1)
pattern = strings.Replace(pattern, "\\?", ".", -1)
c.allowOriginPatterns = append(c.allowOriginPatterns, "^"+pattern+"$")
}
}
} | [
"func",
"(",
"c",
"*",
"CORS",
")",
"generatePatterns",
"(",
")",
"{",
"if",
"c",
".",
"AllowOrigins",
"!=",
"nil",
"{",
"for",
"_",
",",
"origin",
":=",
"range",
"c",
".",
"AllowOrigins",
"{",
"pattern",
":=",
"regexp",
".",
"QuoteMeta",
"(",
"origin",
")",
"\n",
"pattern",
"=",
"strings",
".",
"Replace",
"(",
"pattern",
",",
"\"",
"\\\\",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"pattern",
"=",
"strings",
".",
"Replace",
"(",
"pattern",
",",
"\"",
"\\\\",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n",
"c",
".",
"allowOriginPatterns",
"=",
"append",
"(",
"c",
".",
"allowOriginPatterns",
",",
"\"",
"\"",
"+",
"pattern",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // generatePatterns generates regex expression for AllowOrigins | [
"generatePatterns",
"generates",
"regex",
"expression",
"for",
"AllowOrigins"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/cors.go#L52-L61 | train |
hybridgroup/gobot | drivers/aio/analog_sensor_driver.go | Read | func (a *AnalogSensorDriver) Read() (val int, err error) {
return a.connection.AnalogRead(a.Pin())
} | go | func (a *AnalogSensorDriver) Read() (val int, err error) {
return a.connection.AnalogRead(a.Pin())
} | [
"func",
"(",
"a",
"*",
"AnalogSensorDriver",
")",
"Read",
"(",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"return",
"a",
".",
"connection",
".",
"AnalogRead",
"(",
"a",
".",
"Pin",
"(",
")",
")",
"\n",
"}"
] | // Read returns the current reading from the Analog Sensor | [
"Read",
"returns",
"the",
"current",
"reading",
"from",
"the",
"Analog",
"Sensor"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/aio/analog_sensor_driver.go#L103-L105 | train |
hybridgroup/gobot | platforms/parrot/ardrone/ardrone_adaptor.go | Connect | func (a *Adaptor) Connect() (err error) {
d, err := a.connect(a)
if err != nil {
return err
}
a.drone = d
return
} | go | func (a *Adaptor) Connect() (err error) {
d, err := a.connect(a)
if err != nil {
return err
}
a.drone = d
return
} | [
"func",
"(",
"a",
"*",
"Adaptor",
")",
"Connect",
"(",
")",
"(",
"err",
"error",
")",
"{",
"d",
",",
"err",
":=",
"a",
".",
"connect",
"(",
"a",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"a",
".",
"drone",
"=",
"d",
"\n",
"return",
"\n",
"}"
] | // Connect establishes a connection to the ardrone | [
"Connect",
"establishes",
"a",
"connection",
"to",
"the",
"ardrone"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_adaptor.go#L58-L65 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | WithMCP23017Bank | func WithMCP23017Bank(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Bank = val
} else {
panic("trying to set bank for non-MCP23017Driver")
}
}
} | go | func WithMCP23017Bank(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Bank = val
} else {
panic("trying to set bank for non-MCP23017Driver")
}
}
} | [
"func",
"WithMCP23017Bank",
"(",
"val",
"uint8",
")",
"func",
"(",
"Config",
")",
"{",
"return",
"func",
"(",
"c",
"Config",
")",
"{",
"d",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"MCP23017Driver",
")",
"\n",
"if",
"ok",
"{",
"d",
".",
"MCPConf",
".",
"Bank",
"=",
"val",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // WithMCP23017Bank option sets the MCP23017Driver bank option | [
"WithMCP23017Bank",
"option",
"sets",
"the",
"MCP23017Driver",
"bank",
"option"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L65-L74 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | WithMCP23017Mirror | func WithMCP23017Mirror(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Mirror = val
} else {
panic("Trying to set Mirror for non-MCP23017Driver")
}
}
} | go | func WithMCP23017Mirror(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Mirror = val
} else {
panic("Trying to set Mirror for non-MCP23017Driver")
}
}
} | [
"func",
"WithMCP23017Mirror",
"(",
"val",
"uint8",
")",
"func",
"(",
"Config",
")",
"{",
"return",
"func",
"(",
"c",
"Config",
")",
"{",
"d",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"MCP23017Driver",
")",
"\n",
"if",
"ok",
"{",
"d",
".",
"MCPConf",
".",
"Mirror",
"=",
"val",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // WithMCP23017Mirror option sets the MCP23017Driver Mirror option | [
"WithMCP23017Mirror",
"option",
"sets",
"the",
"MCP23017Driver",
"Mirror",
"option"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L77-L86 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | WithMCP23017Seqop | func WithMCP23017Seqop(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Seqop = val
} else {
panic("Trying to set Seqop for non-MCP23017Driver")
}
}
} | go | func WithMCP23017Seqop(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Seqop = val
} else {
panic("Trying to set Seqop for non-MCP23017Driver")
}
}
} | [
"func",
"WithMCP23017Seqop",
"(",
"val",
"uint8",
")",
"func",
"(",
"Config",
")",
"{",
"return",
"func",
"(",
"c",
"Config",
")",
"{",
"d",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"MCP23017Driver",
")",
"\n",
"if",
"ok",
"{",
"d",
".",
"MCPConf",
".",
"Seqop",
"=",
"val",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // WithMCP23017Seqop option sets the MCP23017Driver Seqop option | [
"WithMCP23017Seqop",
"option",
"sets",
"the",
"MCP23017Driver",
"Seqop",
"option"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L89-L98 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | WithMCP23017Disslw | func WithMCP23017Disslw(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Disslw = val
} else {
panic("Trying to set Disslw for non-MCP23017Driver")
}
}
} | go | func WithMCP23017Disslw(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Disslw = val
} else {
panic("Trying to set Disslw for non-MCP23017Driver")
}
}
} | [
"func",
"WithMCP23017Disslw",
"(",
"val",
"uint8",
")",
"func",
"(",
"Config",
")",
"{",
"return",
"func",
"(",
"c",
"Config",
")",
"{",
"d",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"MCP23017Driver",
")",
"\n",
"if",
"ok",
"{",
"d",
".",
"MCPConf",
".",
"Disslw",
"=",
"val",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // WithMCP23017Disslw option sets the MCP23017Driver Disslw option | [
"WithMCP23017Disslw",
"option",
"sets",
"the",
"MCP23017Driver",
"Disslw",
"option"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L101-L110 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | WithMCP23017Haen | func WithMCP23017Haen(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Haen = val
} else {
panic("Trying to set Haen for non-MCP23017Driver")
}
}
} | go | func WithMCP23017Haen(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Haen = val
} else {
panic("Trying to set Haen for non-MCP23017Driver")
}
}
} | [
"func",
"WithMCP23017Haen",
"(",
"val",
"uint8",
")",
"func",
"(",
"Config",
")",
"{",
"return",
"func",
"(",
"c",
"Config",
")",
"{",
"d",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"MCP23017Driver",
")",
"\n",
"if",
"ok",
"{",
"d",
".",
"MCPConf",
".",
"Haen",
"=",
"val",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // WithMCP23017Haen option sets the MCP23017Driver Haen option | [
"WithMCP23017Haen",
"option",
"sets",
"the",
"MCP23017Driver",
"Haen",
"option"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L113-L122 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | WithMCP23017Odr | func WithMCP23017Odr(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Odr = val
} else {
panic("Trying to set Odr for non-MCP23017Driver")
}
}
} | go | func WithMCP23017Odr(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Odr = val
} else {
panic("Trying to set Odr for non-MCP23017Driver")
}
}
} | [
"func",
"WithMCP23017Odr",
"(",
"val",
"uint8",
")",
"func",
"(",
"Config",
")",
"{",
"return",
"func",
"(",
"c",
"Config",
")",
"{",
"d",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"MCP23017Driver",
")",
"\n",
"if",
"ok",
"{",
"d",
".",
"MCPConf",
".",
"Odr",
"=",
"val",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // WithMCP23017Odr option sets the MCP23017Driver Odr option | [
"WithMCP23017Odr",
"option",
"sets",
"the",
"MCP23017Driver",
"Odr",
"option"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L125-L134 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | WithMCP23017Intpol | func WithMCP23017Intpol(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Intpol = val
} else {
panic("Trying to set Intpol for non-MCP23017Driver")
}
}
} | go | func WithMCP23017Intpol(val uint8) func(Config) {
return func(c Config) {
d, ok := c.(*MCP23017Driver)
if ok {
d.MCPConf.Intpol = val
} else {
panic("Trying to set Intpol for non-MCP23017Driver")
}
}
} | [
"func",
"WithMCP23017Intpol",
"(",
"val",
"uint8",
")",
"func",
"(",
"Config",
")",
"{",
"return",
"func",
"(",
"c",
"Config",
")",
"{",
"d",
",",
"ok",
":=",
"c",
".",
"(",
"*",
"MCP23017Driver",
")",
"\n",
"if",
"ok",
"{",
"d",
".",
"MCPConf",
".",
"Intpol",
"=",
"val",
"\n",
"}",
"else",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // WithMCP23017Intpol option sets the MCP23017Driver Intpol option | [
"WithMCP23017Intpol",
"option",
"sets",
"the",
"MCP23017Driver",
"Intpol",
"option"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L137-L146 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | Start | func (m *MCP23017Driver) Start() (err error) {
bus := m.GetBusOrDefault(m.connector.GetDefaultBus())
address := m.GetAddressOrDefault(mcp23017Address)
m.connection, err = m.connector.GetConnection(address, bus)
if err != nil {
return err
}
// Set IOCON register with MCP23017 configuration.
ioconReg := m.getPort("A").IOCON // IOCON address is the same for Port A or B.
ioconVal := m.MCPConf.getUint8Value()
if _, err := m.connection.Write([]uint8{ioconReg, ioconVal}); err != nil {
return err
}
return
} | go | func (m *MCP23017Driver) Start() (err error) {
bus := m.GetBusOrDefault(m.connector.GetDefaultBus())
address := m.GetAddressOrDefault(mcp23017Address)
m.connection, err = m.connector.GetConnection(address, bus)
if err != nil {
return err
}
// Set IOCON register with MCP23017 configuration.
ioconReg := m.getPort("A").IOCON // IOCON address is the same for Port A or B.
ioconVal := m.MCPConf.getUint8Value()
if _, err := m.connection.Write([]uint8{ioconReg, ioconVal}); err != nil {
return err
}
return
} | [
"func",
"(",
"m",
"*",
"MCP23017Driver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bus",
":=",
"m",
".",
"GetBusOrDefault",
"(",
"m",
".",
"connector",
".",
"GetDefaultBus",
"(",
")",
")",
"\n",
"address",
":=",
"m",
".",
"GetAddressOrDefault",
"(",
"mcp23017Address",
")",
"\n\n",
"m",
".",
"connection",
",",
"err",
"=",
"m",
".",
"connector",
".",
"GetConnection",
"(",
"address",
",",
"bus",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Set IOCON register with MCP23017 configuration.",
"ioconReg",
":=",
"m",
".",
"getPort",
"(",
"\"",
"\"",
")",
".",
"IOCON",
"// IOCON address is the same for Port A or B.",
"\n",
"ioconVal",
":=",
"m",
".",
"MCPConf",
".",
"getUint8Value",
"(",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"m",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"uint8",
"{",
"ioconReg",
",",
"ioconVal",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Start writes the device configuration. | [
"Start",
"writes",
"the",
"device",
"configuration",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L208-L223 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | write | func (m *MCP23017Driver) write(reg uint8, pin uint8, val uint8) (err error) {
if debug {
log.Printf("write: MCP address: 0x%X, register:0x%X,value: 0x%X\n", m.GetAddressOrDefault(mcp23017Address), reg, val)
}
if _, err = m.connection.Write([]uint8{reg, val}); err != nil {
return err
}
return nil
} | go | func (m *MCP23017Driver) write(reg uint8, pin uint8, val uint8) (err error) {
if debug {
log.Printf("write: MCP address: 0x%X, register:0x%X,value: 0x%X\n", m.GetAddressOrDefault(mcp23017Address), reg, val)
}
if _, err = m.connection.Write([]uint8{reg, val}); err != nil {
return err
}
return nil
} | [
"func",
"(",
"m",
"*",
"MCP23017Driver",
")",
"write",
"(",
"reg",
"uint8",
",",
"pin",
"uint8",
",",
"val",
"uint8",
")",
"(",
"err",
"error",
")",
"{",
"if",
"debug",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"m",
".",
"GetAddressOrDefault",
"(",
"mcp23017Address",
")",
",",
"reg",
",",
"val",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
"=",
"m",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"uint8",
"{",
"reg",
",",
"val",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // write gets the value of the passed in register, and then overwrites
// the bit specified by the pin, with the given value. | [
"write",
"gets",
"the",
"value",
"of",
"the",
"passed",
"in",
"register",
"and",
"then",
"overwrites",
"the",
"bit",
"specified",
"by",
"the",
"pin",
"with",
"the",
"given",
"value",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L305-L313 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | read | func (m *MCP23017Driver) read(reg uint8) (val uint8, err error) {
buf := []byte{0}
if _, err := m.connection.Write([]uint8{reg}); err != nil {
return val, err
}
bytesRead, err := m.connection.Read(buf)
if err != nil {
return val, err
}
if bytesRead != 1 {
err = ErrNotEnoughBytes
return
}
if debug {
log.Printf("reading: MCP address: 0x%X, register:0x%X,value: 0x%X\n", m.GetAddressOrDefault(mcp23017Address), reg, buf)
}
return buf[0], nil
} | go | func (m *MCP23017Driver) read(reg uint8) (val uint8, err error) {
buf := []byte{0}
if _, err := m.connection.Write([]uint8{reg}); err != nil {
return val, err
}
bytesRead, err := m.connection.Read(buf)
if err != nil {
return val, err
}
if bytesRead != 1 {
err = ErrNotEnoughBytes
return
}
if debug {
log.Printf("reading: MCP address: 0x%X, register:0x%X,value: 0x%X\n", m.GetAddressOrDefault(mcp23017Address), reg, buf)
}
return buf[0], nil
} | [
"func",
"(",
"m",
"*",
"MCP23017Driver",
")",
"read",
"(",
"reg",
"uint8",
")",
"(",
"val",
"uint8",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"[",
"]",
"byte",
"{",
"0",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"m",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"uint8",
"{",
"reg",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"val",
",",
"err",
"\n",
"}",
"\n",
"bytesRead",
",",
"err",
":=",
"m",
".",
"connection",
".",
"Read",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"val",
",",
"err",
"\n",
"}",
"\n",
"if",
"bytesRead",
"!=",
"1",
"{",
"err",
"=",
"ErrNotEnoughBytes",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"debug",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"m",
".",
"GetAddressOrDefault",
"(",
"mcp23017Address",
")",
",",
"reg",
",",
"buf",
")",
"\n",
"}",
"\n",
"return",
"buf",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // read get the data from a given register | [
"read",
"get",
"the",
"data",
"from",
"a",
"given",
"register"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L316-L333 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | getUint8Value | func (mc *MCP23017Config) getUint8Value() uint8 {
return mc.Bank<<7 | mc.Mirror<<6 | mc.Seqop<<5 | mc.Disslw<<4 | mc.Haen<<3 | mc.Odr<<2 | mc.Intpol<<1
} | go | func (mc *MCP23017Config) getUint8Value() uint8 {
return mc.Bank<<7 | mc.Mirror<<6 | mc.Seqop<<5 | mc.Disslw<<4 | mc.Haen<<3 | mc.Odr<<2 | mc.Intpol<<1
} | [
"func",
"(",
"mc",
"*",
"MCP23017Config",
")",
"getUint8Value",
"(",
")",
"uint8",
"{",
"return",
"mc",
".",
"Bank",
"<<",
"7",
"|",
"mc",
".",
"Mirror",
"<<",
"6",
"|",
"mc",
".",
"Seqop",
"<<",
"5",
"|",
"mc",
".",
"Disslw",
"<<",
"4",
"|",
"mc",
".",
"Haen",
"<<",
"3",
"|",
"mc",
".",
"Odr",
"<<",
"2",
"|",
"mc",
".",
"Intpol",
"<<",
"1",
"\n",
"}"
] | // getUint8Value returns the configuration data as a packed value. | [
"getUint8Value",
"returns",
"the",
"configuration",
"data",
"as",
"a",
"packed",
"value",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L350-L352 | train |
hybridgroup/gobot | drivers/i2c/mcp23017_driver.go | clearBit | func clearBit(n uint8, pos uint8) uint8 {
mask := ^uint8(1 << pos)
n &= mask
return n
} | go | func clearBit(n uint8, pos uint8) uint8 {
mask := ^uint8(1 << pos)
n &= mask
return n
} | [
"func",
"clearBit",
"(",
"n",
"uint8",
",",
"pos",
"uint8",
")",
"uint8",
"{",
"mask",
":=",
"^",
"uint8",
"(",
"1",
"<<",
"pos",
")",
"\n",
"n",
"&=",
"mask",
"\n",
"return",
"n",
"\n",
"}"
] | // clearBit is used to set a bit at a given position to 0. | [
"clearBit",
"is",
"used",
"to",
"set",
"a",
"bit",
"at",
"a",
"given",
"position",
"to",
"0",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/mcp23017_driver.go#L361-L365 | train |
hybridgroup/gobot | drivers/i2c/drv2605l_driver.go | SetMode | func (d *DRV2605LDriver) SetMode(newMode DRV2605Mode) (err error) {
mode, err := d.connection.ReadByteData(drv2605RegMode)
if err != nil {
return err
}
// clear mode bits (lower three bits)
mode &= 0xf8
// set new mode bits
mode |= uint8(newMode)
err = d.connection.WriteByteData(drv2605RegMode, mode)
return err
} | go | func (d *DRV2605LDriver) SetMode(newMode DRV2605Mode) (err error) {
mode, err := d.connection.ReadByteData(drv2605RegMode)
if err != nil {
return err
}
// clear mode bits (lower three bits)
mode &= 0xf8
// set new mode bits
mode |= uint8(newMode)
err = d.connection.WriteByteData(drv2605RegMode, mode)
return err
} | [
"func",
"(",
"d",
"*",
"DRV2605LDriver",
")",
"SetMode",
"(",
"newMode",
"DRV2605Mode",
")",
"(",
"err",
"error",
")",
"{",
"mode",
",",
"err",
":=",
"d",
".",
"connection",
".",
"ReadByteData",
"(",
"drv2605RegMode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// clear mode bits (lower three bits)",
"mode",
"&=",
"0xf8",
"\n",
"// set new mode bits",
"mode",
"|=",
"uint8",
"(",
"newMode",
")",
"\n\n",
"err",
"=",
"d",
".",
"connection",
".",
"WriteByteData",
"(",
"drv2605RegMode",
",",
"mode",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // SetMode sets the device in one of the eight modes as described in the
// datasheet. Defaults to mode 0, internal trig. | [
"SetMode",
"sets",
"the",
"device",
"in",
"one",
"of",
"the",
"eight",
"modes",
"as",
"described",
"in",
"the",
"datasheet",
".",
"Defaults",
"to",
"mode",
"0",
"internal",
"trig",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/drv2605l_driver.go#L179-L193 | train |
hybridgroup/gobot | drivers/i2c/drv2605l_driver.go | SetStandbyMode | func (d *DRV2605LDriver) SetStandbyMode(standby bool) (err error) {
modeVal, err := d.connection.ReadByteData(drv2605RegMode)
if err != nil {
return err
}
if standby {
modeVal |= drv2605Standby
} else {
modeVal &= 0xFF ^ drv2605Standby
}
err = d.connection.WriteByteData(drv2605RegMode, modeVal)
return err
} | go | func (d *DRV2605LDriver) SetStandbyMode(standby bool) (err error) {
modeVal, err := d.connection.ReadByteData(drv2605RegMode)
if err != nil {
return err
}
if standby {
modeVal |= drv2605Standby
} else {
modeVal &= 0xFF ^ drv2605Standby
}
err = d.connection.WriteByteData(drv2605RegMode, modeVal)
return err
} | [
"func",
"(",
"d",
"*",
"DRV2605LDriver",
")",
"SetStandbyMode",
"(",
"standby",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"modeVal",
",",
"err",
":=",
"d",
".",
"connection",
".",
"ReadByteData",
"(",
"drv2605RegMode",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"standby",
"{",
"modeVal",
"|=",
"drv2605Standby",
"\n",
"}",
"else",
"{",
"modeVal",
"&=",
"0xFF",
"^",
"drv2605Standby",
"\n",
"}",
"\n\n",
"err",
"=",
"d",
".",
"connection",
".",
"WriteByteData",
"(",
"drv2605RegMode",
",",
"modeVal",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // SetStandbyMode controls device low power mode | [
"SetStandbyMode",
"controls",
"device",
"low",
"power",
"mode"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/drv2605l_driver.go#L196-L210 | train |
hybridgroup/gobot | drivers/i2c/drv2605l_driver.go | SelectLibrary | func (d *DRV2605LDriver) SelectLibrary(library uint8) (err error) {
err = d.connection.WriteByteData(drv2605RegLibrary, library&0x7)
return err
} | go | func (d *DRV2605LDriver) SelectLibrary(library uint8) (err error) {
err = d.connection.WriteByteData(drv2605RegLibrary, library&0x7)
return err
} | [
"func",
"(",
"d",
"*",
"DRV2605LDriver",
")",
"SelectLibrary",
"(",
"library",
"uint8",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"d",
".",
"connection",
".",
"WriteByteData",
"(",
"drv2605RegLibrary",
",",
"library",
"&",
"0x7",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // SelectLibrary selects which waveform library to play from, 1-7.
// See datasheet for more info. | [
"SelectLibrary",
"selects",
"which",
"waveform",
"library",
"to",
"play",
"from",
"1",
"-",
"7",
".",
"See",
"datasheet",
"for",
"more",
"info",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/drv2605l_driver.go#L214-L217 | train |
hybridgroup/gobot | drivers/i2c/drv2605l_driver.go | Go | func (d *DRV2605LDriver) Go() (err error) {
err = d.connection.WriteByteData(drv2605RegGo, 1)
return err
} | go | func (d *DRV2605LDriver) Go() (err error) {
err = d.connection.WriteByteData(drv2605RegGo, 1)
return err
} | [
"func",
"(",
"d",
"*",
"DRV2605LDriver",
")",
"Go",
"(",
")",
"(",
"err",
"error",
")",
"{",
"err",
"=",
"d",
".",
"connection",
".",
"WriteByteData",
"(",
"drv2605RegGo",
",",
"1",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Go plays the current sequence of waveforms. | [
"Go",
"plays",
"the",
"current",
"sequence",
"of",
"waveforms",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/drv2605l_driver.go#L253-L256 | train |
hybridgroup/gobot | drivers/i2c/drv2605l_driver.go | Halt | func (d *DRV2605LDriver) Halt() (err error) {
if d.connection != nil {
// stop playback
if err = d.connection.WriteByteData(drv2605RegGo, 0); err != nil {
return err
}
// enter standby
return d.SetStandbyMode(true)
}
return
} | go | func (d *DRV2605LDriver) Halt() (err error) {
if d.connection != nil {
// stop playback
if err = d.connection.WriteByteData(drv2605RegGo, 0); err != nil {
return err
}
// enter standby
return d.SetStandbyMode(true)
}
return
} | [
"func",
"(",
"d",
"*",
"DRV2605LDriver",
")",
"Halt",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"d",
".",
"connection",
"!=",
"nil",
"{",
"// stop playback",
"if",
"err",
"=",
"d",
".",
"connection",
".",
"WriteByteData",
"(",
"drv2605RegGo",
",",
"0",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// enter standby",
"return",
"d",
".",
"SetStandbyMode",
"(",
"true",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Halt halts the device. | [
"Halt",
"halts",
"the",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/drv2605l_driver.go#L259-L270 | train |
hybridgroup/gobot | platforms/mqtt/mqtt_driver.go | On | func (m *Driver) On(n string, f func(msg interface{})) error {
// TODO: also be able to subscribe to Error updates
f1 := func(msg Message) {
f(msg)
}
m.adaptor().On(m.topic, f1)
return nil
} | go | func (m *Driver) On(n string, f func(msg interface{})) error {
// TODO: also be able to subscribe to Error updates
f1 := func(msg Message) {
f(msg)
}
m.adaptor().On(m.topic, f1)
return nil
} | [
"func",
"(",
"m",
"*",
"Driver",
")",
"On",
"(",
"n",
"string",
",",
"f",
"func",
"(",
"msg",
"interface",
"{",
"}",
")",
")",
"error",
"{",
"// TODO: also be able to subscribe to Error updates",
"f1",
":=",
"func",
"(",
"msg",
"Message",
")",
"{",
"f",
"(",
"msg",
")",
"\n",
"}",
"\n",
"m",
".",
"adaptor",
"(",
")",
".",
"On",
"(",
"m",
".",
"topic",
",",
"f1",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // On subscribes to data updates for the current device topic,
// and then calls the message handler function when data is received | [
"On",
"subscribes",
"to",
"data",
"updates",
"for",
"the",
"current",
"device",
"topic",
"and",
"then",
"calls",
"the",
"message",
"handler",
"function",
"when",
"data",
"is",
"received"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mqtt/mqtt_driver.go#L77-L84 | train |
hybridgroup/gobot | platforms/keyboard/keyboard.go | restore | func restore() (err error) {
if _, err = stty("echo"); err != nil {
return
}
if _, err = stty(originalState); err != nil {
return
}
return
} | go | func restore() (err error) {
if _, err = stty("echo"); err != nil {
return
}
if _, err = stty(originalState); err != nil {
return
}
return
} | [
"func",
"restore",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"_",
",",
"err",
"=",
"stty",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
"=",
"stty",
"(",
"originalState",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // restores the TTY to the original state | [
"restores",
"the",
"TTY",
"to",
"the",
"original",
"state"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/keyboard/keyboard.go#L139-L149 | train |
hybridgroup/gobot | master.go | NewJSONMaster | func NewJSONMaster(gobot *Master) *JSONMaster {
jsonGobot := &JSONMaster{
Robots: []*JSONRobot{},
Commands: []string{},
}
for command := range gobot.Commands() {
jsonGobot.Commands = append(jsonGobot.Commands, command)
}
gobot.robots.Each(func(r *Robot) {
jsonGobot.Robots = append(jsonGobot.Robots, NewJSONRobot(r))
})
return jsonGobot
} | go | func NewJSONMaster(gobot *Master) *JSONMaster {
jsonGobot := &JSONMaster{
Robots: []*JSONRobot{},
Commands: []string{},
}
for command := range gobot.Commands() {
jsonGobot.Commands = append(jsonGobot.Commands, command)
}
gobot.robots.Each(func(r *Robot) {
jsonGobot.Robots = append(jsonGobot.Robots, NewJSONRobot(r))
})
return jsonGobot
} | [
"func",
"NewJSONMaster",
"(",
"gobot",
"*",
"Master",
")",
"*",
"JSONMaster",
"{",
"jsonGobot",
":=",
"&",
"JSONMaster",
"{",
"Robots",
":",
"[",
"]",
"*",
"JSONRobot",
"{",
"}",
",",
"Commands",
":",
"[",
"]",
"string",
"{",
"}",
",",
"}",
"\n\n",
"for",
"command",
":=",
"range",
"gobot",
".",
"Commands",
"(",
")",
"{",
"jsonGobot",
".",
"Commands",
"=",
"append",
"(",
"jsonGobot",
".",
"Commands",
",",
"command",
")",
"\n",
"}",
"\n\n",
"gobot",
".",
"robots",
".",
"Each",
"(",
"func",
"(",
"r",
"*",
"Robot",
")",
"{",
"jsonGobot",
".",
"Robots",
"=",
"append",
"(",
"jsonGobot",
".",
"Robots",
",",
"NewJSONRobot",
"(",
"r",
")",
")",
"\n",
"}",
")",
"\n",
"return",
"jsonGobot",
"\n",
"}"
] | // NewJSONMaster returns a JSONMaster given a Gobot Master. | [
"NewJSONMaster",
"returns",
"a",
"JSONMaster",
"given",
"a",
"Gobot",
"Master",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/master.go#L18-L32 | train |
hybridgroup/gobot | master.go | NewMaster | func NewMaster() *Master {
m := &Master{
robots: &Robots{},
trap: func(c chan os.Signal) {
signal.Notify(c, os.Interrupt)
},
AutoRun: true,
Commander: NewCommander(),
Eventer: NewEventer(),
}
m.running.Store(false)
return m
} | go | func NewMaster() *Master {
m := &Master{
robots: &Robots{},
trap: func(c chan os.Signal) {
signal.Notify(c, os.Interrupt)
},
AutoRun: true,
Commander: NewCommander(),
Eventer: NewEventer(),
}
m.running.Store(false)
return m
} | [
"func",
"NewMaster",
"(",
")",
"*",
"Master",
"{",
"m",
":=",
"&",
"Master",
"{",
"robots",
":",
"&",
"Robots",
"{",
"}",
",",
"trap",
":",
"func",
"(",
"c",
"chan",
"os",
".",
"Signal",
")",
"{",
"signal",
".",
"Notify",
"(",
"c",
",",
"os",
".",
"Interrupt",
")",
"\n",
"}",
",",
"AutoRun",
":",
"true",
",",
"Commander",
":",
"NewCommander",
"(",
")",
",",
"Eventer",
":",
"NewEventer",
"(",
")",
",",
"}",
"\n",
"m",
".",
"running",
".",
"Store",
"(",
"false",
")",
"\n",
"return",
"m",
"\n",
"}"
] | // NewMaster returns a new Gobot Master | [
"NewMaster",
"returns",
"a",
"new",
"Gobot",
"Master"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/master.go#L46-L58 | train |
hybridgroup/gobot | master.go | Start | func (g *Master) Start() (err error) {
if rerr := g.robots.Start(!g.AutoRun); rerr != nil {
err = multierror.Append(err, rerr)
return
}
g.running.Store(true)
if g.AutoRun {
c := make(chan os.Signal, 1)
g.trap(c)
// waiting for interrupt coming on the channel
<-c
// Stop calls the Stop method on each robot in its collection of robots.
g.Stop()
}
return err
} | go | func (g *Master) Start() (err error) {
if rerr := g.robots.Start(!g.AutoRun); rerr != nil {
err = multierror.Append(err, rerr)
return
}
g.running.Store(true)
if g.AutoRun {
c := make(chan os.Signal, 1)
g.trap(c)
// waiting for interrupt coming on the channel
<-c
// Stop calls the Stop method on each robot in its collection of robots.
g.Stop()
}
return err
} | [
"func",
"(",
"g",
"*",
"Master",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"rerr",
":=",
"g",
".",
"robots",
".",
"Start",
"(",
"!",
"g",
".",
"AutoRun",
")",
";",
"rerr",
"!=",
"nil",
"{",
"err",
"=",
"multierror",
".",
"Append",
"(",
"err",
",",
"rerr",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"g",
".",
"running",
".",
"Store",
"(",
"true",
")",
"\n\n",
"if",
"g",
".",
"AutoRun",
"{",
"c",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"g",
".",
"trap",
"(",
"c",
")",
"\n\n",
"// waiting for interrupt coming on the channel",
"<-",
"c",
"\n\n",
"// Stop calls the Stop method on each robot in its collection of robots.",
"g",
".",
"Stop",
"(",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] | // Start calls the Start method on each robot in its collection of robots. On
// error, call Stop to ensure that all robots are returned to a sane, stopped
// state. | [
"Start",
"calls",
"the",
"Start",
"method",
"on",
"each",
"robot",
"in",
"its",
"collection",
"of",
"robots",
".",
"On",
"error",
"call",
"Stop",
"to",
"ensure",
"that",
"all",
"robots",
"are",
"returned",
"to",
"a",
"sane",
"stopped",
"state",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/master.go#L63-L83 | train |
hybridgroup/gobot | master.go | Stop | func (g *Master) Stop() (err error) {
if rerr := g.robots.Stop(); rerr != nil {
err = multierror.Append(err, rerr)
}
g.running.Store(false)
return
} | go | func (g *Master) Stop() (err error) {
if rerr := g.robots.Stop(); rerr != nil {
err = multierror.Append(err, rerr)
}
g.running.Store(false)
return
} | [
"func",
"(",
"g",
"*",
"Master",
")",
"Stop",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"rerr",
":=",
"g",
".",
"robots",
".",
"Stop",
"(",
")",
";",
"rerr",
"!=",
"nil",
"{",
"err",
"=",
"multierror",
".",
"Append",
"(",
"err",
",",
"rerr",
")",
"\n",
"}",
"\n\n",
"g",
".",
"running",
".",
"Store",
"(",
"false",
")",
"\n",
"return",
"\n",
"}"
] | // Stop calls the Stop method on each robot in its collection of robots. | [
"Stop",
"calls",
"the",
"Stop",
"method",
"on",
"each",
"robot",
"in",
"its",
"collection",
"of",
"robots",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/master.go#L86-L93 | train |
hybridgroup/gobot | master.go | AddRobot | func (g *Master) AddRobot(r *Robot) *Robot {
*g.robots = append(*g.robots, r)
return r
} | go | func (g *Master) AddRobot(r *Robot) *Robot {
*g.robots = append(*g.robots, r)
return r
} | [
"func",
"(",
"g",
"*",
"Master",
")",
"AddRobot",
"(",
"r",
"*",
"Robot",
")",
"*",
"Robot",
"{",
"*",
"g",
".",
"robots",
"=",
"append",
"(",
"*",
"g",
".",
"robots",
",",
"r",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // AddRobot adds a new robot to the internal collection of robots. Returns the
// added robot | [
"AddRobot",
"adds",
"a",
"new",
"robot",
"to",
"the",
"internal",
"collection",
"of",
"robots",
".",
"Returns",
"the",
"added",
"robot"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/master.go#L107-L110 | train |
hybridgroup/gobot | master.go | Robot | func (g *Master) Robot(name string) *Robot {
for _, robot := range *g.Robots() {
if robot.Name == name {
return robot
}
}
return nil
} | go | func (g *Master) Robot(name string) *Robot {
for _, robot := range *g.Robots() {
if robot.Name == name {
return robot
}
}
return nil
} | [
"func",
"(",
"g",
"*",
"Master",
")",
"Robot",
"(",
"name",
"string",
")",
"*",
"Robot",
"{",
"for",
"_",
",",
"robot",
":=",
"range",
"*",
"g",
".",
"Robots",
"(",
")",
"{",
"if",
"robot",
".",
"Name",
"==",
"name",
"{",
"return",
"robot",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Robot returns a robot given name. Returns nil if the Robot does not exist. | [
"Robot",
"returns",
"a",
"robot",
"given",
"name",
".",
"Returns",
"nil",
"if",
"the",
"Robot",
"does",
"not",
"exist",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/master.go#L113-L120 | train |
hybridgroup/gobot | drivers/i2c/sht3x_driver.go | Start | func (s *SHT3xDriver) Start() (err error) {
bus := s.GetBusOrDefault(s.connector.GetDefaultBus())
address := s.GetAddressOrDefault(s.sht3xAddress)
s.connection, err = s.connector.GetConnection(address, bus)
return
} | go | func (s *SHT3xDriver) Start() (err error) {
bus := s.GetBusOrDefault(s.connector.GetDefaultBus())
address := s.GetAddressOrDefault(s.sht3xAddress)
s.connection, err = s.connector.GetConnection(address, bus)
return
} | [
"func",
"(",
"s",
"*",
"SHT3xDriver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bus",
":=",
"s",
".",
"GetBusOrDefault",
"(",
"s",
".",
"connector",
".",
"GetDefaultBus",
"(",
")",
")",
"\n",
"address",
":=",
"s",
".",
"GetAddressOrDefault",
"(",
"s",
".",
"sht3xAddress",
")",
"\n\n",
"s",
".",
"connection",
",",
"err",
"=",
"s",
".",
"connector",
".",
"GetConnection",
"(",
"address",
",",
"bus",
")",
"\n",
"return",
"\n",
"}"
] | // Start initializes the SHT3x | [
"Start",
"initializes",
"the",
"SHT3x"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/sht3x_driver.go#L104-L110 | train |
hybridgroup/gobot | drivers/i2c/sht3x_driver.go | SetAccuracy | func (s *SHT3xDriver) SetAccuracy(a byte) (err error) {
switch a {
case SHT3xAccuracyLow:
s.delay = 5 * time.Millisecond // Actual max is 4, wait 1 ms longer
case SHT3xAccuracyMedium:
s.delay = 7 * time.Millisecond // Actual max is 6, wait 1 ms longer
case SHT3xAccuracyHigh:
s.delay = 16 * time.Millisecond // Actual max is 15, wait 1 ms longer
default:
err = ErrInvalidAccuracy
return
}
s.accuracy = a
return
} | go | func (s *SHT3xDriver) SetAccuracy(a byte) (err error) {
switch a {
case SHT3xAccuracyLow:
s.delay = 5 * time.Millisecond // Actual max is 4, wait 1 ms longer
case SHT3xAccuracyMedium:
s.delay = 7 * time.Millisecond // Actual max is 6, wait 1 ms longer
case SHT3xAccuracyHigh:
s.delay = 16 * time.Millisecond // Actual max is 15, wait 1 ms longer
default:
err = ErrInvalidAccuracy
return
}
s.accuracy = a
return
} | [
"func",
"(",
"s",
"*",
"SHT3xDriver",
")",
"SetAccuracy",
"(",
"a",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"switch",
"a",
"{",
"case",
"SHT3xAccuracyLow",
":",
"s",
".",
"delay",
"=",
"5",
"*",
"time",
".",
"Millisecond",
"// Actual max is 4, wait 1 ms longer",
"\n",
"case",
"SHT3xAccuracyMedium",
":",
"s",
".",
"delay",
"=",
"7",
"*",
"time",
".",
"Millisecond",
"// Actual max is 6, wait 1 ms longer",
"\n",
"case",
"SHT3xAccuracyHigh",
":",
"s",
".",
"delay",
"=",
"16",
"*",
"time",
".",
"Millisecond",
"// Actual max is 15, wait 1 ms longer",
"\n",
"default",
":",
"err",
"=",
"ErrInvalidAccuracy",
"\n",
"return",
"\n",
"}",
"\n\n",
"s",
".",
"accuracy",
"=",
"a",
"\n\n",
"return",
"\n",
"}"
] | // SetAccuracy sets the accuracy of the sampling | [
"SetAccuracy",
"sets",
"the",
"accuracy",
"of",
"the",
"sampling"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/sht3x_driver.go#L122-L138 | train |
hybridgroup/gobot | drivers/i2c/sht3x_driver.go | SerialNumber | func (s *SHT3xDriver) SerialNumber() (sn uint32, err error) {
ret, err := s.sendCommandDelayGetResponse([]byte{0x37, 0x80}, nil, 2)
if nil == err {
sn = (uint32(ret[0]) << 16) | uint32(ret[1])
}
return
} | go | func (s *SHT3xDriver) SerialNumber() (sn uint32, err error) {
ret, err := s.sendCommandDelayGetResponse([]byte{0x37, 0x80}, nil, 2)
if nil == err {
sn = (uint32(ret[0]) << 16) | uint32(ret[1])
}
return
} | [
"func",
"(",
"s",
"*",
"SHT3xDriver",
")",
"SerialNumber",
"(",
")",
"(",
"sn",
"uint32",
",",
"err",
"error",
")",
"{",
"ret",
",",
"err",
":=",
"s",
".",
"sendCommandDelayGetResponse",
"(",
"[",
"]",
"byte",
"{",
"0x37",
",",
"0x80",
"}",
",",
"nil",
",",
"2",
")",
"\n",
"if",
"nil",
"==",
"err",
"{",
"sn",
"=",
"(",
"uint32",
"(",
"ret",
"[",
"0",
"]",
")",
"<<",
"16",
")",
"|",
"uint32",
"(",
"ret",
"[",
"1",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // SerialNumber returns the serial number of the chip | [
"SerialNumber",
"returns",
"the",
"serial",
"number",
"of",
"the",
"chip"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/sht3x_driver.go#L141-L148 | train |
hybridgroup/gobot | drivers/i2c/sht3x_driver.go | Heater | func (s *SHT3xDriver) Heater() (status bool, err error) {
sr, err := s.getStatusRegister()
if err == nil {
if (1 << 13) == (sr & (1 << 13)) {
status = true
}
}
return
} | go | func (s *SHT3xDriver) Heater() (status bool, err error) {
sr, err := s.getStatusRegister()
if err == nil {
if (1 << 13) == (sr & (1 << 13)) {
status = true
}
}
return
} | [
"func",
"(",
"s",
"*",
"SHT3xDriver",
")",
"Heater",
"(",
")",
"(",
"status",
"bool",
",",
"err",
"error",
")",
"{",
"sr",
",",
"err",
":=",
"s",
".",
"getStatusRegister",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"if",
"(",
"1",
"<<",
"13",
")",
"==",
"(",
"sr",
"&",
"(",
"1",
"<<",
"13",
")",
")",
"{",
"status",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Heater returns true if the heater is enabled | [
"Heater",
"returns",
"true",
"if",
"the",
"heater",
"is",
"enabled"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/sht3x_driver.go#L151-L159 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.