repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
hybridgroup/gobot
platforms/mavlink/common/common.go
Decode
func (m *Debug) Decode(buf []byte) { data := bytes.NewBuffer(buf) binary.Read(data, binary.LittleEndian, &m.TIME_BOOT_MS) binary.Read(data, binary.LittleEndian, &m.VALUE) binary.Read(data, binary.LittleEndian, &m.IND) }
go
func (m *Debug) Decode(buf []byte) { data := bytes.NewBuffer(buf) binary.Read(data, binary.LittleEndian, &m.TIME_BOOT_MS) binary.Read(data, binary.LittleEndian, &m.VALUE) binary.Read(data, binary.LittleEndian, &m.IND) }
[ "func", "(", "m", "*", "Debug", ")", "Decode", "(", "buf", "[", "]", "byte", ")", "{", "data", ":=", "bytes", ".", "NewBuffer", "(", "buf", ")", "\n", "binary", ".", "Read", "(", "data", ",", "binary", ".", "LittleEndian", ",", "&", "m", ".", "TIME_BOOT_MS", ")", "\n", "binary", ".", "Read", "(", "data", ",", "binary", ".", "LittleEndian", ",", "&", "m", ".", "VALUE", ")", "\n", "binary", ".", "Read", "(", "data", ",", "binary", ".", "LittleEndian", ",", "&", "m", ".", "IND", ")", "\n", "}" ]
// Decode accepts a packed byte array and populates the fields of the Debug
[ "Decode", "accepts", "a", "packed", "byte", "array", "and", "populates", "the", "fields", "of", "the", "Debug" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mavlink/common/common.go#L9003-L9008
train
hybridgroup/gobot
platforms/keyboard/keyboard_driver.go
NewDriver
func NewDriver() *Driver { k := &Driver{ name: gobot.DefaultName("Keyboard"), connect: func(k *Driver) (err error) { if err := configure(); err != nil { return err } k.stdin = os.Stdin return }, listen: func(k *Driver) { ctrlc := bytes{3} for { var keybuf bytes k.stdin.Read(keybuf[0:3]) if keybuf == ctrlc { proc, err := os.FindProcess(os.Getpid()) if err != nil { log.Fatal(err) } proc.Signal(os.Interrupt) break } k.Publish(Key, Parse(keybuf)) } }, Eventer: gobot.NewEventer(), } k.AddEvent(Key) return k }
go
func NewDriver() *Driver { k := &Driver{ name: gobot.DefaultName("Keyboard"), connect: func(k *Driver) (err error) { if err := configure(); err != nil { return err } k.stdin = os.Stdin return }, listen: func(k *Driver) { ctrlc := bytes{3} for { var keybuf bytes k.stdin.Read(keybuf[0:3]) if keybuf == ctrlc { proc, err := os.FindProcess(os.Getpid()) if err != nil { log.Fatal(err) } proc.Signal(os.Interrupt) break } k.Publish(Key, Parse(keybuf)) } }, Eventer: gobot.NewEventer(), } k.AddEvent(Key) return k }
[ "func", "NewDriver", "(", ")", "*", "Driver", "{", "k", ":=", "&", "Driver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connect", ":", "func", "(", "k", "*", "Driver", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "configure", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "k", ".", "stdin", "=", "os", ".", "Stdin", "\n", "return", "\n", "}", ",", "listen", ":", "func", "(", "k", "*", "Driver", ")", "{", "ctrlc", ":=", "bytes", "{", "3", "}", "\n\n", "for", "{", "var", "keybuf", "bytes", "\n", "k", ".", "stdin", ".", "Read", "(", "keybuf", "[", "0", ":", "3", "]", ")", "\n\n", "if", "keybuf", "==", "ctrlc", "{", "proc", ",", "err", ":=", "os", ".", "FindProcess", "(", "os", ".", "Getpid", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Fatal", "(", "err", ")", "\n", "}", "\n\n", "proc", ".", "Signal", "(", "os", ".", "Interrupt", ")", "\n", "break", "\n", "}", "\n\n", "k", ".", "Publish", "(", "Key", ",", "Parse", "(", "keybuf", ")", ")", "\n\n", "}", "\n", "}", ",", "Eventer", ":", "gobot", ".", "NewEventer", "(", ")", ",", "}", "\n\n", "k", ".", "AddEvent", "(", "Key", ")", "\n\n", "return", "k", "\n", "}" ]
// NewDriver returns a new keyboard Driver. //
[ "NewDriver", "returns", "a", "new", "keyboard", "Driver", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/keyboard/keyboard_driver.go#L26-L64
train
hybridgroup/gobot
platforms/keyboard/keyboard_driver.go
Start
func (k *Driver) Start() (err error) { if err = k.connect(k); err != nil { return err } go k.listen(k) return }
go
func (k *Driver) Start() (err error) { if err = k.connect(k); err != nil { return err } go k.listen(k) return }
[ "func", "(", "k", "*", "Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "k", ".", "connect", "(", "k", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "go", "k", ".", "listen", "(", "k", ")", "\n\n", "return", "\n", "}" ]
// Start initializes keyboard by grabbing key events as they come in and // publishing each as a key event
[ "Start", "initializes", "keyboard", "by", "grabbing", "key", "events", "as", "they", "come", "in", "and", "publishing", "each", "as", "a", "key", "event" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/keyboard/keyboard_driver.go#L77-L85
train
hybridgroup/gobot
platforms/raspi/pwm_pin.go
Unexport
func (p *PWMPin) Unexport() error { return p.piBlaster(fmt.Sprintf("release %v\n", p.pin)) }
go
func (p *PWMPin) Unexport() error { return p.piBlaster(fmt.Sprintf("release %v\n", p.pin)) }
[ "func", "(", "p", "*", "PWMPin", ")", "Unexport", "(", ")", "error", "{", "return", "p", ".", "piBlaster", "(", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "p", ".", "pin", ")", ")", "\n", "}" ]
// Unexport unexports the pin and releases the pin from the operating system
[ "Unexport", "unexports", "the", "pin", "and", "releases", "the", "pin", "from", "the", "operating", "system" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/pwm_pin.go#L32-L34
train
hybridgroup/gobot
platforms/raspi/pwm_pin.go
Period
func (p *PWMPin) Period() (period uint32, err error) { if p.period == 0 { return p.period, errors.New("Raspi PWM pin period not set") } return p.period, nil }
go
func (p *PWMPin) Period() (period uint32, err error) { if p.period == 0 { return p.period, errors.New("Raspi PWM pin period not set") } return p.period, nil }
[ "func", "(", "p", "*", "PWMPin", ")", "Period", "(", ")", "(", "period", "uint32", ",", "err", "error", ")", "{", "if", "p", ".", "period", "==", "0", "{", "return", "p", ".", "period", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "p", ".", "period", ",", "nil", "\n", "}" ]
// Period returns the current PWM period for pin
[ "Period", "returns", "the", "current", "PWM", "period", "for", "pin" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/pwm_pin.go#L52-L58
train
hybridgroup/gobot
platforms/raspi/pwm_pin.go
DutyCycle
func (p *PWMPin) DutyCycle() (duty uint32, err error) { return p.dc, nil }
go
func (p *PWMPin) DutyCycle() (duty uint32, err error) { return p.dc, nil }
[ "func", "(", "p", "*", "PWMPin", ")", "DutyCycle", "(", ")", "(", "duty", "uint32", ",", "err", "error", ")", "{", "return", "p", ".", "dc", ",", "nil", "\n", "}" ]
// DutyCycle returns the duty cycle for the pin
[ "DutyCycle", "returns", "the", "duty", "cycle", "for", "the", "pin" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/pwm_pin.go#L70-L72
train
hybridgroup/gobot
platforms/raspi/pwm_pin.go
SetDutyCycle
func (p *PWMPin) SetDutyCycle(duty uint32) (err error) { if p.period == 0 { return errors.New("Raspi PWM pin period not set") } if duty > p.period { return errors.New("Duty cycle exceeds period.") } p.dc = duty val := gobot.FromScale(float64(p.dc), 0, float64(p.period)) // never go below minimum allowed duty for pi blaster if val < 0.05 { val = 0.05 } return p.piBlaster(fmt.Sprintf("%v=%v\n", p.pin, val)) }
go
func (p *PWMPin) SetDutyCycle(duty uint32) (err error) { if p.period == 0 { return errors.New("Raspi PWM pin period not set") } if duty > p.period { return errors.New("Duty cycle exceeds period.") } p.dc = duty val := gobot.FromScale(float64(p.dc), 0, float64(p.period)) // never go below minimum allowed duty for pi blaster if val < 0.05 { val = 0.05 } return p.piBlaster(fmt.Sprintf("%v=%v\n", p.pin, val)) }
[ "func", "(", "p", "*", "PWMPin", ")", "SetDutyCycle", "(", "duty", "uint32", ")", "(", "err", "error", ")", "{", "if", "p", ".", "period", "==", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "duty", ">", "p", ".", "period", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "p", ".", "dc", "=", "duty", "\n\n", "val", ":=", "gobot", ".", "FromScale", "(", "float64", "(", "p", ".", "dc", ")", ",", "0", ",", "float64", "(", "p", ".", "period", ")", ")", "\n\n", "// never go below minimum allowed duty for pi blaster", "if", "val", "<", "0.05", "{", "val", "=", "0.05", "\n", "}", "\n", "return", "p", ".", "piBlaster", "(", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "p", ".", "pin", ",", "val", ")", ")", "\n", "}" ]
// SetDutyCycle writes the duty cycle to the pin
[ "SetDutyCycle", "writes", "the", "duty", "cycle", "to", "the", "pin" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/pwm_pin.go#L75-L92
train
hybridgroup/gobot
platforms/digispark/littleWire.go
i2cStart
func (l *littleWire) i2cStart(address7bit uint8, direction uint8) error { if C.i2c_start(l.lwHandle, C.uchar(address7bit), C.uchar(direction)) == 1 { return nil } if err := l.error(); err != nil { return err } return fmt.Errorf("Littlewire i2cStart failed for %d in direction %d", address7bit, direction) }
go
func (l *littleWire) i2cStart(address7bit uint8, direction uint8) error { if C.i2c_start(l.lwHandle, C.uchar(address7bit), C.uchar(direction)) == 1 { return nil } if err := l.error(); err != nil { return err } return fmt.Errorf("Littlewire i2cStart failed for %d in direction %d", address7bit, direction) }
[ "func", "(", "l", "*", "littleWire", ")", "i2cStart", "(", "address7bit", "uint8", ",", "direction", "uint8", ")", "error", "{", "if", "C", ".", "i2c_start", "(", "l", ".", "lwHandle", ",", "C", ".", "uchar", "(", "address7bit", ")", ",", "C", ".", "uchar", "(", "direction", ")", ")", "==", "1", "{", "return", "nil", "\n", "}", "\n", "if", "err", ":=", "l", ".", "error", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "address7bit", ",", "direction", ")", "\n", "}" ]
// i2cStart starts the i2c communication; set direction to 1 for reading, 0 for writing
[ "i2cStart", "starts", "the", "i2c", "communication", ";", "set", "direction", "to", "1", "for", "reading", "0", "for", "writing" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/digispark/littleWire.go#L87-L95
train
hybridgroup/gobot
platforms/digispark/littleWire.go
i2cUpdateDelay
func (l *littleWire) i2cUpdateDelay(duration uint) error { C.i2c_updateDelay(l.lwHandle, C.uint(duration)) return l.error() }
go
func (l *littleWire) i2cUpdateDelay(duration uint) error { C.i2c_updateDelay(l.lwHandle, C.uint(duration)) return l.error() }
[ "func", "(", "l", "*", "littleWire", ")", "i2cUpdateDelay", "(", "duration", "uint", ")", "error", "{", "C", ".", "i2c_updateDelay", "(", "l", ".", "lwHandle", ",", "C", ".", "uint", "(", "duration", ")", ")", "\n", "return", "l", ".", "error", "(", ")", "\n", "}" ]
// i2cUpdateDelay updates i2c signal delay amount. Tune if neccessary to fit your requirements
[ "i2cUpdateDelay", "updates", "i2c", "signal", "delay", "amount", ".", "Tune", "if", "neccessary", "to", "fit", "your", "requirements" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/digispark/littleWire.go#L110-L113
train
hybridgroup/gobot
drivers/gpio/motor_driver.go
NewMotorDriver
func NewMotorDriver(a DigitalWriter, speedPin string) *MotorDriver { return &MotorDriver{ name: gobot.DefaultName("Motor"), connection: a, SpeedPin: speedPin, CurrentState: 0, CurrentSpeed: 0, CurrentMode: "digital", CurrentDirection: "forward", } }
go
func NewMotorDriver(a DigitalWriter, speedPin string) *MotorDriver { return &MotorDriver{ name: gobot.DefaultName("Motor"), connection: a, SpeedPin: speedPin, CurrentState: 0, CurrentSpeed: 0, CurrentMode: "digital", CurrentDirection: "forward", } }
[ "func", "NewMotorDriver", "(", "a", "DigitalWriter", ",", "speedPin", "string", ")", "*", "MotorDriver", "{", "return", "&", "MotorDriver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connection", ":", "a", ",", "SpeedPin", ":", "speedPin", ",", "CurrentState", ":", "0", ",", "CurrentSpeed", ":", "0", ",", "CurrentMode", ":", "\"", "\"", ",", "CurrentDirection", ":", "\"", "\"", ",", "}", "\n", "}" ]
// NewMotorDriver return a new MotorDriver given a DigitalWriter and pin
[ "NewMotorDriver", "return", "a", "new", "MotorDriver", "given", "a", "DigitalWriter", "and", "pin" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/motor_driver.go#L23-L33
train
hybridgroup/gobot
drivers/gpio/motor_driver.go
Off
func (m *MotorDriver) Off() (err error) { if m.isDigital() { err = m.changeState(0) } else { err = m.Speed(0) } return }
go
func (m *MotorDriver) Off() (err error) { if m.isDigital() { err = m.changeState(0) } else { err = m.Speed(0) } return }
[ "func", "(", "m", "*", "MotorDriver", ")", "Off", "(", ")", "(", "err", "error", ")", "{", "if", "m", ".", "isDigital", "(", ")", "{", "err", "=", "m", ".", "changeState", "(", "0", ")", "\n", "}", "else", "{", "err", "=", "m", ".", "Speed", "(", "0", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Off turns the motor off or sets the motor to a 0 speed
[ "Off", "turns", "the", "motor", "off", "or", "sets", "the", "motor", "to", "a", "0", "speed" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/motor_driver.go#L51-L58
train
hybridgroup/gobot
drivers/gpio/motor_driver.go
On
func (m *MotorDriver) On() (err error) { if m.isDigital() { err = m.changeState(1) } else { if m.CurrentSpeed == 0 { m.CurrentSpeed = 255 } err = m.Speed(m.CurrentSpeed) } return }
go
func (m *MotorDriver) On() (err error) { if m.isDigital() { err = m.changeState(1) } else { if m.CurrentSpeed == 0 { m.CurrentSpeed = 255 } err = m.Speed(m.CurrentSpeed) } return }
[ "func", "(", "m", "*", "MotorDriver", ")", "On", "(", ")", "(", "err", "error", ")", "{", "if", "m", ".", "isDigital", "(", ")", "{", "err", "=", "m", ".", "changeState", "(", "1", ")", "\n", "}", "else", "{", "if", "m", ".", "CurrentSpeed", "==", "0", "{", "m", ".", "CurrentSpeed", "=", "255", "\n", "}", "\n", "err", "=", "m", ".", "Speed", "(", "m", ".", "CurrentSpeed", ")", "\n", "}", "\n", "return", "\n", "}" ]
// On turns the motor on or sets the motor to a maximum speed
[ "On", "turns", "the", "motor", "on", "or", "sets", "the", "motor", "to", "a", "maximum", "speed" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/motor_driver.go#L61-L71
train
hybridgroup/gobot
drivers/gpio/motor_driver.go
IsOn
func (m *MotorDriver) IsOn() bool { if m.isDigital() { return m.CurrentState == 1 } return m.CurrentSpeed > 0 }
go
func (m *MotorDriver) IsOn() bool { if m.isDigital() { return m.CurrentState == 1 } return m.CurrentSpeed > 0 }
[ "func", "(", "m", "*", "MotorDriver", ")", "IsOn", "(", ")", "bool", "{", "if", "m", ".", "isDigital", "(", ")", "{", "return", "m", ".", "CurrentState", "==", "1", "\n", "}", "\n", "return", "m", ".", "CurrentSpeed", ">", "0", "\n", "}" ]
// IsOn returns true if the motor is on
[ "IsOn", "returns", "true", "if", "the", "motor", "is", "on" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/motor_driver.go#L84-L89
train
hybridgroup/gobot
drivers/gpio/motor_driver.go
Toggle
func (m *MotorDriver) Toggle() (err error) { if m.IsOn() { err = m.Off() } else { err = m.On() } return }
go
func (m *MotorDriver) Toggle() (err error) { if m.IsOn() { err = m.Off() } else { err = m.On() } return }
[ "func", "(", "m", "*", "MotorDriver", ")", "Toggle", "(", ")", "(", "err", "error", ")", "{", "if", "m", ".", "IsOn", "(", ")", "{", "err", "=", "m", ".", "Off", "(", ")", "\n", "}", "else", "{", "err", "=", "m", ".", "On", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Toggle sets the motor to the opposite of it's current state
[ "Toggle", "sets", "the", "motor", "to", "the", "opposite", "of", "it", "s", "current", "state" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/motor_driver.go#L97-L104
train
hybridgroup/gobot
drivers/gpio/motor_driver.go
Speed
func (m *MotorDriver) Speed(value byte) (err error) { if writer, ok := m.connection.(PwmWriter); ok { m.CurrentMode = "analog" m.CurrentSpeed = value return writer.PwmWrite(m.SpeedPin, value) } return ErrPwmWriteUnsupported }
go
func (m *MotorDriver) Speed(value byte) (err error) { if writer, ok := m.connection.(PwmWriter); ok { m.CurrentMode = "analog" m.CurrentSpeed = value return writer.PwmWrite(m.SpeedPin, value) } return ErrPwmWriteUnsupported }
[ "func", "(", "m", "*", "MotorDriver", ")", "Speed", "(", "value", "byte", ")", "(", "err", "error", ")", "{", "if", "writer", ",", "ok", ":=", "m", ".", "connection", ".", "(", "PwmWriter", ")", ";", "ok", "{", "m", ".", "CurrentMode", "=", "\"", "\"", "\n", "m", ".", "CurrentSpeed", "=", "value", "\n", "return", "writer", ".", "PwmWrite", "(", "m", ".", "SpeedPin", ",", "value", ")", "\n", "}", "\n", "return", "ErrPwmWriteUnsupported", "\n", "}" ]
// Speed sets the speed of the motor
[ "Speed", "sets", "the", "speed", "of", "the", "motor" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/motor_driver.go#L107-L114
train
hybridgroup/gobot
drivers/gpio/motor_driver.go
Forward
func (m *MotorDriver) Forward(speed byte) (err error) { err = m.Direction("forward") if err != nil { return } err = m.Speed(speed) if err != nil { return } return }
go
func (m *MotorDriver) Forward(speed byte) (err error) { err = m.Direction("forward") if err != nil { return } err = m.Speed(speed) if err != nil { return } return }
[ "func", "(", "m", "*", "MotorDriver", ")", "Forward", "(", "speed", "byte", ")", "(", "err", "error", ")", "{", "err", "=", "m", ".", "Direction", "(", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "err", "=", "m", ".", "Speed", "(", "speed", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "return", "\n", "}" ]
// Forward sets the forward pin to the specified speed
[ "Forward", "sets", "the", "forward", "pin", "to", "the", "specified", "speed" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/motor_driver.go#L117-L127
train
hybridgroup/gobot
drivers/gpio/motor_driver.go
Direction
func (m *MotorDriver) Direction(direction string) (err error) { m.CurrentDirection = direction if m.DirectionPin != "" { var level byte if direction == "forward" { level = 1 } else { level = 0 } err = m.connection.DigitalWrite(m.DirectionPin, level) } else { var forwardLevel, backwardLevel byte switch direction { case "forward": forwardLevel = 1 backwardLevel = 0 case "backward": forwardLevel = 0 backwardLevel = 1 case "none": forwardLevel = 0 backwardLevel = 0 } err = m.connection.DigitalWrite(m.ForwardPin, forwardLevel) if err != nil { return } err = m.connection.DigitalWrite(m.BackwardPin, backwardLevel) if err != nil { return } } return }
go
func (m *MotorDriver) Direction(direction string) (err error) { m.CurrentDirection = direction if m.DirectionPin != "" { var level byte if direction == "forward" { level = 1 } else { level = 0 } err = m.connection.DigitalWrite(m.DirectionPin, level) } else { var forwardLevel, backwardLevel byte switch direction { case "forward": forwardLevel = 1 backwardLevel = 0 case "backward": forwardLevel = 0 backwardLevel = 1 case "none": forwardLevel = 0 backwardLevel = 0 } err = m.connection.DigitalWrite(m.ForwardPin, forwardLevel) if err != nil { return } err = m.connection.DigitalWrite(m.BackwardPin, backwardLevel) if err != nil { return } } return }
[ "func", "(", "m", "*", "MotorDriver", ")", "Direction", "(", "direction", "string", ")", "(", "err", "error", ")", "{", "m", ".", "CurrentDirection", "=", "direction", "\n", "if", "m", ".", "DirectionPin", "!=", "\"", "\"", "{", "var", "level", "byte", "\n", "if", "direction", "==", "\"", "\"", "{", "level", "=", "1", "\n", "}", "else", "{", "level", "=", "0", "\n", "}", "\n", "err", "=", "m", ".", "connection", ".", "DigitalWrite", "(", "m", ".", "DirectionPin", ",", "level", ")", "\n", "}", "else", "{", "var", "forwardLevel", ",", "backwardLevel", "byte", "\n", "switch", "direction", "{", "case", "\"", "\"", ":", "forwardLevel", "=", "1", "\n", "backwardLevel", "=", "0", "\n", "case", "\"", "\"", ":", "forwardLevel", "=", "0", "\n", "backwardLevel", "=", "1", "\n", "case", "\"", "\"", ":", "forwardLevel", "=", "0", "\n", "backwardLevel", "=", "0", "\n", "}", "\n", "err", "=", "m", ".", "connection", ".", "DigitalWrite", "(", "m", ".", "ForwardPin", ",", "forwardLevel", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "err", "=", "m", ".", "connection", ".", "DigitalWrite", "(", "m", ".", "BackwardPin", ",", "backwardLevel", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Direction sets the direction pin to the specified speed
[ "Direction", "sets", "the", "direction", "pin", "to", "the", "specified", "speed" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/motor_driver.go#L143-L176
train
hybridgroup/gobot
drivers/i2c/bh1750_driver.go
Start
func (h *BH1750Driver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) address := h.GetAddressOrDefault(bh1750Address) h.connection, err = h.connector.GetConnection(address, bus) if err != nil { return err } err = h.connection.WriteByte(h.mode) time.Sleep(10 * time.Microsecond) if err != nil { return err } return }
go
func (h *BH1750Driver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) address := h.GetAddressOrDefault(bh1750Address) h.connection, err = h.connector.GetConnection(address, bus) if err != nil { return err } err = h.connection.WriteByte(h.mode) time.Sleep(10 * time.Microsecond) if err != nil { return err } return }
[ "func", "(", "h", "*", "BH1750Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "h", ".", "GetBusOrDefault", "(", "h", ".", "connector", ".", "GetDefaultBus", "(", ")", ")", "\n", "address", ":=", "h", ".", "GetAddressOrDefault", "(", "bh1750Address", ")", "\n\n", "h", ".", "connection", ",", "err", "=", "h", ".", "connector", ".", "GetConnection", "(", "address", ",", "bus", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "h", ".", "connection", ".", "WriteByte", "(", "h", ".", "mode", ")", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Microsecond", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "\n", "}" ]
// Start initialized the bh1750
[ "Start", "initialized", "the", "bh1750" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bh1750_driver.go#L68-L84
train
hybridgroup/gobot
drivers/i2c/bh1750_driver.go
RawSensorData
func (h *BH1750Driver) RawSensorData() (level int, err error) { buf := []byte{0, 0} bytesRead, err := h.connection.Read(buf) if bytesRead != 2 { err = errors.New("wrong number of bytes read") return } if err != nil { return } level = int(buf[0])<<8 | int(buf[1]) return }
go
func (h *BH1750Driver) RawSensorData() (level int, err error) { buf := []byte{0, 0} bytesRead, err := h.connection.Read(buf) if bytesRead != 2 { err = errors.New("wrong number of bytes read") return } if err != nil { return } level = int(buf[0])<<8 | int(buf[1]) return }
[ "func", "(", "h", "*", "BH1750Driver", ")", "RawSensorData", "(", ")", "(", "level", "int", ",", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0", ",", "0", "}", "\n", "bytesRead", ",", "err", ":=", "h", ".", "connection", ".", "Read", "(", "buf", ")", "\n", "if", "bytesRead", "!=", "2", "{", "err", "=", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "level", "=", "int", "(", "buf", "[", "0", "]", ")", "<<", "8", "|", "int", "(", "buf", "[", "1", "]", ")", "\n\n", "return", "\n", "}" ]
// RawSensorData returns the raw value from the bh1750
[ "RawSensorData", "returns", "the", "raw", "value", "from", "the", "bh1750" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bh1750_driver.go#L90-L104
train
hybridgroup/gobot
drivers/i2c/bh1750_driver.go
Lux
func (h *BH1750Driver) Lux() (lux int, err error) { lux, err = h.RawSensorData() lux = int(float64(lux) / 1.2) return }
go
func (h *BH1750Driver) Lux() (lux int, err error) { lux, err = h.RawSensorData() lux = int(float64(lux) / 1.2) return }
[ "func", "(", "h", "*", "BH1750Driver", ")", "Lux", "(", ")", "(", "lux", "int", ",", "err", "error", ")", "{", "lux", ",", "err", "=", "h", ".", "RawSensorData", "(", ")", "\n", "lux", "=", "int", "(", "float64", "(", "lux", ")", "/", "1.2", ")", "\n\n", "return", "\n", "}" ]
// Lux returns the adjusted value from the bh1750
[ "Lux", "returns", "the", "adjusted", "value", "from", "the", "bh1750" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bh1750_driver.go#L107-L113
train
hybridgroup/gobot
platforms/intel-iot/edison/edison_adaptor.go
NewAdaptor
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Edison"), pinmap: arduinoPinMap, writeFile: writeFile, readFile: readFile, mutex: &sync.Mutex{}, } }
go
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Edison"), pinmap: arduinoPinMap, writeFile: writeFile, readFile: readFile, mutex: &sync.Mutex{}, } }
[ "func", "NewAdaptor", "(", ")", "*", "Adaptor", "{", "return", "&", "Adaptor", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "pinmap", ":", "arduinoPinMap", ",", "writeFile", ":", "writeFile", ",", "readFile", ":", "readFile", ",", "mutex", ":", "&", "sync", ".", "Mutex", "{", "}", ",", "}", "\n", "}" ]
// NewAdaptor returns a new Edison Adaptor
[ "NewAdaptor", "returns", "a", "new", "Edison", "Adaptor" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/edison/edison_adaptor.go#L45-L53
train
hybridgroup/gobot
platforms/intel-iot/edison/edison_adaptor.go
Connect
func (e *Adaptor) Connect() (err error) { e.digitalPins = make(map[int]*sysfs.DigitalPin) e.pwmPins = make(map[int]*sysfs.PWMPin) if e.Board() == "arduino" || e.Board() == "" { aerr := e.checkForArduino() if aerr != nil { return aerr } e.board = "arduino" } switch e.Board() { case "sparkfun": e.pinmap = sparkfunPinMap e.sparkfunSetup() case "arduino": e.pinmap = arduinoPinMap if errs := e.arduinoSetup(); errs != nil { err = multierror.Append(err, errs) } case "miniboard": e.pinmap = miniboardPinMap e.miniboardSetup() default: errs := errors.New("Unknown board type: " + e.Board()) err = multierror.Append(err, errs) } return }
go
func (e *Adaptor) Connect() (err error) { e.digitalPins = make(map[int]*sysfs.DigitalPin) e.pwmPins = make(map[int]*sysfs.PWMPin) if e.Board() == "arduino" || e.Board() == "" { aerr := e.checkForArduino() if aerr != nil { return aerr } e.board = "arduino" } switch e.Board() { case "sparkfun": e.pinmap = sparkfunPinMap e.sparkfunSetup() case "arduino": e.pinmap = arduinoPinMap if errs := e.arduinoSetup(); errs != nil { err = multierror.Append(err, errs) } case "miniboard": e.pinmap = miniboardPinMap e.miniboardSetup() default: errs := errors.New("Unknown board type: " + e.Board()) err = multierror.Append(err, errs) } return }
[ "func", "(", "e", "*", "Adaptor", ")", "Connect", "(", ")", "(", "err", "error", ")", "{", "e", ".", "digitalPins", "=", "make", "(", "map", "[", "int", "]", "*", "sysfs", ".", "DigitalPin", ")", "\n", "e", ".", "pwmPins", "=", "make", "(", "map", "[", "int", "]", "*", "sysfs", ".", "PWMPin", ")", "\n\n", "if", "e", ".", "Board", "(", ")", "==", "\"", "\"", "||", "e", ".", "Board", "(", ")", "==", "\"", "\"", "{", "aerr", ":=", "e", ".", "checkForArduino", "(", ")", "\n", "if", "aerr", "!=", "nil", "{", "return", "aerr", "\n", "}", "\n", "e", ".", "board", "=", "\"", "\"", "\n", "}", "\n\n", "switch", "e", ".", "Board", "(", ")", "{", "case", "\"", "\"", ":", "e", ".", "pinmap", "=", "sparkfunPinMap", "\n", "e", ".", "sparkfunSetup", "(", ")", "\n", "case", "\"", "\"", ":", "e", ".", "pinmap", "=", "arduinoPinMap", "\n", "if", "errs", ":=", "e", ".", "arduinoSetup", "(", ")", ";", "errs", "!=", "nil", "{", "err", "=", "multierror", ".", "Append", "(", "err", ",", "errs", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "e", ".", "pinmap", "=", "miniboardPinMap", "\n", "e", ".", "miniboardSetup", "(", ")", "\n", "default", ":", "errs", ":=", "errors", ".", "New", "(", "\"", "\"", "+", "e", ".", "Board", "(", ")", ")", "\n", "err", "=", "multierror", ".", "Append", "(", "err", ",", "errs", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Connect initializes the Edison for use with the Arduino beakout board
[ "Connect", "initializes", "the", "Edison", "for", "use", "with", "the", "Arduino", "beakout", "board" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/edison/edison_adaptor.go#L68-L97
train
hybridgroup/gobot
platforms/intel-iot/edison/edison_adaptor.go
DigitalPin
func (e *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) { e.mutex.Lock() defer e.mutex.Unlock() i := e.pinmap[pin] if e.digitalPins[i.pin] == nil { e.digitalPins[i.pin], err = e.newExportedPin(i.pin) if err != nil { return } if i.resistor > 0 { e.digitalPins[i.resistor], err = e.newExportedPin(i.resistor) if err != nil { return } } if i.levelShifter > 0 { e.digitalPins[i.levelShifter], err = e.newExportedPin(i.levelShifter) if err != nil { return } } if len(i.mux) > 0 { for _, mux := range i.mux { e.digitalPins[mux.pin], err = e.newExportedPin(mux.pin) if err != nil { return } err = pinWrite(e.digitalPins[mux.pin], sysfs.OUT, mux.value) if err != nil { return } } } } if dir == "in" { if err = e.digitalPins[i.pin].Direction(sysfs.IN); err != nil { return } if i.resistor > 0 { err = pinWrite(e.digitalPins[i.resistor], sysfs.OUT, sysfs.LOW) if err != nil { return } } if i.levelShifter > 0 { err = pinWrite(e.digitalPins[i.levelShifter], sysfs.OUT, sysfs.LOW) if err != nil { return } } } else if dir == "out" { if err = e.digitalPins[i.pin].Direction(sysfs.OUT); err != nil { return } if i.resistor > 0 { if err = e.digitalPins[i.resistor].Direction(sysfs.IN); err != nil { return } } if i.levelShifter > 0 { err = pinWrite(e.digitalPins[i.levelShifter], sysfs.OUT, sysfs.HIGH) if err != nil { return } } } return e.digitalPins[i.pin], nil }
go
func (e *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) { e.mutex.Lock() defer e.mutex.Unlock() i := e.pinmap[pin] if e.digitalPins[i.pin] == nil { e.digitalPins[i.pin], err = e.newExportedPin(i.pin) if err != nil { return } if i.resistor > 0 { e.digitalPins[i.resistor], err = e.newExportedPin(i.resistor) if err != nil { return } } if i.levelShifter > 0 { e.digitalPins[i.levelShifter], err = e.newExportedPin(i.levelShifter) if err != nil { return } } if len(i.mux) > 0 { for _, mux := range i.mux { e.digitalPins[mux.pin], err = e.newExportedPin(mux.pin) if err != nil { return } err = pinWrite(e.digitalPins[mux.pin], sysfs.OUT, mux.value) if err != nil { return } } } } if dir == "in" { if err = e.digitalPins[i.pin].Direction(sysfs.IN); err != nil { return } if i.resistor > 0 { err = pinWrite(e.digitalPins[i.resistor], sysfs.OUT, sysfs.LOW) if err != nil { return } } if i.levelShifter > 0 { err = pinWrite(e.digitalPins[i.levelShifter], sysfs.OUT, sysfs.LOW) if err != nil { return } } } else if dir == "out" { if err = e.digitalPins[i.pin].Direction(sysfs.OUT); err != nil { return } if i.resistor > 0 { if err = e.digitalPins[i.resistor].Direction(sysfs.IN); err != nil { return } } if i.levelShifter > 0 { err = pinWrite(e.digitalPins[i.levelShifter], sysfs.OUT, sysfs.HIGH) if err != nil { return } } } return e.digitalPins[i.pin], nil }
[ "func", "(", "e", "*", "Adaptor", ")", "DigitalPin", "(", "pin", "string", ",", "dir", "string", ")", "(", "sysfsPin", "sysfs", ".", "DigitalPinner", ",", "err", "error", ")", "{", "e", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "mutex", ".", "Unlock", "(", ")", "\n\n", "i", ":=", "e", ".", "pinmap", "[", "pin", "]", "\n", "if", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", "==", "nil", "{", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", ",", "err", "=", "e", ".", "newExportedPin", "(", "i", ".", "pin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "i", ".", "resistor", ">", "0", "{", "e", ".", "digitalPins", "[", "i", ".", "resistor", "]", ",", "err", "=", "e", ".", "newExportedPin", "(", "i", ".", "resistor", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n\n", "if", "i", ".", "levelShifter", ">", "0", "{", "e", ".", "digitalPins", "[", "i", ".", "levelShifter", "]", ",", "err", "=", "e", ".", "newExportedPin", "(", "i", ".", "levelShifter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "i", ".", "mux", ")", ">", "0", "{", "for", "_", ",", "mux", ":=", "range", "i", ".", "mux", "{", "e", ".", "digitalPins", "[", "mux", ".", "pin", "]", ",", "err", "=", "e", ".", "newExportedPin", "(", "mux", ".", "pin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "err", "=", "pinWrite", "(", "e", ".", "digitalPins", "[", "mux", ".", "pin", "]", ",", "sysfs", ".", "OUT", ",", "mux", ".", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "dir", "==", "\"", "\"", "{", "if", "err", "=", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", ".", "Direction", "(", "sysfs", ".", "IN", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "i", ".", "resistor", ">", "0", "{", "err", "=", "pinWrite", "(", "e", ".", "digitalPins", "[", "i", ".", "resistor", "]", ",", "sysfs", ".", "OUT", ",", "sysfs", ".", "LOW", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n\n", "if", "i", ".", "levelShifter", ">", "0", "{", "err", "=", "pinWrite", "(", "e", ".", "digitalPins", "[", "i", ".", "levelShifter", "]", ",", "sysfs", ".", "OUT", ",", "sysfs", ".", "LOW", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "}", "else", "if", "dir", "==", "\"", "\"", "{", "if", "err", "=", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", ".", "Direction", "(", "sysfs", ".", "OUT", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "if", "i", ".", "resistor", ">", "0", "{", "if", "err", "=", "e", ".", "digitalPins", "[", "i", ".", "resistor", "]", ".", "Direction", "(", "sysfs", ".", "IN", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n\n", "if", "i", ".", "levelShifter", ">", "0", "{", "err", "=", "pinWrite", "(", "e", ".", "digitalPins", "[", "i", ".", "levelShifter", "]", ",", "sysfs", ".", "OUT", ",", "sysfs", ".", "HIGH", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "e", ".", "digitalPins", "[", "i", ".", "pin", "]", ",", "nil", "\n", "}" ]
// DigitalPin returns matched sysfs.DigitalPin for specified values
[ "DigitalPin", "returns", "matched", "sysfs", ".", "DigitalPin", "for", "specified", "values" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/edison/edison_adaptor.go#L204-L281
train
hybridgroup/gobot
platforms/intel-iot/edison/edison_adaptor.go
arduinoSetup
func (e *Adaptor) arduinoSetup() (err error) { if err = e.exportTristatePin(); err != nil { return err } err = pinWrite(e.tristate, sysfs.OUT, sysfs.LOW) if err != nil { return } for _, i := range []int{263, 262} { if err = e.newDigitalPin(i, sysfs.HIGH); err != nil { return err } } for _, i := range []int{240, 241, 242, 243} { if err = e.newDigitalPin(i, sysfs.LOW); err != nil { return err } } for _, i := range []string{"111", "115", "114", "109"} { if err = changePinMode(e, i, "1"); err != nil { return err } } for _, i := range []string{"131", "129", "40"} { if err = changePinMode(e, i, "0"); err != nil { return err } } err = e.tristate.Write(sysfs.HIGH) return }
go
func (e *Adaptor) arduinoSetup() (err error) { if err = e.exportTristatePin(); err != nil { return err } err = pinWrite(e.tristate, sysfs.OUT, sysfs.LOW) if err != nil { return } for _, i := range []int{263, 262} { if err = e.newDigitalPin(i, sysfs.HIGH); err != nil { return err } } for _, i := range []int{240, 241, 242, 243} { if err = e.newDigitalPin(i, sysfs.LOW); err != nil { return err } } for _, i := range []string{"111", "115", "114", "109"} { if err = changePinMode(e, i, "1"); err != nil { return err } } for _, i := range []string{"131", "129", "40"} { if err = changePinMode(e, i, "0"); err != nil { return err } } err = e.tristate.Write(sysfs.HIGH) return }
[ "func", "(", "e", "*", "Adaptor", ")", "arduinoSetup", "(", ")", "(", "err", "error", ")", "{", "if", "err", "=", "e", ".", "exportTristatePin", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "err", "=", "pinWrite", "(", "e", ".", "tristate", ",", "sysfs", ".", "OUT", ",", "sysfs", ".", "LOW", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "for", "_", ",", "i", ":=", "range", "[", "]", "int", "{", "263", ",", "262", "}", "{", "if", "err", "=", "e", ".", "newDigitalPin", "(", "i", ",", "sysfs", ".", "HIGH", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "i", ":=", "range", "[", "]", "int", "{", "240", ",", "241", ",", "242", ",", "243", "}", "{", "if", "err", "=", "e", ".", "newDigitalPin", "(", "i", ",", "sysfs", ".", "LOW", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "i", ":=", "range", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "{", "if", "err", "=", "changePinMode", "(", "e", ",", "i", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "i", ":=", "range", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", "}", "{", "if", "err", "=", "changePinMode", "(", "e", ",", "i", ",", "\"", "\"", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "err", "=", "e", ".", "tristate", ".", "Write", "(", "sysfs", ".", "HIGH", ")", "\n", "return", "\n", "}" ]
// arduinoSetup does needed setup for the Arduino compatible breakout board
[ "arduinoSetup", "does", "needed", "setup", "for", "the", "Arduino", "compatible", "breakout", "board" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/edison/edison_adaptor.go#L334-L370
train
hybridgroup/gobot
platforms/intel-iot/edison/edison_adaptor.go
changePinMode
func changePinMode(a *Adaptor, pin, mode string) (err error) { _, err = a.writeFile( "/sys/kernel/debug/gpio_debug/gpio"+pin+"/current_pinmux", []byte("mode"+mode), ) return }
go
func changePinMode(a *Adaptor, pin, mode string) (err error) { _, err = a.writeFile( "/sys/kernel/debug/gpio_debug/gpio"+pin+"/current_pinmux", []byte("mode"+mode), ) return }
[ "func", "changePinMode", "(", "a", "*", "Adaptor", ",", "pin", ",", "mode", "string", ")", "(", "err", "error", ")", "{", "_", ",", "err", "=", "a", ".", "writeFile", "(", "\"", "\"", "+", "pin", "+", "\"", "\"", ",", "[", "]", "byte", "(", "\"", "\"", "+", "mode", ")", ",", ")", "\n", "return", "\n", "}" ]
// changePinMode writes pin mode to current_pinmux file
[ "changePinMode", "writes", "pin", "mode", "to", "current_pinmux", "file" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/edison/edison_adaptor.go#L460-L466
train
hybridgroup/gobot
platforms/intel-iot/edison/edison_adaptor.go
pinWrite
func pinWrite(pin *sysfs.DigitalPin, dir string, level int) (err error) { if err = pin.Direction(dir); err != nil { return } err = pin.Write(level) return }
go
func pinWrite(pin *sysfs.DigitalPin, dir string, level int) (err error) { if err = pin.Direction(dir); err != nil { return } err = pin.Write(level) return }
[ "func", "pinWrite", "(", "pin", "*", "sysfs", ".", "DigitalPin", ",", "dir", "string", ",", "level", "int", ")", "(", "err", "error", ")", "{", "if", "err", "=", "pin", ".", "Direction", "(", "dir", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "err", "=", "pin", ".", "Write", "(", "level", ")", "\n", "return", "\n", "}" ]
// pinWrite sets Direction and writes level for a specific pin
[ "pinWrite", "sets", "Direction", "and", "writes", "level", "for", "a", "specific", "pin" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/intel-iot/edison/edison_adaptor.go#L469-L476
train
hybridgroup/gobot
drivers/spi/apa102.go
SetRGBA
func (d *APA102Driver) SetRGBA(i int, v color.RGBA) { d.vals[i] = v }
go
func (d *APA102Driver) SetRGBA(i int, v color.RGBA) { d.vals[i] = v }
[ "func", "(", "d", "*", "APA102Driver", ")", "SetRGBA", "(", "i", "int", ",", "v", "color", ".", "RGBA", ")", "{", "d", ".", "vals", "[", "i", "]", "=", "v", "\n", "}" ]
// SetRGBA sets the ith LED's color to the given RGBA value. // A subsequent call to Draw is required to transmit values // to the LED strip.
[ "SetRGBA", "sets", "the", "ith", "LED", "s", "color", "to", "the", "given", "RGBA", "value", ".", "A", "subsequent", "call", "to", "Draw", "is", "required", "to", "transmit", "values", "to", "the", "LED", "strip", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/apa102.go#L79-L81
train
hybridgroup/gobot
drivers/spi/apa102.go
Draw
func (d *APA102Driver) Draw() error { // TODO(jbd): dotstar allows other RGBA alignments, support those layouts. n := len(d.vals) tx := make([]byte, 4*(n+1)+(n/2+1)) tx[0] = 0x00 tx[1] = 0x00 tx[2] = 0x00 tx[3] = 0x00 for i, c := range d.vals { j := (i + 1) * 4 tx[j] = 0xe0 + byte(c.R) tx[j+1] = byte(c.B) tx[j+2] = byte(c.G) tx[j+3] = byte(c.R) } // end frame with at least n/2 0xff vals for i := (n + 1) * 4; i < len(tx); i++ { tx[i] = 0xff } return d.connection.Tx(tx, nil) }
go
func (d *APA102Driver) Draw() error { // TODO(jbd): dotstar allows other RGBA alignments, support those layouts. n := len(d.vals) tx := make([]byte, 4*(n+1)+(n/2+1)) tx[0] = 0x00 tx[1] = 0x00 tx[2] = 0x00 tx[3] = 0x00 for i, c := range d.vals { j := (i + 1) * 4 tx[j] = 0xe0 + byte(c.R) tx[j+1] = byte(c.B) tx[j+2] = byte(c.G) tx[j+3] = byte(c.R) } // end frame with at least n/2 0xff vals for i := (n + 1) * 4; i < len(tx); i++ { tx[i] = 0xff } return d.connection.Tx(tx, nil) }
[ "func", "(", "d", "*", "APA102Driver", ")", "Draw", "(", ")", "error", "{", "// TODO(jbd): dotstar allows other RGBA alignments, support those layouts.", "n", ":=", "len", "(", "d", ".", "vals", ")", "\n\n", "tx", ":=", "make", "(", "[", "]", "byte", ",", "4", "*", "(", "n", "+", "1", ")", "+", "(", "n", "/", "2", "+", "1", ")", ")", "\n", "tx", "[", "0", "]", "=", "0x00", "\n", "tx", "[", "1", "]", "=", "0x00", "\n", "tx", "[", "2", "]", "=", "0x00", "\n", "tx", "[", "3", "]", "=", "0x00", "\n\n", "for", "i", ",", "c", ":=", "range", "d", ".", "vals", "{", "j", ":=", "(", "i", "+", "1", ")", "*", "4", "\n", "tx", "[", "j", "]", "=", "0xe0", "+", "byte", "(", "c", ".", "R", ")", "\n", "tx", "[", "j", "+", "1", "]", "=", "byte", "(", "c", ".", "B", ")", "\n", "tx", "[", "j", "+", "2", "]", "=", "byte", "(", "c", ".", "G", ")", "\n", "tx", "[", "j", "+", "3", "]", "=", "byte", "(", "c", ".", "R", ")", "\n", "}", "\n\n", "// end frame with at least n/2 0xff vals", "for", "i", ":=", "(", "n", "+", "1", ")", "*", "4", ";", "i", "<", "len", "(", "tx", ")", ";", "i", "++", "{", "tx", "[", "i", "]", "=", "0xff", "\n", "}", "\n\n", "return", "d", ".", "connection", ".", "Tx", "(", "tx", ",", "nil", ")", "\n", "}" ]
// Draw displays the RGBA values set on the actual LED strip.
[ "Draw", "displays", "the", "RGBA", "values", "set", "on", "the", "actual", "LED", "strip", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/apa102.go#L84-L108
train
hybridgroup/gobot
drivers/i2c/bmp280_driver.go
Start
func (d *BMP280Driver) Start() (err error) { bus := d.GetBusOrDefault(d.connector.GetDefaultBus()) address := d.GetAddressOrDefault(bmp180Address) if d.connection, err = d.connector.GetConnection(address, bus); err != nil { return err } if err := d.initialization(); err != nil { return err } return nil }
go
func (d *BMP280Driver) Start() (err error) { bus := d.GetBusOrDefault(d.connector.GetDefaultBus()) address := d.GetAddressOrDefault(bmp180Address) if d.connection, err = d.connector.GetConnection(address, bus); err != nil { return err } if err := d.initialization(); err != nil { return err } return nil }
[ "func", "(", "d", "*", "BMP280Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "d", ".", "GetBusOrDefault", "(", "d", ".", "connector", ".", "GetDefaultBus", "(", ")", ")", "\n", "address", ":=", "d", ".", "GetAddressOrDefault", "(", "bmp180Address", ")", "\n\n", "if", "d", ".", "connection", ",", "err", "=", "d", ".", "connector", ".", "GetConnection", "(", "address", ",", "bus", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "d", ".", "initialization", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Start initializes the BMP280 and loads the calibration coefficients.
[ "Start", "initializes", "the", "BMP280", "and", "loads", "the", "calibration", "coefficients", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bmp280_driver.go#L85-L98
train
hybridgroup/gobot
drivers/i2c/bmp280_driver.go
Pressure
func (d *BMP280Driver) Pressure() (press float32, err error) { var rawT, rawP int32 if rawT, err = d.rawTemp(); err != nil { return 0.0, err } if rawP, err = d.rawPressure(); err != nil { return 0.0, err } _, tFine := d.calculateTemp(rawT) return d.calculatePress(rawP, tFine), nil }
go
func (d *BMP280Driver) Pressure() (press float32, err error) { var rawT, rawP int32 if rawT, err = d.rawTemp(); err != nil { return 0.0, err } if rawP, err = d.rawPressure(); err != nil { return 0.0, err } _, tFine := d.calculateTemp(rawT) return d.calculatePress(rawP, tFine), nil }
[ "func", "(", "d", "*", "BMP280Driver", ")", "Pressure", "(", ")", "(", "press", "float32", ",", "err", "error", ")", "{", "var", "rawT", ",", "rawP", "int32", "\n", "if", "rawT", ",", "err", "=", "d", ".", "rawTemp", "(", ")", ";", "err", "!=", "nil", "{", "return", "0.0", ",", "err", "\n", "}", "\n\n", "if", "rawP", ",", "err", "=", "d", ".", "rawPressure", "(", ")", ";", "err", "!=", "nil", "{", "return", "0.0", ",", "err", "\n", "}", "\n", "_", ",", "tFine", ":=", "d", ".", "calculateTemp", "(", "rawT", ")", "\n", "return", "d", ".", "calculatePress", "(", "rawP", ",", "tFine", ")", ",", "nil", "\n", "}" ]
// Pressure returns the current barometric pressure, in Pa
[ "Pressure", "returns", "the", "current", "barometric", "pressure", "in", "Pa" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bmp280_driver.go#L116-L127
train
hybridgroup/gobot
drivers/i2c/bmp280_driver.go
initialization
func (d *BMP280Driver) initialization() (err error) { var coefficients []byte if coefficients, err = d.read(bmp280RegisterCalib00, 24); err != nil { return err } buf := bytes.NewBuffer(coefficients) binary.Read(buf, binary.LittleEndian, &d.tpc.t1) binary.Read(buf, binary.LittleEndian, &d.tpc.t2) binary.Read(buf, binary.LittleEndian, &d.tpc.t3) binary.Read(buf, binary.LittleEndian, &d.tpc.p1) binary.Read(buf, binary.LittleEndian, &d.tpc.p2) binary.Read(buf, binary.LittleEndian, &d.tpc.p3) binary.Read(buf, binary.LittleEndian, &d.tpc.p4) binary.Read(buf, binary.LittleEndian, &d.tpc.p5) binary.Read(buf, binary.LittleEndian, &d.tpc.p6) binary.Read(buf, binary.LittleEndian, &d.tpc.p7) binary.Read(buf, binary.LittleEndian, &d.tpc.p8) binary.Read(buf, binary.LittleEndian, &d.tpc.p9) d.connection.WriteByteData(bmp280RegisterControl, 0x3F) return nil }
go
func (d *BMP280Driver) initialization() (err error) { var coefficients []byte if coefficients, err = d.read(bmp280RegisterCalib00, 24); err != nil { return err } buf := bytes.NewBuffer(coefficients) binary.Read(buf, binary.LittleEndian, &d.tpc.t1) binary.Read(buf, binary.LittleEndian, &d.tpc.t2) binary.Read(buf, binary.LittleEndian, &d.tpc.t3) binary.Read(buf, binary.LittleEndian, &d.tpc.p1) binary.Read(buf, binary.LittleEndian, &d.tpc.p2) binary.Read(buf, binary.LittleEndian, &d.tpc.p3) binary.Read(buf, binary.LittleEndian, &d.tpc.p4) binary.Read(buf, binary.LittleEndian, &d.tpc.p5) binary.Read(buf, binary.LittleEndian, &d.tpc.p6) binary.Read(buf, binary.LittleEndian, &d.tpc.p7) binary.Read(buf, binary.LittleEndian, &d.tpc.p8) binary.Read(buf, binary.LittleEndian, &d.tpc.p9) d.connection.WriteByteData(bmp280RegisterControl, 0x3F) return nil }
[ "func", "(", "d", "*", "BMP280Driver", ")", "initialization", "(", ")", "(", "err", "error", ")", "{", "var", "coefficients", "[", "]", "byte", "\n", "if", "coefficients", ",", "err", "=", "d", ".", "read", "(", "bmp280RegisterCalib00", ",", "24", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "coefficients", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "t1", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "t2", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "t3", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p1", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p2", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p3", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p4", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p5", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p6", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p7", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p8", ")", "\n", "binary", ".", "Read", "(", "buf", ",", "binary", ".", "LittleEndian", ",", "&", "d", ".", "tpc", ".", "p9", ")", "\n\n", "d", ".", "connection", ".", "WriteByteData", "(", "bmp280RegisterControl", ",", "0x3F", ")", "\n\n", "return", "nil", "\n", "}" ]
// initialization reads the calibration coefficients.
[ "initialization", "reads", "the", "calibration", "coefficients", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/bmp280_driver.go#L142-L164
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
Set
func (s *DisplayBuffer) Set(x, y, c int) { idx := x + (y/ssd1306PageSize)*s.Width bit := uint(y) % ssd1306PageSize if c == 0 { s.buffer[idx] &= ^(1 << bit) } else { s.buffer[idx] |= (1 << bit) } }
go
func (s *DisplayBuffer) Set(x, y, c int) { idx := x + (y/ssd1306PageSize)*s.Width bit := uint(y) % ssd1306PageSize if c == 0 { s.buffer[idx] &= ^(1 << bit) } else { s.buffer[idx] |= (1 << bit) } }
[ "func", "(", "s", "*", "DisplayBuffer", ")", "Set", "(", "x", ",", "y", ",", "c", "int", ")", "{", "idx", ":=", "x", "+", "(", "y", "/", "ssd1306PageSize", ")", "*", "s", ".", "Width", "\n", "bit", ":=", "uint", "(", "y", ")", "%", "ssd1306PageSize", "\n\n", "if", "c", "==", "0", "{", "s", ".", "buffer", "[", "idx", "]", "&=", "^", "(", "1", "<<", "bit", ")", "\n", "}", "else", "{", "s", ".", "buffer", "[", "idx", "]", "|=", "(", "1", "<<", "bit", ")", "\n", "}", "\n", "}" ]
// Set sets the x, y pixel with c color
[ "Set", "sets", "the", "x", "y", "pixel", "with", "c", "color" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L104-L113
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
WithDisplayWidth
func WithDisplayWidth(val int) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.DisplayWidth = val } else { // TODO: return error for trying to set DisplayWidth for non-SSD1306Driver return } } }
go
func WithDisplayWidth(val int) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.DisplayWidth = val } else { // TODO: return error for trying to set DisplayWidth for non-SSD1306Driver return } } }
[ "func", "WithDisplayWidth", "(", "val", "int", ")", "func", "(", "Config", ")", "{", "return", "func", "(", "c", "Config", ")", "{", "d", ",", "ok", ":=", "c", ".", "(", "*", "SSD1306Driver", ")", "\n", "if", "ok", "{", "d", ".", "DisplayWidth", "=", "val", "\n", "}", "else", "{", "// TODO: return error for trying to set DisplayWidth for non-SSD1306Driver", "return", "\n", "}", "\n", "}", "\n", "}" ]
// WithDisplayWidth option sets the SSD1306Driver DisplayWidth option.
[ "WithDisplayWidth", "option", "sets", "the", "SSD1306Driver", "DisplayWidth", "option", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L222-L232
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
WithDisplayHeight
func WithDisplayHeight(val int) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.DisplayHeight = val } else { // TODO: return error for trying to set DisplayHeight for non-SSD1306Driver return } } }
go
func WithDisplayHeight(val int) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.DisplayHeight = val } else { // TODO: return error for trying to set DisplayHeight for non-SSD1306Driver return } } }
[ "func", "WithDisplayHeight", "(", "val", "int", ")", "func", "(", "Config", ")", "{", "return", "func", "(", "c", "Config", ")", "{", "d", ",", "ok", ":=", "c", ".", "(", "*", "SSD1306Driver", ")", "\n", "if", "ok", "{", "d", ".", "DisplayHeight", "=", "val", "\n", "}", "else", "{", "// TODO: return error for trying to set DisplayHeight for non-SSD1306Driver", "return", "\n", "}", "\n", "}", "\n", "}" ]
// WithDisplayHeight option sets the SSD1306Driver DisplayHeight option.
[ "WithDisplayHeight", "option", "sets", "the", "SSD1306Driver", "DisplayHeight", "option", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L235-L245
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
Init
func (s *SSD1306Driver) Init() (err error) { s.Off() s.commands(ssd1306InitSequence) s.commands([]byte{ssd1306ColumnAddr, 0, // Start at 0, byte(s.Buffer.Width) - 1, // End at last column (127?) }) s.commands([]byte{ssd1306PageAddr, 0, // Start at 0, (byte(s.Buffer.Height) / ssd1306PageSize) - 1, // End at page 7 }) return nil }
go
func (s *SSD1306Driver) Init() (err error) { s.Off() s.commands(ssd1306InitSequence) s.commands([]byte{ssd1306ColumnAddr, 0, // Start at 0, byte(s.Buffer.Width) - 1, // End at last column (127?) }) s.commands([]byte{ssd1306PageAddr, 0, // Start at 0, (byte(s.Buffer.Height) / ssd1306PageSize) - 1, // End at page 7 }) return nil }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Init", "(", ")", "(", "err", "error", ")", "{", "s", ".", "Off", "(", ")", "\n", "s", ".", "commands", "(", "ssd1306InitSequence", ")", "\n\n", "s", ".", "commands", "(", "[", "]", "byte", "{", "ssd1306ColumnAddr", ",", "0", ",", "// Start at 0,", "byte", "(", "s", ".", "Buffer", ".", "Width", ")", "-", "1", ",", "// End at last column (127?)", "}", ")", "\n\n", "s", ".", "commands", "(", "[", "]", "byte", "{", "ssd1306PageAddr", ",", "0", ",", "// Start at 0,", "(", "byte", "(", "s", ".", "Buffer", ".", "Height", ")", "/", "ssd1306PageSize", ")", "-", "1", ",", "// End at page 7", "}", ")", "\n\n", "return", "nil", "\n", "}" ]
// Init turns display on
[ "Init", "turns", "display", "on" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L248-L261
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
Set
func (s *SSD1306Driver) Set(x, y, c int) { s.Buffer.Set(x, y, c) }
go
func (s *SSD1306Driver) Set(x, y, c int) { s.Buffer.Set(x, y, c) }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Set", "(", "x", ",", "y", ",", "c", "int", ")", "{", "s", ".", "Buffer", ".", "Set", "(", "x", ",", "y", ",", "c", ")", "\n", "}" ]
// Set sets a pixel
[ "Set", "sets", "a", "pixel" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L280-L282
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
Reset
func (s *SSD1306Driver) Reset() (err error) { s.Off() s.Clear() s.On() return nil }
go
func (s *SSD1306Driver) Reset() (err error) { s.Off() s.Clear() s.On() return nil }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Reset", "(", ")", "(", "err", "error", ")", "{", "s", ".", "Off", "(", ")", "\n", "s", ".", "Clear", "(", ")", "\n", "s", ".", "On", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Reset sends the memory buffer to the display
[ "Reset", "sends", "the", "memory", "buffer", "to", "the", "display" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L285-L290
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
SetContrast
func (s *SSD1306Driver) SetContrast(contrast byte) (err error) { err = s.commands([]byte{ssd1306SetContrast, contrast}) return }
go
func (s *SSD1306Driver) SetContrast(contrast byte) (err error) { err = s.commands([]byte{ssd1306SetContrast, contrast}) return }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "SetContrast", "(", "contrast", "byte", ")", "(", "err", "error", ")", "{", "err", "=", "s", ".", "commands", "(", "[", "]", "byte", "{", "ssd1306SetContrast", ",", "contrast", "}", ")", "\n", "return", "\n", "}" ]
// SetContrast sets the display contrast
[ "SetContrast", "sets", "the", "display", "contrast" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L293-L296
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
Display
func (s *SSD1306Driver) Display() (err error) { // Write the buffer _, err = s.connection.Write(append([]byte{0x40}, s.Buffer.buffer...)) return err }
go
func (s *SSD1306Driver) Display() (err error) { // Write the buffer _, err = s.connection.Write(append([]byte{0x40}, s.Buffer.buffer...)) return err }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Display", "(", ")", "(", "err", "error", ")", "{", "// Write the buffer", "_", ",", "err", "=", "s", ".", "connection", ".", "Write", "(", "append", "(", "[", "]", "byte", "{", "0x40", "}", ",", "s", ".", "Buffer", ".", "buffer", "...", ")", ")", "\n", "return", "err", "\n", "}" ]
// Display sends the memory buffer to the display
[ "Display", "sends", "the", "memory", "buffer", "to", "the", "display" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L299-L303
train
hybridgroup/gobot
drivers/i2c/ssd1306_driver.go
commands
func (s *SSD1306Driver) commands(commands []byte) (err error) { var command []byte for _, d := range commands { command = append(command, []byte{0x80, d}...) } _, err = s.connection.Write(command) return }
go
func (s *SSD1306Driver) commands(commands []byte) (err error) { var command []byte for _, d := range commands { command = append(command, []byte{0x80, d}...) } _, err = s.connection.Write(command) return }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "commands", "(", "commands", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "var", "command", "[", "]", "byte", "\n", "for", "_", ",", "d", ":=", "range", "commands", "{", "command", "=", "append", "(", "command", ",", "[", "]", "byte", "{", "0x80", ",", "d", "}", "...", ")", "\n", "}", "\n", "_", ",", "err", "=", "s", ".", "connection", ".", "Write", "(", "command", ")", "\n", "return", "\n", "}" ]
// commands sends a command sequence
[ "commands", "sends", "a", "command", "sequence" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ssd1306_driver.go#L330-L337
train
hybridgroup/gobot
platforms/firmata/ble_firmata_adaptor.go
NewBLEAdaptor
func NewBLEAdaptor(args ...interface{}) *BLEAdaptor { address := args[0].(string) rid := ReceiveID wid := TransmitID if len(args) >= 3 { rid = args[1].(string) wid = args[2].(string) } a := NewAdaptor(address) a.SetName(gobot.DefaultName("BLEFirmata")) a.PortOpener = func(port string) (io.ReadWriteCloser, error) { sp := ble.NewSerialPort(address, rid, wid) sp.Open() return sp, nil } return &BLEAdaptor{ Adaptor: a, } }
go
func NewBLEAdaptor(args ...interface{}) *BLEAdaptor { address := args[0].(string) rid := ReceiveID wid := TransmitID if len(args) >= 3 { rid = args[1].(string) wid = args[2].(string) } a := NewAdaptor(address) a.SetName(gobot.DefaultName("BLEFirmata")) a.PortOpener = func(port string) (io.ReadWriteCloser, error) { sp := ble.NewSerialPort(address, rid, wid) sp.Open() return sp, nil } return &BLEAdaptor{ Adaptor: a, } }
[ "func", "NewBLEAdaptor", "(", "args", "...", "interface", "{", "}", ")", "*", "BLEAdaptor", "{", "address", ":=", "args", "[", "0", "]", ".", "(", "string", ")", "\n", "rid", ":=", "ReceiveID", "\n", "wid", ":=", "TransmitID", "\n\n", "if", "len", "(", "args", ")", ">=", "3", "{", "rid", "=", "args", "[", "1", "]", ".", "(", "string", ")", "\n", "wid", "=", "args", "[", "2", "]", ".", "(", "string", ")", "\n", "}", "\n\n", "a", ":=", "NewAdaptor", "(", "address", ")", "\n", "a", ".", "SetName", "(", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ")", "\n", "a", ".", "PortOpener", "=", "func", "(", "port", "string", ")", "(", "io", ".", "ReadWriteCloser", ",", "error", ")", "{", "sp", ":=", "ble", ".", "NewSerialPort", "(", "address", ",", "rid", ",", "wid", ")", "\n", "sp", ".", "Open", "(", ")", "\n", "return", "sp", ",", "nil", "\n", "}", "\n\n", "return", "&", "BLEAdaptor", "{", "Adaptor", ":", "a", ",", "}", "\n", "}" ]
// NewBLEAdaptor opens and uses a BLE connection to a // microcontroller running FirmataBLE
[ "NewBLEAdaptor", "opens", "and", "uses", "a", "BLE", "connection", "to", "a", "microcontroller", "running", "FirmataBLE" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/ble_firmata_adaptor.go#L26-L47
train
hybridgroup/gobot
platforms/holystone/hs200/hs200_driver.go
NewDriver
func NewDriver(tcpaddress string, udpaddress string) *Driver { command := []byte{ 0xff, // 2 byte header 0x04, // Left joystick 0x7e, // throttle 0x00 - 0xff(?) 0x3f, // rotate left/right // Right joystick 0xc0, // forward / backward 0x80 - 0xfe(?) 0x3f, // left / right 0x00 - 0x7e(?) // Trim 0x90, // ? yaw (used as a setting to trim the yaw of the uav) 0x10, // ? pitch (used as a setting to trim the pitch of the uav) 0x10, // ? roll (used as a setting to trim the roll of the uav) 0x00, // flags/buttons 0x00, // checksum; 255 - ((sum of flight controls from index 1 to 9) % 256) } command[10] = checksum(command) return &Driver{name: gobot.DefaultName("HS200"), stopc: make(chan struct{}), tcpaddress: tcpaddress, udpaddress: udpaddress, cmd: command, mutex: &sync.RWMutex{}} }
go
func NewDriver(tcpaddress string, udpaddress string) *Driver { command := []byte{ 0xff, // 2 byte header 0x04, // Left joystick 0x7e, // throttle 0x00 - 0xff(?) 0x3f, // rotate left/right // Right joystick 0xc0, // forward / backward 0x80 - 0xfe(?) 0x3f, // left / right 0x00 - 0x7e(?) // Trim 0x90, // ? yaw (used as a setting to trim the yaw of the uav) 0x10, // ? pitch (used as a setting to trim the pitch of the uav) 0x10, // ? roll (used as a setting to trim the roll of the uav) 0x00, // flags/buttons 0x00, // checksum; 255 - ((sum of flight controls from index 1 to 9) % 256) } command[10] = checksum(command) return &Driver{name: gobot.DefaultName("HS200"), stopc: make(chan struct{}), tcpaddress: tcpaddress, udpaddress: udpaddress, cmd: command, mutex: &sync.RWMutex{}} }
[ "func", "NewDriver", "(", "tcpaddress", "string", ",", "udpaddress", "string", ")", "*", "Driver", "{", "command", ":=", "[", "]", "byte", "{", "0xff", ",", "// 2 byte header", "0x04", ",", "// Left joystick", "0x7e", ",", "// throttle 0x00 - 0xff(?)", "0x3f", ",", "// rotate left/right", "// Right joystick", "0xc0", ",", "// forward / backward 0x80 - 0xfe(?)", "0x3f", ",", "// left / right 0x00 - 0x7e(?)", "// Trim", "0x90", ",", "// ? yaw (used as a setting to trim the yaw of the uav)", "0x10", ",", "// ? pitch (used as a setting to trim the pitch of the uav)", "0x10", ",", "// ? roll (used as a setting to trim the roll of the uav)", "0x00", ",", "// flags/buttons", "0x00", ",", "// checksum; 255 - ((sum of flight controls from index 1 to 9) % 256)", "}", "\n", "command", "[", "10", "]", "=", "checksum", "(", "command", ")", "\n\n", "return", "&", "Driver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "stopc", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "tcpaddress", ":", "tcpaddress", ",", "udpaddress", ":", "udpaddress", ",", "cmd", ":", "command", ",", "mutex", ":", "&", "sync", ".", "RWMutex", "{", "}", "}", "\n", "}" ]
// NewDriver creates a driver for the HolyStone hs200
[ "NewDriver", "creates", "a", "driver", "for", "the", "HolyStone", "hs200" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/holystone/hs200/hs200_driver.go#L25-L50
train
hybridgroup/gobot
platforms/holystone/hs200/hs200_driver.go
Enable
func (d Driver) Enable() { d.mutex.Lock() defer d.mutex.Unlock() if !d.enabled { go d.flightLoop(d.stopc) d.enabled = true } }
go
func (d Driver) Enable() { d.mutex.Lock() defer d.mutex.Unlock() if !d.enabled { go d.flightLoop(d.stopc) d.enabled = true } }
[ "func", "(", "d", "Driver", ")", "Enable", "(", ")", "{", "d", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "!", "d", ".", "enabled", "{", "go", "d", ".", "flightLoop", "(", "d", ".", "stopc", ")", "\n", "d", ".", "enabled", "=", "true", "\n", "}", "\n", "}" ]
// Enable enables the drone to start flying.
[ "Enable", "enables", "the", "drone", "to", "start", "flying", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/holystone/hs200/hs200_driver.go#L123-L130
train
hybridgroup/gobot
platforms/holystone/hs200/hs200_driver.go
Disable
func (d Driver) Disable() { d.mutex.Lock() defer d.mutex.Unlock() if d.enabled { d.stopc <- struct{}{} } }
go
func (d Driver) Disable() { d.mutex.Lock() defer d.mutex.Unlock() if d.enabled { d.stopc <- struct{}{} } }
[ "func", "(", "d", "Driver", ")", "Disable", "(", ")", "{", "d", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "mutex", ".", "Unlock", "(", ")", "\n", "if", "d", ".", "enabled", "{", "d", ".", "stopc", "<-", "struct", "{", "}", "{", "}", "\n", "}", "\n", "}" ]
// Disable disables the drone from flying.
[ "Disable", "disables", "the", "drone", "from", "flying", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/holystone/hs200/hs200_driver.go#L133-L139
train
hybridgroup/gobot
platforms/holystone/hs200/hs200_driver.go
floatToCmdByte
func floatToCmdByte(cmd float32, mid byte, maxv byte) byte { if cmd > 1.0 { cmd = 1.0 } if cmd < -1.0 { cmd = -1.0 } cmd = cmd * float32(maxv) bval := byte(cmd + float32(mid) + 0.5) return bval }
go
func floatToCmdByte(cmd float32, mid byte, maxv byte) byte { if cmd > 1.0 { cmd = 1.0 } if cmd < -1.0 { cmd = -1.0 } cmd = cmd * float32(maxv) bval := byte(cmd + float32(mid) + 0.5) return bval }
[ "func", "floatToCmdByte", "(", "cmd", "float32", ",", "mid", "byte", ",", "maxv", "byte", ")", "byte", "{", "if", "cmd", ">", "1.0", "{", "cmd", "=", "1.0", "\n", "}", "\n", "if", "cmd", "<", "-", "1.0", "{", "cmd", "=", "-", "1.0", "\n", "}", "\n", "cmd", "=", "cmd", "*", "float32", "(", "maxv", ")", "\n", "bval", ":=", "byte", "(", "cmd", "+", "float32", "(", "mid", ")", "+", "0.5", ")", "\n", "return", "bval", "\n", "}" ]
// floatToCmdByte converts a float in the range of -1 to +1 to an integer command
[ "floatToCmdByte", "converts", "a", "float", "in", "the", "range", "of", "-", "1", "to", "+", "1", "to", "an", "integer", "command" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/holystone/hs200/hs200_driver.go#L168-L178
train
hybridgroup/gobot
platforms/firmata/client/client.go
Disconnect
func (b *Client) Disconnect() (err error) { b.setConnected(false) return b.connection.Close() }
go
func (b *Client) Disconnect() (err error) { b.setConnected(false) return b.connection.Close() }
[ "func", "(", "b", "*", "Client", ")", "Disconnect", "(", ")", "(", "err", "error", ")", "{", "b", ".", "setConnected", "(", "false", ")", "\n", "return", "b", ".", "connection", ".", "Close", "(", ")", "\n", "}" ]
// Disconnect disconnects the Client
[ "Disconnect", "disconnects", "the", "Client" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L134-L137
train
hybridgroup/gobot
platforms/firmata/client/client.go
Connect
func (b *Client) Connect(conn io.ReadWriteCloser) (err error) { if b.Connected() { return ErrConnected } b.connection = conn b.Reset() connected := make(chan bool, 1) connectError := make(chan error, 1) b.Once(b.Event("ProtocolVersion"), func(data interface{}) { e := b.FirmwareQuery() if e != nil { b.setConnecting(false) connectError <- e } }) b.Once(b.Event("FirmwareQuery"), func(data interface{}) { e := b.CapabilitiesQuery() if e != nil { b.setConnecting(false) connectError <- e } }) b.Once(b.Event("CapabilityQuery"), func(data interface{}) { e := b.AnalogMappingQuery() if e != nil { b.setConnecting(false) connectError <- e } }) b.Once(b.Event("AnalogMappingQuery"), func(data interface{}) { b.ReportDigital(0, 1) b.ReportDigital(1, 1) b.setConnecting(false) b.setConnected(true) connected <- true }) // start it off... b.setConnecting(true) b.ProtocolVersionQuery() go func() { for { if !b.Connecting() { return } if e := b.process(); e != nil { connectError <- e return } time.Sleep(10 * time.Millisecond) } }() select { case <-connected: case e := <-connectError: return e case <-time.After(b.ConnectTimeout): return errors.New("unable to connect. Perhaps you need to flash your Arduino with Firmata?") } go func() { for { if !b.Connected() { break } if err := b.process(); err != nil { b.Publish(b.Event("Error"), err) } } }() return }
go
func (b *Client) Connect(conn io.ReadWriteCloser) (err error) { if b.Connected() { return ErrConnected } b.connection = conn b.Reset() connected := make(chan bool, 1) connectError := make(chan error, 1) b.Once(b.Event("ProtocolVersion"), func(data interface{}) { e := b.FirmwareQuery() if e != nil { b.setConnecting(false) connectError <- e } }) b.Once(b.Event("FirmwareQuery"), func(data interface{}) { e := b.CapabilitiesQuery() if e != nil { b.setConnecting(false) connectError <- e } }) b.Once(b.Event("CapabilityQuery"), func(data interface{}) { e := b.AnalogMappingQuery() if e != nil { b.setConnecting(false) connectError <- e } }) b.Once(b.Event("AnalogMappingQuery"), func(data interface{}) { b.ReportDigital(0, 1) b.ReportDigital(1, 1) b.setConnecting(false) b.setConnected(true) connected <- true }) // start it off... b.setConnecting(true) b.ProtocolVersionQuery() go func() { for { if !b.Connecting() { return } if e := b.process(); e != nil { connectError <- e return } time.Sleep(10 * time.Millisecond) } }() select { case <-connected: case e := <-connectError: return e case <-time.After(b.ConnectTimeout): return errors.New("unable to connect. Perhaps you need to flash your Arduino with Firmata?") } go func() { for { if !b.Connected() { break } if err := b.process(); err != nil { b.Publish(b.Event("Error"), err) } } }() return }
[ "func", "(", "b", "*", "Client", ")", "Connect", "(", "conn", "io", ".", "ReadWriteCloser", ")", "(", "err", "error", ")", "{", "if", "b", ".", "Connected", "(", ")", "{", "return", "ErrConnected", "\n", "}", "\n\n", "b", ".", "connection", "=", "conn", "\n", "b", ".", "Reset", "(", ")", "\n", "connected", ":=", "make", "(", "chan", "bool", ",", "1", ")", "\n", "connectError", ":=", "make", "(", "chan", "error", ",", "1", ")", "\n\n", "b", ".", "Once", "(", "b", ".", "Event", "(", "\"", "\"", ")", ",", "func", "(", "data", "interface", "{", "}", ")", "{", "e", ":=", "b", ".", "FirmwareQuery", "(", ")", "\n", "if", "e", "!=", "nil", "{", "b", ".", "setConnecting", "(", "false", ")", "\n", "connectError", "<-", "e", "\n", "}", "\n", "}", ")", "\n\n", "b", ".", "Once", "(", "b", ".", "Event", "(", "\"", "\"", ")", ",", "func", "(", "data", "interface", "{", "}", ")", "{", "e", ":=", "b", ".", "CapabilitiesQuery", "(", ")", "\n", "if", "e", "!=", "nil", "{", "b", ".", "setConnecting", "(", "false", ")", "\n", "connectError", "<-", "e", "\n", "}", "\n", "}", ")", "\n\n", "b", ".", "Once", "(", "b", ".", "Event", "(", "\"", "\"", ")", ",", "func", "(", "data", "interface", "{", "}", ")", "{", "e", ":=", "b", ".", "AnalogMappingQuery", "(", ")", "\n", "if", "e", "!=", "nil", "{", "b", ".", "setConnecting", "(", "false", ")", "\n", "connectError", "<-", "e", "\n", "}", "\n", "}", ")", "\n\n", "b", ".", "Once", "(", "b", ".", "Event", "(", "\"", "\"", ")", ",", "func", "(", "data", "interface", "{", "}", ")", "{", "b", ".", "ReportDigital", "(", "0", ",", "1", ")", "\n", "b", ".", "ReportDigital", "(", "1", ",", "1", ")", "\n", "b", ".", "setConnecting", "(", "false", ")", "\n", "b", ".", "setConnected", "(", "true", ")", "\n", "connected", "<-", "true", "\n", "}", ")", "\n\n", "// start it off...", "b", ".", "setConnecting", "(", "true", ")", "\n", "b", ".", "ProtocolVersionQuery", "(", ")", "\n\n", "go", "func", "(", ")", "{", "for", "{", "if", "!", "b", ".", "Connecting", "(", ")", "{", "return", "\n", "}", "\n", "if", "e", ":=", "b", ".", "process", "(", ")", ";", "e", "!=", "nil", "{", "connectError", "<-", "e", "\n", "return", "\n", "}", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "select", "{", "case", "<-", "connected", ":", "case", "e", ":=", "<-", "connectError", ":", "return", "e", "\n", "case", "<-", "time", ".", "After", "(", "b", ".", "ConnectTimeout", ")", ":", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "go", "func", "(", ")", "{", "for", "{", "if", "!", "b", ".", "Connected", "(", ")", "{", "break", "\n", "}", "\n\n", "if", "err", ":=", "b", ".", "process", "(", ")", ";", "err", "!=", "nil", "{", "b", ".", "Publish", "(", "b", ".", "Event", "(", "\"", "\"", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "\n", "}" ]
// Connect connects to the Client given conn. It first resets the firmata board // then continuously polls the firmata board for new information when it's // available.
[ "Connect", "connects", "to", "the", "Client", "given", "conn", ".", "It", "first", "resets", "the", "firmata", "board", "then", "continuously", "polls", "the", "firmata", "board", "for", "new", "information", "when", "it", "s", "available", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L157-L237
train
hybridgroup/gobot
platforms/firmata/client/client.go
SetPinMode
func (b *Client) SetPinMode(pin int, mode int) error { b.pins[byte(pin)].Mode = mode return b.write([]byte{PinMode, byte(pin), byte(mode)}) }
go
func (b *Client) SetPinMode(pin int, mode int) error { b.pins[byte(pin)].Mode = mode return b.write([]byte{PinMode, byte(pin), byte(mode)}) }
[ "func", "(", "b", "*", "Client", ")", "SetPinMode", "(", "pin", "int", ",", "mode", "int", ")", "error", "{", "b", ".", "pins", "[", "byte", "(", "pin", ")", "]", ".", "Mode", "=", "mode", "\n", "return", "b", ".", "write", "(", "[", "]", "byte", "{", "PinMode", ",", "byte", "(", "pin", ")", ",", "byte", "(", "mode", ")", "}", ")", "\n", "}" ]
// SetPinMode sets the pin to mode.
[ "SetPinMode", "sets", "the", "pin", "to", "mode", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L245-L248
train
hybridgroup/gobot
platforms/firmata/client/client.go
DigitalWrite
func (b *Client) DigitalWrite(pin int, value int) error { port := byte(math.Floor(float64(pin) / 8)) portValue := byte(0) b.pins[pin].Value = value for i := byte(0); i < 8; i++ { if b.pins[8*port+i].Value != 0 { portValue = portValue | (1 << i) } } return b.write([]byte{DigitalMessage | port, portValue & 0x7F, (portValue >> 7) & 0x7F}) }
go
func (b *Client) DigitalWrite(pin int, value int) error { port := byte(math.Floor(float64(pin) / 8)) portValue := byte(0) b.pins[pin].Value = value for i := byte(0); i < 8; i++ { if b.pins[8*port+i].Value != 0 { portValue = portValue | (1 << i) } } return b.write([]byte{DigitalMessage | port, portValue & 0x7F, (portValue >> 7) & 0x7F}) }
[ "func", "(", "b", "*", "Client", ")", "DigitalWrite", "(", "pin", "int", ",", "value", "int", ")", "error", "{", "port", ":=", "byte", "(", "math", ".", "Floor", "(", "float64", "(", "pin", ")", "/", "8", ")", ")", "\n", "portValue", ":=", "byte", "(", "0", ")", "\n\n", "b", ".", "pins", "[", "pin", "]", ".", "Value", "=", "value", "\n\n", "for", "i", ":=", "byte", "(", "0", ")", ";", "i", "<", "8", ";", "i", "++", "{", "if", "b", ".", "pins", "[", "8", "*", "port", "+", "i", "]", ".", "Value", "!=", "0", "{", "portValue", "=", "portValue", "|", "(", "1", "<<", "i", ")", "\n", "}", "\n", "}", "\n", "return", "b", ".", "write", "(", "[", "]", "byte", "{", "DigitalMessage", "|", "port", ",", "portValue", "&", "0x7F", ",", "(", "portValue", ">>", "7", ")", "&", "0x7F", "}", ")", "\n", "}" ]
// DigitalWrite writes value to pin.
[ "DigitalWrite", "writes", "value", "to", "pin", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L251-L263
train
hybridgroup/gobot
platforms/firmata/client/client.go
ServoConfig
func (b *Client) ServoConfig(pin int, max int, min int) error { ret := []byte{ ServoConfig, byte(pin), byte(min & 0x7F), byte((min >> 7) & 0x7F), byte(max & 0x7F), byte((max >> 7) & 0x7F), } return b.WriteSysex(ret) }
go
func (b *Client) ServoConfig(pin int, max int, min int) error { ret := []byte{ ServoConfig, byte(pin), byte(min & 0x7F), byte((min >> 7) & 0x7F), byte(max & 0x7F), byte((max >> 7) & 0x7F), } return b.WriteSysex(ret) }
[ "func", "(", "b", "*", "Client", ")", "ServoConfig", "(", "pin", "int", ",", "max", "int", ",", "min", "int", ")", "error", "{", "ret", ":=", "[", "]", "byte", "{", "ServoConfig", ",", "byte", "(", "pin", ")", ",", "byte", "(", "min", "&", "0x7F", ")", ",", "byte", "(", "(", "min", ">>", "7", ")", "&", "0x7F", ")", ",", "byte", "(", "max", "&", "0x7F", ")", ",", "byte", "(", "(", "max", ">>", "7", ")", "&", "0x7F", ")", ",", "}", "\n", "return", "b", ".", "WriteSysex", "(", "ret", ")", "\n", "}" ]
// ServoConfig sets the min and max pulse width for servo PWM range
[ "ServoConfig", "sets", "the", "min", "and", "max", "pulse", "width", "for", "servo", "PWM", "range" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L266-L276
train
hybridgroup/gobot
platforms/firmata/client/client.go
AnalogWrite
func (b *Client) AnalogWrite(pin int, value int) error { b.pins[pin].Value = value return b.write([]byte{AnalogMessage | byte(pin), byte(value & 0x7F), byte((value >> 7) & 0x7F)}) }
go
func (b *Client) AnalogWrite(pin int, value int) error { b.pins[pin].Value = value return b.write([]byte{AnalogMessage | byte(pin), byte(value & 0x7F), byte((value >> 7) & 0x7F)}) }
[ "func", "(", "b", "*", "Client", ")", "AnalogWrite", "(", "pin", "int", ",", "value", "int", ")", "error", "{", "b", ".", "pins", "[", "pin", "]", ".", "Value", "=", "value", "\n", "return", "b", ".", "write", "(", "[", "]", "byte", "{", "AnalogMessage", "|", "byte", "(", "pin", ")", ",", "byte", "(", "value", "&", "0x7F", ")", ",", "byte", "(", "(", "value", ">>", "7", ")", "&", "0x7F", ")", "}", ")", "\n", "}" ]
// AnalogWrite writes value to pin.
[ "AnalogWrite", "writes", "value", "to", "pin", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L279-L282
train
hybridgroup/gobot
platforms/firmata/client/client.go
PinStateQuery
func (b *Client) PinStateQuery(pin int) error { return b.WriteSysex([]byte{PinStateQuery, byte(pin)}) }
go
func (b *Client) PinStateQuery(pin int) error { return b.WriteSysex([]byte{PinStateQuery, byte(pin)}) }
[ "func", "(", "b", "*", "Client", ")", "PinStateQuery", "(", "pin", "int", ")", "error", "{", "return", "b", ".", "WriteSysex", "(", "[", "]", "byte", "{", "PinStateQuery", ",", "byte", "(", "pin", ")", "}", ")", "\n", "}" ]
// PinStateQuery sends a PinStateQuery for pin.
[ "PinStateQuery", "sends", "a", "PinStateQuery", "for", "pin", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L290-L292
train
hybridgroup/gobot
platforms/firmata/client/client.go
ReportDigital
func (b *Client) ReportDigital(pin int, state int) error { return b.togglePinReporting(pin, state, ReportDigital) }
go
func (b *Client) ReportDigital(pin int, state int) error { return b.togglePinReporting(pin, state, ReportDigital) }
[ "func", "(", "b", "*", "Client", ")", "ReportDigital", "(", "pin", "int", ",", "state", "int", ")", "error", "{", "return", "b", ".", "togglePinReporting", "(", "pin", ",", "state", ",", "ReportDigital", ")", "\n", "}" ]
// ReportDigital enables or disables digital reporting for pin, a non zero // state enables reporting
[ "ReportDigital", "enables", "or", "disables", "digital", "reporting", "for", "pin", "a", "non", "zero", "state", "enables", "reporting" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L311-L313
train
hybridgroup/gobot
platforms/firmata/client/client.go
ReportAnalog
func (b *Client) ReportAnalog(pin int, state int) error { return b.togglePinReporting(pin, state, ReportAnalog) }
go
func (b *Client) ReportAnalog(pin int, state int) error { return b.togglePinReporting(pin, state, ReportAnalog) }
[ "func", "(", "b", "*", "Client", ")", "ReportAnalog", "(", "pin", "int", ",", "state", "int", ")", "error", "{", "return", "b", ".", "togglePinReporting", "(", "pin", ",", "state", ",", "ReportAnalog", ")", "\n", "}" ]
// ReportAnalog enables or disables analog reporting for pin, a non zero // state enables reporting
[ "ReportAnalog", "enables", "or", "disables", "analog", "reporting", "for", "pin", "a", "non", "zero", "state", "enables", "reporting" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L317-L319
train
hybridgroup/gobot
platforms/firmata/client/client.go
I2cRead
func (b *Client) I2cRead(address int, numBytes int) error { return b.WriteSysex([]byte{I2CRequest, byte(address), (I2CModeRead << 3), byte(numBytes) & 0x7F, (byte(numBytes) >> 7) & 0x7F}) }
go
func (b *Client) I2cRead(address int, numBytes int) error { return b.WriteSysex([]byte{I2CRequest, byte(address), (I2CModeRead << 3), byte(numBytes) & 0x7F, (byte(numBytes) >> 7) & 0x7F}) }
[ "func", "(", "b", "*", "Client", ")", "I2cRead", "(", "address", "int", ",", "numBytes", "int", ")", "error", "{", "return", "b", ".", "WriteSysex", "(", "[", "]", "byte", "{", "I2CRequest", ",", "byte", "(", "address", ")", ",", "(", "I2CModeRead", "<<", "3", ")", ",", "byte", "(", "numBytes", ")", "&", "0x7F", ",", "(", "byte", "(", "numBytes", ")", ">>", "7", ")", "&", "0x7F", "}", ")", "\n", "}" ]
// I2cRead reads numBytes from address once.
[ "I2cRead", "reads", "numBytes", "from", "address", "once", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L322-L325
train
hybridgroup/gobot
platforms/firmata/client/client.go
I2cWrite
func (b *Client) I2cWrite(address int, data []byte) error { ret := []byte{I2CRequest, byte(address), (I2CModeWrite << 3)} for _, val := range data { ret = append(ret, byte(val&0x7F)) ret = append(ret, byte((val>>7)&0x7F)) } return b.WriteSysex(ret) }
go
func (b *Client) I2cWrite(address int, data []byte) error { ret := []byte{I2CRequest, byte(address), (I2CModeWrite << 3)} for _, val := range data { ret = append(ret, byte(val&0x7F)) ret = append(ret, byte((val>>7)&0x7F)) } return b.WriteSysex(ret) }
[ "func", "(", "b", "*", "Client", ")", "I2cWrite", "(", "address", "int", ",", "data", "[", "]", "byte", ")", "error", "{", "ret", ":=", "[", "]", "byte", "{", "I2CRequest", ",", "byte", "(", "address", ")", ",", "(", "I2CModeWrite", "<<", "3", ")", "}", "\n", "for", "_", ",", "val", ":=", "range", "data", "{", "ret", "=", "append", "(", "ret", ",", "byte", "(", "val", "&", "0x7F", ")", ")", "\n", "ret", "=", "append", "(", "ret", ",", "byte", "(", "(", "val", ">>", "7", ")", "&", "0x7F", ")", ")", "\n", "}", "\n", "return", "b", ".", "WriteSysex", "(", "ret", ")", "\n", "}" ]
// I2cWrite writes data to address.
[ "I2cWrite", "writes", "data", "to", "address", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L328-L335
train
hybridgroup/gobot
platforms/firmata/client/client.go
I2cConfig
func (b *Client) I2cConfig(delay int) error { return b.WriteSysex([]byte{I2CConfig, byte(delay & 0xFF), byte((delay >> 8) & 0xFF)}) }
go
func (b *Client) I2cConfig(delay int) error { return b.WriteSysex([]byte{I2CConfig, byte(delay & 0xFF), byte((delay >> 8) & 0xFF)}) }
[ "func", "(", "b", "*", "Client", ")", "I2cConfig", "(", "delay", "int", ")", "error", "{", "return", "b", ".", "WriteSysex", "(", "[", "]", "byte", "{", "I2CConfig", ",", "byte", "(", "delay", "&", "0xFF", ")", ",", "byte", "(", "(", "delay", ">>", "8", ")", "&", "0xFF", ")", "}", ")", "\n", "}" ]
// I2cConfig configures the delay in which a register can be read from after it // has been written to.
[ "I2cConfig", "configures", "the", "delay", "in", "which", "a", "register", "can", "be", "read", "from", "after", "it", "has", "been", "written", "to", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L339-L341
train
hybridgroup/gobot
platforms/firmata/client/client.go
WriteSysex
func (b *Client) WriteSysex(data []byte) (err error) { return b.write(append([]byte{StartSysex}, append(data, EndSysex)...)) }
go
func (b *Client) WriteSysex(data []byte) (err error) { return b.write(append([]byte{StartSysex}, append(data, EndSysex)...)) }
[ "func", "(", "b", "*", "Client", ")", "WriteSysex", "(", "data", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "return", "b", ".", "write", "(", "append", "(", "[", "]", "byte", "{", "StartSysex", "}", ",", "append", "(", "data", ",", "EndSysex", ")", "...", ")", ")", "\n", "}" ]
// WriteSysex writes an arbitrary Sysex command to the microcontroller.
[ "WriteSysex", "writes", "an", "arbitrary", "Sysex", "command", "to", "the", "microcontroller", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/client/client.go#L355-L357
train
hybridgroup/gobot
platforms/parrot/minidrone/minidrone_driver.go
NewDriver
func NewDriver(a ble.BLEConnector) *Driver { n := &Driver{ name: gobot.DefaultName("Minidrone"), connection: a, Pcmd: Pcmd{ Flag: 0, Roll: 0, Pitch: 0, Yaw: 0, Gaz: 0, Psi: 0, }, Eventer: gobot.NewEventer(), } n.AddEvent(Battery) n.AddEvent(FlightStatus) n.AddEvent(Takeoff) n.AddEvent(Flying) n.AddEvent(Hovering) n.AddEvent(Landing) n.AddEvent(Landed) n.AddEvent(Emergency) n.AddEvent(Rolling) return n }
go
func NewDriver(a ble.BLEConnector) *Driver { n := &Driver{ name: gobot.DefaultName("Minidrone"), connection: a, Pcmd: Pcmd{ Flag: 0, Roll: 0, Pitch: 0, Yaw: 0, Gaz: 0, Psi: 0, }, Eventer: gobot.NewEventer(), } n.AddEvent(Battery) n.AddEvent(FlightStatus) n.AddEvent(Takeoff) n.AddEvent(Flying) n.AddEvent(Hovering) n.AddEvent(Landing) n.AddEvent(Landed) n.AddEvent(Emergency) n.AddEvent(Rolling) return n }
[ "func", "NewDriver", "(", "a", "ble", ".", "BLEConnector", ")", "*", "Driver", "{", "n", ":=", "&", "Driver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connection", ":", "a", ",", "Pcmd", ":", "Pcmd", "{", "Flag", ":", "0", ",", "Roll", ":", "0", ",", "Pitch", ":", "0", ",", "Yaw", ":", "0", ",", "Gaz", ":", "0", ",", "Psi", ":", "0", ",", "}", ",", "Eventer", ":", "gobot", ".", "NewEventer", "(", ")", ",", "}", "\n\n", "n", ".", "AddEvent", "(", "Battery", ")", "\n", "n", ".", "AddEvent", "(", "FlightStatus", ")", "\n\n", "n", ".", "AddEvent", "(", "Takeoff", ")", "\n", "n", ".", "AddEvent", "(", "Flying", ")", "\n", "n", ".", "AddEvent", "(", "Hovering", ")", "\n", "n", ".", "AddEvent", "(", "Landing", ")", "\n", "n", ".", "AddEvent", "(", "Landed", ")", "\n", "n", ".", "AddEvent", "(", "Emergency", ")", "\n", "n", ".", "AddEvent", "(", "Rolling", ")", "\n\n", "return", "n", "\n", "}" ]
// NewDriver creates a Parrot Minidrone Driver
[ "NewDriver", "creates", "a", "Parrot", "Minidrone", "Driver" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/minidrone/minidrone_driver.go#L110-L137
train
hybridgroup/gobot
platforms/parrot/minidrone/minidrone_driver.go
Init
func (b *Driver) Init() (err error) { b.GenerateAllStates() // subscribe to battery notifications b.adaptor().Subscribe(batteryCharacteristic, func(data []byte, e error) { b.Publish(b.Event(Battery), data[len(data)-1]) }) // subscribe to flying status notifications b.adaptor().Subscribe(flightStatusCharacteristic, func(data []byte, e error) { b.processFlightStatus(data) }) return }
go
func (b *Driver) Init() (err error) { b.GenerateAllStates() // subscribe to battery notifications b.adaptor().Subscribe(batteryCharacteristic, func(data []byte, e error) { b.Publish(b.Event(Battery), data[len(data)-1]) }) // subscribe to flying status notifications b.adaptor().Subscribe(flightStatusCharacteristic, func(data []byte, e error) { b.processFlightStatus(data) }) return }
[ "func", "(", "b", "*", "Driver", ")", "Init", "(", ")", "(", "err", "error", ")", "{", "b", ".", "GenerateAllStates", "(", ")", "\n\n", "// subscribe to battery notifications", "b", ".", "adaptor", "(", ")", ".", "Subscribe", "(", "batteryCharacteristic", ",", "func", "(", "data", "[", "]", "byte", ",", "e", "error", ")", "{", "b", ".", "Publish", "(", "b", ".", "Event", "(", "Battery", ")", ",", "data", "[", "len", "(", "data", ")", "-", "1", "]", ")", "\n", "}", ")", "\n\n", "// subscribe to flying status notifications", "b", ".", "adaptor", "(", ")", ".", "Subscribe", "(", "flightStatusCharacteristic", ",", "func", "(", "data", "[", "]", "byte", ",", "e", "error", ")", "{", "b", ".", "processFlightStatus", "(", "data", ")", "\n", "}", ")", "\n\n", "return", "\n", "}" ]
// Init initializes the BLE insterfaces used by the Minidrone
[ "Init", "initializes", "the", "BLE", "insterfaces", "used", "by", "the", "Minidrone" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/minidrone/minidrone_driver.go#L173-L187
train
hybridgroup/gobot
platforms/parrot/minidrone/minidrone_driver.go
GenerateAllStates
func (b *Driver) GenerateAllStates() (err error) { b.stepsfa0b++ buf := []byte{0x04, byte(b.stepsfa0b), 0x00, 0x04, 0x01, 0x00, 0x32, 0x30, 0x31, 0x34, 0x2D, 0x31, 0x30, 0x2D, 0x32, 0x38, 0x00} err = b.adaptor().WriteCharacteristic(commandCharacteristic, buf) return }
go
func (b *Driver) GenerateAllStates() (err error) { b.stepsfa0b++ buf := []byte{0x04, byte(b.stepsfa0b), 0x00, 0x04, 0x01, 0x00, 0x32, 0x30, 0x31, 0x34, 0x2D, 0x31, 0x30, 0x2D, 0x32, 0x38, 0x00} err = b.adaptor().WriteCharacteristic(commandCharacteristic, buf) return }
[ "func", "(", "b", "*", "Driver", ")", "GenerateAllStates", "(", ")", "(", "err", "error", ")", "{", "b", ".", "stepsfa0b", "++", "\n", "buf", ":=", "[", "]", "byte", "{", "0x04", ",", "byte", "(", "b", ".", "stepsfa0b", ")", ",", "0x00", ",", "0x04", ",", "0x01", ",", "0x00", ",", "0x32", ",", "0x30", ",", "0x31", ",", "0x34", ",", "0x2D", ",", "0x31", ",", "0x30", ",", "0x2D", ",", "0x32", ",", "0x38", ",", "0x00", "}", "\n", "err", "=", "b", ".", "adaptor", "(", ")", ".", "WriteCharacteristic", "(", "commandCharacteristic", ",", "buf", ")", "\n\n", "return", "\n", "}" ]
// GenerateAllStates sets up all the default states aka settings on the drone
[ "GenerateAllStates", "sets", "up", "all", "the", "default", "states", "aka", "settings", "on", "the", "drone" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/minidrone/minidrone_driver.go#L190-L196
train
hybridgroup/gobot
platforms/parrot/minidrone/minidrone_driver.go
Emergency
func (b *Driver) Emergency() (err error) { b.stepsfa0b++ buf := []byte{0x02, byte(b.stepsfa0b) & 0xff, 0x02, 0x00, 0x04, 0x00} err = b.adaptor().WriteCharacteristic(priorityCharacteristic, buf) return err }
go
func (b *Driver) Emergency() (err error) { b.stepsfa0b++ buf := []byte{0x02, byte(b.stepsfa0b) & 0xff, 0x02, 0x00, 0x04, 0x00} err = b.adaptor().WriteCharacteristic(priorityCharacteristic, buf) return err }
[ "func", "(", "b", "*", "Driver", ")", "Emergency", "(", ")", "(", "err", "error", ")", "{", "b", ".", "stepsfa0b", "++", "\n", "buf", ":=", "[", "]", "byte", "{", "0x02", ",", "byte", "(", "b", ".", "stepsfa0b", ")", "&", "0xff", ",", "0x02", ",", "0x00", ",", "0x04", ",", "0x00", "}", "\n", "err", "=", "b", ".", "adaptor", "(", ")", ".", "WriteCharacteristic", "(", "priorityCharacteristic", ",", "buf", ")", "\n\n", "return", "err", "\n", "}" ]
// Emergency sets the Minidrone into emergency mode
[ "Emergency", "sets", "the", "Minidrone", "into", "emergency", "mode" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/minidrone/minidrone_driver.go#L226-L232
train
hybridgroup/gobot
platforms/parrot/minidrone/minidrone_driver.go
StartPcmd
func (b *Driver) StartPcmd() { go func() { // wait a little bit so that there is enough time to get some ACKs time.Sleep(500 * time.Millisecond) for { err := b.adaptor().WriteCharacteristic(pcmdCharacteristic, b.generatePcmd().Bytes()) if err != nil { fmt.Println("pcmd write error:", err) } time.Sleep(50 * time.Millisecond) } }() }
go
func (b *Driver) StartPcmd() { go func() { // wait a little bit so that there is enough time to get some ACKs time.Sleep(500 * time.Millisecond) for { err := b.adaptor().WriteCharacteristic(pcmdCharacteristic, b.generatePcmd().Bytes()) if err != nil { fmt.Println("pcmd write error:", err) } time.Sleep(50 * time.Millisecond) } }() }
[ "func", "(", "b", "*", "Driver", ")", "StartPcmd", "(", ")", "{", "go", "func", "(", ")", "{", "// wait a little bit so that there is enough time to get some ACKs", "time", ".", "Sleep", "(", "500", "*", "time", ".", "Millisecond", ")", "\n", "for", "{", "err", ":=", "b", ".", "adaptor", "(", ")", ".", "WriteCharacteristic", "(", "pcmdCharacteristic", ",", "b", ".", "generatePcmd", "(", ")", ".", "Bytes", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "fmt", ".", "Println", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "time", ".", "Sleep", "(", "50", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n", "}", "(", ")", "\n", "}" ]
// StartPcmd starts the continuous Pcmd communication with the Minidrone
[ "StartPcmd", "starts", "the", "continuous", "Pcmd", "communication", "with", "the", "Minidrone" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/minidrone/minidrone_driver.go#L244-L256
train
hybridgroup/gobot
platforms/parrot/minidrone/minidrone_driver.go
Stop
func (b *Driver) Stop() error { b.pcmdMutex.Lock() defer b.pcmdMutex.Unlock() b.Pcmd = Pcmd{ Flag: 0, Roll: 0, Pitch: 0, Yaw: 0, Gaz: 0, Psi: 0, } return nil }
go
func (b *Driver) Stop() error { b.pcmdMutex.Lock() defer b.pcmdMutex.Unlock() b.Pcmd = Pcmd{ Flag: 0, Roll: 0, Pitch: 0, Yaw: 0, Gaz: 0, Psi: 0, } return nil }
[ "func", "(", "b", "*", "Driver", ")", "Stop", "(", ")", "error", "{", "b", ".", "pcmdMutex", ".", "Lock", "(", ")", "\n", "defer", "b", ".", "pcmdMutex", ".", "Unlock", "(", ")", "\n\n", "b", ".", "Pcmd", "=", "Pcmd", "{", "Flag", ":", "0", ",", "Roll", ":", "0", ",", "Pitch", ":", "0", ",", "Yaw", ":", "0", ",", "Gaz", ":", "0", ",", "Psi", ":", "0", ",", "}", "\n\n", "return", "nil", "\n", "}" ]
// Stop tells the drone to stop moving in any direction and simply hover in place
[ "Stop", "tells", "the", "drone", "to", "stop", "moving", "in", "any", "direction", "and", "simply", "hover", "in", "place" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/minidrone/minidrone_driver.go#L340-L354
train
hybridgroup/gobot
platforms/parrot/minidrone/minidrone_driver.go
RightFlip
func (b *Driver) RightFlip() (err error) { return b.adaptor().WriteCharacteristic(commandCharacteristic, b.generateAnimation(2).Bytes()) }
go
func (b *Driver) RightFlip() (err error) { return b.adaptor().WriteCharacteristic(commandCharacteristic, b.generateAnimation(2).Bytes()) }
[ "func", "(", "b", "*", "Driver", ")", "RightFlip", "(", ")", "(", "err", "error", ")", "{", "return", "b", ".", "adaptor", "(", ")", ".", "WriteCharacteristic", "(", "commandCharacteristic", ",", "b", ".", "generateAnimation", "(", "2", ")", ".", "Bytes", "(", ")", ")", "\n", "}" ]
// RightFlip tells the drone to perform a flip to the right
[ "RightFlip", "tells", "the", "drone", "to", "perform", "a", "flip", "to", "the", "right" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/minidrone/minidrone_driver.go#L387-L389
train
hybridgroup/gobot
platforms/ble/device_information_driver.go
NewDeviceInformationDriver
func NewDeviceInformationDriver(a BLEConnector) *DeviceInformationDriver { n := &DeviceInformationDriver{ name: gobot.DefaultName("DeviceInformation"), connection: a, Eventer: gobot.NewEventer(), } return n }
go
func NewDeviceInformationDriver(a BLEConnector) *DeviceInformationDriver { n := &DeviceInformationDriver{ name: gobot.DefaultName("DeviceInformation"), connection: a, Eventer: gobot.NewEventer(), } return n }
[ "func", "NewDeviceInformationDriver", "(", "a", "BLEConnector", ")", "*", "DeviceInformationDriver", "{", "n", ":=", "&", "DeviceInformationDriver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connection", ":", "a", ",", "Eventer", ":", "gobot", ".", "NewEventer", "(", ")", ",", "}", "\n\n", "return", "n", "\n", "}" ]
// NewDeviceInformationDriver creates a DeviceInformationDriver
[ "NewDeviceInformationDriver", "creates", "a", "DeviceInformationDriver" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/device_information_driver.go#L17-L25
train
hybridgroup/gobot
platforms/ble/device_information_driver.go
GetFirmwareRevision
func (b *DeviceInformationDriver) GetFirmwareRevision() (revision string) { c, _ := b.adaptor().ReadCharacteristic("2a26") buf := bytes.NewBuffer(c) val := buf.String() return val }
go
func (b *DeviceInformationDriver) GetFirmwareRevision() (revision string) { c, _ := b.adaptor().ReadCharacteristic("2a26") buf := bytes.NewBuffer(c) val := buf.String() return val }
[ "func", "(", "b", "*", "DeviceInformationDriver", ")", "GetFirmwareRevision", "(", ")", "(", "revision", "string", ")", "{", "c", ",", "_", ":=", "b", ".", "adaptor", "(", ")", ".", "ReadCharacteristic", "(", "\"", "\"", ")", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "c", ")", "\n", "val", ":=", "buf", ".", "String", "(", ")", "\n", "return", "val", "\n", "}" ]
// GetFirmwareRevision returns the firmware revision for the BLE Peripheral
[ "GetFirmwareRevision", "returns", "the", "firmware", "revision", "for", "the", "BLE", "Peripheral" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/device_information_driver.go#L58-L63
train
hybridgroup/gobot
platforms/ble/device_information_driver.go
GetManufacturerName
func (b *DeviceInformationDriver) GetManufacturerName() (manufacturer string) { c, _ := b.adaptor().ReadCharacteristic("2a29") buf := bytes.NewBuffer(c) val := buf.String() return val }
go
func (b *DeviceInformationDriver) GetManufacturerName() (manufacturer string) { c, _ := b.adaptor().ReadCharacteristic("2a29") buf := bytes.NewBuffer(c) val := buf.String() return val }
[ "func", "(", "b", "*", "DeviceInformationDriver", ")", "GetManufacturerName", "(", ")", "(", "manufacturer", "string", ")", "{", "c", ",", "_", ":=", "b", ".", "adaptor", "(", ")", ".", "ReadCharacteristic", "(", "\"", "\"", ")", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "c", ")", "\n", "val", ":=", "buf", ".", "String", "(", ")", "\n", "return", "val", "\n", "}" ]
// GetManufacturerName returns the manufacturer name for the BLE Peripheral
[ "GetManufacturerName", "returns", "the", "manufacturer", "name", "for", "the", "BLE", "Peripheral" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/device_information_driver.go#L74-L79
train
hybridgroup/gobot
platforms/ble/device_information_driver.go
GetPnPId
func (b *DeviceInformationDriver) GetPnPId() (model string) { c, _ := b.adaptor().ReadCharacteristic("2a50") buf := bytes.NewBuffer(c) val := buf.String() return val }
go
func (b *DeviceInformationDriver) GetPnPId() (model string) { c, _ := b.adaptor().ReadCharacteristic("2a50") buf := bytes.NewBuffer(c) val := buf.String() return val }
[ "func", "(", "b", "*", "DeviceInformationDriver", ")", "GetPnPId", "(", ")", "(", "model", "string", ")", "{", "c", ",", "_", ":=", "b", ".", "adaptor", "(", ")", ".", "ReadCharacteristic", "(", "\"", "\"", ")", "\n", "buf", ":=", "bytes", ".", "NewBuffer", "(", "c", ")", "\n", "val", ":=", "buf", ".", "String", "(", ")", "\n", "return", "val", "\n", "}" ]
// GetPnPId returns the PnP ID for the BLE Peripheral
[ "GetPnPId", "returns", "the", "PnP", "ID", "for", "the", "BLE", "Peripheral" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/device_information_driver.go#L82-L87
train
hybridgroup/gobot
platforms/megapi/motor_driver.go
NewMotorDriver
func NewMotorDriver(megaPi *Adaptor, port byte) *MotorDriver { return &MotorDriver{ name: "MegaPiMotor", megaPi: megaPi, port: port, halted: true, syncRoot: &sync.Mutex{}, } }
go
func NewMotorDriver(megaPi *Adaptor, port byte) *MotorDriver { return &MotorDriver{ name: "MegaPiMotor", megaPi: megaPi, port: port, halted: true, syncRoot: &sync.Mutex{}, } }
[ "func", "NewMotorDriver", "(", "megaPi", "*", "Adaptor", ",", "port", "byte", ")", "*", "MotorDriver", "{", "return", "&", "MotorDriver", "{", "name", ":", "\"", "\"", ",", "megaPi", ":", "megaPi", ",", "port", ":", "port", ",", "halted", ":", "true", ",", "syncRoot", ":", "&", "sync", ".", "Mutex", "{", "}", ",", "}", "\n", "}" ]
// NewMotorDriver creates a new MotorDriver at the given port
[ "NewMotorDriver", "creates", "a", "new", "MotorDriver", "at", "the", "given", "port" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/motor_driver.go#L23-L31
train
hybridgroup/gobot
platforms/megapi/motor_driver.go
Start
func (m *MotorDriver) Start() error { m.syncRoot.Lock() defer m.syncRoot.Unlock() m.halted = false m.speedHelper(0) return nil }
go
func (m *MotorDriver) Start() error { m.syncRoot.Lock() defer m.syncRoot.Unlock() m.halted = false m.speedHelper(0) return nil }
[ "func", "(", "m", "*", "MotorDriver", ")", "Start", "(", ")", "error", "{", "m", ".", "syncRoot", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "syncRoot", ".", "Unlock", "(", ")", "\n", "m", ".", "halted", "=", "false", "\n", "m", ".", "speedHelper", "(", "0", ")", "\n", "return", "nil", "\n", "}" ]
// Start implements the Driver interface
[ "Start", "implements", "the", "Driver", "interface" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/motor_driver.go#L44-L50
train
hybridgroup/gobot
platforms/megapi/motor_driver.go
Halt
func (m *MotorDriver) Halt() error { m.syncRoot.Lock() defer m.syncRoot.Unlock() m.halted = true m.speedHelper(0) return nil }
go
func (m *MotorDriver) Halt() error { m.syncRoot.Lock() defer m.syncRoot.Unlock() m.halted = true m.speedHelper(0) return nil }
[ "func", "(", "m", "*", "MotorDriver", ")", "Halt", "(", ")", "error", "{", "m", ".", "syncRoot", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "syncRoot", ".", "Unlock", "(", ")", "\n", "m", ".", "halted", "=", "true", "\n", "m", ".", "speedHelper", "(", "0", ")", "\n", "return", "nil", "\n", "}" ]
// Halt terminates the Driver interface
[ "Halt", "terminates", "the", "Driver", "interface" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/motor_driver.go#L53-L59
train
hybridgroup/gobot
platforms/megapi/motor_driver.go
Speed
func (m *MotorDriver) Speed(speed int16) error { m.syncRoot.Lock() defer m.syncRoot.Unlock() if m.halted { return nil } m.speedHelper(speed) return nil }
go
func (m *MotorDriver) Speed(speed int16) error { m.syncRoot.Lock() defer m.syncRoot.Unlock() if m.halted { return nil } m.speedHelper(speed) return nil }
[ "func", "(", "m", "*", "MotorDriver", ")", "Speed", "(", "speed", "int16", ")", "error", "{", "m", ".", "syncRoot", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "syncRoot", ".", "Unlock", "(", ")", "\n", "if", "m", ".", "halted", "{", "return", "nil", "\n", "}", "\n", "m", ".", "speedHelper", "(", "speed", ")", "\n", "return", "nil", "\n", "}" ]
// Speed sets the motors speed to the specified value
[ "Speed", "sets", "the", "motors", "speed", "to", "the", "specified", "value" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/motor_driver.go#L67-L75
train
hybridgroup/gobot
platforms/megapi/motor_driver.go
speedHelper
func (m *MotorDriver) speedHelper(speed int16) { m.sendSpeed(speed - 1) m.sendSpeed(speed) }
go
func (m *MotorDriver) speedHelper(speed int16) { m.sendSpeed(speed - 1) m.sendSpeed(speed) }
[ "func", "(", "m", "*", "MotorDriver", ")", "speedHelper", "(", "speed", "int16", ")", "{", "m", ".", "sendSpeed", "(", "speed", "-", "1", ")", "\n", "m", ".", "sendSpeed", "(", "speed", ")", "\n", "}" ]
// there is some sort of bug on the hardware such that you cannot // send the exact same speed to 2 different motors consecutively // hence we ensure we always alternate speeds
[ "there", "is", "some", "sort", "of", "bug", "on", "the", "hardware", "such", "that", "you", "cannot", "send", "the", "exact", "same", "speed", "to", "2", "different", "motors", "consecutively", "hence", "we", "ensure", "we", "always", "alternate", "speeds" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/motor_driver.go#L80-L83
train
hybridgroup/gobot
platforms/megapi/motor_driver.go
sendSpeed
func (m *MotorDriver) sendSpeed(speed int16) { bufOut := new(bytes.Buffer) // byte sequence: 0xff, 0x55, id, action, device, port bufOut.Write([]byte{0xff, 0x55, 0x6, 0x0, 0x2, 0xa, m.port}) binary.Write(bufOut, binary.LittleEndian, speed) bufOut.Write([]byte{0xa}) m.megaPi.writeBytesChannel <- bufOut.Bytes() }
go
func (m *MotorDriver) sendSpeed(speed int16) { bufOut := new(bytes.Buffer) // byte sequence: 0xff, 0x55, id, action, device, port bufOut.Write([]byte{0xff, 0x55, 0x6, 0x0, 0x2, 0xa, m.port}) binary.Write(bufOut, binary.LittleEndian, speed) bufOut.Write([]byte{0xa}) m.megaPi.writeBytesChannel <- bufOut.Bytes() }
[ "func", "(", "m", "*", "MotorDriver", ")", "sendSpeed", "(", "speed", "int16", ")", "{", "bufOut", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n\n", "// byte sequence: 0xff, 0x55, id, action, device, port", "bufOut", ".", "Write", "(", "[", "]", "byte", "{", "0xff", ",", "0x55", ",", "0x6", ",", "0x0", ",", "0x2", ",", "0xa", ",", "m", ".", "port", "}", ")", "\n", "binary", ".", "Write", "(", "bufOut", ",", "binary", ".", "LittleEndian", ",", "speed", ")", "\n", "bufOut", ".", "Write", "(", "[", "]", "byte", "{", "0xa", "}", ")", "\n", "m", ".", "megaPi", ".", "writeBytesChannel", "<-", "bufOut", ".", "Bytes", "(", ")", "\n", "}" ]
// sendSpeed sets the motors speed to the specified value
[ "sendSpeed", "sets", "the", "motors", "speed", "to", "the", "specified", "value" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/megapi/motor_driver.go#L86-L94
train
hybridgroup/gobot
platforms/firmata/tcp_firmata_adaptor.go
NewTCPAdaptor
func NewTCPAdaptor(args ...interface{}) *TCPAdaptor { address := args[0].(string) a := NewAdaptor(address) a.SetName(gobot.DefaultName("TCPFirmata")) a.PortOpener = func(port string) (io.ReadWriteCloser, error) { return connect(port) } return &TCPAdaptor{ Adaptor: a, } }
go
func NewTCPAdaptor(args ...interface{}) *TCPAdaptor { address := args[0].(string) a := NewAdaptor(address) a.SetName(gobot.DefaultName("TCPFirmata")) a.PortOpener = func(port string) (io.ReadWriteCloser, error) { return connect(port) } return &TCPAdaptor{ Adaptor: a, } }
[ "func", "NewTCPAdaptor", "(", "args", "...", "interface", "{", "}", ")", "*", "TCPAdaptor", "{", "address", ":=", "args", "[", "0", "]", ".", "(", "string", ")", "\n\n", "a", ":=", "NewAdaptor", "(", "address", ")", "\n", "a", ".", "SetName", "(", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ")", "\n", "a", ".", "PortOpener", "=", "func", "(", "port", "string", ")", "(", "io", ".", "ReadWriteCloser", ",", "error", ")", "{", "return", "connect", "(", "port", ")", "\n", "}", "\n\n", "return", "&", "TCPAdaptor", "{", "Adaptor", ":", "a", ",", "}", "\n", "}" ]
// NewTCPAdaptor opens and uses a TCP connection to a microcontroller running // WiFiFirmata
[ "NewTCPAdaptor", "opens", "and", "uses", "a", "TCP", "connection", "to", "a", "microcontroller", "running", "WiFiFirmata" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/tcp_firmata_adaptor.go#L22-L34
train
hybridgroup/gobot
api/api.go
NewAPI
func NewAPI(m *gobot.Master) *API { return &API{ master: m, router: pat.New(), Port: "3000", start: func(a *API) { log.Println("Initializing API on " + a.Host + ":" + a.Port + "...") http.Handle("/", a) go func() { if a.Cert != "" && a.Key != "" { http.ListenAndServeTLS(a.Host+":"+a.Port, a.Cert, a.Key, nil) } else { log.Println("WARNING: API using insecure connection. " + "We recommend using an SSL certificate with Gobot.") http.ListenAndServe(a.Host+":"+a.Port, nil) } }() }, } }
go
func NewAPI(m *gobot.Master) *API { return &API{ master: m, router: pat.New(), Port: "3000", start: func(a *API) { log.Println("Initializing API on " + a.Host + ":" + a.Port + "...") http.Handle("/", a) go func() { if a.Cert != "" && a.Key != "" { http.ListenAndServeTLS(a.Host+":"+a.Port, a.Cert, a.Key, nil) } else { log.Println("WARNING: API using insecure connection. " + "We recommend using an SSL certificate with Gobot.") http.ListenAndServe(a.Host+":"+a.Port, nil) } }() }, } }
[ "func", "NewAPI", "(", "m", "*", "gobot", ".", "Master", ")", "*", "API", "{", "return", "&", "API", "{", "master", ":", "m", ",", "router", ":", "pat", ".", "New", "(", ")", ",", "Port", ":", "\"", "\"", ",", "start", ":", "func", "(", "a", "*", "API", ")", "{", "log", ".", "Println", "(", "\"", "\"", "+", "a", ".", "Host", "+", "\"", "\"", "+", "a", ".", "Port", "+", "\"", "\"", ")", "\n", "http", ".", "Handle", "(", "\"", "\"", ",", "a", ")", "\n\n", "go", "func", "(", ")", "{", "if", "a", ".", "Cert", "!=", "\"", "\"", "&&", "a", ".", "Key", "!=", "\"", "\"", "{", "http", ".", "ListenAndServeTLS", "(", "a", ".", "Host", "+", "\"", "\"", "+", "a", ".", "Port", ",", "a", ".", "Cert", ",", "a", ".", "Key", ",", "nil", ")", "\n", "}", "else", "{", "log", ".", "Println", "(", "\"", "\"", "+", "\"", "\"", ")", "\n", "http", ".", "ListenAndServe", "(", "a", ".", "Host", "+", "\"", "\"", "+", "a", ".", "Port", ",", "nil", ")", "\n", "}", "\n", "}", "(", ")", "\n", "}", ",", "}", "\n", "}" ]
// NewAPI returns a new api instance
[ "NewAPI", "returns", "a", "new", "api", "instance" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L30-L50
train
hybridgroup/gobot
api/api.go
ServeHTTP
func (a *API) ServeHTTP(res http.ResponseWriter, req *http.Request) { for _, handler := range a.handlers { rec := httptest.NewRecorder() handler(rec, req) for k, v := range rec.Header() { res.Header()[k] = v } if rec.Code == http.StatusUnauthorized { http.Error(res, "Not Authorized", http.StatusUnauthorized) return } } a.router.ServeHTTP(res, req) }
go
func (a *API) ServeHTTP(res http.ResponseWriter, req *http.Request) { for _, handler := range a.handlers { rec := httptest.NewRecorder() handler(rec, req) for k, v := range rec.Header() { res.Header()[k] = v } if rec.Code == http.StatusUnauthorized { http.Error(res, "Not Authorized", http.StatusUnauthorized) return } } a.router.ServeHTTP(res, req) }
[ "func", "(", "a", "*", "API", ")", "ServeHTTP", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "for", "_", ",", "handler", ":=", "range", "a", ".", "handlers", "{", "rec", ":=", "httptest", ".", "NewRecorder", "(", ")", "\n", "handler", "(", "rec", ",", "req", ")", "\n", "for", "k", ",", "v", ":=", "range", "rec", ".", "Header", "(", ")", "{", "res", ".", "Header", "(", ")", "[", "k", "]", "=", "v", "\n", "}", "\n", "if", "rec", ".", "Code", "==", "http", ".", "StatusUnauthorized", "{", "http", ".", "Error", "(", "res", ",", "\"", "\"", ",", "http", ".", "StatusUnauthorized", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "a", ".", "router", ".", "ServeHTTP", "(", "res", ",", "req", ")", "\n", "}" ]
// ServeHTTP calls api handlers and then serves request using api router
[ "ServeHTTP", "calls", "api", "handlers", "and", "then", "serves", "request", "using", "api", "router" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L53-L66
train
hybridgroup/gobot
api/api.go
Delete
func (a *API) Delete(path string, f func(http.ResponseWriter, *http.Request)) { a.router.Del(path, http.HandlerFunc(f)) }
go
func (a *API) Delete(path string, f func(http.ResponseWriter, *http.Request)) { a.router.Del(path, http.HandlerFunc(f)) }
[ "func", "(", "a", "*", "API", ")", "Delete", "(", "path", "string", ",", "f", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", ")", "{", "a", ".", "router", ".", "Del", "(", "path", ",", "http", ".", "HandlerFunc", "(", "f", ")", ")", "\n", "}" ]
// Delete wraps api router Delete call
[ "Delete", "wraps", "api", "router", "Delete", "call" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L79-L81
train
hybridgroup/gobot
api/api.go
Options
func (a *API) Options(path string, f func(http.ResponseWriter, *http.Request)) { a.router.Options(path, http.HandlerFunc(f)) }
go
func (a *API) Options(path string, f func(http.ResponseWriter, *http.Request)) { a.router.Options(path, http.HandlerFunc(f)) }
[ "func", "(", "a", "*", "API", ")", "Options", "(", "path", "string", ",", "f", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", ")", "{", "a", ".", "router", ".", "Options", "(", "path", ",", "http", ".", "HandlerFunc", "(", "f", ")", ")", "\n", "}" ]
// Options wraps api router Options call
[ "Options", "wraps", "api", "router", "Options", "call" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L84-L86
train
hybridgroup/gobot
api/api.go
AddHandler
func (a *API) AddHandler(f func(http.ResponseWriter, *http.Request)) { a.handlers = append(a.handlers, f) }
go
func (a *API) AddHandler(f func(http.ResponseWriter, *http.Request)) { a.handlers = append(a.handlers, f) }
[ "func", "(", "a", "*", "API", ")", "AddHandler", "(", "f", "func", "(", "http", ".", "ResponseWriter", ",", "*", "http", ".", "Request", ")", ")", "{", "a", ".", "handlers", "=", "append", "(", "a", ".", "handlers", ",", "f", ")", "\n", "}" ]
// AddHandler appends handler to api handlers
[ "AddHandler", "appends", "handler", "to", "api", "handlers" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L99-L101
train
hybridgroup/gobot
api/api.go
AddRobeauxRoutes
func (a *API) AddRobeauxRoutes() { a.AddC3PIORoutes() a.Get("/", func(res http.ResponseWriter, req *http.Request) { http.Redirect(res, req, "/index.html", http.StatusMovedPermanently) }) a.Get("/index.html", a.robeaux) a.Get("/images/:a", a.robeaux) a.Get("/js/:a", a.robeaux) a.Get("/js/:a/", a.robeaux) a.Get("/js/:a/:b", a.robeaux) a.Get("/css/:a", a.robeaux) a.Get("/css/:a/", a.robeaux) a.Get("/css/:a/:b", a.robeaux) a.Get("/partials/:a", a.robeaux) }
go
func (a *API) AddRobeauxRoutes() { a.AddC3PIORoutes() a.Get("/", func(res http.ResponseWriter, req *http.Request) { http.Redirect(res, req, "/index.html", http.StatusMovedPermanently) }) a.Get("/index.html", a.robeaux) a.Get("/images/:a", a.robeaux) a.Get("/js/:a", a.robeaux) a.Get("/js/:a/", a.robeaux) a.Get("/js/:a/:b", a.robeaux) a.Get("/css/:a", a.robeaux) a.Get("/css/:a/", a.robeaux) a.Get("/css/:a/:b", a.robeaux) a.Get("/partials/:a", a.robeaux) }
[ "func", "(", "a", "*", "API", ")", "AddRobeauxRoutes", "(", ")", "{", "a", ".", "AddC3PIORoutes", "(", ")", "\n\n", "a", ".", "Get", "(", "\"", "\"", ",", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "http", ".", "Redirect", "(", "res", ",", "req", ",", "\"", "\"", ",", "http", ".", "StatusMovedPermanently", ")", "\n", "}", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "a", ".", "Get", "(", "\"", "\"", ",", "a", ".", "robeaux", ")", "\n", "}" ]
// AddRobeauxRoutes adds all of the robeaux web interface routes to the API. // The Robeaux web interface requires the C3PIO API, so it is also // activated when you call this method.
[ "AddRobeauxRoutes", "adds", "all", "of", "the", "robeaux", "web", "interface", "routes", "to", "the", "API", ".", "The", "Robeaux", "web", "interface", "requires", "the", "C3PIO", "API", "so", "it", "is", "also", "activated", "when", "you", "call", "this", "method", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L148-L163
train
hybridgroup/gobot
api/api.go
robeaux
func (a *API) robeaux(res http.ResponseWriter, req *http.Request) { path := req.URL.Path buf, err := robeaux.Asset(path[1:]) if err != nil { http.Error(res, err.Error(), http.StatusNotFound) return } t := strings.Split(path, ".") if t[len(t)-1] == "js" { res.Header().Set("Content-Type", "text/javascript; charset=utf-8") } else if t[len(t)-1] == "css" { res.Header().Set("Content-Type", "text/css; charset=utf-8") } else if t[len(t)-1] == "html" { res.Header().Set("Content-Type", "text/html; charset=utf-8") } res.Write(buf) }
go
func (a *API) robeaux(res http.ResponseWriter, req *http.Request) { path := req.URL.Path buf, err := robeaux.Asset(path[1:]) if err != nil { http.Error(res, err.Error(), http.StatusNotFound) return } t := strings.Split(path, ".") if t[len(t)-1] == "js" { res.Header().Set("Content-Type", "text/javascript; charset=utf-8") } else if t[len(t)-1] == "css" { res.Header().Set("Content-Type", "text/css; charset=utf-8") } else if t[len(t)-1] == "html" { res.Header().Set("Content-Type", "text/html; charset=utf-8") } res.Write(buf) }
[ "func", "(", "a", "*", "API", ")", "robeaux", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "path", ":=", "req", ".", "URL", ".", "Path", "\n", "buf", ",", "err", ":=", "robeaux", ".", "Asset", "(", "path", "[", "1", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "http", ".", "Error", "(", "res", ",", "err", ".", "Error", "(", ")", ",", "http", ".", "StatusNotFound", ")", "\n", "return", "\n", "}", "\n", "t", ":=", "strings", ".", "Split", "(", "path", ",", "\"", "\"", ")", "\n", "if", "t", "[", "len", "(", "t", ")", "-", "1", "]", "==", "\"", "\"", "{", "res", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "else", "if", "t", "[", "len", "(", "t", ")", "-", "1", "]", "==", "\"", "\"", "{", "res", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "else", "if", "t", "[", "len", "(", "t", ")", "-", "1", "]", "==", "\"", "\"", "{", "res", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "}", "\n", "res", ".", "Write", "(", "buf", ")", "\n", "}" ]
// robeaux returns handler for robeaux routes. // Writes asset in response and sets correct header
[ "robeaux", "returns", "handler", "for", "robeaux", "routes", ".", "Writes", "asset", "in", "response", "and", "sets", "correct", "header" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L167-L183
train
hybridgroup/gobot
api/api.go
mcp
func (a *API) mcp(res http.ResponseWriter, req *http.Request) { a.writeJSON(map[string]interface{}{"MCP": gobot.NewJSONMaster(a.master)}, res) }
go
func (a *API) mcp(res http.ResponseWriter, req *http.Request) { a.writeJSON(map[string]interface{}{"MCP": gobot.NewJSONMaster(a.master)}, res) }
[ "func", "(", "a", "*", "API", ")", "mcp", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "gobot", ".", "NewJSONMaster", "(", "a", ".", "master", ")", "}", ",", "res", ")", "\n", "}" ]
// mcp returns MCP route handler. // Writes JSON with gobot representation
[ "mcp", "returns", "MCP", "route", "handler", ".", "Writes", "JSON", "with", "gobot", "representation" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L187-L189
train
hybridgroup/gobot
api/api.go
robots
func (a *API) robots(res http.ResponseWriter, req *http.Request) { jsonRobots := []*gobot.JSONRobot{} a.master.Robots().Each(func(r *gobot.Robot) { jsonRobots = append(jsonRobots, gobot.NewJSONRobot(r)) }) a.writeJSON(map[string]interface{}{"robots": jsonRobots}, res) }
go
func (a *API) robots(res http.ResponseWriter, req *http.Request) { jsonRobots := []*gobot.JSONRobot{} a.master.Robots().Each(func(r *gobot.Robot) { jsonRobots = append(jsonRobots, gobot.NewJSONRobot(r)) }) a.writeJSON(map[string]interface{}{"robots": jsonRobots}, res) }
[ "func", "(", "a", "*", "API", ")", "robots", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "jsonRobots", ":=", "[", "]", "*", "gobot", ".", "JSONRobot", "{", "}", "\n", "a", ".", "master", ".", "Robots", "(", ")", ".", "Each", "(", "func", "(", "r", "*", "gobot", ".", "Robot", ")", "{", "jsonRobots", "=", "append", "(", "jsonRobots", ",", "gobot", ".", "NewJSONRobot", "(", "r", ")", ")", "\n", "}", ")", "\n", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "jsonRobots", "}", ",", "res", ")", "\n", "}" ]
// robots returns route handler. // Writes JSON with robots representation
[ "robots", "returns", "route", "handler", ".", "Writes", "JSON", "with", "robots", "representation" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L199-L205
train
hybridgroup/gobot
api/api.go
robot
func (a *API) robot(res http.ResponseWriter, req *http.Request) { if robot, err := a.jsonRobotFor(req.URL.Query().Get(":robot")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.writeJSON(map[string]interface{}{"robot": robot}, res) } }
go
func (a *API) robot(res http.ResponseWriter, req *http.Request) { if robot, err := a.jsonRobotFor(req.URL.Query().Get(":robot")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.writeJSON(map[string]interface{}{"robot": robot}, res) } }
[ "func", "(", "a", "*", "API", ")", "robot", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "if", "robot", ",", "err", ":=", "a", ".", "jsonRobotFor", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ";", "err", "!=", "nil", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", "}", ",", "res", ")", "\n", "}", "else", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "robot", "}", ",", "res", ")", "\n", "}", "\n", "}" ]
// robot returns route handler. // Writes JSON with robot representation
[ "robot", "returns", "route", "handler", ".", "Writes", "JSON", "with", "robot", "representation" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L209-L215
train
hybridgroup/gobot
api/api.go
robotDevices
func (a *API) robotDevices(res http.ResponseWriter, req *http.Request) { if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil { jsonDevices := []*gobot.JSONDevice{} robot.Devices().Each(func(d gobot.Device) { jsonDevices = append(jsonDevices, gobot.NewJSONDevice(d)) }) a.writeJSON(map[string]interface{}{"devices": jsonDevices}, res) } else { a.writeJSON(map[string]interface{}{"error": "No Robot found with the name " + req.URL.Query().Get(":robot")}, res) } }
go
func (a *API) robotDevices(res http.ResponseWriter, req *http.Request) { if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil { jsonDevices := []*gobot.JSONDevice{} robot.Devices().Each(func(d gobot.Device) { jsonDevices = append(jsonDevices, gobot.NewJSONDevice(d)) }) a.writeJSON(map[string]interface{}{"devices": jsonDevices}, res) } else { a.writeJSON(map[string]interface{}{"error": "No Robot found with the name " + req.URL.Query().Get(":robot")}, res) } }
[ "func", "(", "a", "*", "API", ")", "robotDevices", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "if", "robot", ":=", "a", ".", "master", ".", "Robot", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ";", "robot", "!=", "nil", "{", "jsonDevices", ":=", "[", "]", "*", "gobot", ".", "JSONDevice", "{", "}", "\n", "robot", ".", "Devices", "(", ")", ".", "Each", "(", "func", "(", "d", "gobot", ".", "Device", ")", "{", "jsonDevices", "=", "append", "(", "jsonDevices", ",", "gobot", ".", "NewJSONDevice", "(", "d", ")", ")", "\n", "}", ")", "\n", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "jsonDevices", "}", ",", "res", ")", "\n", "}", "else", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "\"", "\"", "+", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", "}", ",", "res", ")", "\n", "}", "\n", "}" ]
// robotDevices returns devices route handler. // Writes JSON with robot devices representation
[ "robotDevices", "returns", "devices", "route", "handler", ".", "Writes", "JSON", "with", "robot", "devices", "representation" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L229-L239
train
hybridgroup/gobot
api/api.go
robotDevice
func (a *API) robotDevice(res http.ResponseWriter, req *http.Request) { if device, err := a.jsonDeviceFor(req.URL.Query().Get(":robot"), req.URL.Query().Get(":device")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.writeJSON(map[string]interface{}{"device": device}, res) } }
go
func (a *API) robotDevice(res http.ResponseWriter, req *http.Request) { if device, err := a.jsonDeviceFor(req.URL.Query().Get(":robot"), req.URL.Query().Get(":device")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.writeJSON(map[string]interface{}{"device": device}, res) } }
[ "func", "(", "a", "*", "API", ")", "robotDevice", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "if", "device", ",", "err", ":=", "a", ".", "jsonDeviceFor", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ",", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ";", "err", "!=", "nil", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", "}", ",", "res", ")", "\n", "}", "else", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "device", "}", ",", "res", ")", "\n", "}", "\n", "}" ]
// robotDevice returns device route handler. // Writes JSON with robot device representation
[ "robotDevice", "returns", "device", "route", "handler", ".", "Writes", "JSON", "with", "robot", "device", "representation" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L243-L249
train
hybridgroup/gobot
api/api.go
robotConnections
func (a *API) robotConnections(res http.ResponseWriter, req *http.Request) { jsonConnections := []*gobot.JSONConnection{} if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil { robot.Connections().Each(func(c gobot.Connection) { jsonConnections = append(jsonConnections, gobot.NewJSONConnection(c)) }) a.writeJSON(map[string]interface{}{"connections": jsonConnections}, res) } else { a.writeJSON(map[string]interface{}{"error": "No Robot found with the name " + req.URL.Query().Get(":robot")}, res) } }
go
func (a *API) robotConnections(res http.ResponseWriter, req *http.Request) { jsonConnections := []*gobot.JSONConnection{} if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil { robot.Connections().Each(func(c gobot.Connection) { jsonConnections = append(jsonConnections, gobot.NewJSONConnection(c)) }) a.writeJSON(map[string]interface{}{"connections": jsonConnections}, res) } else { a.writeJSON(map[string]interface{}{"error": "No Robot found with the name " + req.URL.Query().Get(":robot")}, res) } }
[ "func", "(", "a", "*", "API", ")", "robotConnections", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "jsonConnections", ":=", "[", "]", "*", "gobot", ".", "JSONConnection", "{", "}", "\n", "if", "robot", ":=", "a", ".", "master", ".", "Robot", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ";", "robot", "!=", "nil", "{", "robot", ".", "Connections", "(", ")", ".", "Each", "(", "func", "(", "c", "gobot", ".", "Connection", ")", "{", "jsonConnections", "=", "append", "(", "jsonConnections", ",", "gobot", ".", "NewJSONConnection", "(", "c", ")", ")", "\n", "}", ")", "\n", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "jsonConnections", "}", ",", "res", ")", "\n", "}", "else", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "\"", "\"", "+", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", "}", ",", "res", ")", "\n", "}", "\n\n", "}" ]
// robotConnections returns connections route handler // writes JSON with robot connections representation
[ "robotConnections", "returns", "connections", "route", "handler", "writes", "JSON", "with", "robot", "connections", "representation" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L302-L313
train
hybridgroup/gobot
api/api.go
robotConnection
func (a *API) robotConnection(res http.ResponseWriter, req *http.Request) { if conn, err := a.jsonConnectionFor(req.URL.Query().Get(":robot"), req.URL.Query().Get(":connection")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.writeJSON(map[string]interface{}{"connection": conn}, res) } }
go
func (a *API) robotConnection(res http.ResponseWriter, req *http.Request) { if conn, err := a.jsonConnectionFor(req.URL.Query().Get(":robot"), req.URL.Query().Get(":connection")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.writeJSON(map[string]interface{}{"connection": conn}, res) } }
[ "func", "(", "a", "*", "API", ")", "robotConnection", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "if", "conn", ",", "err", ":=", "a", ".", "jsonConnectionFor", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ",", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ";", "err", "!=", "nil", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", "}", ",", "res", ")", "\n", "}", "else", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "conn", "}", ",", "res", ")", "\n", "}", "\n", "}" ]
// robotConnection returns connection route handler // writes JSON with robot connection representation
[ "robotConnection", "returns", "connection", "route", "handler", "writes", "JSON", "with", "robot", "connection", "representation" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L317-L323
train
hybridgroup/gobot
api/api.go
executeMcpCommand
func (a *API) executeMcpCommand(res http.ResponseWriter, req *http.Request) { a.executeCommand(a.master.Command(req.URL.Query().Get(":command")), res, req, ) }
go
func (a *API) executeMcpCommand(res http.ResponseWriter, req *http.Request) { a.executeCommand(a.master.Command(req.URL.Query().Get(":command")), res, req, ) }
[ "func", "(", "a", "*", "API", ")", "executeMcpCommand", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "a", ".", "executeCommand", "(", "a", ".", "master", ".", "Command", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ",", "res", ",", "req", ",", ")", "\n", "}" ]
// executeMcpCommand calls a global command associated to requested route
[ "executeMcpCommand", "calls", "a", "global", "command", "associated", "to", "requested", "route" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L326-L331
train
hybridgroup/gobot
api/api.go
executeRobotDeviceCommand
func (a *API) executeRobotDeviceCommand(res http.ResponseWriter, req *http.Request) { if _, err := a.jsonDeviceFor(req.URL.Query().Get(":robot"), req.URL.Query().Get(":device")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.executeCommand( a.master.Robot(req.URL.Query().Get(":robot")). Device(req.URL.Query().Get(":device")).(gobot.Commander). Command(req.URL.Query().Get(":command")), res, req, ) } }
go
func (a *API) executeRobotDeviceCommand(res http.ResponseWriter, req *http.Request) { if _, err := a.jsonDeviceFor(req.URL.Query().Get(":robot"), req.URL.Query().Get(":device")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.executeCommand( a.master.Robot(req.URL.Query().Get(":robot")). Device(req.URL.Query().Get(":device")).(gobot.Commander). Command(req.URL.Query().Get(":command")), res, req, ) } }
[ "func", "(", "a", "*", "API", ")", "executeRobotDeviceCommand", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "if", "_", ",", "err", ":=", "a", ".", "jsonDeviceFor", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ",", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ";", "err", "!=", "nil", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", "}", ",", "res", ")", "\n", "}", "else", "{", "a", ".", "executeCommand", "(", "a", ".", "master", ".", "Robot", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ".", "Device", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ".", "(", "gobot", ".", "Commander", ")", ".", "Command", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ",", "res", ",", "req", ",", ")", "\n", "}", "\n", "}" ]
// executeRobotDeviceCommand calls a device command associated to requested route
[ "executeRobotDeviceCommand", "calls", "a", "device", "command", "associated", "to", "requested", "route" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L334-L347
train
hybridgroup/gobot
api/api.go
executeRobotCommand
func (a *API) executeRobotCommand(res http.ResponseWriter, req *http.Request) { if _, err := a.jsonRobotFor(req.URL.Query().Get(":robot")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.executeCommand( a.master.Robot(req.URL.Query().Get(":robot")). Command(req.URL.Query().Get(":command")), res, req, ) } }
go
func (a *API) executeRobotCommand(res http.ResponseWriter, req *http.Request) { if _, err := a.jsonRobotFor(req.URL.Query().Get(":robot")); err != nil { a.writeJSON(map[string]interface{}{"error": err.Error()}, res) } else { a.executeCommand( a.master.Robot(req.URL.Query().Get(":robot")). Command(req.URL.Query().Get(":command")), res, req, ) } }
[ "func", "(", "a", "*", "API", ")", "executeRobotCommand", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "if", "_", ",", "err", ":=", "a", ".", "jsonRobotFor", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ";", "err", "!=", "nil", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "err", ".", "Error", "(", ")", "}", ",", "res", ")", "\n", "}", "else", "{", "a", ".", "executeCommand", "(", "a", ".", "master", ".", "Robot", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ".", "Command", "(", "req", ".", "URL", ".", "Query", "(", ")", ".", "Get", "(", "\"", "\"", ")", ")", ",", "res", ",", "req", ",", ")", "\n", "}", "\n", "}" ]
// executeRobotCommand calls a robot command associated to requested route
[ "executeRobotCommand", "calls", "a", "robot", "command", "associated", "to", "requested", "route" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L350-L361
train
hybridgroup/gobot
api/api.go
executeCommand
func (a *API) executeCommand(f func(map[string]interface{}) interface{}, res http.ResponseWriter, req *http.Request, ) { body := make(map[string]interface{}) json.NewDecoder(req.Body).Decode(&body) if f != nil { a.writeJSON(map[string]interface{}{"result": f(body)}, res) } else { a.writeJSON(map[string]interface{}{"error": "Unknown Command"}, res) } }
go
func (a *API) executeCommand(f func(map[string]interface{}) interface{}, res http.ResponseWriter, req *http.Request, ) { body := make(map[string]interface{}) json.NewDecoder(req.Body).Decode(&body) if f != nil { a.writeJSON(map[string]interface{}{"result": f(body)}, res) } else { a.writeJSON(map[string]interface{}{"error": "Unknown Command"}, res) } }
[ "func", "(", "a", "*", "API", ")", "executeCommand", "(", "f", "func", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "interface", "{", "}", ",", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ",", ")", "{", "body", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "json", ".", "NewDecoder", "(", "req", ".", "Body", ")", ".", "Decode", "(", "&", "body", ")", "\n\n", "if", "f", "!=", "nil", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "f", "(", "body", ")", "}", ",", "res", ")", "\n", "}", "else", "{", "a", ".", "writeJSON", "(", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "\"", "\"", "}", ",", "res", ")", "\n", "}", "\n", "}" ]
// executeCommand writes JSON response with `f` returned value.
[ "executeCommand", "writes", "JSON", "response", "with", "f", "returned", "value", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L364-L377
train
hybridgroup/gobot
api/api.go
writeJSON
func (a *API) writeJSON(j interface{}, res http.ResponseWriter) { data, _ := json.Marshal(j) res.Header().Set("Content-Type", "application/json; charset=utf-8") res.Write(data) }
go
func (a *API) writeJSON(j interface{}, res http.ResponseWriter) { data, _ := json.Marshal(j) res.Header().Set("Content-Type", "application/json; charset=utf-8") res.Write(data) }
[ "func", "(", "a", "*", "API", ")", "writeJSON", "(", "j", "interface", "{", "}", ",", "res", "http", ".", "ResponseWriter", ")", "{", "data", ",", "_", ":=", "json", ".", "Marshal", "(", "j", ")", "\n", "res", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "res", ".", "Write", "(", "data", ")", "\n", "}" ]
// writeJSON writes `j` as JSON in response
[ "writeJSON", "writes", "j", "as", "JSON", "in", "response" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L380-L384
train
hybridgroup/gobot
api/api.go
Debug
func (a *API) Debug() { a.AddHandler(func(res http.ResponseWriter, req *http.Request) { log.Println(req) }) }
go
func (a *API) Debug() { a.AddHandler(func(res http.ResponseWriter, req *http.Request) { log.Println(req) }) }
[ "func", "(", "a", "*", "API", ")", "Debug", "(", ")", "{", "a", ".", "AddHandler", "(", "func", "(", "res", "http", ".", "ResponseWriter", ",", "req", "*", "http", ".", "Request", ")", "{", "log", ".", "Println", "(", "req", ")", "\n", "}", ")", "\n", "}" ]
// Debug add handler to api that prints each request
[ "Debug", "add", "handler", "to", "api", "that", "prints", "each", "request" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/api.go#L387-L391
train
hybridgroup/gobot
platforms/particle/adaptor.go
NewAdaptor
func NewAdaptor(deviceID string, accessToken string) *Adaptor { return &Adaptor{ name: gobot.DefaultName("Particle"), DeviceID: deviceID, AccessToken: accessToken, servoPins: make(map[string]bool), APIServer: "https://api.particle.io", Eventer: gobot.NewEventer(), } }
go
func NewAdaptor(deviceID string, accessToken string) *Adaptor { return &Adaptor{ name: gobot.DefaultName("Particle"), DeviceID: deviceID, AccessToken: accessToken, servoPins: make(map[string]bool), APIServer: "https://api.particle.io", Eventer: gobot.NewEventer(), } }
[ "func", "NewAdaptor", "(", "deviceID", "string", ",", "accessToken", "string", ")", "*", "Adaptor", "{", "return", "&", "Adaptor", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "DeviceID", ":", "deviceID", ",", "AccessToken", ":", "accessToken", ",", "servoPins", ":", "make", "(", "map", "[", "string", "]", "bool", ")", ",", "APIServer", ":", "\"", "\"", ",", "Eventer", ":", "gobot", ".", "NewEventer", "(", ")", ",", "}", "\n", "}" ]
// NewAdaptor creates new Photon adaptor with deviceId and accessToken // using api.particle.io server as default
[ "NewAdaptor", "creates", "new", "Photon", "adaptor", "with", "deviceId", "and", "accessToken", "using", "api", ".", "particle", ".", "io", "server", "as", "default" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L43-L52
train
hybridgroup/gobot
platforms/particle/adaptor.go
AnalogRead
func (s *Adaptor) AnalogRead(pin string) (val int, err error) { params := url.Values{ "params": {pin}, "access_token": {s.AccessToken}, } url := fmt.Sprintf("%v/analogread", s.deviceURL()) resp, err := s.request("POST", url, params) if err == nil { val = int(resp["return_value"].(float64)) return } return 0, err }
go
func (s *Adaptor) AnalogRead(pin string) (val int, err error) { params := url.Values{ "params": {pin}, "access_token": {s.AccessToken}, } url := fmt.Sprintf("%v/analogread", s.deviceURL()) resp, err := s.request("POST", url, params) if err == nil { val = int(resp["return_value"].(float64)) return } return 0, err }
[ "func", "(", "s", "*", "Adaptor", ")", "AnalogRead", "(", "pin", "string", ")", "(", "val", "int", ",", "err", "error", ")", "{", "params", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "pin", "}", ",", "\"", "\"", ":", "{", "s", ".", "AccessToken", "}", ",", "}", "\n\n", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "deviceURL", "(", ")", ")", "\n\n", "resp", ",", "err", ":=", "s", ".", "request", "(", "\"", "\"", ",", "url", ",", "params", ")", "\n", "if", "err", "==", "nil", "{", "val", "=", "int", "(", "resp", "[", "\"", "\"", "]", ".", "(", "float64", ")", ")", "\n", "return", "\n", "}", "\n\n", "return", "0", ",", "err", "\n", "}" ]
// AnalogRead reads analog ping value using Particle cloud api
[ "AnalogRead", "reads", "analog", "ping", "value", "using", "Particle", "cloud", "api" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L71-L86
train
hybridgroup/gobot
platforms/particle/adaptor.go
PwmWrite
func (s *Adaptor) PwmWrite(pin string, level byte) (err error) { return s.AnalogWrite(pin, level) }
go
func (s *Adaptor) PwmWrite(pin string, level byte) (err error) { return s.AnalogWrite(pin, level) }
[ "func", "(", "s", "*", "Adaptor", ")", "PwmWrite", "(", "pin", "string", ",", "level", "byte", ")", "(", "err", "error", ")", "{", "return", "s", ".", "AnalogWrite", "(", "pin", ",", "level", ")", "\n", "}" ]
// PwmWrite writes in pin using analog write api
[ "PwmWrite", "writes", "in", "pin", "using", "analog", "write", "api" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L89-L91
train
hybridgroup/gobot
platforms/particle/adaptor.go
AnalogWrite
func (s *Adaptor) AnalogWrite(pin string, level byte) (err error) { params := url.Values{ "params": {fmt.Sprintf("%v,%v", pin, level)}, "access_token": {s.AccessToken}, } url := fmt.Sprintf("%v/analogwrite", s.deviceURL()) _, err = s.request("POST", url, params) return }
go
func (s *Adaptor) AnalogWrite(pin string, level byte) (err error) { params := url.Values{ "params": {fmt.Sprintf("%v,%v", pin, level)}, "access_token": {s.AccessToken}, } url := fmt.Sprintf("%v/analogwrite", s.deviceURL()) _, err = s.request("POST", url, params) return }
[ "func", "(", "s", "*", "Adaptor", ")", "AnalogWrite", "(", "pin", "string", ",", "level", "byte", ")", "(", "err", "error", ")", "{", "params", ":=", "url", ".", "Values", "{", "\"", "\"", ":", "{", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "pin", ",", "level", ")", "}", ",", "\"", "\"", ":", "{", "s", ".", "AccessToken", "}", ",", "}", "\n", "url", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "deviceURL", "(", ")", ")", "\n", "_", ",", "err", "=", "s", ".", "request", "(", "\"", "\"", ",", "url", ",", "params", ")", "\n", "return", "\n", "}" ]
// AnalogWrite writes analog pin with specified level using Particle cloud api
[ "AnalogWrite", "writes", "analog", "pin", "with", "specified", "level", "using", "Particle", "cloud", "api" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/particle/adaptor.go#L94-L102
train