repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
hybridgroup/gobot
drivers/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", "{", "a", ".", "buffer", "[", "y", "]", "|=", "1", "<<", "x", "\n", "}", "else", "{", "a", ".", "buffer", "[", "y", "]", "&^=", "1", "<<", "x", "\n", "}", "\n", "}" ]
// 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
train
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
train
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", "]", "\n", "}", "\n", "}" ]
// 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
train
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
train
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", ".", "send", "(", "AIP1640AddrCmd", "|", "address", ")", "\n", "a", ".", "send", "(", "data", ")", "\n", "a", ".", "pinData", ".", "On", "(", ")", "\n", "}" ]
// 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
train
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", ":", "gobot", ".", "NewEventer", "(", ")", ",", "}", "\n\n", "return", "n", "\n", "}" ]
// NewGenericAccessDriver creates a GenericAccessDriver
[ "NewGenericAccessDriver", "creates", "a", "GenericAccessDriver" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/generic_access_driver.go#L18-L26
train
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", ")", "\n", "val", ":=", "buf", ".", "String", "(", ")", "\n", "return", "val", "\n", "}" ]
// 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
train
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", ")", "\n\n", "var", "val", "uint16", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "val", ")", "\n", "return", "appearances", "[", "val", "]", "\n", "}" ]
// 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
train
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", "}", "\n", "return", "\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
train
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", ":", "\"", "\"", ",", "Eventer", ":", "gobot", ".", "NewEventer", "(", ")", ",", "}", "\n\n", "d", ".", "AddEvent", "(", "ConnectedEvent", ")", "\n", "d", ".", "AddEvent", "(", "FlightDataEvent", ")", "\n", "d", ".", "AddEvent", "(", "TakeoffEvent", ")", "\n", "d", ".", "AddEvent", "(", "LandingEvent", ")", "\n", "d", ".", "AddEvent", "(", "PalmLandingEvent", ")", "\n", "d", ".", "AddEvent", "(", "BounceEvent", ")", "\n", "d", ".", "AddEvent", "(", "FlipEvent", ")", "\n", "d", ".", "AddEvent", "(", "TimeEvent", ")", "\n", "d", ".", "AddEvent", "(", "LogEvent", ")", "\n", "d", ".", "AddEvent", "(", "WifiDataEvent", ")", "\n", "d", ".", "AddEvent", "(", "LightStrengthEvent", ")", "\n", "d", ".", "AddEvent", "(", "SetExposureEvent", ")", "\n", "d", ".", "AddEvent", "(", "VideoFrameEvent", ")", "\n", "d", ".", "AddEvent", "(", "SetVideoEncoderRateEvent", ")", "\n\n", "return", "d", "\n", "}" ]
// 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
train
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", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "d", ".", "seq", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "CalculateCRC16", "(", "buf", ".", "Bytes", "(", ")", ")", ")", "\n\n", "_", ",", "err", "=", "d", ".", "cmdConn", ".", "Write", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "return", "\n", "}" ]
// 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
train
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", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "d", ".", "seq", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "CalculateCRC16", "(", "buf", ".", "Bytes", "(", ")", ")", ")", "\n\n", "_", ",", "err", "=", "d", ".", "cmdConn", ".", "Write", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "return", "\n", "}" ]
// Throw & Go support
[ "Throw", "&", "Go", "support" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/driver.go#L310-L318
train
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", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "d", ".", "seq", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "0x00", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "CalculateCRC16", "(", "buf", ".", "Bytes", "(", ")", ")", ")", "\n\n", "_", ",", "err", "=", "d", ".", "cmdConn", ".", "Write", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "return", "\n", "}" ]
// 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
train
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", ",", "_", ":=", "d", ".", "createPacket", "(", "exposureCommand", ",", "0x48", ",", "1", ")", "\n", "d", ".", "seq", "++", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "d", ".", "seq", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "level", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "CalculateCRC16", "(", "buf", ".", "Bytes", "(", ")", ")", ")", "\n\n", "_", ",", "err", "=", "d", ".", "cmdConn", ".", "Write", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "return", "\n", "}" ]
// 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
train
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", ".", "seq", "++", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "d", ".", "seq", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "rate", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "CalculateCRC16", "(", "buf", ".", "Bytes", "(", ")", ")", ")", "\n\n", "_", ",", "err", "=", "d", ".", "cmdConn", ".", "Write", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "return", "\n", "}" ]
// 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
train
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", "\n", "}" ]
// 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
train
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", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "d", ".", "seq", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "CalculateCRC16", "(", "buf", ".", "Bytes", "(", ")", ")", ")", "\n\n", "_", ",", "err", "=", "d", ".", "cmdConn", ".", "Write", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "return", "\n", "}" ]
// 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
train
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", ".", "ry", "=", "float32", "(", "0", ")", "\n", "d", ".", "lx", "=", "float32", "(", "0", ")", "\n", "d", ".", "ly", "=", "float32", "(", "0", ")", "\n", "}" ]
// 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
train
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
train
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", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "d", ".", "seq", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "direction", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "CalculateCRC16", "(", "buf", ".", "Bytes", "(", ")", ")", ")", "\n\n", "_", ",", "err", "=", "d", ".", "cmdConn", ".", "Write", "(", "buf", ".", "Bytes", "(", ")", ")", "\n", "return", "\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
train
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", ".", "createPacket", "(", "stickCommand", ",", "0x60", ",", "11", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "int16", "(", "0x00", ")", ")", "// seq = 0", "\n\n", "// RightX center=1024 left =364 right =-364", "axis1", ":=", "int16", "(", "660.0", "*", "d", ".", "rx", "+", "1024.0", ")", "\n\n", "// RightY down =364 up =-364", "axis2", ":=", "int16", "(", "660.0", "*", "d", ".", "ry", "+", "1024.0", ")", "\n\n", "// LeftY down =364 up =-364", "axis3", ":=", "int16", "(", "660.0", "*", "d", ".", "ly", "+", "1024.0", ")", "\n\n", "// LeftX left =364 right =-364", "axis4", ":=", "int16", "(", "660.0", "*", "d", ".", "lx", "+", "1024.0", ")", "\n\n", "// speed control", "axis5", ":=", "int16", "(", "d", ".", "throttle", ")", "\n\n", "packedAxis", ":=", "int64", "(", "axis1", ")", "&", "0x7FF", "|", "int64", "(", "axis2", "&", "0x7FF", ")", "<<", "11", "|", "0x7FF", "&", "int64", "(", "axis3", ")", "<<", "22", "|", "0x7FF", "&", "int64", "(", "axis4", ")", "<<", "33", "|", "int64", "(", "axis5", ")", "<<", "44", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "0xFF", "&", "packedAxis", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "packedAxis", ">>", "8", "&", "0xFF", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "packedAxis", ">>", "16", "&", "0xFF", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "packedAxis", ">>", "24", "&", "0xFF", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "packedAxis", ">>", "32", "&", "0xFF", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "packedAxis", ">>", "40", "&", "0xFF", ")", ")", "\n\n", "now", ":=", "time", ".", "Now", "(", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "now", ".", "Hour", "(", ")", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "now", ".", "Minute", "(", ")", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "now", ".", "Second", "(", ")", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "now", ".", "UnixNano", "(", ")", "/", "int64", "(", "time", ".", "Millisecond", ")", "&", "0xff", ")", ")", "\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "byte", "(", "now", ".", "UnixNano", "(", ")", "/", "int64", "(", "time", ".", "Millisecond", ")", ">>", "8", ")", ")", "\n\n", "binary", ".", "Write", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "CalculateCRC16", "(", "buf", ".", "Bytes", "(", ")", ")", ")", "\n\n", "_", ",", "err", "=", "d", ".", "cmdConn", ".", "Write", "(", "buf", ".", "Bytes", "(", ")", ")", "\n\n", "return", "\n", "}" ]
// 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
train
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
train
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", ":", "[", "]", "*", "JSONConnection", "{", "}", ",", "Devices", ":", "[", "]", "*", "JSONDevice", "{", "}", ",", "}", "\n\n", "for", "command", ":=", "range", "robot", ".", "Commands", "(", ")", "{", "jsonRobot", ".", "Commands", "=", "append", "(", "jsonRobot", ".", "Commands", ",", "command", ")", "\n", "}", "\n\n", "robot", ".", "Devices", "(", ")", ".", "Each", "(", "func", "(", "device", "Device", ")", "{", "jsonDevice", ":=", "NewJSONDevice", "(", "device", ")", "\n", "jsonRobot", ".", "Connections", "=", "append", "(", "jsonRobot", ".", "Connections", ",", "NewJSONConnection", "(", "robot", ".", "Connection", "(", "jsonDevice", ".", "Connection", ")", ")", ")", "\n", "jsonRobot", ".", "Devices", "=", "append", "(", "jsonRobot", ".", "Devices", ",", "jsonDevice", ")", "\n", "}", ")", "\n", "return", "jsonRobot", "\n", "}" ]
// 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
train
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", "]", ".", "(", "bool", ")", "\n", "}", "\n", "for", "_", ",", "robot", ":=", "range", "*", "r", "{", "if", "rerr", ":=", "robot", ".", "Start", "(", "autoRun", ")", ";", "rerr", "!=", "nil", "{", "err", "=", "multierror", ".", "Append", "(", "err", ",", "rerr", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// 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
train
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", "=", "multierror", ".", "Append", "(", "err", ",", "rerr", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// 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
train
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
train
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", "=", "args", "[", "0", "]", ".", "(", "bool", ")", "\n", "}", "\n", "log", ".", "Println", "(", "\"", "\"", ",", "r", ".", "Name", ",", "\"", "\"", ")", "\n", "if", "cerr", ":=", "r", ".", "Connections", "(", ")", ".", "Start", "(", ")", ";", "cerr", "!=", "nil", "{", "err", "=", "multierror", ".", "Append", "(", "err", ",", "cerr", ")", "\n", "log", ".", "Println", "(", "err", ")", "\n", "return", "\n", "}", "\n", "if", "derr", ":=", "r", ".", "Devices", "(", ")", ".", "Start", "(", ")", ";", "derr", "!=", "nil", "{", "err", "=", "multierror", ".", "Append", "(", "err", ",", "derr", ")", "\n", "log", ".", "Println", "(", "err", ")", "\n", "return", "\n", "}", "\n", "if", "r", ".", "Work", "==", "nil", "{", "r", ".", "Work", "=", "func", "(", ")", "{", "}", "\n", "}", "\n\n", "log", ".", "Println", "(", "\"", "\"", ")", "\n", "go", "func", "(", ")", "{", "r", ".", "Work", "(", ")", "\n", "<-", "r", ".", "done", "\n", "}", "(", ")", "\n\n", "r", ".", "running", ".", "Store", "(", "true", ")", "\n", "if", "r", ".", "AutoRun", "{", "c", ":=", "make", "(", "chan", "os", ".", "Signal", ",", "1", ")", "\n", "r", ".", "trap", "(", "c", ")", "\n\n", "// waiting for interrupt coming on the channel", "<-", "c", "\n\n", "// Stop calls the Stop method on itself, if we are \"auto-running\".", "r", ".", "Stop", "(", ")", "\n", "}", "\n\n", "return", "\n", "}" ]
// 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
train
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", "(", ")", ".", "Halt", "(", ")", "\n", "if", "err", "!=", "nil", "{", "result", "=", "multierror", ".", "Append", "(", "result", ",", "err", ")", "\n", "}", "\n", "err", "=", "r", ".", "Connections", "(", ")", ".", "Finalize", "(", ")", "\n", "if", "err", "!=", "nil", "{", "result", "=", "multierror", ".", "Append", "(", "result", ",", "err", ")", "\n", "}", "\n\n", "r", ".", "done", "<-", "true", "\n", "r", ".", "running", ".", "Store", "(", "false", ")", "\n", "return", "result", "\n", "}" ]
// 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
train
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
train
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", ".", "Name", "(", ")", "==", "name", "{", "return", "device", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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
train
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
train
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", ".", "Name", "(", ")", "==", "name", "{", "return", "connection", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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
train
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", "{", "l3gd20hRegisterOutXLSB", "}", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "0", ",", "0", ",", "err", "\n", "}", "\n", "measurements", ":=", "make", "(", "[", "]", "byte", ",", "6", ")", "\n", "if", "_", ",", "err", "=", "d", ".", "connection", ".", "Read", "(", "measurements", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "0", ",", "0", ",", "err", "\n", "}", "\n\n", "var", "rawX", "int16", "\n", "var", "rawY", "int16", "\n", "var", "rawZ", "int16", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "measurements", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "rawX", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "rawY", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "rawZ", ")", "\n\n", "// Sensitivity values from the mechanical characteristics in the datasheet.", "sensitivity", ":=", "d", ".", "getSensitivity", "(", ")", "\n\n", "return", "float32", "(", "rawX", ")", "*", "sensitivity", ",", "float32", "(", "rawY", ")", "*", "sensitivity", ",", "float32", "(", "rawZ", ")", "*", "sensitivity", ",", "nil", "\n", "}" ]
// 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
train
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", "(", "d", ".", "Pin", "(", ")", ",", "byte", "(", "0", ")", ")", "\n", "}", "\n", "err", "=", "ErrDigitalWriteUnsupported", "\n", "return", "\n", "}" ]
// Turn Off pin
[ "Turn", "Off", "pin" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/direct_pin_driver.go#L72-L78
train
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", "reader", ".", "DigitalRead", "(", "d", ".", "Pin", "(", ")", ")", "\n", "}", "\n", "err", "=", "ErrDigitalReadUnsupported", "\n", "return", "\n", "}" ]
// 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
train
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", "writer", ".", "ServoWrite", "(", "d", ".", "Pin", "(", ")", ",", "level", ")", "\n", "}", "\n", "err", "=", "ErrServoWriteUnsupported", "\n", "return", "\n", "}" ]
// 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
train
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", ")", ".", "String", "(", ")", ",", "}", "\n", "}" ]
// 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
train
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
train
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", ":=", "\"", "\"", "+", "connection", ".", "Name", "(", ")", "\n\n", "if", "porter", ",", "ok", ":=", "connection", ".", "(", "Porter", ")", ";", "ok", "{", "info", "=", "info", "+", "\"", "\"", "+", "porter", ".", "Port", "(", ")", "\n", "}", "\n\n", "log", ".", "Println", "(", "info", "+", "\"", "\"", ")", "\n\n", "if", "cerr", ":=", "connection", ".", "Connect", "(", ")", ";", "cerr", "!=", "nil", "{", "err", "=", "multierror", ".", "Append", "(", "err", ",", "cerr", ")", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// 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
train
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", "{", "err", "=", "multierror", ".", "Append", "(", "err", ",", "cerr", ")", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// 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
train
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", ",", "Dead", ":", "0x01", ",", "}", "\n", "}" ]
// 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
train
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", "(", ")", "\n", "return", "c", "\n", "}" ]
// NewAdaptor creates a Tinkerboard Adaptor
[ "NewAdaptor", "creates", "a", "Tinkerboard", "Adaptor" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/tinkerboard/adaptor.go#L30-L38
train
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
train
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", ".", "NewEventer", "(", ")", ",", "}", "\n\n", "return", "n", "\n", "}" ]
// 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
train
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", ":=", "bytes", ".", "NewBuffer", "(", "c", ")", "\n", "pinsData", ":=", "make", "(", "[", "]", "PinData", ",", "buf", ".", "Len", "(", ")", "/", "2", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "buf", ".", "Len", "(", ")", "/", "2", ";", "i", "++", "{", "pinData", ":=", "PinData", "{", "}", "\n", "pinData", ".", "pin", ",", "_", "=", "buf", ".", "ReadByte", "(", ")", "\n", "pinData", ".", "value", ",", "_", "=", "buf", ".", "ReadByte", "(", ")", "\n", "pinsData", "[", "i", "]", "=", "pinData", "\n", "}", "\n\n", "return", "pinsData", "\n", "}" ]
// 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
train
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", "\n", "}", "\n\n", "buf", ":=", "[", "]", "byte", "{", "byte", "(", "i", ")", ",", "data", "}", "\n", "err", "=", "b", ".", "adaptor", "(", ")", ".", "WriteCharacteristic", "(", "pinDataCharacteristic", ",", "buf", ")", "\n", "return", "err", "\n", "}" ]
// 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
train
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", "e", "!=", "nil", "{", "return", "0", ",", "e", "\n", "}", "\n\n", "var", "result", "byte", "\n", "for", "i", ":=", "0", ";", "i", "<", "4", ";", "i", "++", "{", "result", "|=", "c", "[", "i", "]", "<<", "uint", "(", "i", ")", "\n", "}", "\n\n", "b", ".", "ioMask", "=", "int", "(", "result", ")", "\n", "return", "int", "(", "result", ")", ",", "nil", "\n", "}" ]
// 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
train
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", "}", "\n\n", "b", ".", "ensureDigital", "(", "p", ")", "\n", "b", ".", "ensureInput", "(", "p", ")", "\n\n", "pins", ":=", "b", ".", "ReadAllPinData", "(", ")", "\n", "return", "int", "(", "pins", "[", "p", "]", ".", "value", ")", ",", "nil", "\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
train
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", "}", "\n\n", "b", ".", "ensureDigital", "(", "p", ")", "\n", "b", ".", "ensureOutput", "(", "p", ")", "\n\n", "return", "b", ".", "WritePinData", "(", "pin", ",", "level", ")", "\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
train
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", "}", "\n\n", "b", ".", "ensureAnalog", "(", "p", ")", "\n", "b", ".", "ensureInput", "(", "p", ")", "\n\n", "pins", ":=", "b", ".", "ReadAllPinData", "(", ")", "\n", "return", "int", "(", "pins", "[", "p", "]", ".", "value", ")", ",", "nil", "\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
train
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
train
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", "(", "g", ".", "connector", ".", "GetSpiDefaultChip", "(", ")", ")", "\n", "mode", ":=", "g", ".", "GetModeOrDefault", "(", "g", ".", "connector", ".", "GetSpiDefaultMode", "(", ")", ")", "\n", "bits", ":=", "g", ".", "GetBitsOrDefault", "(", "g", ".", "connector", ".", "GetSpiDefaultBits", "(", ")", ")", "\n", "maxSpeed", ":=", "g", ".", "GetSpeedOrDefault", "(", "g", ".", "connector", ".", "GetSpiDefaultMaxSpeed", "(", ")", ")", "\n\n", "g", ".", "connection", ",", "err", "=", "g", ".", "connector", ".", "GetSpiConnection", "(", "bus", ",", "chip", ",", "mode", ",", "bits", ",", "maxSpeed", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Start initializes the GoPiGo3
[ "Start", "initializes", "the", "GoPiGo3" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dexter/gopigo3/driver.go#L211-L223
train
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_MANUFACTURER", ",", "24", ")", "\n", "if", "err", "!=", "nil", "{", "return", "mName", ",", "err", "\n", "}", "\n", "if", "err", ":=", "g", ".", "responseValid", "(", "response", ")", ";", "err", "!=", "nil", "{", "return", "mName", ",", "err", "\n", "}", "\n", "mf", ":=", "response", "[", "4", ":", "23", "]", "\n", "mf", "=", "bytes", ".", "Trim", "(", "mf", ",", "\"", "\\x00", "\"", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "string", "(", "mf", ")", ")", ",", "nil", "\n", "}" ]
// 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
train
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", ",", "24", ")", "\n", "if", "err", "!=", "nil", "{", "return", "bName", ",", "err", "\n", "}", "\n", "if", "err", ":=", "g", ".", "responseValid", "(", "response", ")", ";", "err", "!=", "nil", "{", "return", "bName", ",", "err", "\n", "}", "\n", "mf", ":=", "response", "[", "4", ":", "23", "]", "\n", "mf", "=", "bytes", ".", "Trim", "(", "mf", ",", "\"", "\\x00", "\"", ")", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "string", "(", "mf", ")", ")", ",", "nil", "\n", "}" ]
// 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
train
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", "!=", "nil", "{", "return", "hVer", ",", "err", "\n", "}", "\n", "major", ":=", "response", "/", "1000000", "\n", "minor", ":=", "response", "/", "1000", "%", "1000", "\n", "patch", ":=", "response", "%", "1000", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "major", ",", "minor", ",", "patch", ")", ",", "nil", "\n", "}" ]
// 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
train
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", "!=", "nil", "{", "return", "fVer", ",", "err", "\n", "}", "\n", "major", ":=", "response", "/", "1000000", "\n", "minor", ":=", "response", "/", "1000", "%", "1000", "\n", "patch", ":=", "response", "%", "1000", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "major", ",", "minor", ",", "patch", ")", ",", "nil", "\n", "}" ]
// 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
train
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", ",", "20", ")", "\n", "if", "err", "!=", "nil", "{", "return", "sNum", ",", "err", "\n", "}", "\n", "if", "err", ":=", "g", ".", "responseValid", "(", "response", ")", ";", "err", "!=", "nil", "{", "return", "sNum", ",", "err", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "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", "\n", "}" ]
// 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
train
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", "(", "val", ")", "/", "1000.0", ")", ",", "err", "\n", "}" ]
// 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
train
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", "(", "led", ")", ",", "byte", "(", "red", ")", ",", "byte", "(", "green", ")", ",", "byte", "(", "blue", ")", ",", "}", ")", "\n", "}" ]
// 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
train
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", ")", ",", "byte", "(", "power", ")", ",", "}", ")", "\n", "}" ]
// 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
train
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", "{", "goPiGo3Address", ",", "SET_MOTOR_POSITION", ",", "byte", "(", "motor", ")", ",", "byte", "(", "(", "positionRaw", ">>", "24", ")", "&", "0xFF", ")", ",", "byte", "(", "(", "positionRaw", ">>", "16", ")", "&", "0xFF", ")", ",", "byte", "(", "(", "positionRaw", ">>", "8", ")", "&", "0xFF", ")", ",", "byte", "(", "positionRaw", "&", "0xFF", ")", ",", "}", ")", "\n", "}" ]
// 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
train
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", ",", "SET_MOTOR_DPS", ",", "byte", "(", "motor", ")", ",", "byte", "(", "(", "d", ">>", "8", ")", "&", "0xFF", ")", ",", "byte", "(", "d", "&", "0xFF", ")", ",", "}", ")", "\n", "}" ]
// 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
train
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", "(", "[", "]", "byte", "{", "goPiGo3Address", ",", "SET_MOTOR_LIMITS", ",", "byte", "(", "motor", ")", ",", "byte", "(", "power", ")", ",", "byte", "(", "(", "dpsUint", ">>", "8", ")", "&", "0xFF", ")", ",", "byte", "(", "dpsUint", "&", "0xFF", ")", ",", "}", ")", "\n", "}" ]
// 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
train
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", "motor", "==", "MOTOR_LEFT", "{", "message", "=", "GET_MOTOR_STATUS_LEFT", "\n", "}", "\n", "response", ",", "err", ":=", "g", ".", "readBytes", "(", "goPiGo3Address", ",", "message", ",", "12", ")", "\n", "if", "err", "!=", "nil", "{", "return", "flags", ",", "power", ",", "encoder", ",", "dps", ",", "err", "\n", "}", "\n", "if", "err", ":=", "g", ".", "responseValid", "(", "response", ")", ";", "err", "!=", "nil", "{", "return", "flags", ",", "power", ",", "encoder", ",", "dps", ",", "err", "\n", "}", "\n", "// get flags", "flags", "=", "uint8", "(", "response", "[", "4", "]", ")", "\n", "// get power", "power", "=", "uint16", "(", "response", "[", "5", "]", ")", "\n", "if", "power", "&", "0x80", "==", "0x80", "{", "power", "=", "power", "-", "0x100", "\n", "}", "\n", "// get encoder", "enc", ":=", "make", "(", "[", "]", "byte", ",", "4", ")", "\n", "enc", "[", "3", "]", "=", "response", "[", "6", "]", "\n", "enc", "[", "2", "]", "=", "response", "[", "7", "]", "\n", "enc", "[", "1", "]", "=", "response", "[", "8", "]", "\n", "enc", "[", "0", "]", "=", "response", "[", "9", "]", "\n", "e", ":=", "binary", ".", "LittleEndian", ".", "Uint32", "(", "enc", ")", "\n", "if", "e", "&", "0x80000000", "==", "0x80000000", "{", "encoder", "=", "int", "(", "uint64", "(", "e", ")", "-", "0x100000000", ")", "\n", "}", "\n", "encoder", "=", "int", "(", "e", ")", "\n", "//get dps", "d", ":=", "make", "(", "[", "]", "byte", ",", "4", ")", "\n", "d", "[", "1", "]", "=", "response", "[", "10", "]", "\n", "d", "[", "0", "]", "=", "response", "[", "11", "]", "\n", "ds", ":=", "binary", ".", "LittleEndian", ".", "Uint32", "(", "d", ")", "\n", "if", "ds", "&", "0x8000", "==", "0x8000", "{", "dps", "=", "int", "(", "ds", "-", "0x10000", ")", "\n", "}", "\n", "dps", "=", "int", "(", "ds", ")", "\n", "return", "flags", ",", "power", ",", "encoder", "/", "MOTOR_TICKS_PER_DEGREE", ",", "dps", "/", "MOTOR_TICKS_PER_DEGREE", ",", "nil", "\n", "}" ]
// 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
train
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_MOTOR_ENCODER_LEFT", "\n", "}", "\n", "response", ",", "err", ":=", "g", ".", "readUint32", "(", "goPiGo3Address", ",", "message", ")", "\n", "if", "err", "!=", "nil", "{", "return", "encoder", ",", "err", "\n", "}", "\n", "encoder", "=", "int64", "(", "response", ")", "\n", "if", "response", "&", "0x80000000", "!=", "0", "{", "encoder", "=", "encoder", "-", "0x100000000", "\n", "}", "\n", "encoder", "=", "encoder", "/", "MOTOR_TICKS_PER_DEGREE", "\n", "return", "encoder", ",", "nil", "\n", "}" ]
// 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
train
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", ".", "writeBytes", "(", "[", "]", "byte", "{", "goPiGo3Address", ",", "OFFSET_MOTOR_ENCODER", ",", "byte", "(", "motor", ")", ",", "byte", "(", "(", "offsetUint", ">>", "24", ")", "&", "0xFF", ")", ",", "byte", "(", "(", "offsetUint", ">>", "16", ")", "&", "0xFF", ")", ",", "byte", "(", "(", "offsetUint", ">>", "8", ")", "&", "0xFF", ")", ",", "byte", "(", "offsetUint", "&", "0xFF", ")", ",", "}", ")", "\n", "}" ]
// 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
train
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", ")", ",", "byte", "(", "gType", ")", ",", "}", ")", "\n", "}" ]
// 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
train
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", ",", "_", ",", "_", ",", "err", "=", "getGroveAddresses", "(", "pin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "g", ".", "SetGroveType", "(", "grovePort", ",", "CUSTOM", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "err", "=", "g", ".", "SetGroveMode", "(", "grovePin", ",", "GROVE_OUTPUT_PWM", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "err", "=", "g", ".", "SetPWMFreq", "(", "grovePin", ",", "24000", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "val64", ":=", "math", ".", "Float64frombits", "(", "uint64", "(", "val", ")", ")", "\n", "dutyCycle", ":=", "uint16", "(", "math", ".", "Float64bits", "(", "(", "100.0", "/", "255.0", ")", "*", "val64", ")", ")", "\n", "return", "g", ".", "SetPWMDuty", "(", "grovePin", ",", "dutyCycle", ")", "\n", "}" ]
// 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
train
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", ",", "grovePort", ",", "analogCmd", ",", "_", ",", "err", "=", "getGroveAddresses", "(", "pin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "value", ",", "err", "\n", "}", "\n", "err", "=", "g", ".", "SetGroveType", "(", "grovePort", ",", "CUSTOM", ")", "\n", "if", "err", "!=", "nil", "{", "return", "value", ",", "err", "\n", "}", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "err", "=", "g", ".", "SetGroveMode", "(", "grovePin", ",", "GROVE_INPUT_ANALOG", ")", "\n", "if", "err", "!=", "nil", "{", "return", "value", ",", "err", "\n", "}", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "response", ",", "err", ":=", "g", ".", "readBytes", "(", "goPiGo3Address", ",", "analogCmd", ",", "7", ")", "\n", "if", "err", "!=", "nil", "{", "return", "value", ",", "err", "\n", "}", "\n", "if", "err", ":=", "g", ".", "responseValid", "(", "response", ")", ";", "err", "!=", "nil", "{", "return", "value", ",", "err", "\n", "}", "\n", "if", "err", ":=", "g", ".", "valueValid", "(", "response", ")", ";", "err", "!=", "nil", "{", "return", "value", ",", "err", "\n", "}", "\n", "highBytes", ":=", "uint16", "(", "response", "[", "5", "]", ")", "\n", "lowBytes", ":=", "uint16", "(", "response", "[", "6", "]", ")", "\n", "return", "int", "(", "(", "highBytes", "<<", "8", ")", "&", "0xFF00", ")", "|", "int", "(", "lowBytes", "&", "0xFF", ")", ",", "nil", "\n", "}" ]
// 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
train
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", "(", ")", "{", "s", ".", "Stop", "(", ")", "\n", "}", ")", "\n", "time", ".", "Sleep", "(", "1", "*", "time", ".", "Second", ")", "\n", "}", "\n", "return", "\n", "}" ]
// 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
train
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", "}", ",", "0x02", ",", "0x20", ")", "\n", "}" ]
// 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
train
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", "len", "(", "buf", ")", "==", "9", "{", "return", "[", "]", "uint8", "{", "buf", "[", "5", "]", ",", "buf", "[", "6", "]", ",", "buf", "[", "7", "]", "}", "\n", "}", "\n", "return", "[", "]", "uint8", "{", "}", "\n", "}" ]
// 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
train
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
train
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", "&", "0xFF", ")", "}", ",", "0x02", ",", "0x01", ")", "\n", "}" ]
// 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
train
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", ".", "craftPacket", "(", "[", "]", "uint8", "{", "b", "}", ",", "0x02", ",", "0x02", ")", "\n", "}" ]
// 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
train
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", ")", ",", "uint8", "(", "heading", "&", "0xFF", ")", ",", "0x01", "}", ",", "0x02", ",", "0x30", ")", "\n", "}" ]
// 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
train
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", "s", ".", "packetChannel", "<-", "s", ".", "craftPacket", "(", "buf", ".", "Bytes", "(", ")", ",", "0x02", ",", "0x13", ")", "\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
train
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", ")", "\n\n", "s", ".", "packetChannel", "<-", "s", ".", "craftPacket", "(", "buf", ".", "Bytes", "(", ")", ",", "0x02", ",", "0x11", ")", "\n", "}" ]
// 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
train
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", "!=", "nil", "{", "return", "e", "\n", "}", "\n", "f", ".", "conn", "=", "sp", "\n", "}", "\n", "if", "err", "=", "f", ".", "Board", ".", "Connect", "(", "f", ".", "conn", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "f", ".", "Board", ".", "On", "(", "\"", "\"", ",", "func", "(", "data", "interface", "{", "}", ")", "{", "f", ".", "Publish", "(", "\"", "\"", ",", "data", ")", "\n", "}", ")", "\n\n", "return", "\n", "}" ]
// 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
train
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
train
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", "\n", "}", "\n\n", "return", "f", ".", "Board", ".", "ServoConfig", "(", "p", ",", "max", ",", "min", ")", "\n", "}" ]
// 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
train
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", "err", "\n", "}", "\n\n", "if", "f", ".", "Board", ".", "Pins", "(", ")", "[", "p", "]", ".", "Mode", "!=", "client", ".", "Servo", "{", "err", "=", "f", ".", "Board", ".", "SetPinMode", "(", "p", ",", "client", ".", "Servo", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "err", "=", "f", ".", "Board", ".", "AnalogWrite", "(", "p", ",", "int", "(", "angle", ")", ")", "\n", "return", "\n", "}" ]
// 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
train
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", "\n", "}", "\n\n", "if", "f", ".", "Board", ".", "Pins", "(", ")", "[", "p", "]", ".", "Mode", "!=", "client", ".", "Input", "{", "if", "err", "=", "f", ".", "Board", ".", "SetPinMode", "(", "p", ",", "client", ".", "Input", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "err", "=", "f", ".", "Board", ".", "ReportDigital", "(", "p", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "<-", "time", ".", "After", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n\n", "return", "f", ".", "Board", ".", "Pins", "(", ")", "[", "p", "]", ".", "Value", ",", "nil", "\n", "}" ]
// 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
train
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", "}", "\n\n", "p", "=", "f", ".", "digitalPin", "(", "p", ")", "\n\n", "if", "f", ".", "Board", ".", "Pins", "(", ")", "[", "p", "]", ".", "Mode", "!=", "client", ".", "Analog", "{", "if", "err", "=", "f", ".", "Board", ".", "SetPinMode", "(", "p", ",", "client", ".", "Analog", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "err", "=", "f", ".", "Board", ".", "ReportAnalog", "(", "p", ",", "1", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "<-", "time", ".", "After", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n\n", "return", "f", ".", "Board", ".", "Pins", "(", ")", "[", "p", "]", ".", "Value", ",", "nil", "\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
train
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", "{", "m", ".", "Publish", "(", "ErrorIOEvent", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "m", ".", "Publish", "(", "PacketEvent", ",", "packet", ")", "\n", "message", ",", "err", ":=", "packet", ".", "MAVLinkMessage", "(", ")", "\n", "if", "err", "!=", "nil", "{", "m", ".", "Publish", "(", "ErrorMAVLinkEvent", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "m", ".", "Publish", "(", "MessageEvent", ",", "message", ")", "\n", "time", ".", "Sleep", "(", "m", ".", "interval", ")", "\n", "}", "\n", "}", "(", ")", "\n", "return", "nil", "\n", "}" ]
// 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
train
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", "(", ")", ")", "\n", "return", "err", "\n", "}" ]
// 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
train
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", ".", "NewEventer", "(", ")", ",", "packetChannel", ":", "make", "(", "chan", "*", "packet", ",", "1024", ")", ",", "}", "\n\n", "n", ".", "AddEvent", "(", "Collision", ")", "\n\n", "return", "n", "\n", "}" ]
// 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
train
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 notifications", "b", ".", "adaptor", "(", ")", ".", "Subscribe", "(", "responseCharacteristic", ",", "b", ".", "HandleResponses", ")", "\n\n", "return", "\n", "}" ]
// 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
train
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", "=", "b", ".", "adaptor", "(", ")", ".", "WriteCharacteristic", "(", "antiDosCharacteristic", ",", "buf", ".", "Bytes", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "\n", "}" ]
// 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
train
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", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "\n", "}" ]
// 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
train
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", "(", ")", ".", "WriteCharacteristic", "(", "txPowerCharacteristic", ",", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "\n", "}" ]
// SetTXPower sets transmit level
[ "SetTXPower", "sets", "transmit", "level" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/sphero/ollie/ollie_driver.go#L180-L190
train
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
train
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", "}", ",", "0x02", ",", "0x20", ")", "\n", "}" ]
// 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
train
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", ")", ",", "uint8", "(", "heading", "&", "0xFF", ")", ",", "0x01", "}", ",", "0x02", ",", "0x30", ")", "\n", "}" ]
// 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
train
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", "(", "[", "]", "uint8", "{", "s", "}", ",", "0x02", ",", "0x31", ")", "\n", "}" ]
// 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
train
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", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ",", "err", ":=", "p", ".", "Connect", "(", "physic", ".", "Frequency", "(", "maxSpeed", ")", "*", "physic", ".", "Hertz", ",", "xspi", ".", "Mode", "(", "mode", ")", ",", "bits", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "NewConnection", "(", "p", ",", "c", ")", ",", "nil", "\n", "}" ]
// 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
train
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", ",", "write", ":", "writePwmFile", "}", "\n", "}" ]
// NewPwmPin returns a new pwmPin
[ "NewPwmPin", "returns", "a", "new", "pwmPin" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L49-L56
train
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", "{", "// If EBUSY then the pin has already been exported", "e", ",", "ok", ":=", "err", ".", "(", "*", "os", ".", "PathError", ")", "\n", "if", "!", "ok", "||", "e", ".", "Err", "!=", "syscall", ".", "EBUSY", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// 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", ")", "\n\n", "return", "nil", "\n", "}" ]
// 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
train
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", "return", "\n", "}" ]
// 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
train
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", "{", "enableVal", "=", "1", "\n", "}", "\n", "_", ",", "err", "=", "p", ".", "write", "(", "p", ".", "pwmEnablePath", "(", ")", ",", "[", "]", "byte", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "enableVal", ")", ")", ")", "\n", "}", "\n", "return", "\n", "}" ]
// 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
train