id int32 0 167k | 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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
156,000 | hybridgroup/gobot | drivers/gpio/aip1640_driver.go | DrawPixel | func (a *AIP1640Driver) DrawPixel(x, y byte, enabled bool) {
if x >= 8 || y >= 8 {
return
}
y = 7 - y
if enabled {
a.buffer[y] |= 1 << x
} else {
a.buffer[y] &^= 1 << x
}
} | go | func (a *AIP1640Driver) DrawPixel(x, y byte, enabled bool) {
if x >= 8 || y >= 8 {
return
}
y = 7 - y
if enabled {
a.buffer[y] |= 1 << x
} else {
a.buffer[y] &^= 1 << x
}
} | [
"func",
"(",
"a",
"*",
"AIP1640Driver",
")",
"DrawPixel",
"(",
"x",
",",
"y",
"byte",
",",
"enabled",
"bool",
")",
"{",
"if",
"x",
">=",
"8",
"||",
"y",
">=",
"8",
"{",
"return",
"\n",
"}",
"\n",
"y",
"=",
"7",
"-",
"y",
"\n",
"if",
"enabled"... | // DrawPixel turns on or off a specific in the buffer | [
"DrawPixel",
"turns",
"on",
"or",
"off",
"a",
"specific",
"in",
"the",
"buffer"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/aip1640_driver.go#L102-L112 |
156,001 | hybridgroup/gobot | drivers/gpio/aip1640_driver.go | DrawRow | func (a *AIP1640Driver) DrawRow(row, data byte) {
if row >= 8 {
return
}
a.buffer[7-row] = data
} | go | func (a *AIP1640Driver) DrawRow(row, data byte) {
if row >= 8 {
return
}
a.buffer[7-row] = data
} | [
"func",
"(",
"a",
"*",
"AIP1640Driver",
")",
"DrawRow",
"(",
"row",
",",
"data",
"byte",
")",
"{",
"if",
"row",
">=",
"8",
"{",
"return",
"\n",
"}",
"\n",
"a",
".",
"buffer",
"[",
"7",
"-",
"row",
"]",
"=",
"data",
"\n",
"}"
] | // DrawRow sets any given row of LEDs in the buffer | [
"DrawRow",
"sets",
"any",
"given",
"row",
"of",
"LEDs",
"in",
"the",
"buffer"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/aip1640_driver.go#L115-L120 |
156,002 | hybridgroup/gobot | drivers/gpio/aip1640_driver.go | DrawMatrix | func (a *AIP1640Driver) DrawMatrix(data [8]byte) {
for i := 0; i < 8; i++ {
a.buffer[7-i] = data[i]
}
} | go | func (a *AIP1640Driver) DrawMatrix(data [8]byte) {
for i := 0; i < 8; i++ {
a.buffer[7-i] = data[i]
}
} | [
"func",
"(",
"a",
"*",
"AIP1640Driver",
")",
"DrawMatrix",
"(",
"data",
"[",
"8",
"]",
"byte",
")",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"8",
";",
"i",
"++",
"{",
"a",
".",
"buffer",
"[",
"7",
"-",
"i",
"]",
"=",
"data",
"[",
"i",
"... | // DrawMatrix sets the whole buffer | [
"DrawMatrix",
"sets",
"the",
"whole",
"buffer"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/aip1640_driver.go#L123-L127 |
156,003 | hybridgroup/gobot | drivers/gpio/aip1640_driver.go | sendCommand | func (a *AIP1640Driver) sendCommand(cmd byte) {
a.pinData.Off()
a.send(cmd)
a.pinData.On()
} | go | func (a *AIP1640Driver) sendCommand(cmd byte) {
a.pinData.Off()
a.send(cmd)
a.pinData.On()
} | [
"func",
"(",
"a",
"*",
"AIP1640Driver",
")",
"sendCommand",
"(",
"cmd",
"byte",
")",
"{",
"a",
".",
"pinData",
".",
"Off",
"(",
")",
"\n",
"a",
".",
"send",
"(",
"cmd",
")",
"\n",
"a",
".",
"pinData",
".",
"On",
"(",
")",
"\n",
"}"
] | // sendCommand is an auxiliary function to send commands to the AIP1640Driver module | [
"sendCommand",
"is",
"an",
"auxiliary",
"function",
"to",
"send",
"commands",
"to",
"the",
"AIP1640Driver",
"module"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/aip1640_driver.go#L130-L134 |
156,004 | hybridgroup/gobot | drivers/gpio/aip1640_driver.go | sendData | func (a *AIP1640Driver) sendData(address byte, data byte) {
a.sendCommand(AIP1640DataCmd | AIP1640FixedAddr)
a.pinData.Off()
a.send(AIP1640AddrCmd | address)
a.send(data)
a.pinData.On()
} | go | func (a *AIP1640Driver) sendData(address byte, data byte) {
a.sendCommand(AIP1640DataCmd | AIP1640FixedAddr)
a.pinData.Off()
a.send(AIP1640AddrCmd | address)
a.send(data)
a.pinData.On()
} | [
"func",
"(",
"a",
"*",
"AIP1640Driver",
")",
"sendData",
"(",
"address",
"byte",
",",
"data",
"byte",
")",
"{",
"a",
".",
"sendCommand",
"(",
"AIP1640DataCmd",
"|",
"AIP1640FixedAddr",
")",
"\n",
"a",
".",
"pinData",
".",
"Off",
"(",
")",
"\n",
"a",
... | // sendData is an auxiliary function to send data to the AIP1640Driver module | [
"sendData",
"is",
"an",
"auxiliary",
"function",
"to",
"send",
"data",
"to",
"the",
"AIP1640Driver",
"module"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/aip1640_driver.go#L137-L143 |
156,005 | hybridgroup/gobot | platforms/ble/generic_access_driver.go | NewGenericAccessDriver | func NewGenericAccessDriver(a BLEConnector) *GenericAccessDriver {
n := &GenericAccessDriver{
name: gobot.DefaultName("GenericAccess"),
connection: a,
Eventer: gobot.NewEventer(),
}
return n
} | go | func NewGenericAccessDriver(a BLEConnector) *GenericAccessDriver {
n := &GenericAccessDriver{
name: gobot.DefaultName("GenericAccess"),
connection: a,
Eventer: gobot.NewEventer(),
}
return n
} | [
"func",
"NewGenericAccessDriver",
"(",
"a",
"BLEConnector",
")",
"*",
"GenericAccessDriver",
"{",
"n",
":=",
"&",
"GenericAccessDriver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"connection",
":",
"a",
",",
"Eventer",
":",
... | // NewGenericAccessDriver creates a GenericAccessDriver | [
"NewGenericAccessDriver",
"creates",
"a",
"GenericAccessDriver"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/generic_access_driver.go#L18-L26 |
156,006 | hybridgroup/gobot | platforms/ble/generic_access_driver.go | GetDeviceName | func (b *GenericAccessDriver) GetDeviceName() string {
c, _ := b.adaptor().ReadCharacteristic("2a00")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
} | go | func (b *GenericAccessDriver) GetDeviceName() string {
c, _ := b.adaptor().ReadCharacteristic("2a00")
buf := bytes.NewBuffer(c)
val := buf.String()
return val
} | [
"func",
"(",
"b",
"*",
"GenericAccessDriver",
")",
"GetDeviceName",
"(",
")",
"string",
"{",
"c",
",",
"_",
":=",
"b",
".",
"adaptor",
"(",
")",
".",
"ReadCharacteristic",
"(",
"\"",
"\"",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"c",
... | // GetDeviceName returns the device name for the BLE Peripheral | [
"GetDeviceName",
"returns",
"the",
"device",
"name",
"for",
"the",
"BLE",
"Peripheral"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/generic_access_driver.go#L51-L56 |
156,007 | hybridgroup/gobot | platforms/ble/generic_access_driver.go | GetAppearance | func (b *GenericAccessDriver) GetAppearance() string {
c, _ := b.adaptor().ReadCharacteristic("2a01")
buf := bytes.NewBuffer(c)
var val uint16
binary.Read(buf, binary.LittleEndian, &val)
return appearances[val]
} | go | func (b *GenericAccessDriver) GetAppearance() string {
c, _ := b.adaptor().ReadCharacteristic("2a01")
buf := bytes.NewBuffer(c)
var val uint16
binary.Read(buf, binary.LittleEndian, &val)
return appearances[val]
} | [
"func",
"(",
"b",
"*",
"GenericAccessDriver",
")",
"GetAppearance",
"(",
")",
"string",
"{",
"c",
",",
"_",
":=",
"b",
".",
"adaptor",
"(",
")",
".",
"ReadCharacteristic",
"(",
"\"",
"\"",
")",
"\n",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"c",
... | // GetAppearance returns the appearance string for the BLE Peripheral | [
"GetAppearance",
"returns",
"the",
"appearance",
"string",
"for",
"the",
"BLE",
"Peripheral"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/generic_access_driver.go#L59-L66 |
156,008 | hybridgroup/gobot | drivers/gpio/relay_driver.go | Toggle | func (l *RelayDriver) Toggle() (err error) {
if l.State() {
err = l.Off()
} else {
err = l.On()
}
return
} | go | func (l *RelayDriver) Toggle() (err error) {
if l.State() {
err = l.Off()
} else {
err = l.On()
}
return
} | [
"func",
"(",
"l",
"*",
"RelayDriver",
")",
"Toggle",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"l",
".",
"State",
"(",
")",
"{",
"err",
"=",
"l",
".",
"Off",
"(",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"l",
".",
"On",
"(",
")",
"\n... | // Toggle sets the relay to the opposite of it's current state | [
"Toggle",
"sets",
"the",
"relay",
"to",
"the",
"opposite",
"of",
"it",
"s",
"current",
"state"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/relay_driver.go#L88-L95 |
156,009 | hybridgroup/gobot | platforms/dji/tello/driver.go | NewDriver | func NewDriver(port string) *Driver {
d := &Driver{name: gobot.DefaultName("Tello"),
reqAddr: "192.168.10.1:8889",
respPort: port,
videoPort: "6038",
Eventer: gobot.NewEventer(),
}
d.AddEvent(ConnectedEvent)
d.AddEvent(FlightDataEvent)
d.AddEvent(TakeoffEvent)
d.AddEvent(LandingEvent)
d.AddEvent(PalmLandingEvent)
d.AddEvent(BounceEvent)
d.AddEvent(FlipEvent)
d.AddEvent(TimeEvent)
d.AddEvent(LogEvent)
d.AddEvent(WifiDataEvent)
d.AddEvent(LightStrengthEvent)
d.AddEvent(SetExposureEvent)
d.AddEvent(VideoFrameEvent)
d.AddEvent(SetVideoEncoderRateEvent)
return d
} | go | func NewDriver(port string) *Driver {
d := &Driver{name: gobot.DefaultName("Tello"),
reqAddr: "192.168.10.1:8889",
respPort: port,
videoPort: "6038",
Eventer: gobot.NewEventer(),
}
d.AddEvent(ConnectedEvent)
d.AddEvent(FlightDataEvent)
d.AddEvent(TakeoffEvent)
d.AddEvent(LandingEvent)
d.AddEvent(PalmLandingEvent)
d.AddEvent(BounceEvent)
d.AddEvent(FlipEvent)
d.AddEvent(TimeEvent)
d.AddEvent(LogEvent)
d.AddEvent(WifiDataEvent)
d.AddEvent(LightStrengthEvent)
d.AddEvent(SetExposureEvent)
d.AddEvent(VideoFrameEvent)
d.AddEvent(SetVideoEncoderRateEvent)
return d
} | [
"func",
"NewDriver",
"(",
"port",
"string",
")",
"*",
"Driver",
"{",
"d",
":=",
"&",
"Driver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"reqAddr",
":",
"\"",
"\"",
",",
"respPort",
":",
"port",
",",
"videoPort",
":"... | // NewDriver creates a driver for the Tello drone. Pass in the UDP port to use for the responses
// from the drone. | [
"NewDriver",
"creates",
"a",
"driver",
"for",
"the",
"Tello",
"drone",
".",
"Pass",
"in",
"the",
"UDP",
"port",
"to",
"use",
"for",
"the",
"responses",
"from",
"the",
"drone",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L200-L224 |
156,010 | hybridgroup/gobot | platforms/dji/tello/driver.go | TakeOff | func (d *Driver) TakeOff() (err error) {
buf, _ := d.createPacket(takeoffCommand, 0x68, 0)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | go | func (d *Driver) TakeOff() (err error) {
buf, _ := d.createPacket(takeoffCommand, 0x68, 0)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"TakeOff",
"(",
")",
"(",
"err",
"error",
")",
"{",
"buf",
",",
"_",
":=",
"d",
".",
"createPacket",
"(",
"takeoffCommand",
",",
"0x68",
",",
"0",
")",
"\n",
"d",
".",
"seq",
"++",
"\n",
"binary",
".",
"Wri... | // TakeOff tells drones to liftoff and start flying. | [
"TakeOff",
"tells",
"drones",
"to",
"liftoff",
"and",
"start",
"flying",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L299-L307 |
156,011 | hybridgroup/gobot | platforms/dji/tello/driver.go | ThrowTakeOff | func (d *Driver) ThrowTakeOff() (err error) {
buf, _ := d.createPacket(throwtakeoffCommand, 0x48, 0)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | go | func (d *Driver) ThrowTakeOff() (err error) {
buf, _ := d.createPacket(throwtakeoffCommand, 0x48, 0)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"ThrowTakeOff",
"(",
")",
"(",
"err",
"error",
")",
"{",
"buf",
",",
"_",
":=",
"d",
".",
"createPacket",
"(",
"throwtakeoffCommand",
",",
"0x48",
",",
"0",
")",
"\n",
"d",
".",
"seq",
"++",
"\n",
"binary",
"... | // Throw & Go support | [
"Throw",
"&",
"Go",
"support"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L310-L318 |
156,012 | hybridgroup/gobot | platforms/dji/tello/driver.go | PalmLand | func (d *Driver) PalmLand() (err error) {
buf, _ := d.createPacket(palmLandCommand, 0x68, 1)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, byte(0x00))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | go | func (d *Driver) PalmLand() (err error) {
buf, _ := d.createPacket(palmLandCommand, 0x68, 1)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, byte(0x00))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"PalmLand",
"(",
")",
"(",
"err",
"error",
")",
"{",
"buf",
",",
"_",
":=",
"d",
".",
"createPacket",
"(",
"palmLandCommand",
",",
"0x68",
",",
"1",
")",
"\n",
"d",
".",
"seq",
"++",
"\n",
"binary",
".",
"W... | // PalmLand tells drone to come in for a hand landing. | [
"PalmLand",
"tells",
"drone",
"to",
"come",
"in",
"for",
"a",
"hand",
"landing",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L345-L354 |
156,013 | hybridgroup/gobot | platforms/dji/tello/driver.go | SetExposure | func (d *Driver) SetExposure(level int) (err error) {
if level < 0 || level > 2 {
return errors.New("Invalid exposure level")
}
buf, _ := d.createPacket(exposureCommand, 0x48, 1)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, byte(level))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | go | func (d *Driver) SetExposure(level int) (err error) {
if level < 0 || level > 2 {
return errors.New("Invalid exposure level")
}
buf, _ := d.createPacket(exposureCommand, 0x48, 1)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, byte(level))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"SetExposure",
"(",
"level",
"int",
")",
"(",
"err",
"error",
")",
"{",
"if",
"level",
"<",
"0",
"||",
"level",
">",
"2",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"buf",... | // SetExposure sets the drone camera exposure level. Valid levels are 0, 1, and 2. | [
"SetExposure",
"sets",
"the",
"drone",
"camera",
"exposure",
"level",
".",
"Valid",
"levels",
"are",
"0",
"1",
"and",
"2",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L367-L380 |
156,014 | hybridgroup/gobot | platforms/dji/tello/driver.go | SetVideoEncoderRate | func (d *Driver) SetVideoEncoderRate(rate VideoBitRate) (err error) {
buf, _ := d.createPacket(videoEncoderRateCommand, 0x68, 1)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, byte(rate))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | go | func (d *Driver) SetVideoEncoderRate(rate VideoBitRate) (err error) {
buf, _ := d.createPacket(videoEncoderRateCommand, 0x68, 1)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, byte(rate))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"SetVideoEncoderRate",
"(",
"rate",
"VideoBitRate",
")",
"(",
"err",
"error",
")",
"{",
"buf",
",",
"_",
":=",
"d",
".",
"createPacket",
"(",
"videoEncoderRateCommand",
",",
"0x68",
",",
"1",
")",
"\n",
"d",
".",
... | // SetVideoEncoderRate sets the drone video encoder rate. | [
"SetVideoEncoderRate",
"sets",
"the",
"drone",
"video",
"encoder",
"rate",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L383-L392 |
156,015 | hybridgroup/gobot | platforms/dji/tello/driver.go | SetFastMode | func (d *Driver) SetFastMode() error {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()
d.throttle = 1
return nil
} | go | func (d *Driver) SetFastMode() error {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()
d.throttle = 1
return nil
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"SetFastMode",
"(",
")",
"error",
"{",
"d",
".",
"cmdMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"cmdMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"d",
".",
"throttle",
"=",
"1",
"\n",
"return",
"nil",... | // SetFastMode sets the drone throttle to 1. | [
"SetFastMode",
"sets",
"the",
"drone",
"throttle",
"to",
"1",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L395-L401 |
156,016 | hybridgroup/gobot | platforms/dji/tello/driver.go | Rate | func (d *Driver) Rate() (err error) {
buf, _ := d.createPacket(videoRateQuery, 0x48, 0)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | go | func (d *Driver) Rate() (err error) {
buf, _ := d.createPacket(videoRateQuery, 0x48, 0)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Rate",
"(",
")",
"(",
"err",
"error",
")",
"{",
"buf",
",",
"_",
":=",
"d",
".",
"createPacket",
"(",
"videoRateQuery",
",",
"0x48",
",",
"0",
")",
"\n",
"d",
".",
"seq",
"++",
"\n",
"binary",
".",
"Write"... | // Rate queries the current video bit rate. | [
"Rate",
"queries",
"the",
"current",
"video",
"bit",
"rate",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L413-L421 |
156,017 | hybridgroup/gobot | platforms/dji/tello/driver.go | Hover | func (d *Driver) Hover() {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()
d.rx = float32(0)
d.ry = float32(0)
d.lx = float32(0)
d.ly = float32(0)
} | go | func (d *Driver) Hover() {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()
d.rx = float32(0)
d.ry = float32(0)
d.lx = float32(0)
d.ly = float32(0)
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Hover",
"(",
")",
"{",
"d",
".",
"cmdMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"cmdMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"d",
".",
"rx",
"=",
"float32",
"(",
"0",
")",
"\n",
"d",
".",
... | // Hover tells the drone to stop moving on the X, Y, and Z axes and stay in place | [
"Hover",
"tells",
"the",
"drone",
"to",
"stop",
"moving",
"on",
"the",
"X",
"Y",
"and",
"Z",
"axes",
"and",
"stay",
"in",
"place"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L497-L505 |
156,018 | hybridgroup/gobot | platforms/dji/tello/driver.go | CeaseRotation | func (d *Driver) CeaseRotation() {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()
d.lx = float32(0)
} | go | func (d *Driver) CeaseRotation() {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()
d.lx = float32(0)
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"CeaseRotation",
"(",
")",
"{",
"d",
".",
"cmdMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"cmdMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"d",
".",
"lx",
"=",
"float32",
"(",
"0",
")",
"\n",
"}"
] | // CeaseRotation stops any rotational motion | [
"CeaseRotation",
"stops",
"any",
"rotational",
"motion"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L508-L513 |
156,019 | hybridgroup/gobot | platforms/dji/tello/driver.go | Flip | func (d *Driver) Flip(direction FlipType) (err error) {
buf, _ := d.createPacket(flipCommand, 0x70, 1)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, byte(direction))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | go | func (d *Driver) Flip(direction FlipType) (err error) {
buf, _ := d.createPacket(flipCommand, 0x70, 1)
d.seq++
binary.Write(buf, binary.LittleEndian, d.seq)
binary.Write(buf, binary.LittleEndian, byte(direction))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"Flip",
"(",
"direction",
"FlipType",
")",
"(",
"err",
"error",
")",
"{",
"buf",
",",
"_",
":=",
"d",
".",
"createPacket",
"(",
"flipCommand",
",",
"0x70",
",",
"1",
")",
"\n",
"d",
".",
"seq",
"++",
"\n",
... | // Flip tells drone to flip | [
"Flip",
"tells",
"drone",
"to",
"flip"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L532-L541 |
156,020 | hybridgroup/gobot | platforms/dji/tello/driver.go | SendStickCommand | func (d *Driver) SendStickCommand() (err error) {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()
buf, _ := d.createPacket(stickCommand, 0x60, 11)
binary.Write(buf, binary.LittleEndian, int16(0x00)) // seq = 0
// RightX center=1024 left =364 right =-364
axis1 := int16(660.0*d.rx + 1024.0)
// RightY down =364 up =-364
axis2 := int16(660.0*d.ry + 1024.0)
// LeftY down =364 up =-364
axis3 := int16(660.0*d.ly + 1024.0)
// LeftX left =364 right =-364
axis4 := int16(660.0*d.lx + 1024.0)
// speed control
axis5 := int16(d.throttle)
packedAxis := int64(axis1)&0x7FF | int64(axis2&0x7FF)<<11 | 0x7FF&int64(axis3)<<22 | 0x7FF&int64(axis4)<<33 | int64(axis5)<<44
binary.Write(buf, binary.LittleEndian, byte(0xFF&packedAxis))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>8&0xFF))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>16&0xFF))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>24&0xFF))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>32&0xFF))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>40&0xFF))
now := time.Now()
binary.Write(buf, binary.LittleEndian, byte(now.Hour()))
binary.Write(buf, binary.LittleEndian, byte(now.Minute()))
binary.Write(buf, binary.LittleEndian, byte(now.Second()))
binary.Write(buf, binary.LittleEndian, byte(now.UnixNano()/int64(time.Millisecond)&0xff))
binary.Write(buf, binary.LittleEndian, byte(now.UnixNano()/int64(time.Millisecond)>>8))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | go | func (d *Driver) SendStickCommand() (err error) {
d.cmdMutex.Lock()
defer d.cmdMutex.Unlock()
buf, _ := d.createPacket(stickCommand, 0x60, 11)
binary.Write(buf, binary.LittleEndian, int16(0x00)) // seq = 0
// RightX center=1024 left =364 right =-364
axis1 := int16(660.0*d.rx + 1024.0)
// RightY down =364 up =-364
axis2 := int16(660.0*d.ry + 1024.0)
// LeftY down =364 up =-364
axis3 := int16(660.0*d.ly + 1024.0)
// LeftX left =364 right =-364
axis4 := int16(660.0*d.lx + 1024.0)
// speed control
axis5 := int16(d.throttle)
packedAxis := int64(axis1)&0x7FF | int64(axis2&0x7FF)<<11 | 0x7FF&int64(axis3)<<22 | 0x7FF&int64(axis4)<<33 | int64(axis5)<<44
binary.Write(buf, binary.LittleEndian, byte(0xFF&packedAxis))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>8&0xFF))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>16&0xFF))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>24&0xFF))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>32&0xFF))
binary.Write(buf, binary.LittleEndian, byte(packedAxis>>40&0xFF))
now := time.Now()
binary.Write(buf, binary.LittleEndian, byte(now.Hour()))
binary.Write(buf, binary.LittleEndian, byte(now.Minute()))
binary.Write(buf, binary.LittleEndian, byte(now.Second()))
binary.Write(buf, binary.LittleEndian, byte(now.UnixNano()/int64(time.Millisecond)&0xff))
binary.Write(buf, binary.LittleEndian, byte(now.UnixNano()/int64(time.Millisecond)>>8))
binary.Write(buf, binary.LittleEndian, CalculateCRC16(buf.Bytes()))
_, err = d.cmdConn.Write(buf.Bytes())
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"SendStickCommand",
"(",
")",
"(",
"err",
"error",
")",
"{",
"d",
".",
"cmdMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"d",
".",
"cmdMutex",
".",
"Unlock",
"(",
")",
"\n\n",
"buf",
",",
"_",
":=",
"d",
".... | // SendStickCommand sends the joystick command packet to the drone. | [
"SendStickCommand",
"sends",
"the",
"joystick",
"command",
"packet",
"to",
"the",
"drone",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L675-L717 |
156,021 | hybridgroup/gobot | platforms/dji/tello/driver.go | SendCommand | func (d *Driver) SendCommand(cmd string) (err error) {
_, err = d.cmdConn.Write([]byte(cmd))
return
} | go | func (d *Driver) SendCommand(cmd string) (err error) {
_, err = d.cmdConn.Write([]byte(cmd))
return
} | [
"func",
"(",
"d",
"*",
"Driver",
")",
"SendCommand",
"(",
"cmd",
"string",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"d",
".",
"cmdConn",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"cmd",
")",
")",
"\n",
"return",
"\n",
"}"
] | // SendCommand is used to send a text command such as the initial connection request to the drone. | [
"SendCommand",
"is",
"used",
"to",
"send",
"a",
"text",
"command",
"such",
"as",
"the",
"initial",
"connection",
"request",
"to",
"the",
"drone",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L743-L746 |
156,022 | hybridgroup/gobot | robot.go | NewJSONRobot | func NewJSONRobot(robot *Robot) *JSONRobot {
jsonRobot := &JSONRobot{
Name: robot.Name,
Commands: []string{},
Connections: []*JSONConnection{},
Devices: []*JSONDevice{},
}
for command := range robot.Commands() {
jsonRobot.Commands = append(jsonRobot.Commands, command)
}
robot.Devices().Each(func(device Device) {
jsonDevice := NewJSONDevice(device)
jsonRobot.Connections = append(jsonRobot.Connections, NewJSONConnection(robot.Connection(jsonDevice.Connection)))
jsonRobot.Devices = append(jsonRobot.Devices, jsonDevice)
})
return jsonRobot
} | go | func NewJSONRobot(robot *Robot) *JSONRobot {
jsonRobot := &JSONRobot{
Name: robot.Name,
Commands: []string{},
Connections: []*JSONConnection{},
Devices: []*JSONDevice{},
}
for command := range robot.Commands() {
jsonRobot.Commands = append(jsonRobot.Commands, command)
}
robot.Devices().Each(func(device Device) {
jsonDevice := NewJSONDevice(device)
jsonRobot.Connections = append(jsonRobot.Connections, NewJSONConnection(robot.Connection(jsonDevice.Connection)))
jsonRobot.Devices = append(jsonRobot.Devices, jsonDevice)
})
return jsonRobot
} | [
"func",
"NewJSONRobot",
"(",
"robot",
"*",
"Robot",
")",
"*",
"JSONRobot",
"{",
"jsonRobot",
":=",
"&",
"JSONRobot",
"{",
"Name",
":",
"robot",
".",
"Name",
",",
"Commands",
":",
"[",
"]",
"string",
"{",
"}",
",",
"Connections",
":",
"[",
"]",
"*",
... | // NewJSONRobot returns a JSONRobot given a Robot. | [
"NewJSONRobot",
"returns",
"a",
"JSONRobot",
"given",
"a",
"Robot",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L22-L40 |
156,023 | hybridgroup/gobot | robot.go | Start | func (r *Robots) Start(args ...interface{}) (err error) {
autoRun := true
if args[0] != nil {
autoRun = args[0].(bool)
}
for _, robot := range *r {
if rerr := robot.Start(autoRun); rerr != nil {
err = multierror.Append(err, rerr)
return
}
}
return
} | go | func (r *Robots) Start(args ...interface{}) (err error) {
autoRun := true
if args[0] != nil {
autoRun = args[0].(bool)
}
for _, robot := range *r {
if rerr := robot.Start(autoRun); rerr != nil {
err = multierror.Append(err, rerr)
return
}
}
return
} | [
"func",
"(",
"r",
"*",
"Robots",
")",
"Start",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"autoRun",
":=",
"true",
"\n",
"if",
"args",
"[",
"0",
"]",
"!=",
"nil",
"{",
"autoRun",
"=",
"args",
"[",
"0",
"]",
... | // Start calls the Start method of each Robot in the collection | [
"Start",
"calls",
"the",
"Start",
"method",
"of",
"each",
"Robot",
"in",
"the",
"collection"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L67-L79 |
156,024 | hybridgroup/gobot | robot.go | Stop | func (r *Robots) Stop() (err error) {
for _, robot := range *r {
if rerr := robot.Stop(); rerr != nil {
err = multierror.Append(err, rerr)
return
}
}
return
} | go | func (r *Robots) Stop() (err error) {
for _, robot := range *r {
if rerr := robot.Stop(); rerr != nil {
err = multierror.Append(err, rerr)
return
}
}
return
} | [
"func",
"(",
"r",
"*",
"Robots",
")",
"Stop",
"(",
")",
"(",
"err",
"error",
")",
"{",
"for",
"_",
",",
"robot",
":=",
"range",
"*",
"r",
"{",
"if",
"rerr",
":=",
"robot",
".",
"Stop",
"(",
")",
";",
"rerr",
"!=",
"nil",
"{",
"err",
"=",
"m... | // Stop calls the Stop method of each Robot in the collection | [
"Stop",
"calls",
"the",
"Stop",
"method",
"of",
"each",
"Robot",
"in",
"the",
"collection"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L82-L90 |
156,025 | hybridgroup/gobot | robot.go | Each | func (r *Robots) Each(f func(*Robot)) {
for _, robot := range *r {
f(robot)
}
} | go | func (r *Robots) Each(f func(*Robot)) {
for _, robot := range *r {
f(robot)
}
} | [
"func",
"(",
"r",
"*",
"Robots",
")",
"Each",
"(",
"f",
"func",
"(",
"*",
"Robot",
")",
")",
"{",
"for",
"_",
",",
"robot",
":=",
"range",
"*",
"r",
"{",
"f",
"(",
"robot",
")",
"\n",
"}",
"\n",
"}"
] | // Each enumerates through the Robots and calls specified callback function. | [
"Each",
"enumerates",
"through",
"the",
"Robots",
"and",
"calls",
"specified",
"callback",
"function",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L93-L97 |
156,026 | hybridgroup/gobot | robot.go | Start | func (r *Robot) Start(args ...interface{}) (err error) {
if len(args) > 0 && args[0] != nil {
r.AutoRun = args[0].(bool)
}
log.Println("Starting Robot", r.Name, "...")
if cerr := r.Connections().Start(); cerr != nil {
err = multierror.Append(err, cerr)
log.Println(err)
return
}
if derr := r.Devices().Start(); derr != nil {
err = multierror.Append(err, derr)
log.Println(err)
return
}
if r.Work == nil {
r.Work = func() {}
}
log.Println("Starting work...")
go func() {
r.Work()
<-r.done
}()
r.running.Store(true)
if r.AutoRun {
c := make(chan os.Signal, 1)
r.trap(c)
// waiting for interrupt coming on the channel
<-c
// Stop calls the Stop method on itself, if we are "auto-running".
r.Stop()
}
return
} | go | func (r *Robot) Start(args ...interface{}) (err error) {
if len(args) > 0 && args[0] != nil {
r.AutoRun = args[0].(bool)
}
log.Println("Starting Robot", r.Name, "...")
if cerr := r.Connections().Start(); cerr != nil {
err = multierror.Append(err, cerr)
log.Println(err)
return
}
if derr := r.Devices().Start(); derr != nil {
err = multierror.Append(err, derr)
log.Println(err)
return
}
if r.Work == nil {
r.Work = func() {}
}
log.Println("Starting work...")
go func() {
r.Work()
<-r.done
}()
r.running.Store(true)
if r.AutoRun {
c := make(chan os.Signal, 1)
r.trap(c)
// waiting for interrupt coming on the channel
<-c
// Stop calls the Stop method on itself, if we are "auto-running".
r.Stop()
}
return
} | [
"func",
"(",
"r",
"*",
"Robot",
")",
"Start",
"(",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"if",
"len",
"(",
"args",
")",
">",
"0",
"&&",
"args",
"[",
"0",
"]",
"!=",
"nil",
"{",
"r",
".",
"AutoRun",
"=",
"... | // Start a Robot's Connections, Devices, and work. | [
"Start",
"a",
"Robot",
"s",
"Connections",
"Devices",
"and",
"work",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L149-L187 |
156,027 | hybridgroup/gobot | robot.go | Stop | func (r *Robot) Stop() error {
var result error
log.Println("Stopping Robot", r.Name, "...")
err := r.Devices().Halt()
if err != nil {
result = multierror.Append(result, err)
}
err = r.Connections().Finalize()
if err != nil {
result = multierror.Append(result, err)
}
r.done <- true
r.running.Store(false)
return result
} | go | func (r *Robot) Stop() error {
var result error
log.Println("Stopping Robot", r.Name, "...")
err := r.Devices().Halt()
if err != nil {
result = multierror.Append(result, err)
}
err = r.Connections().Finalize()
if err != nil {
result = multierror.Append(result, err)
}
r.done <- true
r.running.Store(false)
return result
} | [
"func",
"(",
"r",
"*",
"Robot",
")",
"Stop",
"(",
")",
"error",
"{",
"var",
"result",
"error",
"\n",
"log",
".",
"Println",
"(",
"\"",
"\"",
",",
"r",
".",
"Name",
",",
"\"",
"\"",
")",
"\n",
"err",
":=",
"r",
".",
"Devices",
"(",
")",
".",
... | // Stop stops a Robot's connections and Devices | [
"Stop",
"stops",
"a",
"Robot",
"s",
"connections",
"and",
"Devices"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L190-L205 |
156,028 | hybridgroup/gobot | robot.go | AddDevice | func (r *Robot) AddDevice(d Device) Device {
*r.devices = append(*r.Devices(), d)
return d
} | go | func (r *Robot) AddDevice(d Device) Device {
*r.devices = append(*r.Devices(), d)
return d
} | [
"func",
"(",
"r",
"*",
"Robot",
")",
"AddDevice",
"(",
"d",
"Device",
")",
"Device",
"{",
"*",
"r",
".",
"devices",
"=",
"append",
"(",
"*",
"r",
".",
"Devices",
"(",
")",
",",
"d",
")",
"\n",
"return",
"d",
"\n",
"}"
] | // AddDevice adds a new Device to the robots collection of devices. Returns the
// added device. | [
"AddDevice",
"adds",
"a",
"new",
"Device",
"to",
"the",
"robots",
"collection",
"of",
"devices",
".",
"Returns",
"the",
"added",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L219-L222 |
156,029 | hybridgroup/gobot | robot.go | Device | func (r *Robot) Device(name string) Device {
if r == nil {
return nil
}
for _, device := range *r.devices {
if device.Name() == name {
return device
}
}
return nil
} | go | func (r *Robot) Device(name string) Device {
if r == nil {
return nil
}
for _, device := range *r.devices {
if device.Name() == name {
return device
}
}
return nil
} | [
"func",
"(",
"r",
"*",
"Robot",
")",
"Device",
"(",
"name",
"string",
")",
"Device",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"device",
":=",
"range",
"*",
"r",
".",
"devices",
"{",
"if",
"device",
".... | // Device returns a device given a name. Returns nil if the Device does not exist. | [
"Device",
"returns",
"a",
"device",
"given",
"a",
"name",
".",
"Returns",
"nil",
"if",
"the",
"Device",
"does",
"not",
"exist",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L225-L235 |
156,030 | hybridgroup/gobot | robot.go | AddConnection | func (r *Robot) AddConnection(c Connection) Connection {
*r.connections = append(*r.Connections(), c)
return c
} | go | func (r *Robot) AddConnection(c Connection) Connection {
*r.connections = append(*r.Connections(), c)
return c
} | [
"func",
"(",
"r",
"*",
"Robot",
")",
"AddConnection",
"(",
"c",
"Connection",
")",
"Connection",
"{",
"*",
"r",
".",
"connections",
"=",
"append",
"(",
"*",
"r",
".",
"Connections",
"(",
")",
",",
"c",
")",
"\n",
"return",
"c",
"\n",
"}"
] | // AddConnection adds a new connection to the robots collection of connections.
// Returns the added connection. | [
"AddConnection",
"adds",
"a",
"new",
"connection",
"to",
"the",
"robots",
"collection",
"of",
"connections",
".",
"Returns",
"the",
"added",
"connection",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L244-L247 |
156,031 | hybridgroup/gobot | robot.go | Connection | func (r *Robot) Connection(name string) Connection {
if r == nil {
return nil
}
for _, connection := range *r.connections {
if connection.Name() == name {
return connection
}
}
return nil
} | go | func (r *Robot) Connection(name string) Connection {
if r == nil {
return nil
}
for _, connection := range *r.connections {
if connection.Name() == name {
return connection
}
}
return nil
} | [
"func",
"(",
"r",
"*",
"Robot",
")",
"Connection",
"(",
"name",
"string",
")",
"Connection",
"{",
"if",
"r",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"connection",
":=",
"range",
"*",
"r",
".",
"connections",
"{",
"if",
... | // Connection returns a connection given a name. Returns nil if the Connection
// does not exist. | [
"Connection",
"returns",
"a",
"connection",
"given",
"a",
"name",
".",
"Returns",
"nil",
"if",
"the",
"Connection",
"does",
"not",
"exist",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/robot.go#L251-L261 |
156,032 | hybridgroup/gobot | drivers/i2c/l3gd20h_driver.go | XYZ | func (d *L3GD20HDriver) XYZ() (x float32, y float32, z float32, err error) {
if _, err = d.connection.Write([]byte{l3gd20hRegisterOutXLSB}); err != nil {
return 0, 0, 0, err
}
measurements := make([]byte, 6)
if _, err = d.connection.Read(measurements); err != nil {
return 0, 0, 0, err
}
var rawX int16
var rawY int16
var rawZ int16
buf := bytes.NewBuffer(measurements)
binary.Read(buf, binary.LittleEndian, &rawX)
binary.Read(buf, binary.LittleEndian, &rawY)
binary.Read(buf, binary.LittleEndian, &rawZ)
// Sensitivity values from the mechanical characteristics in the datasheet.
sensitivity := d.getSensitivity()
return float32(rawX) * sensitivity, float32(rawY) * sensitivity, float32(rawZ) * sensitivity, nil
} | go | func (d *L3GD20HDriver) XYZ() (x float32, y float32, z float32, err error) {
if _, err = d.connection.Write([]byte{l3gd20hRegisterOutXLSB}); err != nil {
return 0, 0, 0, err
}
measurements := make([]byte, 6)
if _, err = d.connection.Read(measurements); err != nil {
return 0, 0, 0, err
}
var rawX int16
var rawY int16
var rawZ int16
buf := bytes.NewBuffer(measurements)
binary.Read(buf, binary.LittleEndian, &rawX)
binary.Read(buf, binary.LittleEndian, &rawY)
binary.Read(buf, binary.LittleEndian, &rawZ)
// Sensitivity values from the mechanical characteristics in the datasheet.
sensitivity := d.getSensitivity()
return float32(rawX) * sensitivity, float32(rawY) * sensitivity, float32(rawZ) * sensitivity, nil
} | [
"func",
"(",
"d",
"*",
"L3GD20HDriver",
")",
"XYZ",
"(",
")",
"(",
"x",
"float32",
",",
"y",
"float32",
",",
"z",
"float32",
",",
"err",
"error",
")",
"{",
"if",
"_",
",",
"err",
"=",
"d",
".",
"connection",
".",
"Write",
"(",
"[",
"]",
"byte",... | // XYZ returns the current change in degrees per second, for the 3 axis. | [
"XYZ",
"returns",
"the",
"current",
"change",
"in",
"degrees",
"per",
"second",
"for",
"the",
"3",
"axis",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/l3gd20h_driver.go#L111-L132 |
156,033 | hybridgroup/gobot | drivers/gpio/direct_pin_driver.go | Off | func (d *DirectPinDriver) Off() (err error) {
if writer, ok := d.Connection().(DigitalWriter); ok {
return writer.DigitalWrite(d.Pin(), byte(0))
}
err = ErrDigitalWriteUnsupported
return
} | go | func (d *DirectPinDriver) Off() (err error) {
if writer, ok := d.Connection().(DigitalWriter); ok {
return writer.DigitalWrite(d.Pin(), byte(0))
}
err = ErrDigitalWriteUnsupported
return
} | [
"func",
"(",
"d",
"*",
"DirectPinDriver",
")",
"Off",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"writer",
",",
"ok",
":=",
"d",
".",
"Connection",
"(",
")",
".",
"(",
"DigitalWriter",
")",
";",
"ok",
"{",
"return",
"writer",
".",
"DigitalWrite... | // Turn Off pin | [
"Turn",
"Off",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/direct_pin_driver.go#L72-L78 |
156,034 | hybridgroup/gobot | drivers/gpio/direct_pin_driver.go | DigitalRead | func (d *DirectPinDriver) DigitalRead() (val int, err error) {
if reader, ok := d.Connection().(DigitalReader); ok {
return reader.DigitalRead(d.Pin())
}
err = ErrDigitalReadUnsupported
return
} | go | func (d *DirectPinDriver) DigitalRead() (val int, err error) {
if reader, ok := d.Connection().(DigitalReader); ok {
return reader.DigitalRead(d.Pin())
}
err = ErrDigitalReadUnsupported
return
} | [
"func",
"(",
"d",
"*",
"DirectPinDriver",
")",
"DigitalRead",
"(",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"if",
"reader",
",",
"ok",
":=",
"d",
".",
"Connection",
"(",
")",
".",
"(",
"DigitalReader",
")",
";",
"ok",
"{",
"return",
... | // DigitalRead returns the current digital state of the pin | [
"DigitalRead",
"returns",
"the",
"current",
"digital",
"state",
"of",
"the",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/direct_pin_driver.go#L90-L96 |
156,035 | hybridgroup/gobot | drivers/gpio/direct_pin_driver.go | ServoWrite | func (d *DirectPinDriver) ServoWrite(level byte) (err error) {
if writer, ok := d.Connection().(ServoWriter); ok {
return writer.ServoWrite(d.Pin(), level)
}
err = ErrServoWriteUnsupported
return
} | go | func (d *DirectPinDriver) ServoWrite(level byte) (err error) {
if writer, ok := d.Connection().(ServoWriter); ok {
return writer.ServoWrite(d.Pin(), level)
}
err = ErrServoWriteUnsupported
return
} | [
"func",
"(",
"d",
"*",
"DirectPinDriver",
")",
"ServoWrite",
"(",
"level",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"writer",
",",
"ok",
":=",
"d",
".",
"Connection",
"(",
")",
".",
"(",
"ServoWriter",
")",
";",
"ok",
"{",
"return",
"write... | // ServoWrite writes value to the specified pin | [
"ServoWrite",
"writes",
"value",
"to",
"the",
"specified",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/direct_pin_driver.go#L117-L123 |
156,036 | hybridgroup/gobot | connection.go | NewJSONConnection | func NewJSONConnection(connection Connection) *JSONConnection {
return &JSONConnection{
Name: connection.Name(),
Adaptor: reflect.TypeOf(connection).String(),
}
} | go | func NewJSONConnection(connection Connection) *JSONConnection {
return &JSONConnection{
Name: connection.Name(),
Adaptor: reflect.TypeOf(connection).String(),
}
} | [
"func",
"NewJSONConnection",
"(",
"connection",
"Connection",
")",
"*",
"JSONConnection",
"{",
"return",
"&",
"JSONConnection",
"{",
"Name",
":",
"connection",
".",
"Name",
"(",
")",
",",
"Adaptor",
":",
"reflect",
".",
"TypeOf",
"(",
"connection",
")",
".",... | // NewJSONConnection returns a JSONConnection given a Connection. | [
"NewJSONConnection",
"returns",
"a",
"JSONConnection",
"given",
"a",
"Connection",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/connection.go#L17-L22 |
156,037 | hybridgroup/gobot | connection.go | Each | func (c *Connections) Each(f func(Connection)) {
for _, connection := range *c {
f(connection)
}
} | go | func (c *Connections) Each(f func(Connection)) {
for _, connection := range *c {
f(connection)
}
} | [
"func",
"(",
"c",
"*",
"Connections",
")",
"Each",
"(",
"f",
"func",
"(",
"Connection",
")",
")",
"{",
"for",
"_",
",",
"connection",
":=",
"range",
"*",
"c",
"{",
"f",
"(",
"connection",
")",
"\n",
"}",
"\n",
"}"
] | // Each enumerates through the Connections and calls specified callback function. | [
"Each",
"enumerates",
"through",
"the",
"Connections",
"and",
"calls",
"specified",
"callback",
"function",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/connection.go#L36-L40 |
156,038 | hybridgroup/gobot | connection.go | Start | func (c *Connections) Start() (err error) {
log.Println("Starting connections...")
for _, connection := range *c {
info := "Starting connection " + connection.Name()
if porter, ok := connection.(Porter); ok {
info = info + " on port " + porter.Port()
}
log.Println(info + "...")
if cerr := connection.Connect(); cerr != nil {
err = multierror.Append(err, cerr)
}
}
return err
} | go | func (c *Connections) Start() (err error) {
log.Println("Starting connections...")
for _, connection := range *c {
info := "Starting connection " + connection.Name()
if porter, ok := connection.(Porter); ok {
info = info + " on port " + porter.Port()
}
log.Println(info + "...")
if cerr := connection.Connect(); cerr != nil {
err = multierror.Append(err, cerr)
}
}
return err
} | [
"func",
"(",
"c",
"*",
"Connections",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"log",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"connection",
":=",
"range",
"*",
"c",
"{",
"info",
":=",
"\"",
"\"",
"+",
"connect... | // Start calls Connect on each Connection in c | [
"Start",
"calls",
"Connect",
"on",
"each",
"Connection",
"in",
"c"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/connection.go#L43-L59 |
156,039 | hybridgroup/gobot | connection.go | Finalize | func (c *Connections) Finalize() (err error) {
for _, connection := range *c {
if cerr := connection.Finalize(); cerr != nil {
err = multierror.Append(err, cerr)
}
}
return err
} | go | func (c *Connections) Finalize() (err error) {
for _, connection := range *c {
if cerr := connection.Finalize(); cerr != nil {
err = multierror.Append(err, cerr)
}
}
return err
} | [
"func",
"(",
"c",
"*",
"Connections",
")",
"Finalize",
"(",
")",
"(",
"err",
"error",
")",
"{",
"for",
"_",
",",
"connection",
":=",
"range",
"*",
"c",
"{",
"if",
"cerr",
":=",
"connection",
".",
"Finalize",
"(",
")",
";",
"cerr",
"!=",
"nil",
"{... | // Finalize calls Finalize on each Connection in c | [
"Finalize",
"calls",
"Finalize",
"on",
"each",
"Connection",
"in",
"c"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/connection.go#L62-L69 |
156,040 | hybridgroup/gobot | platforms/sphero/sprkplus/sprkplus_packets.go | DefaultCollisionConfig | func DefaultCollisionConfig() sphero.CollisionConfig {
return sphero.CollisionConfig{
Method: 0x01,
Xt: 0x20,
Yt: 0x20,
Xs: 0x20,
Ys: 0x20,
Dead: 0x01,
}
} | go | func DefaultCollisionConfig() sphero.CollisionConfig {
return sphero.CollisionConfig{
Method: 0x01,
Xt: 0x20,
Yt: 0x20,
Xs: 0x20,
Ys: 0x20,
Dead: 0x01,
}
} | [
"func",
"DefaultCollisionConfig",
"(",
")",
"sphero",
".",
"CollisionConfig",
"{",
"return",
"sphero",
".",
"CollisionConfig",
"{",
"Method",
":",
"0x01",
",",
"Xt",
":",
"0x20",
",",
"Yt",
":",
"0x20",
",",
"Xs",
":",
"0x20",
",",
"Ys",
":",
"0x20",
"... | // DefaultCollisionConfig returns a CollisionConfig with sensible collision defaults | [
"DefaultCollisionConfig",
"returns",
"a",
"CollisionConfig",
"with",
"sensible",
"collision",
"defaults"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sprkplus/sprkplus_packets.go#L6-L15 |
156,041 | hybridgroup/gobot | platforms/tinkerboard/adaptor.go | NewAdaptor | func NewAdaptor() *Adaptor {
c := &Adaptor{
name: gobot.DefaultName("Tinker Board"),
mutex: &sync.Mutex{},
}
c.setPins()
return c
} | go | func NewAdaptor() *Adaptor {
c := &Adaptor{
name: gobot.DefaultName("Tinker Board"),
mutex: &sync.Mutex{},
}
c.setPins()
return c
} | [
"func",
"NewAdaptor",
"(",
")",
"*",
"Adaptor",
"{",
"c",
":=",
"&",
"Adaptor",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"mutex",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"}",
"\n\n",
"c",
".",
"setPins",
... | // NewAdaptor creates a Tinkerboard Adaptor | [
"NewAdaptor",
"creates",
"a",
"Tinkerboard",
"Adaptor"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/tinkerboard/adaptor.go#L30-L38 |
156,042 | hybridgroup/gobot | drivers/gpio/grove_drivers.go | NewGroveBuzzerDriver | func NewGroveBuzzerDriver(a DigitalWriter, pin string) *GroveBuzzerDriver {
return &GroveBuzzerDriver{
BuzzerDriver: NewBuzzerDriver(a, pin),
}
} | go | func NewGroveBuzzerDriver(a DigitalWriter, pin string) *GroveBuzzerDriver {
return &GroveBuzzerDriver{
BuzzerDriver: NewBuzzerDriver(a, pin),
}
} | [
"func",
"NewGroveBuzzerDriver",
"(",
"a",
"DigitalWriter",
",",
"pin",
"string",
")",
"*",
"GroveBuzzerDriver",
"{",
"return",
"&",
"GroveBuzzerDriver",
"{",
"BuzzerDriver",
":",
"NewBuzzerDriver",
"(",
"a",
",",
"pin",
")",
",",
"}",
"\n",
"}"
] | // NewGroveBuzzerDriver return a new GroveBuzzerDriver given a DigitalWriter and pin. | [
"NewGroveBuzzerDriver",
"return",
"a",
"new",
"GroveBuzzerDriver",
"given",
"a",
"DigitalWriter",
"and",
"pin",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/grove_drivers.go#L49-L53 |
156,043 | hybridgroup/gobot | platforms/microbit/io_pin_driver.go | NewIOPinDriver | func NewIOPinDriver(a ble.BLEConnector) *IOPinDriver {
n := &IOPinDriver{
name: gobot.DefaultName("Microbit IO Pins"),
connection: a,
Eventer: gobot.NewEventer(),
}
return n
} | go | func NewIOPinDriver(a ble.BLEConnector) *IOPinDriver {
n := &IOPinDriver{
name: gobot.DefaultName("Microbit IO Pins"),
connection: a,
Eventer: gobot.NewEventer(),
}
return n
} | [
"func",
"NewIOPinDriver",
"(",
"a",
"ble",
".",
"BLEConnector",
")",
"*",
"IOPinDriver",
"{",
"n",
":=",
"&",
"IOPinDriver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"connection",
":",
"a",
",",
"Eventer",
":",
"gobot",... | // NewIOPinDriver creates a Microbit IOPinDriver | [
"NewIOPinDriver",
"creates",
"a",
"Microbit",
"IOPinDriver"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/io_pin_driver.go#L40-L48 |
156,044 | hybridgroup/gobot | platforms/microbit/io_pin_driver.go | ReadAllPinData | func (b *IOPinDriver) ReadAllPinData() (pins []PinData) {
c, _ := b.adaptor().ReadCharacteristic(pinDataCharacteristic)
buf := bytes.NewBuffer(c)
pinsData := make([]PinData, buf.Len()/2)
for i := 0; i < buf.Len()/2; i++ {
pinData := PinData{}
pinData.pin, _ = buf.ReadByte()
pinData.value, _ = buf.ReadByte()
pinsData[i] = pinData
}
return pinsData
} | go | func (b *IOPinDriver) ReadAllPinData() (pins []PinData) {
c, _ := b.adaptor().ReadCharacteristic(pinDataCharacteristic)
buf := bytes.NewBuffer(c)
pinsData := make([]PinData, buf.Len()/2)
for i := 0; i < buf.Len()/2; i++ {
pinData := PinData{}
pinData.pin, _ = buf.ReadByte()
pinData.value, _ = buf.ReadByte()
pinsData[i] = pinData
}
return pinsData
} | [
"func",
"(",
"b",
"*",
"IOPinDriver",
")",
"ReadAllPinData",
"(",
")",
"(",
"pins",
"[",
"]",
"PinData",
")",
"{",
"c",
",",
"_",
":=",
"b",
".",
"adaptor",
"(",
")",
".",
"ReadCharacteristic",
"(",
"pinDataCharacteristic",
")",
"\n",
"buf",
":=",
"b... | // ReadAllPinData reads and returns the pin data for all pins | [
"ReadAllPinData",
"reads",
"and",
"returns",
"the",
"pin",
"data",
"for",
"all",
"pins"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/io_pin_driver.go#L80-L93 |
156,045 | hybridgroup/gobot | platforms/microbit/io_pin_driver.go | WritePinData | func (b *IOPinDriver) WritePinData(pin string, data byte) (err error) {
i, err := strconv.Atoi(pin)
if err != nil {
return
}
buf := []byte{byte(i), data}
err = b.adaptor().WriteCharacteristic(pinDataCharacteristic, buf)
return err
} | go | func (b *IOPinDriver) WritePinData(pin string, data byte) (err error) {
i, err := strconv.Atoi(pin)
if err != nil {
return
}
buf := []byte{byte(i), data}
err = b.adaptor().WriteCharacteristic(pinDataCharacteristic, buf)
return err
} | [
"func",
"(",
"b",
"*",
"IOPinDriver",
")",
"WritePinData",
"(",
"pin",
"string",
",",
"data",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return... | // WritePinData writes the pin data for a single pin | [
"WritePinData",
"writes",
"the",
"pin",
"data",
"for",
"a",
"single",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/io_pin_driver.go#L96-L105 |
156,046 | hybridgroup/gobot | platforms/microbit/io_pin_driver.go | ReadPinIOConfig | func (b *IOPinDriver) ReadPinIOConfig() (config int, err error) {
c, e := b.adaptor().ReadCharacteristic(pinIOConfigCharacteristic)
if e != nil {
return 0, e
}
var result byte
for i := 0; i < 4; i++ {
result |= c[i] << uint(i)
}
b.ioMask = int(result)
return int(result), nil
} | go | func (b *IOPinDriver) ReadPinIOConfig() (config int, err error) {
c, e := b.adaptor().ReadCharacteristic(pinIOConfigCharacteristic)
if e != nil {
return 0, e
}
var result byte
for i := 0; i < 4; i++ {
result |= c[i] << uint(i)
}
b.ioMask = int(result)
return int(result), nil
} | [
"func",
"(",
"b",
"*",
"IOPinDriver",
")",
"ReadPinIOConfig",
"(",
")",
"(",
"config",
"int",
",",
"err",
"error",
")",
"{",
"c",
",",
"e",
":=",
"b",
".",
"adaptor",
"(",
")",
".",
"ReadCharacteristic",
"(",
"pinIOConfigCharacteristic",
")",
"\n",
"if... | // ReadPinIOConfig reads and returns the pin IO config mask for all pins | [
"ReadPinIOConfig",
"reads",
"and",
"returns",
"the",
"pin",
"IO",
"config",
"mask",
"for",
"all",
"pins"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/io_pin_driver.go#L132-L145 |
156,047 | hybridgroup/gobot | platforms/microbit/io_pin_driver.go | DigitalRead | func (b *IOPinDriver) DigitalRead(pin string) (val int, err error) {
p, err := validatedPin(pin)
if err != nil {
return
}
b.ensureDigital(p)
b.ensureInput(p)
pins := b.ReadAllPinData()
return int(pins[p].value), nil
} | go | func (b *IOPinDriver) DigitalRead(pin string) (val int, err error) {
p, err := validatedPin(pin)
if err != nil {
return
}
b.ensureDigital(p)
b.ensureInput(p)
pins := b.ReadAllPinData()
return int(pins[p].value), nil
} | [
"func",
"(",
"b",
"*",
"IOPinDriver",
")",
"DigitalRead",
"(",
"pin",
"string",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"validatedPin",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}... | // DigitalRead reads from a pin | [
"DigitalRead",
"reads",
"from",
"a",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/io_pin_driver.go#L157-L168 |
156,048 | hybridgroup/gobot | platforms/microbit/io_pin_driver.go | DigitalWrite | func (b *IOPinDriver) DigitalWrite(pin string, level byte) (err error) {
p, err := validatedPin(pin)
if err != nil {
return
}
b.ensureDigital(p)
b.ensureOutput(p)
return b.WritePinData(pin, level)
} | go | func (b *IOPinDriver) DigitalWrite(pin string, level byte) (err error) {
p, err := validatedPin(pin)
if err != nil {
return
}
b.ensureDigital(p)
b.ensureOutput(p)
return b.WritePinData(pin, level)
} | [
"func",
"(",
"b",
"*",
"IOPinDriver",
")",
"DigitalWrite",
"(",
"pin",
"string",
",",
"level",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"validatedPin",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
... | // DigitalWrite writes to a pin | [
"DigitalWrite",
"writes",
"to",
"a",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/io_pin_driver.go#L171-L181 |
156,049 | hybridgroup/gobot | platforms/microbit/io_pin_driver.go | AnalogRead | func (b *IOPinDriver) AnalogRead(pin string) (val int, err error) {
p, err := validatedPin(pin)
if err != nil {
return
}
b.ensureAnalog(p)
b.ensureInput(p)
pins := b.ReadAllPinData()
return int(pins[p].value), nil
} | go | func (b *IOPinDriver) AnalogRead(pin string) (val int, err error) {
p, err := validatedPin(pin)
if err != nil {
return
}
b.ensureAnalog(p)
b.ensureInput(p)
pins := b.ReadAllPinData()
return int(pins[p].value), nil
} | [
"func",
"(",
"b",
"*",
"IOPinDriver",
")",
"AnalogRead",
"(",
"pin",
"string",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"validatedPin",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}"... | // AnalogRead reads from a pin | [
"AnalogRead",
"reads",
"from",
"a",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/io_pin_driver.go#L184-L195 |
156,050 | hybridgroup/gobot | platforms/microbit/io_pin_driver.go | hasBit | func hasBit(n int, pos int) bool {
val := n & (1 << uint(pos))
return (val > 0)
} | go | func hasBit(n int, pos int) bool {
val := n & (1 << uint(pos))
return (val > 0)
} | [
"func",
"hasBit",
"(",
"n",
"int",
",",
"pos",
"int",
")",
"bool",
"{",
"val",
":=",
"n",
"&",
"(",
"1",
"<<",
"uint",
"(",
"pos",
")",
")",
"\n",
"return",
"(",
"val",
">",
"0",
")",
"\n",
"}"
] | // Test if the bit at pos is set in the integer n. | [
"Test",
"if",
"the",
"bit",
"at",
"pos",
"is",
"set",
"in",
"the",
"integer",
"n",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/io_pin_driver.go#L242-L245 |
156,051 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | Start | func (g *Driver) Start() (err error) {
bus := g.GetBusOrDefault(g.connector.GetSpiDefaultBus())
chip := g.GetChipOrDefault(g.connector.GetSpiDefaultChip())
mode := g.GetModeOrDefault(g.connector.GetSpiDefaultMode())
bits := g.GetBitsOrDefault(g.connector.GetSpiDefaultBits())
maxSpeed := g.GetSpeedOrDefault(g.connector.GetSpiDefaultMaxSpeed())
g.connection, err = g.connector.GetSpiConnection(bus, chip, mode, bits, maxSpeed)
if err != nil {
return err
}
return nil
} | go | func (g *Driver) Start() (err error) {
bus := g.GetBusOrDefault(g.connector.GetSpiDefaultBus())
chip := g.GetChipOrDefault(g.connector.GetSpiDefaultChip())
mode := g.GetModeOrDefault(g.connector.GetSpiDefaultMode())
bits := g.GetBitsOrDefault(g.connector.GetSpiDefaultBits())
maxSpeed := g.GetSpeedOrDefault(g.connector.GetSpiDefaultMaxSpeed())
g.connection, err = g.connector.GetSpiConnection(bus, chip, mode, bits, maxSpeed)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bus",
":=",
"g",
".",
"GetBusOrDefault",
"(",
"g",
".",
"connector",
".",
"GetSpiDefaultBus",
"(",
")",
")",
"\n",
"chip",
":=",
"g",
".",
"GetChipOrDefault",
... | // Start initializes the GoPiGo3 | [
"Start",
"initializes",
"the",
"GoPiGo3"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L211-L223 |
156,052 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | GetManufacturerName | func (g *Driver) GetManufacturerName() (mName string, err error) {
// read 24 bytes to get manufacturer name
response, err := g.readBytes(goPiGo3Address, GET_MANUFACTURER, 24)
if err != nil {
return mName, err
}
if err := g.responseValid(response); err != nil {
return mName, err
}
mf := response[4:23]
mf = bytes.Trim(mf, "\x00")
return fmt.Sprintf("%s", string(mf)), nil
} | go | func (g *Driver) GetManufacturerName() (mName string, err error) {
// read 24 bytes to get manufacturer name
response, err := g.readBytes(goPiGo3Address, GET_MANUFACTURER, 24)
if err != nil {
return mName, err
}
if err := g.responseValid(response); err != nil {
return mName, err
}
mf := response[4:23]
mf = bytes.Trim(mf, "\x00")
return fmt.Sprintf("%s", string(mf)), nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"GetManufacturerName",
"(",
")",
"(",
"mName",
"string",
",",
"err",
"error",
")",
"{",
"// read 24 bytes to get manufacturer name",
"response",
",",
"err",
":=",
"g",
".",
"readBytes",
"(",
"goPiGo3Address",
",",
"GET_MAN... | // GetManufacturerName returns the manufacturer from the firmware. | [
"GetManufacturerName",
"returns",
"the",
"manufacturer",
"from",
"the",
"firmware",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L226-L238 |
156,053 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | GetBoardName | func (g *Driver) GetBoardName() (bName string, err error) {
// read 24 bytes to get board name
response, err := g.readBytes(goPiGo3Address, GET_NAME, 24)
if err != nil {
return bName, err
}
if err := g.responseValid(response); err != nil {
return bName, err
}
mf := response[4:23]
mf = bytes.Trim(mf, "\x00")
return fmt.Sprintf("%s", string(mf)), nil
} | go | func (g *Driver) GetBoardName() (bName string, err error) {
// read 24 bytes to get board name
response, err := g.readBytes(goPiGo3Address, GET_NAME, 24)
if err != nil {
return bName, err
}
if err := g.responseValid(response); err != nil {
return bName, err
}
mf := response[4:23]
mf = bytes.Trim(mf, "\x00")
return fmt.Sprintf("%s", string(mf)), nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"GetBoardName",
"(",
")",
"(",
"bName",
"string",
",",
"err",
"error",
")",
"{",
"// read 24 bytes to get board name",
"response",
",",
"err",
":=",
"g",
".",
"readBytes",
"(",
"goPiGo3Address",
",",
"GET_NAME",
",",
"... | // GetBoardName returns the board name from the firmware. | [
"GetBoardName",
"returns",
"the",
"board",
"name",
"from",
"the",
"firmware",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L241-L253 |
156,054 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | GetHardwareVersion | func (g *Driver) GetHardwareVersion() (hVer string, err error) {
response, err := g.readUint32(goPiGo3Address, GET_HARDWARE_VERSION)
if err != nil {
return hVer, err
}
major := response / 1000000
minor := response / 1000 % 1000
patch := response % 1000
return fmt.Sprintf("%d.%d.%d", major, minor, patch), nil
} | go | func (g *Driver) GetHardwareVersion() (hVer string, err error) {
response, err := g.readUint32(goPiGo3Address, GET_HARDWARE_VERSION)
if err != nil {
return hVer, err
}
major := response / 1000000
minor := response / 1000 % 1000
patch := response % 1000
return fmt.Sprintf("%d.%d.%d", major, minor, patch), nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"GetHardwareVersion",
"(",
")",
"(",
"hVer",
"string",
",",
"err",
"error",
")",
"{",
"response",
",",
"err",
":=",
"g",
".",
"readUint32",
"(",
"goPiGo3Address",
",",
"GET_HARDWARE_VERSION",
")",
"\n",
"if",
"err",
... | // GetHardwareVersion returns the hardware version from the firmware. | [
"GetHardwareVersion",
"returns",
"the",
"hardware",
"version",
"from",
"the",
"firmware",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L256-L265 |
156,055 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | GetFirmwareVersion | func (g *Driver) GetFirmwareVersion() (fVer string, err error) {
response, err := g.readUint32(goPiGo3Address, GET_FIRMWARE_VERSION)
if err != nil {
return fVer, err
}
major := response / 1000000
minor := response / 1000 % 1000
patch := response % 1000
return fmt.Sprintf("%d.%d.%d", major, minor, patch), nil
} | go | func (g *Driver) GetFirmwareVersion() (fVer string, err error) {
response, err := g.readUint32(goPiGo3Address, GET_FIRMWARE_VERSION)
if err != nil {
return fVer, err
}
major := response / 1000000
minor := response / 1000 % 1000
patch := response % 1000
return fmt.Sprintf("%d.%d.%d", major, minor, patch), nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"GetFirmwareVersion",
"(",
")",
"(",
"fVer",
"string",
",",
"err",
"error",
")",
"{",
"response",
",",
"err",
":=",
"g",
".",
"readUint32",
"(",
"goPiGo3Address",
",",
"GET_FIRMWARE_VERSION",
")",
"\n",
"if",
"err",
... | // GetFirmwareVersion returns the current firmware version. | [
"GetFirmwareVersion",
"returns",
"the",
"current",
"firmware",
"version",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L268-L277 |
156,056 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | GetSerialNumber | func (g *Driver) GetSerialNumber() (sNum string, err error) {
// read 20 bytes to get the serial number
response, err := g.readBytes(goPiGo3Address, GET_ID, 20)
if err != nil {
return sNum, err
}
if err := g.responseValid(response); err != nil {
return sNum, err
}
return fmt.Sprintf("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", response[4], response[5], response[6], response[7], response[8], response[9], response[10], response[11], response[12], response[13], response[14], response[15], response[16], response[17], response[18], response[19]), nil
} | go | func (g *Driver) GetSerialNumber() (sNum string, err error) {
// read 20 bytes to get the serial number
response, err := g.readBytes(goPiGo3Address, GET_ID, 20)
if err != nil {
return sNum, err
}
if err := g.responseValid(response); err != nil {
return sNum, err
}
return fmt.Sprintf("%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", response[4], response[5], response[6], response[7], response[8], response[9], response[10], response[11], response[12], response[13], response[14], response[15], response[16], response[17], response[18], response[19]), nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"GetSerialNumber",
"(",
")",
"(",
"sNum",
"string",
",",
"err",
"error",
")",
"{",
"// read 20 bytes to get the serial number",
"response",
",",
"err",
":=",
"g",
".",
"readBytes",
"(",
"goPiGo3Address",
",",
"GET_ID",
"... | // GetSerialNumber returns the 128-bit hardware serial number of the board. | [
"GetSerialNumber",
"returns",
"the",
"128",
"-",
"bit",
"hardware",
"serial",
"number",
"of",
"the",
"board",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L280-L290 |
156,057 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | Get5vVoltage | func (g *Driver) Get5vVoltage() (voltage float32, err error) {
val, err := g.readUint16(goPiGo3Address, GET_VOLTAGE_5V)
return (float32(val) / 1000.0), err
} | go | func (g *Driver) Get5vVoltage() (voltage float32, err error) {
val, err := g.readUint16(goPiGo3Address, GET_VOLTAGE_5V)
return (float32(val) / 1000.0), err
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"Get5vVoltage",
"(",
")",
"(",
"voltage",
"float32",
",",
"err",
"error",
")",
"{",
"val",
",",
"err",
":=",
"g",
".",
"readUint16",
"(",
"goPiGo3Address",
",",
"GET_VOLTAGE_5V",
")",
"\n",
"return",
"(",
"float32"... | // Get5vVoltage returns the current voltage on the 5v line. | [
"Get5vVoltage",
"returns",
"the",
"current",
"voltage",
"on",
"the",
"5v",
"line",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L293-L296 |
156,058 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | SetLED | func (g *Driver) SetLED(led Led, red, green, blue uint8) error {
return g.writeBytes([]byte{
goPiGo3Address,
SET_LED,
byte(led),
byte(red),
byte(green),
byte(blue),
})
} | go | func (g *Driver) SetLED(led Led, red, green, blue uint8) error {
return g.writeBytes([]byte{
goPiGo3Address,
SET_LED,
byte(led),
byte(red),
byte(green),
byte(blue),
})
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"SetLED",
"(",
"led",
"Led",
",",
"red",
",",
"green",
",",
"blue",
"uint8",
")",
"error",
"{",
"return",
"g",
".",
"writeBytes",
"(",
"[",
"]",
"byte",
"{",
"goPiGo3Address",
",",
"SET_LED",
",",
"byte",
"(",
... | // SetLED sets rgb values from 0 to 255. | [
"SetLED",
"sets",
"rgb",
"values",
"from",
"0",
"to",
"255",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L305-L314 |
156,059 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | SetMotorPower | func (g *Driver) SetMotorPower(motor Motor, power int8) error {
return g.writeBytes([]byte{
goPiGo3Address,
SET_MOTOR_PWM,
byte(motor),
byte(power),
})
} | go | func (g *Driver) SetMotorPower(motor Motor, power int8) error {
return g.writeBytes([]byte{
goPiGo3Address,
SET_MOTOR_PWM,
byte(motor),
byte(power),
})
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"SetMotorPower",
"(",
"motor",
"Motor",
",",
"power",
"int8",
")",
"error",
"{",
"return",
"g",
".",
"writeBytes",
"(",
"[",
"]",
"byte",
"{",
"goPiGo3Address",
",",
"SET_MOTOR_PWM",
",",
"byte",
"(",
"motor",
")",... | // SetMotorPower sets a motor's power from -128 to 127. | [
"SetMotorPower",
"sets",
"a",
"motor",
"s",
"power",
"from",
"-",
"128",
"to",
"127",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L341-L348 |
156,060 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | SetMotorPosition | func (g *Driver) SetMotorPosition(motor Motor, position int) error {
positionRaw := position * MOTOR_TICKS_PER_DEGREE
return g.writeBytes([]byte{
goPiGo3Address,
SET_MOTOR_POSITION,
byte(motor),
byte((positionRaw >> 24) & 0xFF),
byte((positionRaw >> 16) & 0xFF),
byte((positionRaw >> 8) & 0xFF),
byte(positionRaw & 0xFF),
})
} | go | func (g *Driver) SetMotorPosition(motor Motor, position int) error {
positionRaw := position * MOTOR_TICKS_PER_DEGREE
return g.writeBytes([]byte{
goPiGo3Address,
SET_MOTOR_POSITION,
byte(motor),
byte((positionRaw >> 24) & 0xFF),
byte((positionRaw >> 16) & 0xFF),
byte((positionRaw >> 8) & 0xFF),
byte(positionRaw & 0xFF),
})
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"SetMotorPosition",
"(",
"motor",
"Motor",
",",
"position",
"int",
")",
"error",
"{",
"positionRaw",
":=",
"position",
"*",
"MOTOR_TICKS_PER_DEGREE",
"\n",
"return",
"g",
".",
"writeBytes",
"(",
"[",
"]",
"byte",
"{",
... | // SetMotorPosition sets the motor's position in degrees. | [
"SetMotorPosition",
"sets",
"the",
"motor",
"s",
"position",
"in",
"degrees",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L351-L362 |
156,061 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | SetMotorDps | func (g *Driver) SetMotorDps(motor Motor, dps int) error {
d := dps * MOTOR_TICKS_PER_DEGREE
return g.writeBytes([]byte{
goPiGo3Address,
SET_MOTOR_DPS,
byte(motor),
byte((d >> 8) & 0xFF),
byte(d & 0xFF),
})
} | go | func (g *Driver) SetMotorDps(motor Motor, dps int) error {
d := dps * MOTOR_TICKS_PER_DEGREE
return g.writeBytes([]byte{
goPiGo3Address,
SET_MOTOR_DPS,
byte(motor),
byte((d >> 8) & 0xFF),
byte(d & 0xFF),
})
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"SetMotorDps",
"(",
"motor",
"Motor",
",",
"dps",
"int",
")",
"error",
"{",
"d",
":=",
"dps",
"*",
"MOTOR_TICKS_PER_DEGREE",
"\n",
"return",
"g",
".",
"writeBytes",
"(",
"[",
"]",
"byte",
"{",
"goPiGo3Address",
","... | // SetMotorDps sets the motor target speed in degrees per second. | [
"SetMotorDps",
"sets",
"the",
"motor",
"target",
"speed",
"in",
"degrees",
"per",
"second",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L365-L374 |
156,062 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | SetMotorLimits | func (g *Driver) SetMotorLimits(motor Motor, power int8, dps int) error {
dpsUint := dps * MOTOR_TICKS_PER_DEGREE
return g.writeBytes([]byte{
goPiGo3Address,
SET_MOTOR_LIMITS,
byte(motor),
byte(power),
byte((dpsUint >> 8) & 0xFF),
byte(dpsUint & 0xFF),
})
} | go | func (g *Driver) SetMotorLimits(motor Motor, power int8, dps int) error {
dpsUint := dps * MOTOR_TICKS_PER_DEGREE
return g.writeBytes([]byte{
goPiGo3Address,
SET_MOTOR_LIMITS,
byte(motor),
byte(power),
byte((dpsUint >> 8) & 0xFF),
byte(dpsUint & 0xFF),
})
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"SetMotorLimits",
"(",
"motor",
"Motor",
",",
"power",
"int8",
",",
"dps",
"int",
")",
"error",
"{",
"dpsUint",
":=",
"dps",
"*",
"MOTOR_TICKS_PER_DEGREE",
"\n",
"return",
"g",
".",
"writeBytes",
"(",
"[",
"]",
"by... | // SetMotorLimits sets the speed limits for a motor. | [
"SetMotorLimits",
"sets",
"the",
"speed",
"limits",
"for",
"a",
"motor",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L377-L387 |
156,063 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | GetMotorStatus | func (g *Driver) GetMotorStatus(motor Motor) (flags uint8, power uint16, encoder, dps int, err error) {
message := GET_MOTOR_STATUS_RIGHT
if motor == MOTOR_LEFT {
message = GET_MOTOR_STATUS_LEFT
}
response, err := g.readBytes(goPiGo3Address, message, 12)
if err != nil {
return flags, power, encoder, dps, err
}
if err := g.responseValid(response); err != nil {
return flags, power, encoder, dps, err
}
// get flags
flags = uint8(response[4])
// get power
power = uint16(response[5])
if power&0x80 == 0x80 {
power = power - 0x100
}
// get encoder
enc := make([]byte, 4)
enc[3] = response[6]
enc[2] = response[7]
enc[1] = response[8]
enc[0] = response[9]
e := binary.LittleEndian.Uint32(enc)
if e&0x80000000 == 0x80000000 {
encoder = int(uint64(e) - 0x100000000)
}
encoder = int(e)
//get dps
d := make([]byte, 4)
d[1] = response[10]
d[0] = response[11]
ds := binary.LittleEndian.Uint32(d)
if ds&0x8000 == 0x8000 {
dps = int(ds - 0x10000)
}
dps = int(ds)
return flags, power, encoder / MOTOR_TICKS_PER_DEGREE, dps / MOTOR_TICKS_PER_DEGREE, nil
} | go | func (g *Driver) GetMotorStatus(motor Motor) (flags uint8, power uint16, encoder, dps int, err error) {
message := GET_MOTOR_STATUS_RIGHT
if motor == MOTOR_LEFT {
message = GET_MOTOR_STATUS_LEFT
}
response, err := g.readBytes(goPiGo3Address, message, 12)
if err != nil {
return flags, power, encoder, dps, err
}
if err := g.responseValid(response); err != nil {
return flags, power, encoder, dps, err
}
// get flags
flags = uint8(response[4])
// get power
power = uint16(response[5])
if power&0x80 == 0x80 {
power = power - 0x100
}
// get encoder
enc := make([]byte, 4)
enc[3] = response[6]
enc[2] = response[7]
enc[1] = response[8]
enc[0] = response[9]
e := binary.LittleEndian.Uint32(enc)
if e&0x80000000 == 0x80000000 {
encoder = int(uint64(e) - 0x100000000)
}
encoder = int(e)
//get dps
d := make([]byte, 4)
d[1] = response[10]
d[0] = response[11]
ds := binary.LittleEndian.Uint32(d)
if ds&0x8000 == 0x8000 {
dps = int(ds - 0x10000)
}
dps = int(ds)
return flags, power, encoder / MOTOR_TICKS_PER_DEGREE, dps / MOTOR_TICKS_PER_DEGREE, nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"GetMotorStatus",
"(",
"motor",
"Motor",
")",
"(",
"flags",
"uint8",
",",
"power",
"uint16",
",",
"encoder",
",",
"dps",
"int",
",",
"err",
"error",
")",
"{",
"message",
":=",
"GET_MOTOR_STATUS_RIGHT",
"\n",
"if",
... | // GetMotorStatus returns the status for the given motor. | [
"GetMotorStatus",
"returns",
"the",
"status",
"for",
"the",
"given",
"motor",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L390-L430 |
156,064 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | GetMotorEncoder | func (g *Driver) GetMotorEncoder(motor Motor) (encoder int64, err error) {
message := GET_MOTOR_ENCODER_RIGHT
if motor == MOTOR_LEFT {
message = GET_MOTOR_ENCODER_LEFT
}
response, err := g.readUint32(goPiGo3Address, message)
if err != nil {
return encoder, err
}
encoder = int64(response)
if response&0x80000000 != 0 {
encoder = encoder - 0x100000000
}
encoder = encoder / MOTOR_TICKS_PER_DEGREE
return encoder, nil
} | go | func (g *Driver) GetMotorEncoder(motor Motor) (encoder int64, err error) {
message := GET_MOTOR_ENCODER_RIGHT
if motor == MOTOR_LEFT {
message = GET_MOTOR_ENCODER_LEFT
}
response, err := g.readUint32(goPiGo3Address, message)
if err != nil {
return encoder, err
}
encoder = int64(response)
if response&0x80000000 != 0 {
encoder = encoder - 0x100000000
}
encoder = encoder / MOTOR_TICKS_PER_DEGREE
return encoder, nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"GetMotorEncoder",
"(",
"motor",
"Motor",
")",
"(",
"encoder",
"int64",
",",
"err",
"error",
")",
"{",
"message",
":=",
"GET_MOTOR_ENCODER_RIGHT",
"\n",
"if",
"motor",
"==",
"MOTOR_LEFT",
"{",
"message",
"=",
"GET_MOTO... | // GetMotorEncoder reads a motor's encoder in degrees. | [
"GetMotorEncoder",
"reads",
"a",
"motor",
"s",
"encoder",
"in",
"degrees",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L433-L448 |
156,065 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | OffsetMotorEncoder | func (g *Driver) OffsetMotorEncoder(motor Motor, offset float64) error {
offsetUint := math.Float64bits(offset * MOTOR_TICKS_PER_DEGREE)
return g.writeBytes([]byte{
goPiGo3Address,
OFFSET_MOTOR_ENCODER,
byte(motor),
byte((offsetUint >> 24) & 0xFF),
byte((offsetUint >> 16) & 0xFF),
byte((offsetUint >> 8) & 0xFF),
byte(offsetUint & 0xFF),
})
} | go | func (g *Driver) OffsetMotorEncoder(motor Motor, offset float64) error {
offsetUint := math.Float64bits(offset * MOTOR_TICKS_PER_DEGREE)
return g.writeBytes([]byte{
goPiGo3Address,
OFFSET_MOTOR_ENCODER,
byte(motor),
byte((offsetUint >> 24) & 0xFF),
byte((offsetUint >> 16) & 0xFF),
byte((offsetUint >> 8) & 0xFF),
byte(offsetUint & 0xFF),
})
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"OffsetMotorEncoder",
"(",
"motor",
"Motor",
",",
"offset",
"float64",
")",
"error",
"{",
"offsetUint",
":=",
"math",
".",
"Float64bits",
"(",
"offset",
"*",
"MOTOR_TICKS_PER_DEGREE",
")",
"\n",
"return",
"g",
".",
"wr... | // OffsetMotorEncoder offsets a motor's encoder for calibration purposes. | [
"OffsetMotorEncoder",
"offsets",
"a",
"motor",
"s",
"encoder",
"for",
"calibration",
"purposes",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L451-L462 |
156,066 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | SetGroveType | func (g *Driver) SetGroveType(port Grove, gType GroveType) error {
return g.writeBytes([]byte{
goPiGo3Address,
SET_GROVE_TYPE,
byte(port),
byte(gType),
})
} | go | func (g *Driver) SetGroveType(port Grove, gType GroveType) error {
return g.writeBytes([]byte{
goPiGo3Address,
SET_GROVE_TYPE,
byte(port),
byte(gType),
})
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"SetGroveType",
"(",
"port",
"Grove",
",",
"gType",
"GroveType",
")",
"error",
"{",
"return",
"g",
".",
"writeBytes",
"(",
"[",
"]",
"byte",
"{",
"goPiGo3Address",
",",
"SET_GROVE_TYPE",
",",
"byte",
"(",
"port",
"... | // SetGroveType sets the given port to a grove device type. | [
"SetGroveType",
"sets",
"the",
"given",
"port",
"to",
"a",
"grove",
"device",
"type",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L465-L472 |
156,067 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | PwmWrite | func (g *Driver) PwmWrite(pin string, val byte) (err error) {
var (
grovePin, grovePort Grove
)
grovePin, grovePort, _, _, err = getGroveAddresses(pin)
if err != nil {
return err
}
err = g.SetGroveType(grovePort, CUSTOM)
if err != nil {
return err
}
time.Sleep(10 * time.Millisecond)
err = g.SetGroveMode(grovePin, GROVE_OUTPUT_PWM)
if err != nil {
return err
}
time.Sleep(10 * time.Millisecond)
err = g.SetPWMFreq(grovePin, 24000)
if err != nil {
return err
}
val64 := math.Float64frombits(uint64(val))
dutyCycle := uint16(math.Float64bits((100.0 / 255.0) * val64))
return g.SetPWMDuty(grovePin, dutyCycle)
} | go | func (g *Driver) PwmWrite(pin string, val byte) (err error) {
var (
grovePin, grovePort Grove
)
grovePin, grovePort, _, _, err = getGroveAddresses(pin)
if err != nil {
return err
}
err = g.SetGroveType(grovePort, CUSTOM)
if err != nil {
return err
}
time.Sleep(10 * time.Millisecond)
err = g.SetGroveMode(grovePin, GROVE_OUTPUT_PWM)
if err != nil {
return err
}
time.Sleep(10 * time.Millisecond)
err = g.SetPWMFreq(grovePin, 24000)
if err != nil {
return err
}
val64 := math.Float64frombits(uint64(val))
dutyCycle := uint16(math.Float64bits((100.0 / 255.0) * val64))
return g.SetPWMDuty(grovePin, dutyCycle)
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"PwmWrite",
"(",
"pin",
"string",
",",
"val",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"var",
"(",
"grovePin",
",",
"grovePort",
"Grove",
"\n",
")",
"\n",
"grovePin",
",",
"grovePort",
",",
"_",
",",
"_",
... | // PwmWrite implents the pwm interface for the gopigo3. | [
"PwmWrite",
"implents",
"the",
"pwm",
"interface",
"for",
"the",
"gopigo3",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L520-L545 |
156,068 | hybridgroup/gobot | platforms/dexter/gopigo3/driver.go | AnalogRead | func (g *Driver) AnalogRead(pin string) (value int, err error) {
var (
grovePin, grovePort Grove
analogCmd byte
)
grovePin, grovePort, analogCmd, _, err = getGroveAddresses(pin)
if err != nil {
return value, err
}
err = g.SetGroveType(grovePort, CUSTOM)
if err != nil {
return value, err
}
time.Sleep(10 * time.Millisecond)
err = g.SetGroveMode(grovePin, GROVE_INPUT_ANALOG)
if err != nil {
return value, err
}
time.Sleep(10 * time.Millisecond)
response, err := g.readBytes(goPiGo3Address, analogCmd, 7)
if err != nil {
return value, err
}
if err := g.responseValid(response); err != nil {
return value, err
}
if err := g.valueValid(response); err != nil {
return value, err
}
highBytes := uint16(response[5])
lowBytes := uint16(response[6])
return int((highBytes<<8)&0xFF00) | int(lowBytes&0xFF), nil
} | go | func (g *Driver) AnalogRead(pin string) (value int, err error) {
var (
grovePin, grovePort Grove
analogCmd byte
)
grovePin, grovePort, analogCmd, _, err = getGroveAddresses(pin)
if err != nil {
return value, err
}
err = g.SetGroveType(grovePort, CUSTOM)
if err != nil {
return value, err
}
time.Sleep(10 * time.Millisecond)
err = g.SetGroveMode(grovePin, GROVE_INPUT_ANALOG)
if err != nil {
return value, err
}
time.Sleep(10 * time.Millisecond)
response, err := g.readBytes(goPiGo3Address, analogCmd, 7)
if err != nil {
return value, err
}
if err := g.responseValid(response); err != nil {
return value, err
}
if err := g.valueValid(response); err != nil {
return value, err
}
highBytes := uint16(response[5])
lowBytes := uint16(response[6])
return int((highBytes<<8)&0xFF00) | int(lowBytes&0xFF), nil
} | [
"func",
"(",
"g",
"*",
"Driver",
")",
"AnalogRead",
"(",
"pin",
"string",
")",
"(",
"value",
"int",
",",
"err",
"error",
")",
"{",
"var",
"(",
"grovePin",
",",
"grovePort",
"Grove",
"\n",
"analogCmd",
"byte",
"\n",
")",
"\n",
"grovePin",
",",
"groveP... | // AnalogRead returns the analog value of the given pin. | [
"AnalogRead",
"returns",
"the",
"analog",
"value",
"of",
"the",
"given",
"pin",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L548-L580 |
156,069 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | Halt | func (s *SpheroDriver) Halt() (err error) {
if s.adaptor().connected {
gobot.Every(10*time.Millisecond, func() {
s.Stop()
})
time.Sleep(1 * time.Second)
}
return
} | go | func (s *SpheroDriver) Halt() (err error) {
if s.adaptor().connected {
gobot.Every(10*time.Millisecond, func() {
s.Stop()
})
time.Sleep(1 * time.Second)
}
return
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"Halt",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"s",
".",
"adaptor",
"(",
")",
".",
"connected",
"{",
"gobot",
".",
"Every",
"(",
"10",
"*",
"time",
".",
"Millisecond",
",",
"func",
"(",
")",
"... | // Halt halts the SpheroDriver and sends a SpheroDriver.Stop command to the Sphero.
// Returns true on successful halt. | [
"Halt",
"halts",
"the",
"SpheroDriver",
"and",
"sends",
"a",
"SpheroDriver",
".",
"Stop",
"command",
"to",
"the",
"Sphero",
".",
"Returns",
"true",
"on",
"successful",
"halt",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L228-L236 |
156,070 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | SetRGB | func (s *SpheroDriver) SetRGB(r uint8, g uint8, b uint8) {
s.packetChannel <- s.craftPacket([]uint8{r, g, b, 0x01}, 0x02, 0x20)
} | go | func (s *SpheroDriver) SetRGB(r uint8, g uint8, b uint8) {
s.packetChannel <- s.craftPacket([]uint8{r, g, b, 0x01}, 0x02, 0x20)
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"SetRGB",
"(",
"r",
"uint8",
",",
"g",
"uint8",
",",
"b",
"uint8",
")",
"{",
"s",
".",
"packetChannel",
"<-",
"s",
".",
"craftPacket",
"(",
"[",
"]",
"uint8",
"{",
"r",
",",
"g",
",",
"b",
",",
"0x01"... | // SetRGB sets the Sphero to the given r, g, and b values | [
"SetRGB",
"sets",
"the",
"Sphero",
"to",
"the",
"given",
"r",
"g",
"and",
"b",
"values"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L239-L241 |
156,071 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | GetRGB | func (s *SpheroDriver) GetRGB() []uint8 {
buf := s.getSyncResponse(s.craftPacket([]uint8{}, 0x02, 0x22))
if len(buf) == 9 {
return []uint8{buf[5], buf[6], buf[7]}
}
return []uint8{}
} | go | func (s *SpheroDriver) GetRGB() []uint8 {
buf := s.getSyncResponse(s.craftPacket([]uint8{}, 0x02, 0x22))
if len(buf) == 9 {
return []uint8{buf[5], buf[6], buf[7]}
}
return []uint8{}
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"GetRGB",
"(",
")",
"[",
"]",
"uint8",
"{",
"buf",
":=",
"s",
".",
"getSyncResponse",
"(",
"s",
".",
"craftPacket",
"(",
"[",
"]",
"uint8",
"{",
"}",
",",
"0x02",
",",
"0x22",
")",
")",
"\n",
"if",
"l... | // GetRGB returns the current r, g, b value of the Sphero | [
"GetRGB",
"returns",
"the",
"current",
"r",
"g",
"b",
"value",
"of",
"the",
"Sphero"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L244-L250 |
156,072 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | SetBackLED | func (s *SpheroDriver) SetBackLED(level uint8) {
s.packetChannel <- s.craftPacket([]uint8{level}, 0x02, 0x21)
} | go | func (s *SpheroDriver) SetBackLED(level uint8) {
s.packetChannel <- s.craftPacket([]uint8{level}, 0x02, 0x21)
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"SetBackLED",
"(",
"level",
"uint8",
")",
"{",
"s",
".",
"packetChannel",
"<-",
"s",
".",
"craftPacket",
"(",
"[",
"]",
"uint8",
"{",
"level",
"}",
",",
"0x02",
",",
"0x21",
")",
"\n",
"}"
] | // SetBackLED sets the Sphero Back LED to the specified brightness | [
"SetBackLED",
"sets",
"the",
"Sphero",
"Back",
"LED",
"to",
"the",
"specified",
"brightness"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L264-L266 |
156,073 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | SetHeading | func (s *SpheroDriver) SetHeading(heading uint16) {
s.packetChannel <- s.craftPacket([]uint8{uint8(heading >> 8), uint8(heading & 0xFF)}, 0x02, 0x01)
} | go | func (s *SpheroDriver) SetHeading(heading uint16) {
s.packetChannel <- s.craftPacket([]uint8{uint8(heading >> 8), uint8(heading & 0xFF)}, 0x02, 0x01)
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"SetHeading",
"(",
"heading",
"uint16",
")",
"{",
"s",
".",
"packetChannel",
"<-",
"s",
".",
"craftPacket",
"(",
"[",
"]",
"uint8",
"{",
"uint8",
"(",
"heading",
">>",
"8",
")",
",",
"uint8",
"(",
"heading"... | // SetHeading sets the heading of the Sphero | [
"SetHeading",
"sets",
"the",
"heading",
"of",
"the",
"Sphero"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L275-L277 |
156,074 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | SetStabilization | func (s *SpheroDriver) SetStabilization(on bool) {
b := uint8(0x01)
if !on {
b = 0x00
}
s.packetChannel <- s.craftPacket([]uint8{b}, 0x02, 0x02)
} | go | func (s *SpheroDriver) SetStabilization(on bool) {
b := uint8(0x01)
if !on {
b = 0x00
}
s.packetChannel <- s.craftPacket([]uint8{b}, 0x02, 0x02)
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"SetStabilization",
"(",
"on",
"bool",
")",
"{",
"b",
":=",
"uint8",
"(",
"0x01",
")",
"\n",
"if",
"!",
"on",
"{",
"b",
"=",
"0x00",
"\n",
"}",
"\n",
"s",
".",
"packetChannel",
"<-",
"s",
".",
"craftPac... | // SetStabilization enables or disables the built-in auto stabilizing features of the Sphero | [
"SetStabilization",
"enables",
"or",
"disables",
"the",
"built",
"-",
"in",
"auto",
"stabilizing",
"features",
"of",
"the",
"Sphero"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L280-L286 |
156,075 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | Roll | func (s *SpheroDriver) Roll(speed uint8, heading uint16) {
s.packetChannel <- s.craftPacket([]uint8{speed, uint8(heading >> 8), uint8(heading & 0xFF), 0x01}, 0x02, 0x30)
} | go | func (s *SpheroDriver) Roll(speed uint8, heading uint16) {
s.packetChannel <- s.craftPacket([]uint8{speed, uint8(heading >> 8), uint8(heading & 0xFF), 0x01}, 0x02, 0x30)
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"Roll",
"(",
"speed",
"uint8",
",",
"heading",
"uint16",
")",
"{",
"s",
".",
"packetChannel",
"<-",
"s",
".",
"craftPacket",
"(",
"[",
"]",
"uint8",
"{",
"speed",
",",
"uint8",
"(",
"heading",
">>",
"8",
... | // Roll sends a roll command to the Sphero gives a speed and heading | [
"Roll",
"sends",
"a",
"roll",
"command",
"to",
"the",
"Sphero",
"gives",
"a",
"speed",
"and",
"heading"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L289-L291 |
156,076 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | ConfigureLocator | func (s *SpheroDriver) ConfigureLocator(d LocatorConfig) {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, d)
s.packetChannel <- s.craftPacket(buf.Bytes(), 0x02, 0x13)
} | go | func (s *SpheroDriver) ConfigureLocator(d LocatorConfig) {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, d)
s.packetChannel <- s.craftPacket(buf.Bytes(), 0x02, 0x13)
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"ConfigureLocator",
"(",
"d",
"LocatorConfig",
")",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"binary",
".",
"Write",
"(",
"buf",
",",
"binary",
".",
"BigEndian",
",",
"d",
")",
"\n\n... | // ConfigureLocator configures and enables the Locator | [
"ConfigureLocator",
"configures",
"and",
"enables",
"the",
"Locator"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L294-L299 |
156,077 | hybridgroup/gobot | platforms/sphero/sphero_driver.go | SetDataStreaming | func (s *SpheroDriver) SetDataStreaming(d DataStreamingConfig) {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, d)
s.packetChannel <- s.craftPacket(buf.Bytes(), 0x02, 0x11)
} | go | func (s *SpheroDriver) SetDataStreaming(d DataStreamingConfig) {
buf := new(bytes.Buffer)
binary.Write(buf, binary.BigEndian, d)
s.packetChannel <- s.craftPacket(buf.Bytes(), 0x02, 0x11)
} | [
"func",
"(",
"s",
"*",
"SpheroDriver",
")",
"SetDataStreaming",
"(",
"d",
"DataStreamingConfig",
")",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"binary",
".",
"Write",
"(",
"buf",
",",
"binary",
".",
"BigEndian",
",",
"d",
")",
... | // SetDataStreaming enables sensor data streaming | [
"SetDataStreaming",
"enables",
"sensor",
"data",
"streaming"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/sphero_driver.go#L302-L307 |
156,078 | hybridgroup/gobot | platforms/firmata/firmata_adaptor.go | Connect | func (f *Adaptor) Connect() (err error) {
if f.conn == nil {
sp, e := f.PortOpener(f.Port())
if e != nil {
return e
}
f.conn = sp
}
if err = f.Board.Connect(f.conn); err != nil {
return err
}
f.Board.On("SysexResponse", func(data interface{}) {
f.Publish("SysexResponse", data)
})
return
} | go | func (f *Adaptor) Connect() (err error) {
if f.conn == nil {
sp, e := f.PortOpener(f.Port())
if e != nil {
return e
}
f.conn = sp
}
if err = f.Board.Connect(f.conn); err != nil {
return err
}
f.Board.On("SysexResponse", func(data interface{}) {
f.Publish("SysexResponse", data)
})
return
} | [
"func",
"(",
"f",
"*",
"Adaptor",
")",
"Connect",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"f",
".",
"conn",
"==",
"nil",
"{",
"sp",
",",
"e",
":=",
"f",
".",
"PortOpener",
"(",
"f",
".",
"Port",
"(",
")",
")",
"\n",
"if",
"e",
"!=",
... | // Connect starts a connection to the board. | [
"Connect",
"starts",
"a",
"connection",
"to",
"the",
"board",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/firmata_adaptor.go#L85-L102 |
156,079 | hybridgroup/gobot | platforms/firmata/firmata_adaptor.go | Disconnect | func (f *Adaptor) Disconnect() (err error) {
if f.Board != nil {
return f.Board.Disconnect()
}
return nil
} | go | func (f *Adaptor) Disconnect() (err error) {
if f.Board != nil {
return f.Board.Disconnect()
}
return nil
} | [
"func",
"(",
"f",
"*",
"Adaptor",
")",
"Disconnect",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"f",
".",
"Board",
"!=",
"nil",
"{",
"return",
"f",
".",
"Board",
".",
"Disconnect",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Disconnect closes the io connection to the Board | [
"Disconnect",
"closes",
"the",
"io",
"connection",
"to",
"the",
"Board"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/firmata_adaptor.go#L105-L110 |
156,080 | hybridgroup/gobot | platforms/firmata/firmata_adaptor.go | ServoConfig | func (f *Adaptor) ServoConfig(pin string, min, max int) error {
p, err := strconv.Atoi(pin)
if err != nil {
return err
}
return f.Board.ServoConfig(p, max, min)
} | go | func (f *Adaptor) ServoConfig(pin string, min, max int) error {
p, err := strconv.Atoi(pin)
if err != nil {
return err
}
return f.Board.ServoConfig(p, max, min)
} | [
"func",
"(",
"f",
"*",
"Adaptor",
")",
"ServoConfig",
"(",
"pin",
"string",
",",
"min",
",",
"max",
"int",
")",
"error",
"{",
"p",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
... | // ServoConfig sets the pulse width in microseconds for a pin attached to a servo | [
"ServoConfig",
"sets",
"the",
"pulse",
"width",
"in",
"microseconds",
"for",
"a",
"pin",
"attached",
"to",
"a",
"servo"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/firmata_adaptor.go#L128-L135 |
156,081 | hybridgroup/gobot | platforms/firmata/firmata_adaptor.go | ServoWrite | func (f *Adaptor) ServoWrite(pin string, angle byte) (err error) {
p, err := strconv.Atoi(pin)
if err != nil {
return err
}
if f.Board.Pins()[p].Mode != client.Servo {
err = f.Board.SetPinMode(p, client.Servo)
if err != nil {
return err
}
}
err = f.Board.AnalogWrite(p, int(angle))
return
} | go | func (f *Adaptor) ServoWrite(pin string, angle byte) (err error) {
p, err := strconv.Atoi(pin)
if err != nil {
return err
}
if f.Board.Pins()[p].Mode != client.Servo {
err = f.Board.SetPinMode(p, client.Servo)
if err != nil {
return err
}
}
err = f.Board.AnalogWrite(p, int(angle))
return
} | [
"func",
"(",
"f",
"*",
"Adaptor",
")",
"ServoWrite",
"(",
"pin",
"string",
",",
"angle",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
... | // ServoWrite writes the 0-180 degree angle to the specified pin. | [
"ServoWrite",
"writes",
"the",
"0",
"-",
"180",
"degree",
"angle",
"to",
"the",
"specified",
"pin",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/firmata_adaptor.go#L138-L152 |
156,082 | hybridgroup/gobot | platforms/firmata/firmata_adaptor.go | DigitalRead | func (f *Adaptor) DigitalRead(pin string) (val int, err error) {
p, err := strconv.Atoi(pin)
if err != nil {
return
}
if f.Board.Pins()[p].Mode != client.Input {
if err = f.Board.SetPinMode(p, client.Input); err != nil {
return
}
if err = f.Board.ReportDigital(p, 1); err != nil {
return
}
<-time.After(10 * time.Millisecond)
}
return f.Board.Pins()[p].Value, nil
} | go | func (f *Adaptor) DigitalRead(pin string) (val int, err error) {
p, err := strconv.Atoi(pin)
if err != nil {
return
}
if f.Board.Pins()[p].Mode != client.Input {
if err = f.Board.SetPinMode(p, client.Input); err != nil {
return
}
if err = f.Board.ReportDigital(p, 1); err != nil {
return
}
<-time.After(10 * time.Millisecond)
}
return f.Board.Pins()[p].Value, nil
} | [
"func",
"(",
"f",
"*",
"Adaptor",
")",
"DigitalRead",
"(",
"pin",
"string",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\... | // DigitalRead retrieves digital value from specified pin.
// Returns -1 if the response from the board has timed out | [
"DigitalRead",
"retrieves",
"digital",
"value",
"from",
"specified",
"pin",
".",
"Returns",
"-",
"1",
"if",
"the",
"response",
"from",
"the",
"board",
"has",
"timed",
"out"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/firmata_adaptor.go#L191-L208 |
156,083 | hybridgroup/gobot | platforms/firmata/firmata_adaptor.go | AnalogRead | func (f *Adaptor) AnalogRead(pin string) (val int, err error) {
p, err := strconv.Atoi(pin)
if err != nil {
return
}
p = f.digitalPin(p)
if f.Board.Pins()[p].Mode != client.Analog {
if err = f.Board.SetPinMode(p, client.Analog); err != nil {
return
}
if err = f.Board.ReportAnalog(p, 1); err != nil {
return
}
<-time.After(10 * time.Millisecond)
}
return f.Board.Pins()[p].Value, nil
} | go | func (f *Adaptor) AnalogRead(pin string) (val int, err error) {
p, err := strconv.Atoi(pin)
if err != nil {
return
}
p = f.digitalPin(p)
if f.Board.Pins()[p].Mode != client.Analog {
if err = f.Board.SetPinMode(p, client.Analog); err != nil {
return
}
if err = f.Board.ReportAnalog(p, 1); err != nil {
return
}
<-time.After(10 * time.Millisecond)
}
return f.Board.Pins()[p].Value, nil
} | [
"func",
"(",
"f",
"*",
"Adaptor",
")",
"AnalogRead",
"(",
"pin",
"string",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"p",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n... | // AnalogRead retrieves value from analog pin.
// Returns -1 if the response from the board has timed out | [
"AnalogRead",
"retrieves",
"value",
"from",
"analog",
"pin",
".",
"Returns",
"-",
"1",
"if",
"the",
"response",
"from",
"the",
"board",
"has",
"timed",
"out"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/firmata_adaptor.go#L212-L232 |
156,084 | hybridgroup/gobot | platforms/mavlink/mavlink_driver.go | Start | func (m *Driver) Start() error {
go func() {
for {
packet, err := m.adaptor().ReadMAVLinkPacket()
if err != nil {
m.Publish(ErrorIOEvent, err)
continue
}
m.Publish(PacketEvent, packet)
message, err := packet.MAVLinkMessage()
if err != nil {
m.Publish(ErrorMAVLinkEvent, err)
continue
}
m.Publish(MessageEvent, message)
time.Sleep(m.interval)
}
}()
return nil
} | go | func (m *Driver) Start() error {
go func() {
for {
packet, err := m.adaptor().ReadMAVLinkPacket()
if err != nil {
m.Publish(ErrorIOEvent, err)
continue
}
m.Publish(PacketEvent, packet)
message, err := packet.MAVLinkMessage()
if err != nil {
m.Publish(ErrorMAVLinkEvent, err)
continue
}
m.Publish(MessageEvent, message)
time.Sleep(m.interval)
}
}()
return nil
} | [
"func",
"(",
"m",
"*",
"Driver",
")",
"Start",
"(",
")",
"error",
"{",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"packet",
",",
"err",
":=",
"m",
".",
"adaptor",
"(",
")",
".",
"ReadMAVLinkPacket",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // Start begins process to read mavlink packets every m.Interval
// and process them | [
"Start",
"begins",
"process",
"to",
"read",
"mavlink",
"packets",
"every",
"m",
".",
"Interval",
"and",
"process",
"them"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/mavlink_driver.go#L67-L86 |
156,085 | hybridgroup/gobot | platforms/mavlink/mavlink_driver.go | SendPacket | func (m *Driver) SendPacket(packet *common.MAVLinkPacket) (err error) {
_, err = m.adaptor().Write(packet.Pack())
return err
} | go | func (m *Driver) SendPacket(packet *common.MAVLinkPacket) (err error) {
_, err = m.adaptor().Write(packet.Pack())
return err
} | [
"func",
"(",
"m",
"*",
"Driver",
")",
"SendPacket",
"(",
"packet",
"*",
"common",
".",
"MAVLinkPacket",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"m",
".",
"adaptor",
"(",
")",
".",
"Write",
"(",
"packet",
".",
"Pack",
"(",
")",
... | // SendPacket sends a packet to mavlink device | [
"SendPacket",
"sends",
"a",
"packet",
"to",
"mavlink",
"device"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/mavlink_driver.go#L92-L95 |
156,086 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | NewDriver | func NewDriver(a ble.BLEConnector) *Driver {
n := &Driver{
name: gobot.DefaultName("Ollie"),
connection: a,
Eventer: gobot.NewEventer(),
packetChannel: make(chan *packet, 1024),
}
n.AddEvent(Collision)
return n
} | go | func NewDriver(a ble.BLEConnector) *Driver {
n := &Driver{
name: gobot.DefaultName("Ollie"),
connection: a,
Eventer: gobot.NewEventer(),
packetChannel: make(chan *packet, 1024),
}
n.AddEvent(Collision)
return n
} | [
"func",
"NewDriver",
"(",
"a",
"ble",
".",
"BLEConnector",
")",
"*",
"Driver",
"{",
"n",
":=",
"&",
"Driver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"connection",
":",
"a",
",",
"Eventer",
":",
"gobot",
".",
"NewE... | // NewDriver creates a Driver for a Sphero Ollie | [
"NewDriver",
"creates",
"a",
"Driver",
"for",
"a",
"Sphero",
"Ollie"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L78-L89 |
156,087 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | Init | func (b *Driver) Init() (err error) {
b.AntiDOSOff()
b.SetTXPower(7)
b.Wake()
// subscribe to Sphero response notifications
b.adaptor().Subscribe(responseCharacteristic, b.HandleResponses)
return
} | go | func (b *Driver) Init() (err error) {
b.AntiDOSOff()
b.SetTXPower(7)
b.Wake()
// subscribe to Sphero response notifications
b.adaptor().Subscribe(responseCharacteristic, b.HandleResponses)
return
} | [
"func",
"(",
"b",
"*",
"Driver",
")",
"Init",
"(",
")",
"(",
"err",
"error",
")",
"{",
"b",
".",
"AntiDOSOff",
"(",
")",
"\n",
"b",
".",
"SetTXPower",
"(",
"7",
")",
"\n",
"b",
".",
"Wake",
"(",
")",
"\n\n",
"// subscribe to Sphero response notificat... | // Init is used to initialize the Ollie | [
"Init",
"is",
"used",
"to",
"initialize",
"the",
"Ollie"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L140-L149 |
156,088 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | AntiDOSOff | func (b *Driver) AntiDOSOff() (err error) {
str := "011i3"
buf := &bytes.Buffer{}
buf.WriteString(str)
err = b.adaptor().WriteCharacteristic(antiDosCharacteristic, buf.Bytes())
if err != nil {
fmt.Println("AntiDOSOff error:", err)
return err
}
return
} | go | func (b *Driver) AntiDOSOff() (err error) {
str := "011i3"
buf := &bytes.Buffer{}
buf.WriteString(str)
err = b.adaptor().WriteCharacteristic(antiDosCharacteristic, buf.Bytes())
if err != nil {
fmt.Println("AntiDOSOff error:", err)
return err
}
return
} | [
"func",
"(",
"b",
"*",
"Driver",
")",
"AntiDOSOff",
"(",
")",
"(",
"err",
"error",
")",
"{",
"str",
":=",
"\"",
"\"",
"\n",
"buf",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"buf",
".",
"WriteString",
"(",
"str",
")",
"\n\n",
"err",
"="... | // AntiDOSOff turns off Anti-DOS code so we can control Ollie | [
"AntiDOSOff",
"turns",
"off",
"Anti",
"-",
"DOS",
"code",
"so",
"we",
"can",
"control",
"Ollie"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L152-L164 |
156,089 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | Wake | func (b *Driver) Wake() (err error) {
buf := []byte{0x01}
err = b.adaptor().WriteCharacteristic(wakeCharacteristic, buf)
if err != nil {
fmt.Println("Wake error:", err)
return err
}
return
} | go | func (b *Driver) Wake() (err error) {
buf := []byte{0x01}
err = b.adaptor().WriteCharacteristic(wakeCharacteristic, buf)
if err != nil {
fmt.Println("Wake error:", err)
return err
}
return
} | [
"func",
"(",
"b",
"*",
"Driver",
")",
"Wake",
"(",
")",
"(",
"err",
"error",
")",
"{",
"buf",
":=",
"[",
"]",
"byte",
"{",
"0x01",
"}",
"\n\n",
"err",
"=",
"b",
".",
"adaptor",
"(",
")",
".",
"WriteCharacteristic",
"(",
"wakeCharacteristic",
",",
... | // Wake wakes Ollie up so we can play | [
"Wake",
"wakes",
"Ollie",
"up",
"so",
"we",
"can",
"play"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L167-L177 |
156,090 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | SetTXPower | func (b *Driver) SetTXPower(level int) (err error) {
buf := []byte{byte(level)}
err = b.adaptor().WriteCharacteristic(txPowerCharacteristic, buf)
if err != nil {
fmt.Println("SetTXLevel error:", err)
return err
}
return
} | go | func (b *Driver) SetTXPower(level int) (err error) {
buf := []byte{byte(level)}
err = b.adaptor().WriteCharacteristic(txPowerCharacteristic, buf)
if err != nil {
fmt.Println("SetTXLevel error:", err)
return err
}
return
} | [
"func",
"(",
"b",
"*",
"Driver",
")",
"SetTXPower",
"(",
"level",
"int",
")",
"(",
"err",
"error",
")",
"{",
"buf",
":=",
"[",
"]",
"byte",
"{",
"byte",
"(",
"level",
")",
"}",
"\n\n",
"err",
"=",
"b",
".",
"adaptor",
"(",
")",
".",
"WriteChara... | // SetTXPower sets transmit level | [
"SetTXPower",
"sets",
"transmit",
"level"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L180-L190 |
156,091 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | HandleResponses | func (b *Driver) HandleResponses(data []byte, e error) {
//fmt.Println("response data:", data, e)
b.handleCollisionDetected(data)
} | go | func (b *Driver) HandleResponses(data []byte, e error) {
//fmt.Println("response data:", data, e)
b.handleCollisionDetected(data)
} | [
"func",
"(",
"b",
"*",
"Driver",
")",
"HandleResponses",
"(",
"data",
"[",
"]",
"byte",
",",
"e",
"error",
")",
"{",
"//fmt.Println(\"response data:\", data, e)",
"b",
".",
"handleCollisionDetected",
"(",
"data",
")",
"\n",
"}"
] | // HandleResponses handles responses returned from Ollie | [
"HandleResponses",
"handles",
"responses",
"returned",
"from",
"Ollie"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L193-L197 |
156,092 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | SetRGB | func (b *Driver) SetRGB(r uint8, g uint8, bl uint8) {
b.packetChannel <- b.craftPacket([]uint8{r, g, bl, 0x01}, 0x02, 0x20)
} | go | func (b *Driver) SetRGB(r uint8, g uint8, bl uint8) {
b.packetChannel <- b.craftPacket([]uint8{r, g, bl, 0x01}, 0x02, 0x20)
} | [
"func",
"(",
"b",
"*",
"Driver",
")",
"SetRGB",
"(",
"r",
"uint8",
",",
"g",
"uint8",
",",
"bl",
"uint8",
")",
"{",
"b",
".",
"packetChannel",
"<-",
"b",
".",
"craftPacket",
"(",
"[",
"]",
"uint8",
"{",
"r",
",",
"g",
",",
"bl",
",",
"0x01",
... | // SetRGB sets the Ollie to the given r, g, and b values | [
"SetRGB",
"sets",
"the",
"Ollie",
"to",
"the",
"given",
"r",
"g",
"and",
"b",
"values"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L200-L202 |
156,093 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | Roll | func (b *Driver) Roll(speed uint8, heading uint16) {
b.packetChannel <- b.craftPacket([]uint8{speed, uint8(heading >> 8), uint8(heading & 0xFF), 0x01}, 0x02, 0x30)
} | go | func (b *Driver) Roll(speed uint8, heading uint16) {
b.packetChannel <- b.craftPacket([]uint8{speed, uint8(heading >> 8), uint8(heading & 0xFF), 0x01}, 0x02, 0x30)
} | [
"func",
"(",
"b",
"*",
"Driver",
")",
"Roll",
"(",
"speed",
"uint8",
",",
"heading",
"uint16",
")",
"{",
"b",
".",
"packetChannel",
"<-",
"b",
".",
"craftPacket",
"(",
"[",
"]",
"uint8",
"{",
"speed",
",",
"uint8",
"(",
"heading",
">>",
"8",
")",
... | // Roll tells the Ollie to roll | [
"Roll",
"tells",
"the",
"Ollie",
"to",
"roll"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L205-L207 |
156,094 | hybridgroup/gobot | platforms/sphero/ollie/ollie_driver.go | Boost | func (b *Driver) Boost(state bool) {
s := uint8(0x01)
if !state {
s = 0x00
}
b.packetChannel <- b.craftPacket([]uint8{s}, 0x02, 0x31)
} | go | func (b *Driver) Boost(state bool) {
s := uint8(0x01)
if !state {
s = 0x00
}
b.packetChannel <- b.craftPacket([]uint8{s}, 0x02, 0x31)
} | [
"func",
"(",
"b",
"*",
"Driver",
")",
"Boost",
"(",
"state",
"bool",
")",
"{",
"s",
":=",
"uint8",
"(",
"0x01",
")",
"\n",
"if",
"!",
"state",
"{",
"s",
"=",
"0x00",
"\n",
"}",
"\n",
"b",
".",
"packetChannel",
"<-",
"b",
".",
"craftPacket",
"("... | // Boost executes the boost macro from within the SSB which takes a
// 1 byte parameter which is either 01h to begin boosting or 00h to stop. | [
"Boost",
"executes",
"the",
"boost",
"macro",
"from",
"within",
"the",
"SSB",
"which",
"takes",
"a",
"1",
"byte",
"parameter",
"which",
"is",
"either",
"01h",
"to",
"begin",
"boosting",
"or",
"00h",
"to",
"stop",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L211-L217 |
156,095 | hybridgroup/gobot | drivers/spi/spi.go | GetSpiConnection | func GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (Connection, error) {
p, err := xsysfs.NewSPI(busNum, chipNum)
if err != nil {
return nil, err
}
c, err := p.Connect(physic.Frequency(maxSpeed)*physic.Hertz, xspi.Mode(mode), bits)
if err != nil {
return nil, err
}
return NewConnection(p, c), nil
} | go | func GetSpiConnection(busNum, chipNum, mode, bits int, maxSpeed int64) (Connection, error) {
p, err := xsysfs.NewSPI(busNum, chipNum)
if err != nil {
return nil, err
}
c, err := p.Connect(physic.Frequency(maxSpeed)*physic.Hertz, xspi.Mode(mode), bits)
if err != nil {
return nil, err
}
return NewConnection(p, c), nil
} | [
"func",
"GetSpiConnection",
"(",
"busNum",
",",
"chipNum",
",",
"mode",
",",
"bits",
"int",
",",
"maxSpeed",
"int64",
")",
"(",
"Connection",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"xsysfs",
".",
"NewSPI",
"(",
"busNum",
",",
"chipNum",
")",
... | // GetSpiConnection is a helper to return a SPI device. | [
"GetSpiConnection",
"is",
"a",
"helper",
"to",
"return",
"a",
"SPI",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/spi.go#L78-L88 |
156,096 | hybridgroup/gobot | sysfs/pwm_pin.go | NewPWMPin | func NewPWMPin(pin int) *PWMPin {
return &PWMPin{
pin: strconv.Itoa(pin),
enabled: false,
Path: "/sys/class/pwm/pwmchip0",
read: readPwmFile,
write: writePwmFile}
} | go | func NewPWMPin(pin int) *PWMPin {
return &PWMPin{
pin: strconv.Itoa(pin),
enabled: false,
Path: "/sys/class/pwm/pwmchip0",
read: readPwmFile,
write: writePwmFile}
} | [
"func",
"NewPWMPin",
"(",
"pin",
"int",
")",
"*",
"PWMPin",
"{",
"return",
"&",
"PWMPin",
"{",
"pin",
":",
"strconv",
".",
"Itoa",
"(",
"pin",
")",
",",
"enabled",
":",
"false",
",",
"Path",
":",
"\"",
"\"",
",",
"read",
":",
"readPwmFile",
",",
... | // NewPwmPin returns a new pwmPin | [
"NewPwmPin",
"returns",
"a",
"new",
"pwmPin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L49-L56 |
156,097 | hybridgroup/gobot | sysfs/pwm_pin.go | Export | func (p *PWMPin) Export() error {
_, err := p.write(p.pwmExportPath(), []byte(p.pin))
if err != nil {
// If EBUSY then the pin has already been exported
e, ok := err.(*os.PathError)
if !ok || e.Err != syscall.EBUSY {
return err
}
}
// Pause to avoid race condition in case there is any udev rule
// that changes file permissions on newly exported PWMPin. This
// is a common circumstance when running as a non-root user.
time.Sleep(100 * time.Millisecond)
return nil
} | go | func (p *PWMPin) Export() error {
_, err := p.write(p.pwmExportPath(), []byte(p.pin))
if err != nil {
// If EBUSY then the pin has already been exported
e, ok := err.(*os.PathError)
if !ok || e.Err != syscall.EBUSY {
return err
}
}
// Pause to avoid race condition in case there is any udev rule
// that changes file permissions on newly exported PWMPin. This
// is a common circumstance when running as a non-root user.
time.Sleep(100 * time.Millisecond)
return nil
} | [
"func",
"(",
"p",
"*",
"PWMPin",
")",
"Export",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"p",
".",
"write",
"(",
"p",
".",
"pwmExportPath",
"(",
")",
",",
"[",
"]",
"byte",
"(",
"p",
".",
"pin",
")",
")",
"\n",
"if",
"err",
"!=",
"nil... | // Export writes pin to pwm export path | [
"Export",
"writes",
"pin",
"to",
"pwm",
"export",
"path"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L59-L75 |
156,098 | hybridgroup/gobot | sysfs/pwm_pin.go | Unexport | func (p *PWMPin) Unexport() (err error) {
_, err = p.write(p.pwmUnexportPath(), []byte(p.pin))
return
} | go | func (p *PWMPin) Unexport() (err error) {
_, err = p.write(p.pwmUnexportPath(), []byte(p.pin))
return
} | [
"func",
"(",
"p",
"*",
"PWMPin",
")",
"Unexport",
"(",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"p",
".",
"write",
"(",
"p",
".",
"pwmUnexportPath",
"(",
")",
",",
"[",
"]",
"byte",
"(",
"p",
".",
"pin",
")",
")",
"\n",
"re... | // Unexport writes pin to pwm unexport path | [
"Unexport",
"writes",
"pin",
"to",
"pwm",
"unexport",
"path"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L78-L81 |
156,099 | hybridgroup/gobot | sysfs/pwm_pin.go | Enable | func (p *PWMPin) Enable(enable bool) (err error) {
if p.enabled != enable {
p.enabled = enable
enableVal := 0
if enable {
enableVal = 1
}
_, err = p.write(p.pwmEnablePath(), []byte(fmt.Sprintf("%v", enableVal)))
}
return
} | go | func (p *PWMPin) Enable(enable bool) (err error) {
if p.enabled != enable {
p.enabled = enable
enableVal := 0
if enable {
enableVal = 1
}
_, err = p.write(p.pwmEnablePath(), []byte(fmt.Sprintf("%v", enableVal)))
}
return
} | [
"func",
"(",
"p",
"*",
"PWMPin",
")",
"Enable",
"(",
"enable",
"bool",
")",
"(",
"err",
"error",
")",
"{",
"if",
"p",
".",
"enabled",
"!=",
"enable",
"{",
"p",
".",
"enabled",
"=",
"enable",
"\n",
"enableVal",
":=",
"0",
"\n",
"if",
"enable",
"{"... | // Enable writes value to pwm enable path | [
"Enable",
"writes",
"value",
"to",
"pwm",
"enable",
"path"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L84-L94 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.