id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
156,100
hybridgroup/gobot
sysfs/pwm_pin.go
Polarity
func (p *PWMPin) Polarity() (polarity string, err error) { buf, err := p.read(p.pwmPolarityPath()) if err != nil { return } if len(buf) == 0 { return "", nil } return string(buf), nil }
go
func (p *PWMPin) Polarity() (polarity string, err error) { buf, err := p.read(p.pwmPolarityPath()) if err != nil { return } if len(buf) == 0 { return "", nil } return string(buf), nil }
[ "func", "(", "p", "*", "PWMPin", ")", "Polarity", "(", ")", "(", "polarity", "string", ",", "err", "error", ")", "{", "buf", ",", "err", ":=", "p", ".", "read", "(", "p", ".", "pwmPolarityPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{...
// Polarity returns current polarity value
[ "Polarity", "returns", "current", "polarity", "value" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L97-L107
156,101
hybridgroup/gobot
sysfs/pwm_pin.go
InvertPolarity
func (p *PWMPin) InvertPolarity(invert bool) (err error) { if !p.enabled { polarity := "normal" if invert { polarity = "inverted" } _, err = p.write(p.pwmPolarityPath(), []byte(polarity)) } else { err = fmt.Errorf("Cannot set PWM polarity when enabled") } return }
go
func (p *PWMPin) InvertPolarity(invert bool) (err error) { if !p.enabled { polarity := "normal" if invert { polarity = "inverted" } _, err = p.write(p.pwmPolarityPath(), []byte(polarity)) } else { err = fmt.Errorf("Cannot set PWM polarity when enabled") } return }
[ "func", "(", "p", "*", "PWMPin", ")", "InvertPolarity", "(", "invert", "bool", ")", "(", "err", "error", ")", "{", "if", "!", "p", ".", "enabled", "{", "polarity", ":=", "\"", "\"", "\n", "if", "invert", "{", "polarity", "=", "\"", "\"", "\n", "}...
// InvertPolarity writes value to pwm polarity path
[ "InvertPolarity", "writes", "value", "to", "pwm", "polarity", "path" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L110-L121
156,102
hybridgroup/gobot
sysfs/pwm_pin.go
Period
func (p *PWMPin) Period() (period uint32, err error) { buf, err := p.read(p.pwmPeriodPath()) if err != nil { return } if len(buf) == 0 { return 0, nil } v := bytes.TrimRight(buf, "\n") val, e := strconv.Atoi(string(v)) return uint32(val), e }
go
func (p *PWMPin) Period() (period uint32, err error) { buf, err := p.read(p.pwmPeriodPath()) if err != nil { return } if len(buf) == 0 { return 0, nil } v := bytes.TrimRight(buf, "\n") val, e := strconv.Atoi(string(v)) return uint32(val), e }
[ "func", "(", "p", "*", "PWMPin", ")", "Period", "(", ")", "(", "period", "uint32", ",", "err", "error", ")", "{", "buf", ",", "err", ":=", "p", ".", "read", "(", "p", ".", "pwmPeriodPath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "...
// Period reads from pwm period path and returns value in nanoseconds
[ "Period", "reads", "from", "pwm", "period", "path", "and", "returns", "value", "in", "nanoseconds" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L124-L136
156,103
hybridgroup/gobot
sysfs/pwm_pin.go
SetPeriod
func (p *PWMPin) SetPeriod(period uint32) (err error) { _, err = p.write(p.pwmPeriodPath(), []byte(fmt.Sprintf("%v", period))) return }
go
func (p *PWMPin) SetPeriod(period uint32) (err error) { _, err = p.write(p.pwmPeriodPath(), []byte(fmt.Sprintf("%v", period))) return }
[ "func", "(", "p", "*", "PWMPin", ")", "SetPeriod", "(", "period", "uint32", ")", "(", "err", "error", ")", "{", "_", ",", "err", "=", "p", ".", "write", "(", "p", ".", "pwmPeriodPath", "(", ")", ",", "[", "]", "byte", "(", "fmt", ".", "Sprintf"...
// SetPeriod sets pwm period in nanoseconds
[ "SetPeriod", "sets", "pwm", "period", "in", "nanoseconds" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L139-L142
156,104
hybridgroup/gobot
sysfs/pwm_pin.go
DutyCycle
func (p *PWMPin) DutyCycle() (duty uint32, err error) { buf, err := p.read(p.pwmDutyCyclePath()) if err != nil { return } val, e := strconv.Atoi(string(buf)) return uint32(val), e }
go
func (p *PWMPin) DutyCycle() (duty uint32, err error) { buf, err := p.read(p.pwmDutyCyclePath()) if err != nil { return } val, e := strconv.Atoi(string(buf)) return uint32(val), e }
[ "func", "(", "p", "*", "PWMPin", ")", "DutyCycle", "(", ")", "(", "duty", "uint32", ",", "err", "error", ")", "{", "buf", ",", "err", ":=", "p", ".", "read", "(", "p", ".", "pwmDutyCyclePath", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{",...
// DutyCycle reads from pwm duty cycle path and returns value in nanoseconds
[ "DutyCycle", "reads", "from", "pwm", "duty", "cycle", "path", "and", "returns", "value", "in", "nanoseconds" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L145-L153
156,105
hybridgroup/gobot
sysfs/pwm_pin.go
SetDutyCycle
func (p *PWMPin) SetDutyCycle(duty uint32) (err error) { _, err = p.write(p.pwmDutyCyclePath(), []byte(fmt.Sprintf("%v", duty))) return }
go
func (p *PWMPin) SetDutyCycle(duty uint32) (err error) { _, err = p.write(p.pwmDutyCyclePath(), []byte(fmt.Sprintf("%v", duty))) return }
[ "func", "(", "p", "*", "PWMPin", ")", "SetDutyCycle", "(", "duty", "uint32", ")", "(", "err", "error", ")", "{", "_", ",", "err", "=", "p", ".", "write", "(", "p", ".", "pwmDutyCyclePath", "(", ")", ",", "[", "]", "byte", "(", "fmt", ".", "Spri...
// SetDutyCycle writes value to pwm duty cycle path // duty is in nanoseconds
[ "SetDutyCycle", "writes", "value", "to", "pwm", "duty", "cycle", "path", "duty", "is", "in", "nanoseconds" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/pwm_pin.go#L157-L160
156,106
hybridgroup/gobot
platforms/microbit/led_driver.go
NewLEDDriver
func NewLEDDriver(a ble.BLEConnector) *LEDDriver { n := &LEDDriver{ name: gobot.DefaultName("Microbit LED"), connection: a, Eventer: gobot.NewEventer(), } return n }
go
func NewLEDDriver(a ble.BLEConnector) *LEDDriver { n := &LEDDriver{ name: gobot.DefaultName("Microbit LED"), connection: a, Eventer: gobot.NewEventer(), } return n }
[ "func", "NewLEDDriver", "(", "a", "ble", ".", "BLEConnector", ")", "*", "LEDDriver", "{", "n", ":=", "&", "LEDDriver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connection", ":", "a", ",", "Eventer", ":", "gobot", "."...
// NewLEDDriver creates a Microbit LEDDriver
[ "NewLEDDriver", "creates", "a", "Microbit", "LEDDriver" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L26-L34
156,107
hybridgroup/gobot
platforms/microbit/led_driver.go
ReadMatrix
func (b *LEDDriver) ReadMatrix() (data []byte, err error) { data, err = b.adaptor().ReadCharacteristic(ledMatrixStateCharacteristic) return }
go
func (b *LEDDriver) ReadMatrix() (data []byte, err error) { data, err = b.adaptor().ReadCharacteristic(ledMatrixStateCharacteristic) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "ReadMatrix", "(", ")", "(", "data", "[", "]", "byte", ",", "err", "error", ")", "{", "data", ",", "err", "=", "b", ".", "adaptor", "(", ")", ".", "ReadCharacteristic", "(", "ledMatrixStateCharacteristic", ")", ...
// ReadMatrix read the current LED matrix state
[ "ReadMatrix", "read", "the", "current", "LED", "matrix", "state" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L61-L64
156,108
hybridgroup/gobot
platforms/microbit/led_driver.go
WriteMatrix
func (b *LEDDriver) WriteMatrix(data []byte) (err error) { err = b.adaptor().WriteCharacteristic(ledMatrixStateCharacteristic, data) return }
go
func (b *LEDDriver) WriteMatrix(data []byte) (err error) { err = b.adaptor().WriteCharacteristic(ledMatrixStateCharacteristic, data) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "WriteMatrix", "(", "data", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "err", "=", "b", ".", "adaptor", "(", ")", ".", "WriteCharacteristic", "(", "ledMatrixStateCharacteristic", ",", "data", ")", "\n...
// WriteMatrix writes an array of 5 bytes to set the LED matrix
[ "WriteMatrix", "writes", "an", "array", "of", "5", "bytes", "to", "set", "the", "LED", "matrix" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L67-L70
156,109
hybridgroup/gobot
platforms/microbit/led_driver.go
WriteText
func (b *LEDDriver) WriteText(msg string) (err error) { err = b.adaptor().WriteCharacteristic(ledTextCharacteristic, []byte(msg)) return err }
go
func (b *LEDDriver) WriteText(msg string) (err error) { err = b.adaptor().WriteCharacteristic(ledTextCharacteristic, []byte(msg)) return err }
[ "func", "(", "b", "*", "LEDDriver", ")", "WriteText", "(", "msg", "string", ")", "(", "err", "error", ")", "{", "err", "=", "b", ".", "adaptor", "(", ")", ".", "WriteCharacteristic", "(", "ledTextCharacteristic", ",", "[", "]", "byte", "(", "msg", ")...
// WriteText writes a text message to the Microbit LED matrix
[ "WriteText", "writes", "a", "text", "message", "to", "the", "Microbit", "LED", "matrix" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L73-L76
156,110
hybridgroup/gobot
platforms/microbit/led_driver.go
Blank
func (b *LEDDriver) Blank() (err error) { buf := []byte{0x00, 0x00, 0x00, 0x00, 0x00} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) Blank() (err error) { buf := []byte{0x00, 0x00, 0x00, 0x00, 0x00} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "Blank", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x00", ",", "0x00", ",", "0x00", ",", "0x00", ",", "0x00", "}", "\n", "err", "=", "b", ".", "WriteMatrix", "(", "b...
// Blank clears the LEDs on the Microbit
[ "Blank", "clears", "the", "LEDs", "on", "the", "Microbit" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L89-L93
156,111
hybridgroup/gobot
platforms/microbit/led_driver.go
Solid
func (b *LEDDriver) Solid() (err error) { buf := []byte{0x1F, 0x1F, 0x1F, 0x1F, 0x1F} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) Solid() (err error) { buf := []byte{0x1F, 0x1F, 0x1F, 0x1F, 0x1F} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "Solid", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x1F", ",", "0x1F", ",", "0x1F", ",", "0x1F", ",", "0x1F", "}", "\n", "err", "=", "b", ".", "WriteMatrix", "(", "b...
// Solid turns on all of the Microbit LEDs
[ "Solid", "turns", "on", "all", "of", "the", "Microbit", "LEDs" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L96-L100
156,112
hybridgroup/gobot
platforms/microbit/led_driver.go
UpRightArrow
func (b *LEDDriver) UpRightArrow() (err error) { buf := []byte{0x0F, 0x03, 0x05, 0x09, 0x10} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) UpRightArrow() (err error) { buf := []byte{0x0F, 0x03, 0x05, 0x09, 0x10} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "UpRightArrow", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x0F", ",", "0x03", ",", "0x05", ",", "0x09", ",", "0x10", "}", "\n", "err", "=", "b", ".", "WriteMatrix", "(...
// UpRightArrow displays an arrow pointing upwards and to the right on the Microbit LEDs
[ "UpRightArrow", "displays", "an", "arrow", "pointing", "upwards", "and", "to", "the", "right", "on", "the", "Microbit", "LEDs" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L103-L107
156,113
hybridgroup/gobot
platforms/microbit/led_driver.go
UpLeftArrow
func (b *LEDDriver) UpLeftArrow() (err error) { buf := []byte{0x1E, 0x18, 0x14, 0x12, 0x01} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) UpLeftArrow() (err error) { buf := []byte{0x1E, 0x18, 0x14, 0x12, 0x01} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "UpLeftArrow", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x1E", ",", "0x18", ",", "0x14", ",", "0x12", ",", "0x01", "}", "\n", "err", "=", "b", ".", "WriteMatrix", "("...
// UpLeftArrow displays an arrow pointing upwards and to the left on the Microbit LEDs
[ "UpLeftArrow", "displays", "an", "arrow", "pointing", "upwards", "and", "to", "the", "left", "on", "the", "Microbit", "LEDs" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L110-L114
156,114
hybridgroup/gobot
platforms/microbit/led_driver.go
DownRightArrow
func (b *LEDDriver) DownRightArrow() (err error) { buf := []byte{0x10, 0x09, 0x05, 0x03, 0x0F} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) DownRightArrow() (err error) { buf := []byte{0x10, 0x09, 0x05, 0x03, 0x0F} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "DownRightArrow", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x10", ",", "0x09", ",", "0x05", ",", "0x03", ",", "0x0F", "}", "\n", "err", "=", "b", ".", "WriteMatrix", ...
// DownRightArrow displays an arrow pointing down and to the right on the Microbit LEDs
[ "DownRightArrow", "displays", "an", "arrow", "pointing", "down", "and", "to", "the", "right", "on", "the", "Microbit", "LEDs" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L117-L121
156,115
hybridgroup/gobot
platforms/microbit/led_driver.go
DownLeftArrow
func (b *LEDDriver) DownLeftArrow() (err error) { buf := []byte{0x01, 0x12, 0x14, 0x18, 0x1E} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) DownLeftArrow() (err error) { buf := []byte{0x01, 0x12, 0x14, 0x18, 0x1E} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "DownLeftArrow", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x01", ",", "0x12", ",", "0x14", ",", "0x18", ",", "0x1E", "}", "\n", "err", "=", "b", ".", "WriteMatrix", "...
// DownLeftArrow displays an arrow pointing down and to the left on the Microbit LEDs
[ "DownLeftArrow", "displays", "an", "arrow", "pointing", "down", "and", "to", "the", "left", "on", "the", "Microbit", "LEDs" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L124-L128
156,116
hybridgroup/gobot
platforms/microbit/led_driver.go
Dimond
func (b *LEDDriver) Dimond() (err error) { buf := []byte{0x04, 0x0A, 0x11, 0x0A, 0x04} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) Dimond() (err error) { buf := []byte{0x04, 0x0A, 0x11, 0x0A, 0x04} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "Dimond", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x04", ",", "0x0A", ",", "0x11", ",", "0x0A", ",", "0x04", "}", "\n", "err", "=", "b", ".", "WriteMatrix", "(", "...
// Dimond displays a dimond on the Microbit LEDs
[ "Dimond", "displays", "a", "dimond", "on", "the", "Microbit", "LEDs" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L131-L135
156,117
hybridgroup/gobot
platforms/microbit/led_driver.go
Smile
func (b *LEDDriver) Smile() (err error) { buf := []byte{0x0A, 0x0A, 0x00, 0x11, 0x0E} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) Smile() (err error) { buf := []byte{0x0A, 0x0A, 0x00, 0x11, 0x0E} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "Smile", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x0A", ",", "0x0A", ",", "0x00", ",", "0x11", ",", "0x0E", "}", "\n", "err", "=", "b", ".", "WriteMatrix", "(", "b...
// Smile displays a smile on the Microbit LEDs
[ "Smile", "displays", "a", "smile", "on", "the", "Microbit", "LEDs" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L138-L142
156,118
hybridgroup/gobot
platforms/microbit/led_driver.go
Wink
func (b *LEDDriver) Wink() (err error) { buf := []byte{0x08, 0x0B, 0x00, 0x11, 0x0E} err = b.WriteMatrix(buf) return }
go
func (b *LEDDriver) Wink() (err error) { buf := []byte{0x08, 0x0B, 0x00, 0x11, 0x0E} err = b.WriteMatrix(buf) return }
[ "func", "(", "b", "*", "LEDDriver", ")", "Wink", "(", ")", "(", "err", "error", ")", "{", "buf", ":=", "[", "]", "byte", "{", "0x08", ",", "0x0B", ",", "0x00", ",", "0x11", ",", "0x0E", "}", "\n", "err", "=", "b", ".", "WriteMatrix", "(", "bu...
// Wink displays a wink on the Microbit LEDs
[ "Wink", "displays", "a", "wink", "on", "the", "Microbit", "LEDs" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/led_driver.go#L145-L149
156,119
hybridgroup/gobot
drivers/gpio/servo_driver.go
Move
func (s *ServoDriver) Move(angle uint8) (err error) { if !(angle >= 0 && angle <= 180) { return ErrServoOutOfRange } s.CurrentAngle = angle return s.connection.ServoWrite(s.Pin(), angle) }
go
func (s *ServoDriver) Move(angle uint8) (err error) { if !(angle >= 0 && angle <= 180) { return ErrServoOutOfRange } s.CurrentAngle = angle return s.connection.ServoWrite(s.Pin(), angle) }
[ "func", "(", "s", "*", "ServoDriver", ")", "Move", "(", "angle", "uint8", ")", "(", "err", "error", ")", "{", "if", "!", "(", "angle", ">=", "0", "&&", "angle", "<=", "180", ")", "{", "return", "ErrServoOutOfRange", "\n", "}", "\n", "s", ".", "Cu...
// Move sets the servo to the specified angle. Acceptable angles are 0-180
[ "Move", "sets", "the", "servo", "to", "the", "specified", "angle", ".", "Acceptable", "angles", "are", "0", "-", "180" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/servo_driver.go#L67-L73
156,120
hybridgroup/gobot
platforms/microbit/accelerometer_driver.go
NewAccelerometerDriver
func NewAccelerometerDriver(a ble.BLEConnector) *AccelerometerDriver { n := &AccelerometerDriver{ name: gobot.DefaultName("Microbit Accelerometer"), connection: a, Eventer: gobot.NewEventer(), } n.AddEvent(Accelerometer) return n }
go
func NewAccelerometerDriver(a ble.BLEConnector) *AccelerometerDriver { n := &AccelerometerDriver{ name: gobot.DefaultName("Microbit Accelerometer"), connection: a, Eventer: gobot.NewEventer(), } n.AddEvent(Accelerometer) return n }
[ "func", "NewAccelerometerDriver", "(", "a", "ble", ".", "BLEConnector", ")", "*", "AccelerometerDriver", "{", "n", ":=", "&", "AccelerometerDriver", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "connection", ":", "a", ",", "Eve...
// NewAccelerometerDriver creates a Microbit AccelerometerDriver
[ "NewAccelerometerDriver", "creates", "a", "Microbit", "AccelerometerDriver" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/microbit/accelerometer_driver.go#L42-L52
156,121
hybridgroup/gobot
platforms/opencv/window_driver.go
NewWindowDriver
func NewWindowDriver() *WindowDriver { return &WindowDriver{ name: "Window", start: func(w *WindowDriver) { w.window = gocv.NewWindow(w.Name()) }, } }
go
func NewWindowDriver() *WindowDriver { return &WindowDriver{ name: "Window", start: func(w *WindowDriver) { w.window = gocv.NewWindow(w.Name()) }, } }
[ "func", "NewWindowDriver", "(", ")", "*", "WindowDriver", "{", "return", "&", "WindowDriver", "{", "name", ":", "\"", "\"", ",", "start", ":", "func", "(", "w", "*", "WindowDriver", ")", "{", "w", ".", "window", "=", "gocv", ".", "NewWindow", "(", "w...
// NewWindowDriver creates a new window driver. // It adds an start function to initialize window
[ "NewWindowDriver", "creates", "a", "new", "window", "driver", ".", "It", "adds", "an", "start", "function", "to", "initialize", "window" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/opencv/window_driver.go#L21-L28
156,122
hybridgroup/gobot
platforms/opencv/window_driver.go
ShowImage
func (w *WindowDriver) ShowImage(img gocv.Mat) { w.window.IMShow(img) }
go
func (w *WindowDriver) ShowImage(img gocv.Mat) { w.window.IMShow(img) }
[ "func", "(", "w", "*", "WindowDriver", ")", "ShowImage", "(", "img", "gocv", ".", "Mat", ")", "{", "w", ".", "window", ".", "IMShow", "(", "img", ")", "\n", "}" ]
// ShowImage displays image in window
[ "ShowImage", "displays", "image", "in", "window" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/opencv/window_driver.go#L49-L51
156,123
hybridgroup/gobot
commander.go
Command
func (c *commander) Command(name string) (command func(map[string]interface{}) interface{}) { command, _ = c.commands[name] return }
go
func (c *commander) Command(name string) (command func(map[string]interface{}) interface{}) { command, _ = c.commands[name] return }
[ "func", "(", "c", "*", "commander", ")", "Command", "(", "name", "string", ")", "(", "command", "func", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "interface", "{", "}", ")", "{", "command", ",", "_", "=", "c", ".", "commands", "...
// Command returns the command interface whene passed a valid command name
[ "Command", "returns", "the", "command", "interface", "whene", "passed", "a", "valid", "command", "name" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/commander.go#L26-L29
156,124
hybridgroup/gobot
commander.go
AddCommand
func (c *commander) AddCommand(name string, command func(map[string]interface{}) interface{}) { c.commands[name] = command }
go
func (c *commander) AddCommand(name string, command func(map[string]interface{}) interface{}) { c.commands[name] = command }
[ "func", "(", "c", "*", "commander", ")", "AddCommand", "(", "name", "string", ",", "command", "func", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "interface", "{", "}", ")", "{", "c", ".", "commands", "[", "name", "]", "=", "command...
// AddCommand adds a new command, when passed a command name and the command interface.
[ "AddCommand", "adds", "a", "new", "command", "when", "passed", "a", "command", "name", "and", "the", "command", "interface", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/commander.go#L37-L39
156,125
hybridgroup/gobot
platforms/ble/serial_port.go
NewSerialPort
func NewSerialPort(address string, rid string, tid string) *SerialPort { return &SerialPort{address: address, rid: rid, tid: tid} }
go
func NewSerialPort(address string, rid string, tid string) *SerialPort { return &SerialPort{address: address, rid: rid, tid: tid} }
[ "func", "NewSerialPort", "(", "address", "string", ",", "rid", "string", ",", "tid", "string", ")", "*", "SerialPort", "{", "return", "&", "SerialPort", "{", "address", ":", "address", ",", "rid", ":", "rid", ",", "tid", ":", "tid", "}", "\n", "}" ]
// NewSerialPort returns a new serial over Bluetooth LE connection
[ "NewSerialPort", "returns", "a", "new", "serial", "over", "Bluetooth", "LE", "connection" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/serial_port.go#L19-L21
156,126
hybridgroup/gobot
platforms/ble/serial_port.go
Open
func (p *SerialPort) Open() (err error) { p.client = NewClientAdaptor(p.address) err = p.client.Connect() // subscribe to response notifications p.client.Subscribe(p.rid, func(data []byte, e error) { p.responseMutex.Lock() p.responseData = append(p.responseData, data...) p.responseMutex.Unlock() }) return }
go
func (p *SerialPort) Open() (err error) { p.client = NewClientAdaptor(p.address) err = p.client.Connect() // subscribe to response notifications p.client.Subscribe(p.rid, func(data []byte, e error) { p.responseMutex.Lock() p.responseData = append(p.responseData, data...) p.responseMutex.Unlock() }) return }
[ "func", "(", "p", "*", "SerialPort", ")", "Open", "(", ")", "(", "err", "error", ")", "{", "p", ".", "client", "=", "NewClientAdaptor", "(", "p", ".", "address", ")", "\n\n", "err", "=", "p", ".", "client", ".", "Connect", "(", ")", "\n\n", "// s...
// Open opens a connection to a BLE serial device
[ "Open", "opens", "a", "connection", "to", "a", "BLE", "serial", "device" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/serial_port.go#L24-L36
156,127
hybridgroup/gobot
platforms/ble/serial_port.go
Read
func (p *SerialPort) Read(b []byte) (n int, err error) { if len(p.responseData) == 0 { return } p.responseMutex.Lock() n = len(b) if len(p.responseData) < n { n = len(p.responseData) } copy(b, p.responseData[:n]) if len(p.responseData) > n { p.responseData = p.responseData[n:] } else { p.responseData = nil } p.responseMutex.Unlock() return }
go
func (p *SerialPort) Read(b []byte) (n int, err error) { if len(p.responseData) == 0 { return } p.responseMutex.Lock() n = len(b) if len(p.responseData) < n { n = len(p.responseData) } copy(b, p.responseData[:n]) if len(p.responseData) > n { p.responseData = p.responseData[n:] } else { p.responseData = nil } p.responseMutex.Unlock() return }
[ "func", "(", "p", "*", "SerialPort", ")", "Read", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "if", "len", "(", "p", ".", "responseData", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "p", ".", "respon...
// Read reads bytes from BLE serial port connection
[ "Read", "reads", "bytes", "from", "BLE", "serial", "port", "connection" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/serial_port.go#L39-L59
156,128
hybridgroup/gobot
platforms/ble/serial_port.go
Write
func (p *SerialPort) Write(b []byte) (n int, err error) { err = p.client.WriteCharacteristic(p.tid, b) n = len(b) return }
go
func (p *SerialPort) Write(b []byte) (n int, err error) { err = p.client.WriteCharacteristic(p.tid, b) n = len(b) return }
[ "func", "(", "p", "*", "SerialPort", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "err", "=", "p", ".", "client", ".", "WriteCharacteristic", "(", "p", ".", "tid", ",", "b", ")", "\n", "n", "=...
// Write writes to the BLE serial port connection
[ "Write", "writes", "to", "the", "BLE", "serial", "port", "connection" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/ble/serial_port.go#L62-L66
156,129
hybridgroup/gobot
drivers/spi/mcp3004.go
Start
func (d *MCP3004Driver) Start() (err error) { bus := d.GetBusOrDefault(d.connector.GetSpiDefaultBus()) chip := d.GetChipOrDefault(d.connector.GetSpiDefaultChip()) mode := d.GetModeOrDefault(d.connector.GetSpiDefaultMode()) bits := d.GetBitsOrDefault(d.connector.GetSpiDefaultBits()) maxSpeed := d.GetSpeedOrDefault(d.connector.GetSpiDefaultMaxSpeed()) d.connection, err = d.connector.GetSpiConnection(bus, chip, mode, bits, maxSpeed) if err != nil { return err } return nil }
go
func (d *MCP3004Driver) Start() (err error) { bus := d.GetBusOrDefault(d.connector.GetSpiDefaultBus()) chip := d.GetChipOrDefault(d.connector.GetSpiDefaultChip()) mode := d.GetModeOrDefault(d.connector.GetSpiDefaultMode()) bits := d.GetBitsOrDefault(d.connector.GetSpiDefaultBits()) maxSpeed := d.GetSpeedOrDefault(d.connector.GetSpiDefaultMaxSpeed()) d.connection, err = d.connector.GetSpiConnection(bus, chip, mode, bits, maxSpeed) if err != nil { return err } return nil }
[ "func", "(", "d", "*", "MCP3004Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "d", ".", "GetBusOrDefault", "(", "d", ".", "connector", ".", "GetSpiDefaultBus", "(", ")", ")", "\n", "chip", ":=", "d", ".", "GetChipOrDefau...
// Start initializes the driver.
[ "Start", "initializes", "the", "driver", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/mcp3004.go#L56-L68
156,130
hybridgroup/gobot
drivers/spi/mcp3004.go
Read
func (d *MCP3004Driver) Read(channel int) (result int, err error) { if channel < 0 || channel > MCP3004DriverMaxChannel-1 { return 0, errors.New("Invalid channel for read") } tx := make([]byte, 3) tx[0] = 0x01 tx[1] = byte(8+channel) << 4 tx[2] = 0x00 rx := make([]byte, 3) err = d.connection.Tx(tx, rx) if err == nil && len(rx) == 3 { result = int((rx[1]&0x3))<<8 + int(rx[2]) } return result, err }
go
func (d *MCP3004Driver) Read(channel int) (result int, err error) { if channel < 0 || channel > MCP3004DriverMaxChannel-1 { return 0, errors.New("Invalid channel for read") } tx := make([]byte, 3) tx[0] = 0x01 tx[1] = byte(8+channel) << 4 tx[2] = 0x00 rx := make([]byte, 3) err = d.connection.Tx(tx, rx) if err == nil && len(rx) == 3 { result = int((rx[1]&0x3))<<8 + int(rx[2]) } return result, err }
[ "func", "(", "d", "*", "MCP3004Driver", ")", "Read", "(", "channel", "int", ")", "(", "result", "int", ",", "err", "error", ")", "{", "if", "channel", "<", "0", "||", "channel", ">", "MCP3004DriverMaxChannel", "-", "1", "{", "return", "0", ",", "erro...
// Read reads the current analog data for the desired channel.
[ "Read", "reads", "the", "current", "analog", "data", "for", "the", "desired", "channel", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/mcp3004.go#L77-L95
156,131
hybridgroup/gobot
sysfs/i2c_device.go
NewI2cDevice
func NewI2cDevice(location string) (d *i2cDevice, err error) { d = &i2cDevice{} if d.file, err = OpenFile(location, os.O_RDWR, os.ModeExclusive); err != nil { return } if err = d.queryFunctionality(); err != nil { return } return }
go
func NewI2cDevice(location string) (d *i2cDevice, err error) { d = &i2cDevice{} if d.file, err = OpenFile(location, os.O_RDWR, os.ModeExclusive); err != nil { return } if err = d.queryFunctionality(); err != nil { return } return }
[ "func", "NewI2cDevice", "(", "location", "string", ")", "(", "d", "*", "i2cDevice", ",", "err", "error", ")", "{", "d", "=", "&", "i2cDevice", "{", "}", "\n\n", "if", "d", ".", "file", ",", "err", "=", "OpenFile", "(", "location", ",", "os", ".", ...
// NewI2cDevice returns an io.ReadWriteCloser with the proper ioctrl given // an i2c bus location.
[ "NewI2cDevice", "returns", "an", "io", ".", "ReadWriteCloser", "with", "the", "proper", "ioctrl", "given", "an", "i2c", "bus", "location", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/i2c_device.go#L55-L66
156,132
hybridgroup/gobot
sysfs/i2c_device.go
Write
func (d *i2cDevice) Write(b []byte) (n int, err error) { return d.file.Write(b) }
go
func (d *i2cDevice) Write(b []byte) (n int, err error) { return d.file.Write(b) }
[ "func", "(", "d", "*", "i2cDevice", ")", "Write", "(", "b", "[", "]", "byte", ")", "(", "n", "int", ",", "err", "error", ")", "{", "return", "d", ".", "file", ".", "Write", "(", "b", ")", "\n", "}" ]
// Write implements the io.ReadWriteCloser method by direct I2C write operations.
[ "Write", "implements", "the", "io", ".", "ReadWriteCloser", "method", "by", "direct", "I2C", "write", "operations", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/i2c_device.go#L188-L190
156,133
hybridgroup/gobot
platforms/parrot/bebop/bebop_adaptor.go
NewAdaptor
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Bebop"), drone: client.New(), connect: func(a *Adaptor) error { return a.drone.Connect() }, } }
go
func NewAdaptor() *Adaptor { return &Adaptor{ name: gobot.DefaultName("Bebop"), drone: client.New(), connect: func(a *Adaptor) error { return a.drone.Connect() }, } }
[ "func", "NewAdaptor", "(", ")", "*", "Adaptor", "{", "return", "&", "Adaptor", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "drone", ":", "client", ".", "New", "(", ")", ",", "connect", ":", "func", "(", "a", "*", "Ad...
// NewAdaptor returns a new BebopAdaptor
[ "NewAdaptor", "returns", "a", "new", "BebopAdaptor" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/bebop/bebop_adaptor.go#L39-L47
156,134
hybridgroup/gobot
platforms/firmata/firmata_i2c.go
NewFirmataI2cConnection
func NewFirmataI2cConnection(adaptor *Adaptor, address int) (connection *firmataI2cConnection) { return &firmataI2cConnection{adaptor: adaptor, address: address} }
go
func NewFirmataI2cConnection(adaptor *Adaptor, address int) (connection *firmataI2cConnection) { return &firmataI2cConnection{adaptor: adaptor, address: address} }
[ "func", "NewFirmataI2cConnection", "(", "adaptor", "*", "Adaptor", ",", "address", "int", ")", "(", "connection", "*", "firmataI2cConnection", ")", "{", "return", "&", "firmataI2cConnection", "{", "adaptor", ":", "adaptor", ",", "address", ":", "address", "}", ...
// NewFirmataI2cConnection creates an I2C connection to an I2C device at // the specified address
[ "NewFirmataI2cConnection", "creates", "an", "I2C", "connection", "to", "an", "I2C", "device", "at", "the", "specified", "address" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/firmata/firmata_i2c.go#L15-L17
156,135
hybridgroup/gobot
drivers/i2c/lidarlite_driver.go
Start
func (h *LIDARLiteDriver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) address := h.GetAddressOrDefault(lidarliteAddress) h.connection, err = h.connector.GetConnection(address, bus) if err != nil { return err } return }
go
func (h *LIDARLiteDriver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) address := h.GetAddressOrDefault(lidarliteAddress) h.connection, err = h.connector.GetConnection(address, bus) if err != nil { return err } return }
[ "func", "(", "h", "*", "LIDARLiteDriver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "h", ".", "GetBusOrDefault", "(", "h", ".", "connector", ".", "GetDefaultBus", "(", ")", ")", "\n", "address", ":=", "h", ".", "GetAddressOr...
// Start initialized the LIDAR
[ "Start", "initialized", "the", "LIDAR" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/lidarlite_driver.go#L53-L62
156,136
hybridgroup/gobot
drivers/i2c/lidarlite_driver.go
Distance
func (h *LIDARLiteDriver) Distance() (distance int, err error) { if _, err = h.connection.Write([]byte{0x00, 0x04}); err != nil { return } time.Sleep(20 * time.Millisecond) if _, err = h.connection.Write([]byte{0x0F}); err != nil { return } upper := []byte{0} bytesRead, err := h.connection.Read(upper) if err != nil { return } if bytesRead != 1 { err = ErrNotEnoughBytes return } if _, err = h.connection.Write([]byte{0x10}); err != nil { return } lower := []byte{0} bytesRead, err = h.connection.Read(lower) if err != nil { return } if bytesRead != 1 { err = ErrNotEnoughBytes return } distance = ((int(upper[0]) & 0xff) << 8) | (int(lower[0]) & 0xff) return }
go
func (h *LIDARLiteDriver) Distance() (distance int, err error) { if _, err = h.connection.Write([]byte{0x00, 0x04}); err != nil { return } time.Sleep(20 * time.Millisecond) if _, err = h.connection.Write([]byte{0x0F}); err != nil { return } upper := []byte{0} bytesRead, err := h.connection.Read(upper) if err != nil { return } if bytesRead != 1 { err = ErrNotEnoughBytes return } if _, err = h.connection.Write([]byte{0x10}); err != nil { return } lower := []byte{0} bytesRead, err = h.connection.Read(lower) if err != nil { return } if bytesRead != 1 { err = ErrNotEnoughBytes return } distance = ((int(upper[0]) & 0xff) << 8) | (int(lower[0]) & 0xff) return }
[ "func", "(", "h", "*", "LIDARLiteDriver", ")", "Distance", "(", ")", "(", "distance", "int", ",", "err", "error", ")", "{", "if", "_", ",", "err", "=", "h", ".", "connection", ".", "Write", "(", "[", "]", "byte", "{", "0x00", ",", "0x04", "}", ...
// Distance returns the current distance in cm
[ "Distance", "returns", "the", "current", "distance", "in", "cm" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/lidarlite_driver.go#L68-L107
156,137
hybridgroup/gobot
platforms/mqtt/mqtt_adaptor.go
NewAdaptor
func NewAdaptor(host string, clientID string) *Adaptor { return &Adaptor{ name: gobot.DefaultName("MQTT"), Host: host, autoReconnect: false, cleanSession: true, useSSL: false, clientID: clientID, } }
go
func NewAdaptor(host string, clientID string) *Adaptor { return &Adaptor{ name: gobot.DefaultName("MQTT"), Host: host, autoReconnect: false, cleanSession: true, useSSL: false, clientID: clientID, } }
[ "func", "NewAdaptor", "(", "host", "string", ",", "clientID", "string", ")", "*", "Adaptor", "{", "return", "&", "Adaptor", "{", "name", ":", "gobot", ".", "DefaultName", "(", "\"", "\"", ")", ",", "Host", ":", "host", ",", "autoReconnect", ":", "false...
// NewAdaptor creates a new mqtt adaptor with specified host and client id
[ "NewAdaptor", "creates", "a", "new", "mqtt", "adaptor", "with", "specified", "host", "and", "client", "id" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mqtt/mqtt_adaptor.go#L34-L43
156,138
hybridgroup/gobot
platforms/mqtt/mqtt_adaptor.go
NewAdaptorWithAuth
func NewAdaptorWithAuth(host, clientID, username, password string) *Adaptor { return &Adaptor{ name: "MQTT", Host: host, autoReconnect: false, cleanSession: true, useSSL: false, clientID: clientID, username: username, password: password, } }
go
func NewAdaptorWithAuth(host, clientID, username, password string) *Adaptor { return &Adaptor{ name: "MQTT", Host: host, autoReconnect: false, cleanSession: true, useSSL: false, clientID: clientID, username: username, password: password, } }
[ "func", "NewAdaptorWithAuth", "(", "host", ",", "clientID", ",", "username", ",", "password", "string", ")", "*", "Adaptor", "{", "return", "&", "Adaptor", "{", "name", ":", "\"", "\"", ",", "Host", ":", "host", ",", "autoReconnect", ":", "false", ",", ...
// NewAdaptorWithAuth creates a new mqtt adaptor with specified host, client id, username, and password.
[ "NewAdaptorWithAuth", "creates", "a", "new", "mqtt", "adaptor", "with", "specified", "host", "client", "id", "username", "and", "password", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mqtt/mqtt_adaptor.go#L46-L57
156,139
hybridgroup/gobot
platforms/mqtt/mqtt_adaptor.go
Connect
func (a *Adaptor) Connect() (err error) { a.client = paho.NewClient(a.createClientOptions()) if token := a.client.Connect(); token.Wait() && token.Error() != nil { err = multierror.Append(err, token.Error()) } return }
go
func (a *Adaptor) Connect() (err error) { a.client = paho.NewClient(a.createClientOptions()) if token := a.client.Connect(); token.Wait() && token.Error() != nil { err = multierror.Append(err, token.Error()) } return }
[ "func", "(", "a", "*", "Adaptor", ")", "Connect", "(", ")", "(", "err", "error", ")", "{", "a", ".", "client", "=", "paho", ".", "NewClient", "(", "a", ".", "createClientOptions", "(", ")", ")", "\n", "if", "token", ":=", "a", ".", "client", ".",...
// Connect returns true if connection to mqtt is established
[ "Connect", "returns", "true", "if", "connection", "to", "mqtt", "is", "established" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mqtt/mqtt_adaptor.go#L105-L112
156,140
hybridgroup/gobot
platforms/mqtt/mqtt_adaptor.go
Disconnect
func (a *Adaptor) Disconnect() (err error) { if a.client != nil { a.client.Disconnect(500) } return }
go
func (a *Adaptor) Disconnect() (err error) { if a.client != nil { a.client.Disconnect(500) } return }
[ "func", "(", "a", "*", "Adaptor", ")", "Disconnect", "(", ")", "(", "err", "error", ")", "{", "if", "a", ".", "client", "!=", "nil", "{", "a", ".", "client", ".", "Disconnect", "(", "500", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Disconnect returns true if connection to mqtt is closed
[ "Disconnect", "returns", "true", "if", "connection", "to", "mqtt", "is", "closed" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mqtt/mqtt_adaptor.go#L115-L120
156,141
hybridgroup/gobot
platforms/mqtt/mqtt_adaptor.go
On
func (a *Adaptor) On(event string, f func(msg Message)) bool { if a.client == nil { return false } a.client.Subscribe(event, 0, func(client paho.Client, msg paho.Message) { f(msg) }) return true }
go
func (a *Adaptor) On(event string, f func(msg Message)) bool { if a.client == nil { return false } a.client.Subscribe(event, 0, func(client paho.Client, msg paho.Message) { f(msg) }) return true }
[ "func", "(", "a", "*", "Adaptor", ")", "On", "(", "event", "string", ",", "f", "func", "(", "msg", "Message", ")", ")", "bool", "{", "if", "a", ".", "client", "==", "nil", "{", "return", "false", "\n", "}", "\n", "a", ".", "client", ".", "Subsc...
// On subscribes to a topic, and then calls the message handler function when data is received
[ "On", "subscribes", "to", "a", "topic", "and", "then", "calls", "the", "message", "handler", "function", "when", "data", "is", "received" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mqtt/mqtt_adaptor.go#L138-L146
156,142
hybridgroup/gobot
platforms/mqtt/mqtt_adaptor.go
newTLSConfig
func (a *Adaptor) newTLSConfig() *tls.Config { // Import server certificate var certpool *x509.CertPool if len(a.ServerCert()) > 0 { certpool = x509.NewCertPool() pemCerts, err := ioutil.ReadFile(a.ServerCert()) if err == nil { certpool.AppendCertsFromPEM(pemCerts) } } // Import client certificate/key pair var certs []tls.Certificate if len(a.ClientCert()) > 0 && len(a.ClientKey()) > 0 { cert, err := tls.LoadX509KeyPair(a.ClientCert(), a.ClientKey()) if err != nil { // TODO: proper error handling panic(err) } certs = append(certs, cert) } // Create tls.Config with desired tls properties return &tls.Config{ // RootCAs = certs used to verify server cert. RootCAs: certpool, // ClientAuth = whether to request cert from server. // Since the server is set up for SSL, this happens // anyways. ClientAuth: tls.NoClientCert, // ClientCAs = certs used to validate client cert. ClientCAs: nil, // InsecureSkipVerify = verify that cert contents // match server. IP matches what is in cert etc. InsecureSkipVerify: true, // Certificates = list of certs client sends to server. Certificates: certs, } }
go
func (a *Adaptor) newTLSConfig() *tls.Config { // Import server certificate var certpool *x509.CertPool if len(a.ServerCert()) > 0 { certpool = x509.NewCertPool() pemCerts, err := ioutil.ReadFile(a.ServerCert()) if err == nil { certpool.AppendCertsFromPEM(pemCerts) } } // Import client certificate/key pair var certs []tls.Certificate if len(a.ClientCert()) > 0 && len(a.ClientKey()) > 0 { cert, err := tls.LoadX509KeyPair(a.ClientCert(), a.ClientKey()) if err != nil { // TODO: proper error handling panic(err) } certs = append(certs, cert) } // Create tls.Config with desired tls properties return &tls.Config{ // RootCAs = certs used to verify server cert. RootCAs: certpool, // ClientAuth = whether to request cert from server. // Since the server is set up for SSL, this happens // anyways. ClientAuth: tls.NoClientCert, // ClientCAs = certs used to validate client cert. ClientCAs: nil, // InsecureSkipVerify = verify that cert contents // match server. IP matches what is in cert etc. InsecureSkipVerify: true, // Certificates = list of certs client sends to server. Certificates: certs, } }
[ "func", "(", "a", "*", "Adaptor", ")", "newTLSConfig", "(", ")", "*", "tls", ".", "Config", "{", "// Import server certificate", "var", "certpool", "*", "x509", ".", "CertPool", "\n", "if", "len", "(", "a", ".", "ServerCert", "(", ")", ")", ">", "0", ...
// newTLSConfig sets the TLS config in the case that we are using // an MQTT broker with TLS
[ "newTLSConfig", "sets", "the", "TLS", "config", "in", "the", "case", "that", "we", "are", "using", "an", "MQTT", "broker", "with", "TLS" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/mqtt/mqtt_adaptor.go#L167-L205
156,143
hybridgroup/gobot
drivers/i2c/jhd1313m1_driver.go
Start
func (h *JHD1313M1Driver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) if h.lcdConnection, err = h.connector.GetConnection(h.lcdAddress, bus); err != nil { return err } if h.rgbConnection, err = h.connector.GetConnection(h.rgbAddress, bus); err != nil { return err } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 time.Sleep(50 * time.Millisecond) // this is according to the hitachi HD44780 datasheet // page 45 figure 23 // Send function set command sequence init_payload := []byte{LCD_CMD, LCD_FUNCTIONSET | LCD_2LINE} if _, err := h.lcdConnection.Write(init_payload); err != nil { return err } // wait more than 4.1ms time.Sleep(4500 * time.Microsecond) // second try if _, err := h.lcdConnection.Write(init_payload); err != nil { return err } time.Sleep(150 * time.Microsecond) // third go if _, err := h.lcdConnection.Write(init_payload); err != nil { return err } if _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_DISPLAYCONTROL | LCD_DISPLAYON}); err != nil { return err } time.Sleep(100 * time.Microsecond) if err := h.Clear(); err != nil { return err } if _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT}); err != nil { return err } if err := h.setReg(0, 0); err != nil { return err } if err := h.setReg(1, 0); err != nil { return err } if err := h.setReg(0x08, 0xAA); err != nil { return err } if err := h.SetRGB(255, 255, 255); err != nil { return err } return nil }
go
func (h *JHD1313M1Driver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) if h.lcdConnection, err = h.connector.GetConnection(h.lcdAddress, bus); err != nil { return err } if h.rgbConnection, err = h.connector.GetConnection(h.rgbAddress, bus); err != nil { return err } // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! // according to datasheet, we need at least 40ms after power rises above 2.7V // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 time.Sleep(50 * time.Millisecond) // this is according to the hitachi HD44780 datasheet // page 45 figure 23 // Send function set command sequence init_payload := []byte{LCD_CMD, LCD_FUNCTIONSET | LCD_2LINE} if _, err := h.lcdConnection.Write(init_payload); err != nil { return err } // wait more than 4.1ms time.Sleep(4500 * time.Microsecond) // second try if _, err := h.lcdConnection.Write(init_payload); err != nil { return err } time.Sleep(150 * time.Microsecond) // third go if _, err := h.lcdConnection.Write(init_payload); err != nil { return err } if _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_DISPLAYCONTROL | LCD_DISPLAYON}); err != nil { return err } time.Sleep(100 * time.Microsecond) if err := h.Clear(); err != nil { return err } if _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_ENTRYMODESET | LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT}); err != nil { return err } if err := h.setReg(0, 0); err != nil { return err } if err := h.setReg(1, 0); err != nil { return err } if err := h.setReg(0x08, 0xAA); err != nil { return err } if err := h.SetRGB(255, 255, 255); err != nil { return err } return nil }
[ "func", "(", "h", "*", "JHD1313M1Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "h", ".", "GetBusOrDefault", "(", "h", ".", "connector", ".", "GetDefaultBus", "(", ")", ")", "\n\n", "if", "h", ".", "lcdConnection", ",", ...
// Start starts the backlit and the screen and initializes the states.
[ "Start", "starts", "the", "backlit", "and", "the", "screen", "and", "initializes", "the", "states", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/jhd1313m1_driver.go#L146-L211
156,144
hybridgroup/gobot
drivers/i2c/jhd1313m1_driver.go
SetRGB
func (h *JHD1313M1Driver) SetRGB(r, g, b int) error { if err := h.setReg(REG_RED, r); err != nil { return err } if err := h.setReg(REG_GREEN, g); err != nil { return err } return h.setReg(REG_BLUE, b) }
go
func (h *JHD1313M1Driver) SetRGB(r, g, b int) error { if err := h.setReg(REG_RED, r); err != nil { return err } if err := h.setReg(REG_GREEN, g); err != nil { return err } return h.setReg(REG_BLUE, b) }
[ "func", "(", "h", "*", "JHD1313M1Driver", ")", "SetRGB", "(", "r", ",", "g", ",", "b", "int", ")", "error", "{", "if", "err", ":=", "h", ".", "setReg", "(", "REG_RED", ",", "r", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "...
// SetRGB sets the Red Green Blue value of backlit.
[ "SetRGB", "sets", "the", "Red", "Green", "Blue", "value", "of", "backlit", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/jhd1313m1_driver.go#L214-L222
156,145
hybridgroup/gobot
drivers/i2c/jhd1313m1_driver.go
Clear
func (h *JHD1313M1Driver) Clear() error { err := h.command([]byte{LCD_CLEARDISPLAY}) return err }
go
func (h *JHD1313M1Driver) Clear() error { err := h.command([]byte{LCD_CLEARDISPLAY}) return err }
[ "func", "(", "h", "*", "JHD1313M1Driver", ")", "Clear", "(", ")", "error", "{", "err", ":=", "h", ".", "command", "(", "[", "]", "byte", "{", "LCD_CLEARDISPLAY", "}", ")", "\n", "return", "err", "\n", "}" ]
// Clear clears the text on the lCD display.
[ "Clear", "clears", "the", "text", "on", "the", "lCD", "display", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/jhd1313m1_driver.go#L225-L228
156,146
hybridgroup/gobot
drivers/i2c/jhd1313m1_driver.go
Home
func (h *JHD1313M1Driver) Home() error { err := h.command([]byte{LCD_RETURNHOME}) // This wait fixes a race condition when calling home and clear back to back. time.Sleep(2 * time.Millisecond) return err }
go
func (h *JHD1313M1Driver) Home() error { err := h.command([]byte{LCD_RETURNHOME}) // This wait fixes a race condition when calling home and clear back to back. time.Sleep(2 * time.Millisecond) return err }
[ "func", "(", "h", "*", "JHD1313M1Driver", ")", "Home", "(", ")", "error", "{", "err", ":=", "h", ".", "command", "(", "[", "]", "byte", "{", "LCD_RETURNHOME", "}", ")", "\n", "// This wait fixes a race condition when calling home and clear back to back.", "time", ...
// Home sets the cursor to the origin position on the display.
[ "Home", "sets", "the", "cursor", "to", "the", "origin", "position", "on", "the", "display", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/jhd1313m1_driver.go#L231-L236
156,147
hybridgroup/gobot
drivers/i2c/jhd1313m1_driver.go
Write
func (h *JHD1313M1Driver) Write(message string) error { // This wait fixes an odd bug where the clear function doesn't always work properly. time.Sleep(1 * time.Millisecond) for _, val := range message { if val == '\n' { if err := h.SetPosition(16); err != nil { return err } continue } if _, err := h.lcdConnection.Write([]byte{LCD_DATA, byte(val)}); err != nil { return err } } return nil }
go
func (h *JHD1313M1Driver) Write(message string) error { // This wait fixes an odd bug where the clear function doesn't always work properly. time.Sleep(1 * time.Millisecond) for _, val := range message { if val == '\n' { if err := h.SetPosition(16); err != nil { return err } continue } if _, err := h.lcdConnection.Write([]byte{LCD_DATA, byte(val)}); err != nil { return err } } return nil }
[ "func", "(", "h", "*", "JHD1313M1Driver", ")", "Write", "(", "message", "string", ")", "error", "{", "// This wait fixes an odd bug where the clear function doesn't always work properly.", "time", ".", "Sleep", "(", "1", "*", "time", ".", "Millisecond", ")", "\n", "...
// Write displays the passed message on the screen.
[ "Write", "displays", "the", "passed", "message", "on", "the", "screen", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/jhd1313m1_driver.go#L239-L254
156,148
hybridgroup/gobot
drivers/i2c/jhd1313m1_driver.go
SetPosition
func (h *JHD1313M1Driver) SetPosition(pos int) (err error) { if pos < 0 || pos > 31 { err = ErrInvalidPosition return } offset := byte(pos) if pos >= 16 { offset -= 16 offset |= LCD_2NDLINEOFFSET } err = h.command([]byte{LCD_SETDDRAMADDR | offset}) return }
go
func (h *JHD1313M1Driver) SetPosition(pos int) (err error) { if pos < 0 || pos > 31 { err = ErrInvalidPosition return } offset := byte(pos) if pos >= 16 { offset -= 16 offset |= LCD_2NDLINEOFFSET } err = h.command([]byte{LCD_SETDDRAMADDR | offset}) return }
[ "func", "(", "h", "*", "JHD1313M1Driver", ")", "SetPosition", "(", "pos", "int", ")", "(", "err", "error", ")", "{", "if", "pos", "<", "0", "||", "pos", ">", "31", "{", "err", "=", "ErrInvalidPosition", "\n", "return", "\n", "}", "\n", "offset", ":...
// SetPosition sets the cursor and the data display to pos. // 0..15 are the positions in the first display line. // 16..32 are the positions in the second display line.
[ "SetPosition", "sets", "the", "cursor", "and", "the", "data", "display", "to", "pos", ".", "0", "..", "15", "are", "the", "positions", "in", "the", "first", "display", "line", ".", "16", "..", "32", "are", "the", "positions", "in", "the", "second", "di...
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/jhd1313m1_driver.go#L259-L271
156,149
hybridgroup/gobot
drivers/i2c/jhd1313m1_driver.go
Scroll
func (h *JHD1313M1Driver) Scroll(lr bool) error { if lr { _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT}) return err } _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT}) return err }
go
func (h *JHD1313M1Driver) Scroll(lr bool) error { if lr { _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT}) return err } _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT}) return err }
[ "func", "(", "h", "*", "JHD1313M1Driver", ")", "Scroll", "(", "lr", "bool", ")", "error", "{", "if", "lr", "{", "_", ",", "err", ":=", "h", ".", "lcdConnection", ".", "Write", "(", "[", "]", "byte", "{", "LCD_CMD", ",", "LCD_CURSORSHIFT", "|", "LCD...
// Scroll sets the scrolling direction for the display, either left to right, or // right to left.
[ "Scroll", "sets", "the", "scrolling", "direction", "for", "the", "display", "either", "left", "to", "right", "or", "right", "to", "left", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/jhd1313m1_driver.go#L275-L283
156,150
hybridgroup/gobot
platforms/neurosky/neurosky_driver.go
Start
func (n *Driver) Start() (err error) { go func() { for { buff := make([]byte, 1024) _, err := n.adaptor().sp.Read(buff[:]) if err != nil { n.Publish(n.Event("error"), err) } else { n.parse(bytes.NewBuffer(buff)) } } }() return }
go
func (n *Driver) Start() (err error) { go func() { for { buff := make([]byte, 1024) _, err := n.adaptor().sp.Read(buff[:]) if err != nil { n.Publish(n.Event("error"), err) } else { n.parse(bytes.NewBuffer(buff)) } } }() return }
[ "func", "(", "n", "*", "Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "go", "func", "(", ")", "{", "for", "{", "buff", ":=", "make", "(", "[", "]", "byte", ",", "1024", ")", "\n", "_", ",", "err", ":=", "n", ".", "adaptor"...
// Start creates a go routine to listen from serial port // and parse buffer readings
[ "Start", "creates", "a", "go", "routine", "to", "listen", "from", "serial", "port", "and", "parse", "buffer", "readings" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/neurosky/neurosky_driver.go#L123-L136
156,151
hybridgroup/gobot
platforms/neurosky/neurosky_driver.go
parse
func (n *Driver) parse(buf *bytes.Buffer) { for buf.Len() > 2 { b1, _ := buf.ReadByte() b2, _ := buf.ReadByte() if b1 == BTSync && b2 == BTSync { length, _ := buf.ReadByte() payload := make([]byte, length) buf.Read(payload) //checksum, _ := buf.ReadByte() buf.Next(1) n.parsePacket(bytes.NewBuffer(payload)) } } }
go
func (n *Driver) parse(buf *bytes.Buffer) { for buf.Len() > 2 { b1, _ := buf.ReadByte() b2, _ := buf.ReadByte() if b1 == BTSync && b2 == BTSync { length, _ := buf.ReadByte() payload := make([]byte, length) buf.Read(payload) //checksum, _ := buf.ReadByte() buf.Next(1) n.parsePacket(bytes.NewBuffer(payload)) } } }
[ "func", "(", "n", "*", "Driver", ")", "parse", "(", "buf", "*", "bytes", ".", "Buffer", ")", "{", "for", "buf", ".", "Len", "(", ")", ">", "2", "{", "b1", ",", "_", ":=", "buf", ".", "ReadByte", "(", ")", "\n", "b2", ",", "_", ":=", "buf", ...
// parse converts bytes buffer into packets until no more data is present
[ "parse", "converts", "bytes", "buffer", "into", "packets", "until", "no", "more", "data", "is", "present" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/neurosky/neurosky_driver.go#L142-L155
156,152
hybridgroup/gobot
platforms/neurosky/neurosky_driver.go
parsePacket
func (n *Driver) parsePacket(buf *bytes.Buffer) { for buf.Len() > 0 { b, _ := buf.ReadByte() switch b { case CodeEx: n.Publish(n.Event("extended"), nil) case CodeSignalQuality: ret, _ := buf.ReadByte() n.Publish(n.Event("signal"), ret) case CodeAttention: ret, _ := buf.ReadByte() n.Publish(n.Event("attention"), ret) case CodeMeditation: ret, _ := buf.ReadByte() n.Publish(n.Event("meditation"), ret) case CodeBlink: ret, _ := buf.ReadByte() n.Publish(n.Event("blink"), ret) case CodeWave: buf.Next(1) var ret = make([]byte, 2) buf.Read(ret) n.Publish(n.Event("wave"), int16(ret[0])<<8|int16(ret[1])) case CodeAsicEEG: ret := make([]byte, 25) i, _ := buf.Read(ret) if i == 25 { n.Publish(n.Event("eeg"), n.parseEEG(ret)) } } } }
go
func (n *Driver) parsePacket(buf *bytes.Buffer) { for buf.Len() > 0 { b, _ := buf.ReadByte() switch b { case CodeEx: n.Publish(n.Event("extended"), nil) case CodeSignalQuality: ret, _ := buf.ReadByte() n.Publish(n.Event("signal"), ret) case CodeAttention: ret, _ := buf.ReadByte() n.Publish(n.Event("attention"), ret) case CodeMeditation: ret, _ := buf.ReadByte() n.Publish(n.Event("meditation"), ret) case CodeBlink: ret, _ := buf.ReadByte() n.Publish(n.Event("blink"), ret) case CodeWave: buf.Next(1) var ret = make([]byte, 2) buf.Read(ret) n.Publish(n.Event("wave"), int16(ret[0])<<8|int16(ret[1])) case CodeAsicEEG: ret := make([]byte, 25) i, _ := buf.Read(ret) if i == 25 { n.Publish(n.Event("eeg"), n.parseEEG(ret)) } } } }
[ "func", "(", "n", "*", "Driver", ")", "parsePacket", "(", "buf", "*", "bytes", ".", "Buffer", ")", "{", "for", "buf", ".", "Len", "(", ")", ">", "0", "{", "b", ",", "_", ":=", "buf", ".", "ReadByte", "(", ")", "\n", "switch", "b", "{", "case"...
// parsePacket publishes event according to data parsed
[ "parsePacket", "publishes", "event", "according", "to", "data", "parsed" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/neurosky/neurosky_driver.go#L158-L189
156,153
hybridgroup/gobot
platforms/neurosky/neurosky_driver.go
parseEEG
func (n *Driver) parseEEG(data []byte) EEGData { return EEGData{ Delta: n.parse3ByteInteger(data[0:3]), Theta: n.parse3ByteInteger(data[3:6]), LoAlpha: n.parse3ByteInteger(data[6:9]), HiAlpha: n.parse3ByteInteger(data[9:12]), LoBeta: n.parse3ByteInteger(data[12:15]), HiBeta: n.parse3ByteInteger(data[15:18]), LoGamma: n.parse3ByteInteger(data[18:21]), MidGamma: n.parse3ByteInteger(data[21:25]), } }
go
func (n *Driver) parseEEG(data []byte) EEGData { return EEGData{ Delta: n.parse3ByteInteger(data[0:3]), Theta: n.parse3ByteInteger(data[3:6]), LoAlpha: n.parse3ByteInteger(data[6:9]), HiAlpha: n.parse3ByteInteger(data[9:12]), LoBeta: n.parse3ByteInteger(data[12:15]), HiBeta: n.parse3ByteInteger(data[15:18]), LoGamma: n.parse3ByteInteger(data[18:21]), MidGamma: n.parse3ByteInteger(data[21:25]), } }
[ "func", "(", "n", "*", "Driver", ")", "parseEEG", "(", "data", "[", "]", "byte", ")", "EEGData", "{", "return", "EEGData", "{", "Delta", ":", "n", ".", "parse3ByteInteger", "(", "data", "[", "0", ":", "3", "]", ")", ",", "Theta", ":", "n", ".", ...
// parseEEG returns data converted into EEG map
[ "parseEEG", "returns", "data", "converted", "into", "EEG", "map" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/neurosky/neurosky_driver.go#L192-L203
156,154
hybridgroup/gobot
drivers/i2c/blinkm_driver.go
Rgb
func (b *BlinkMDriver) Rgb(red byte, green byte, blue byte) (err error) { if _, err = b.connection.Write([]byte("n")); err != nil { return } _, err = b.connection.Write([]byte{red, green, blue}) return }
go
func (b *BlinkMDriver) Rgb(red byte, green byte, blue byte) (err error) { if _, err = b.connection.Write([]byte("n")); err != nil { return } _, err = b.connection.Write([]byte{red, green, blue}) return }
[ "func", "(", "b", "*", "BlinkMDriver", ")", "Rgb", "(", "red", "byte", ",", "green", "byte", ",", "blue", "byte", ")", "(", "err", "error", ")", "{", "if", "_", ",", "err", "=", "b", ".", "connection", ".", "Write", "(", "[", "]", "byte", "(", ...
// Rgb sets color using r,g,b params
[ "Rgb", "sets", "color", "using", "r", "g", "b", "params" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/blinkm_driver.go#L97-L103
156,155
hybridgroup/gobot
drivers/i2c/blinkm_driver.go
FirmwareVersion
func (b *BlinkMDriver) FirmwareVersion() (version string, err error) { if _, err = b.connection.Write([]byte("Z")); err != nil { return } data := []byte{0, 0} read, err := b.connection.Read(data) if read != 2 || err != nil { return } return fmt.Sprintf("%v.%v", data[0], data[1]), nil }
go
func (b *BlinkMDriver) FirmwareVersion() (version string, err error) { if _, err = b.connection.Write([]byte("Z")); err != nil { return } data := []byte{0, 0} read, err := b.connection.Read(data) if read != 2 || err != nil { return } return fmt.Sprintf("%v.%v", data[0], data[1]), nil }
[ "func", "(", "b", "*", "BlinkMDriver", ")", "FirmwareVersion", "(", ")", "(", "version", "string", ",", "err", "error", ")", "{", "if", "_", ",", "err", "=", "b", ".", "connection", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", ...
// FirmwareVersion returns version with MAYOR.minor format
[ "FirmwareVersion", "returns", "version", "with", "MAYOR", ".", "minor", "format" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/blinkm_driver.go#L115-L125
156,156
hybridgroup/gobot
drivers/i2c/blinkm_driver.go
Color
func (b *BlinkMDriver) Color() (color []byte, err error) { if _, err = b.connection.Write([]byte("g")); err != nil { return } data := []byte{0, 0, 0} read, err := b.connection.Read(data) if read != 3 || err != nil { return []byte{}, err } return []byte{data[0], data[1], data[2]}, nil }
go
func (b *BlinkMDriver) Color() (color []byte, err error) { if _, err = b.connection.Write([]byte("g")); err != nil { return } data := []byte{0, 0, 0} read, err := b.connection.Read(data) if read != 3 || err != nil { return []byte{}, err } return []byte{data[0], data[1], data[2]}, nil }
[ "func", "(", "b", "*", "BlinkMDriver", ")", "Color", "(", ")", "(", "color", "[", "]", "byte", ",", "err", "error", ")", "{", "if", "_", ",", "err", "=", "b", ".", "connection", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", ...
// Color returns an array with current rgb color
[ "Color", "returns", "an", "array", "with", "current", "rgb", "color" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/blinkm_driver.go#L128-L138
156,157
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
ssd1306Init
func (s *SSD1306Driver) ssd1306Init() { s.command(ssd1306SetDisplayOff) s.command(ssd1306SetDisplayClock) if s.DisplayHeight == 16 { s.command(0x60) } else { s.command(0x80) } s.command(ssd1306SetMultiplexRatio) s.command(uint8(s.DisplayHeight) - 1) s.command(ssd1306SetDisplayOffset) s.command(0x0) s.command(ssd1306SetStartLine) s.command(0x0) s.command(ssd1306ChargePumpSetting) if s.ExternalVcc { s.command(0x10) } else { s.command(0x14) } s.command(ssd1306SetMemoryAddressingMode) s.command(0x00) s.command(ssd1306SetSegmentRemap0) s.command(0x01) s.command(ssd1306ComScanInc) s.command(ssd1306SetComPins) if s.DisplayHeight == 64 { s.command(0x12) } else { s.command(0x02) } s.command(ssd1306SetContrast) if s.DisplayHeight == 64 { if s.ExternalVcc { s.command(0x9F) } else { s.command(0xCF) } } else { s.command(0x8F) } s.command(ssd1306SetPrechargePeriod) if s.ExternalVcc { s.command(0x22) } else { s.command(0xF1) } s.command(ssd1306SetVComDeselectLevel) s.command(0x40) s.command(ssd1306DisplayOnResumeToRAM) s.command(ssd1306SetDisplayNormal) s.command(ssd1306DeactivateScroll) s.command(ssd1306SetDisplayOn) }
go
func (s *SSD1306Driver) ssd1306Init() { s.command(ssd1306SetDisplayOff) s.command(ssd1306SetDisplayClock) if s.DisplayHeight == 16 { s.command(0x60) } else { s.command(0x80) } s.command(ssd1306SetMultiplexRatio) s.command(uint8(s.DisplayHeight) - 1) s.command(ssd1306SetDisplayOffset) s.command(0x0) s.command(ssd1306SetStartLine) s.command(0x0) s.command(ssd1306ChargePumpSetting) if s.ExternalVcc { s.command(0x10) } else { s.command(0x14) } s.command(ssd1306SetMemoryAddressingMode) s.command(0x00) s.command(ssd1306SetSegmentRemap0) s.command(0x01) s.command(ssd1306ComScanInc) s.command(ssd1306SetComPins) if s.DisplayHeight == 64 { s.command(0x12) } else { s.command(0x02) } s.command(ssd1306SetContrast) if s.DisplayHeight == 64 { if s.ExternalVcc { s.command(0x9F) } else { s.command(0xCF) } } else { s.command(0x8F) } s.command(ssd1306SetPrechargePeriod) if s.ExternalVcc { s.command(0x22) } else { s.command(0xF1) } s.command(ssd1306SetVComDeselectLevel) s.command(0x40) s.command(ssd1306DisplayOnResumeToRAM) s.command(ssd1306SetDisplayNormal) s.command(ssd1306DeactivateScroll) s.command(ssd1306SetDisplayOn) }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "ssd1306Init", "(", ")", "{", "s", ".", "command", "(", "ssd1306SetDisplayOff", ")", "\n", "s", ".", "command", "(", "ssd1306SetDisplayClock", ")", "\n", "if", "s", ".", "DisplayHeight", "==", "16", "{", "s", ...
// ssd1306Init configures the ssd1306 based on the options passed in when the driver was created
[ "ssd1306Init", "configures", "the", "ssd1306", "based", "on", "the", "options", "passed", "in", "when", "the", "driver", "was", "created" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L59-L112
156,158
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
Size
func (d *DisplayBuffer) Size() int { return (d.width * d.height) / d.pageSize }
go
func (d *DisplayBuffer) Size() int { return (d.width * d.height) / d.pageSize }
[ "func", "(", "d", "*", "DisplayBuffer", ")", "Size", "(", ")", "int", "{", "return", "(", "d", ".", "width", "*", "d", ".", "height", ")", "/", "d", ".", "pageSize", "\n", "}" ]
// Size returns the memory size of the display buffer
[ "Size", "returns", "the", "memory", "size", "of", "the", "display", "buffer" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L132-L134
156,159
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
SetPixel
func (d *DisplayBuffer) SetPixel(x, y, c int) { idx := x + (y/d.pageSize)*d.width bit := uint(y) % uint(d.pageSize) if c == 0 { d.buffer[idx] &= ^(1 << bit) } else { d.buffer[idx] |= (1 << bit) } }
go
func (d *DisplayBuffer) SetPixel(x, y, c int) { idx := x + (y/d.pageSize)*d.width bit := uint(y) % uint(d.pageSize) if c == 0 { d.buffer[idx] &= ^(1 << bit) } else { d.buffer[idx] |= (1 << bit) } }
[ "func", "(", "d", "*", "DisplayBuffer", ")", "SetPixel", "(", "x", ",", "y", ",", "c", "int", ")", "{", "idx", ":=", "x", "+", "(", "y", "/", "d", ".", "pageSize", ")", "*", "d", ".", "width", "\n", "bit", ":=", "uint", "(", "y", ")", "%", ...
// SetPixel sets the x, y pixel with c color
[ "SetPixel", "sets", "the", "x", "y", "pixel", "with", "c", "color" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L142-L150
156,160
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
Start
func (s *SSD1306Driver) Start() (err error) { bus := s.GetBusOrDefault(s.connector.GetSpiDefaultBus()) chip := s.GetChipOrDefault(s.connector.GetSpiDefaultChip()) mode := s.GetModeOrDefault(s.connector.GetSpiDefaultMode()) bits := s.GetBitsOrDefault(s.connector.GetSpiDefaultBits()) maxSpeed := s.GetSpeedOrDefault(s.connector.GetSpiDefaultMaxSpeed()) s.connection, err = s.connector.GetSpiConnection(bus, chip, mode, bits, maxSpeed) if err != nil { return err } s.ssd1306Init() return }
go
func (s *SSD1306Driver) Start() (err error) { bus := s.GetBusOrDefault(s.connector.GetSpiDefaultBus()) chip := s.GetChipOrDefault(s.connector.GetSpiDefaultChip()) mode := s.GetModeOrDefault(s.connector.GetSpiDefaultMode()) bits := s.GetBitsOrDefault(s.connector.GetSpiDefaultBits()) maxSpeed := s.GetSpeedOrDefault(s.connector.GetSpiDefaultMaxSpeed()) s.connection, err = s.connector.GetSpiConnection(bus, chip, mode, bits, maxSpeed) if err != nil { return err } s.ssd1306Init() return }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "s", ".", "GetBusOrDefault", "(", "s", ".", "connector", ".", "GetSpiDefaultBus", "(", ")", ")", "\n", "chip", ":=", "s", ".", "GetChipOrDefau...
// Start sets up the needed connection, and initialized the device.
[ "Start", "sets", "up", "the", "needed", "connection", "and", "initialized", "the", "device", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L257-L270
156,161
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
Halt
func (s *SSD1306Driver) Halt() (err error) { s.Reset() s.Off() return nil }
go
func (s *SSD1306Driver) Halt() (err error) { s.Reset() s.Off() return nil }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Halt", "(", ")", "(", "err", "error", ")", "{", "s", ".", "Reset", "(", ")", "\n", "s", ".", "Off", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Halt returns true if device is halted successfully.
[ "Halt", "returns", "true", "if", "device", "is", "halted", "successfully", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L273-L277
156,162
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
WithDCPin
func WithDCPin(val string) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.DCPin = val } else { panic("unable to set dc pin for ssd1306") } } }
go
func WithDCPin(val string) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.DCPin = val } else { panic("unable to set dc pin for ssd1306") } } }
[ "func", "WithDCPin", "(", "val", "string", ")", "func", "(", "Config", ")", "{", "return", "func", "(", "c", "Config", ")", "{", "d", ",", "ok", ":=", "c", ".", "(", "*", "SSD1306Driver", ")", "\n", "if", "ok", "{", "d", ".", "DCPin", "=", "val...
// WithDCPin option sets the SSD1306Driver DC Pin option.
[ "WithDCPin", "option", "sets", "the", "SSD1306Driver", "DC", "Pin", "option", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L304-L313
156,163
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
WithRstPin
func WithRstPin(val string) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.RSTPin = val } else { panic("unable to set rst pin for ssd1306") } } }
go
func WithRstPin(val string) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.RSTPin = val } else { panic("unable to set rst pin for ssd1306") } } }
[ "func", "WithRstPin", "(", "val", "string", ")", "func", "(", "Config", ")", "{", "return", "func", "(", "c", "Config", ")", "{", "d", ",", "ok", ":=", "c", ".", "(", "*", "SSD1306Driver", ")", "\n", "if", "ok", "{", "d", ".", "RSTPin", "=", "v...
// WithRstPin option sets the SSD1306Driver RST pin option.
[ "WithRstPin", "option", "sets", "the", "SSD1306Driver", "RST", "pin", "option", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L316-L325
156,164
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
WithExternalVCC
func WithExternalVCC(val bool) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.ExternalVcc = val } else { panic("unable to set rst pin for ssd1306") } } }
go
func WithExternalVCC(val bool) func(Config) { return func(c Config) { d, ok := c.(*SSD1306Driver) if ok { d.ExternalVcc = val } else { panic("unable to set rst pin for ssd1306") } } }
[ "func", "WithExternalVCC", "(", "val", "bool", ")", "func", "(", "Config", ")", "{", "return", "func", "(", "c", "Config", ")", "{", "d", ",", "ok", ":=", "c", ".", "(", "*", "SSD1306Driver", ")", "\n", "if", "ok", "{", "d", ".", "ExternalVcc", "...
// WithExternalVCC option sets the SSD1306Driver external vcc option.
[ "WithExternalVCC", "option", "sets", "the", "SSD1306Driver", "external", "vcc", "option", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L328-L337
156,165
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
Set
func (s *SSD1306Driver) Set(x, y, c int) { s.buffer.SetPixel(x, y, c) }
go
func (s *SSD1306Driver) Set(x, y, c int) { s.buffer.SetPixel(x, y, c) }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Set", "(", "x", ",", "y", ",", "c", "int", ")", "{", "s", ".", "buffer", ".", "SetPixel", "(", "x", ",", "y", ",", "c", ")", "\n", "}" ]
// Set sets a pixel in the display buffer.
[ "Set", "sets", "a", "pixel", "in", "the", "display", "buffer", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L356-L358
156,166
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
Reset
func (s *SSD1306Driver) Reset() (err error) { s.rstDriver.DigitalWrite(1) time.Sleep(10 * time.Millisecond) s.rstDriver.DigitalWrite(0) time.Sleep(10 * time.Millisecond) s.rstDriver.DigitalWrite(1) return nil }
go
func (s *SSD1306Driver) Reset() (err error) { s.rstDriver.DigitalWrite(1) time.Sleep(10 * time.Millisecond) s.rstDriver.DigitalWrite(0) time.Sleep(10 * time.Millisecond) s.rstDriver.DigitalWrite(1) return nil }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Reset", "(", ")", "(", "err", "error", ")", "{", "s", ".", "rstDriver", ".", "DigitalWrite", "(", "1", ")", "\n", "time", ".", "Sleep", "(", "10", "*", "time", ".", "Millisecond", ")", "\n", "s", ".",...
// Reset re-initializes the device to a clean state.
[ "Reset", "re", "-", "initializes", "the", "device", "to", "a", "clean", "state", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L361-L368
156,167
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
SetBufferAndDisplay
func (s *SSD1306Driver) SetBufferAndDisplay(buf []byte) (err error) { s.buffer.Set(buf) return s.Display() }
go
func (s *SSD1306Driver) SetBufferAndDisplay(buf []byte) (err error) { s.buffer.Set(buf) return s.Display() }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "SetBufferAndDisplay", "(", "buf", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "s", ".", "buffer", ".", "Set", "(", "buf", ")", "\n", "return", "s", ".", "Display", "(", ")", "\n", "}" ]
// SetBufferAndDisplay sets the display buffer with the given buffer and displays the image.
[ "SetBufferAndDisplay", "sets", "the", "display", "buffer", "with", "the", "given", "buffer", "and", "displays", "the", "image", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L371-L374
156,168
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
Display
func (s *SSD1306Driver) Display() (err error) { s.command(ssd1306ColumnAddr) s.command(0) s.command(uint8(s.DisplayWidth) - 1) s.command(ssd1306PageAddr) s.command(0) s.command(uint8(s.pageSize) - 1) if err = s.dcDriver.DigitalWrite(1); err != nil { return err } return s.connection.Tx(append([]byte{0x40}, s.buffer.buffer...), nil) }
go
func (s *SSD1306Driver) Display() (err error) { s.command(ssd1306ColumnAddr) s.command(0) s.command(uint8(s.DisplayWidth) - 1) s.command(ssd1306PageAddr) s.command(0) s.command(uint8(s.pageSize) - 1) if err = s.dcDriver.DigitalWrite(1); err != nil { return err } return s.connection.Tx(append([]byte{0x40}, s.buffer.buffer...), nil) }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "Display", "(", ")", "(", "err", "error", ")", "{", "s", ".", "command", "(", "ssd1306ColumnAddr", ")", "\n", "s", ".", "command", "(", "0", ")", "\n", "s", ".", "command", "(", "uint8", "(", "s", ".",...
// 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/spi/ssd1306_driver.go#L388-L399
156,169
hybridgroup/gobot
drivers/spi/ssd1306_driver.go
ShowImage
func (s *SSD1306Driver) ShowImage(img image.Image) (err error) { if img.Bounds().Dx() != s.DisplayWidth || img.Bounds().Dy() != s.DisplayHeight { return errors.New("Image must match the display width and height") } s.Clear() for y, w, h := 0, img.Bounds().Dx(), img.Bounds().Dy(); y < h; y++ { for x := 0; x < w; x++ { c := img.At(x, y) if r, g, b, _ := c.RGBA(); r > 0 || g > 0 || b > 0 { s.Set(x, y, 1) } } } return s.Display() }
go
func (s *SSD1306Driver) ShowImage(img image.Image) (err error) { if img.Bounds().Dx() != s.DisplayWidth || img.Bounds().Dy() != s.DisplayHeight { return errors.New("Image must match the display width and height") } s.Clear() for y, w, h := 0, img.Bounds().Dx(), img.Bounds().Dy(); y < h; y++ { for x := 0; x < w; x++ { c := img.At(x, y) if r, g, b, _ := c.RGBA(); r > 0 || g > 0 || b > 0 { s.Set(x, y, 1) } } } return s.Display() }
[ "func", "(", "s", "*", "SSD1306Driver", ")", "ShowImage", "(", "img", "image", ".", "Image", ")", "(", "err", "error", ")", "{", "if", "img", ".", "Bounds", "(", ")", ".", "Dx", "(", ")", "!=", "s", ".", "DisplayWidth", "||", "img", ".", "Bounds"...
// ShowImage takes a standard Go image and shows it on the display in monochrome.
[ "ShowImage", "takes", "a", "standard", "Go", "image", "and", "shows", "it", "on", "the", "display", "in", "monochrome", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/ssd1306_driver.go#L402-L417
156,170
hybridgroup/gobot
drivers/i2c/hmc6352_driver.go
Start
func (h *HMC6352Driver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) address := h.GetAddressOrDefault(hmc6352Address) h.connection, err = h.connector.GetConnection(address, bus) if err != nil { return err } if _, err := h.connection.Write([]byte("A")); err != nil { return err } return }
go
func (h *HMC6352Driver) Start() (err error) { bus := h.GetBusOrDefault(h.connector.GetDefaultBus()) address := h.GetAddressOrDefault(hmc6352Address) h.connection, err = h.connector.GetConnection(address, bus) if err != nil { return err } if _, err := h.connection.Write([]byte("A")); err != nil { return err } return }
[ "func", "(", "h", "*", "HMC6352Driver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "h", ".", "GetBusOrDefault", "(", "h", ".", "connector", ".", "GetDefaultBus", "(", ")", ")", "\n", "address", ":=", "h", ".", "GetAddressOrDe...
// Start initializes the hmc6352
[ "Start", "initializes", "the", "hmc6352" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/hmc6352_driver.go#L47-L60
156,171
hybridgroup/gobot
drivers/i2c/hmc6352_driver.go
Heading
func (h *HMC6352Driver) Heading() (heading uint16, err error) { if _, err = h.connection.Write([]byte("A")); err != nil { return } buf := []byte{0, 0} bytesRead, err := h.connection.Read(buf) if err != nil { return } if bytesRead == 2 { heading = (uint16(buf[1]) + uint16(buf[0])*256) / 10 return } err = ErrNotEnoughBytes return }
go
func (h *HMC6352Driver) Heading() (heading uint16, err error) { if _, err = h.connection.Write([]byte("A")); err != nil { return } buf := []byte{0, 0} bytesRead, err := h.connection.Read(buf) if err != nil { return } if bytesRead == 2 { heading = (uint16(buf[1]) + uint16(buf[0])*256) / 10 return } err = ErrNotEnoughBytes return }
[ "func", "(", "h", "*", "HMC6352Driver", ")", "Heading", "(", ")", "(", "heading", "uint16", ",", "err", "error", ")", "{", "if", "_", ",", "err", "=", "h", ".", "connection", ".", "Write", "(", "[", "]", "byte", "(", "\"", "\"", ")", ")", ";", ...
// Heading returns the current heading
[ "Heading", "returns", "the", "current", "heading" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/hmc6352_driver.go#L66-L82
156,172
hybridgroup/gobot
drivers/spi/spi_config.go
NewConfig
func NewConfig() Config { return &spiConfig{ bus: NotInitialized, chip: NotInitialized, mode: NotInitialized, bits: NotInitialized, speed: NotInitialized} }
go
func NewConfig() Config { return &spiConfig{ bus: NotInitialized, chip: NotInitialized, mode: NotInitialized, bits: NotInitialized, speed: NotInitialized} }
[ "func", "NewConfig", "(", ")", "Config", "{", "return", "&", "spiConfig", "{", "bus", ":", "NotInitialized", ",", "chip", ":", "NotInitialized", ",", "mode", ":", "NotInitialized", ",", "bits", ":", "NotInitialized", ",", "speed", ":", "NotInitialized", "}",...
// NewConfig returns a new SPI Config.
[ "NewConfig", "returns", "a", "new", "SPI", "Config", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/spi_config.go#L46-L53
156,173
hybridgroup/gobot
drivers/gpio/stepper_driver.go
Run
func (s *StepperDriver) Run() (err error) { //halt if already moving if s.moving == true { s.Halt() } s.mutex.Lock() s.moving = true s.mutex.Unlock() go func() { for { if s.moving == false { break } s.step() } }() return }
go
func (s *StepperDriver) Run() (err error) { //halt if already moving if s.moving == true { s.Halt() } s.mutex.Lock() s.moving = true s.mutex.Unlock() go func() { for { if s.moving == false { break } s.step() } }() return }
[ "func", "(", "s", "*", "StepperDriver", ")", "Run", "(", ")", "(", "err", "error", ")", "{", "//halt if already moving", "if", "s", ".", "moving", "==", "true", "{", "s", ".", "Halt", "(", ")", "\n", "}", "\n\n", "s", ".", "mutex", ".", "Lock", "...
// Run continuously runs the stepper
[ "Run", "continuously", "runs", "the", "stepper" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/stepper_driver.go#L112-L132
156,174
hybridgroup/gobot
drivers/gpio/stepper_driver.go
Halt
func (s *StepperDriver) Halt() (err error) { s.mutex.Lock() s.moving = false s.mutex.Unlock() return nil }
go
func (s *StepperDriver) Halt() (err error) { s.mutex.Lock() s.moving = false s.mutex.Unlock() return nil }
[ "func", "(", "s", "*", "StepperDriver", ")", "Halt", "(", ")", "(", "err", "error", ")", "{", "s", ".", "mutex", ".", "Lock", "(", ")", "\n", "s", ".", "moving", "=", "false", "\n", "s", ".", "mutex", ".", "Unlock", "(", ")", "\n", "return", ...
// Halt implements the Driver interface and halts the motion of the Stepper
[ "Halt", "implements", "the", "Driver", "interface", "and", "halts", "the", "motion", "of", "the", "Stepper" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/stepper_driver.go#L135-L140
156,175
hybridgroup/gobot
drivers/gpio/stepper_driver.go
SetDirection
func (s *StepperDriver) SetDirection(direction string) error { direction = strings.ToLower(direction) if direction != "forward" && direction != "backward" { return errors.New("Invalid direction. Value should be forward or backward") } s.mutex.Lock() s.direction = direction s.mutex.Unlock() return nil }
go
func (s *StepperDriver) SetDirection(direction string) error { direction = strings.ToLower(direction) if direction != "forward" && direction != "backward" { return errors.New("Invalid direction. Value should be forward or backward") } s.mutex.Lock() s.direction = direction s.mutex.Unlock() return nil }
[ "func", "(", "s", "*", "StepperDriver", ")", "SetDirection", "(", "direction", "string", ")", "error", "{", "direction", "=", "strings", ".", "ToLower", "(", "direction", ")", "\n", "if", "direction", "!=", "\"", "\"", "&&", "direction", "!=", "\"", "\""...
// SetDirection sets the direction in which motor should be moving, Default is forward
[ "SetDirection", "sets", "the", "direction", "in", "which", "motor", "should", "be", "moving", "Default", "is", "forward" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/stepper_driver.go#L143-L153
156,176
hybridgroup/gobot
drivers/gpio/stepper_driver.go
step
func (s *StepperDriver) step() error { if s.direction == "forward" { s.stepNum++ } else { s.stepNum-- } if s.stepNum >= int(s.stepsPerRev) { s.stepNum = 0 } else if s.stepNum < 0 { s.stepNum = int(s.stepsPerRev) - 1 } r := int(math.Abs(float64(s.stepNum))) % len(s.phase) for i, v := range s.phase[r] { if err := s.connection.DigitalWrite(s.pins[i], v); err != nil { return err } } return nil }
go
func (s *StepperDriver) step() error { if s.direction == "forward" { s.stepNum++ } else { s.stepNum-- } if s.stepNum >= int(s.stepsPerRev) { s.stepNum = 0 } else if s.stepNum < 0 { s.stepNum = int(s.stepsPerRev) - 1 } r := int(math.Abs(float64(s.stepNum))) % len(s.phase) for i, v := range s.phase[r] { if err := s.connection.DigitalWrite(s.pins[i], v); err != nil { return err } } return nil }
[ "func", "(", "s", "*", "StepperDriver", ")", "step", "(", ")", "error", "{", "if", "s", ".", "direction", "==", "\"", "\"", "{", "s", ".", "stepNum", "++", "\n", "}", "else", "{", "s", ".", "stepNum", "--", "\n", "}", "\n\n", "if", "s", ".", ...
// Step moves motor one step in giving direction
[ "Step", "moves", "motor", "one", "step", "in", "giving", "direction" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/stepper_driver.go#L161-L183
156,177
hybridgroup/gobot
drivers/gpio/stepper_driver.go
Move
func (s *StepperDriver) Move(stepsToMove int) error { if stepsToMove == 0 { return s.Halt() } if s.moving == true { //stop previous motion s.Halt() } s.mutex.Lock() s.moving = true s.direction = "forward" if stepsToMove < 0 { s.direction = "backward" } s.mutex.Unlock() stepsLeft := int64(math.Abs(float64(stepsToMove))) //Do not remove *1000 and change duration to time.Millisecond. It has been done for a reason delay := time.Duration(60000*1000/(s.stepsPerRev*s.speed)) * time.Microsecond for stepsLeft > 0 { if err := s.step(); err != nil { return err } stepsLeft-- time.Sleep(delay) } s.moving = false return nil }
go
func (s *StepperDriver) Move(stepsToMove int) error { if stepsToMove == 0 { return s.Halt() } if s.moving == true { //stop previous motion s.Halt() } s.mutex.Lock() s.moving = true s.direction = "forward" if stepsToMove < 0 { s.direction = "backward" } s.mutex.Unlock() stepsLeft := int64(math.Abs(float64(stepsToMove))) //Do not remove *1000 and change duration to time.Millisecond. It has been done for a reason delay := time.Duration(60000*1000/(s.stepsPerRev*s.speed)) * time.Microsecond for stepsLeft > 0 { if err := s.step(); err != nil { return err } stepsLeft-- time.Sleep(delay) } s.moving = false return nil }
[ "func", "(", "s", "*", "StepperDriver", ")", "Move", "(", "stepsToMove", "int", ")", "error", "{", "if", "stepsToMove", "==", "0", "{", "return", "s", ".", "Halt", "(", ")", "\n", "}", "\n\n", "if", "s", ".", "moving", "==", "true", "{", "//stop pr...
// Move moves the motor for given number of steps
[ "Move", "moves", "the", "motor", "for", "given", "number", "of", "steps" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/stepper_driver.go#L186-L219
156,178
hybridgroup/gobot
drivers/gpio/stepper_driver.go
SetSpeed
func (s *StepperDriver) SetSpeed(rpm uint) error { if rpm <= 0 { return errors.New("RPM cannot be a zero or negative value") } m := s.GetMaxSpeed() if rpm > m { rpm = m } s.speed = rpm return nil }
go
func (s *StepperDriver) SetSpeed(rpm uint) error { if rpm <= 0 { return errors.New("RPM cannot be a zero or negative value") } m := s.GetMaxSpeed() if rpm > m { rpm = m } s.speed = rpm return nil }
[ "func", "(", "s", "*", "StepperDriver", ")", "SetSpeed", "(", "rpm", "uint", ")", "error", "{", "if", "rpm", "<=", "0", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "m", ":=", "s", ".", "GetMaxSpeed", "(", ")", ...
// SetSpeed sets the rpm
[ "SetSpeed", "sets", "the", "rpm" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/stepper_driver.go#L233-L245
156,179
hybridgroup/gobot
event.go
NewEvent
func NewEvent(name string, data interface{}) *Event { return &Event{Name: name, Data: data} }
go
func NewEvent(name string, data interface{}) *Event { return &Event{Name: name, Data: data} }
[ "func", "NewEvent", "(", "name", "string", ",", "data", "interface", "{", "}", ")", "*", "Event", "{", "return", "&", "Event", "{", "Name", ":", "name", ",", "Data", ":", "data", "}", "\n", "}" ]
// NewEvent returns a new Event and its associated data.
[ "NewEvent", "returns", "a", "new", "Event", "and", "its", "associated", "data", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/event.go#L11-L13
156,180
hybridgroup/gobot
platforms/parrot/ardrone/ardrone_driver.go
Up
func (a *Driver) Up(speed float64) { a.adaptor().drone.Up(speed) }
go
func (a *Driver) Up(speed float64) { a.adaptor().drone.Up(speed) }
[ "func", "(", "a", "*", "Driver", ")", "Up", "(", "speed", "float64", ")", "{", "a", ".", "adaptor", "(", ")", ".", "drone", ".", "Up", "(", "speed", ")", "\n", "}" ]
// Up makes the drone gain altitude. // speed can be a value from `0.0` to `1.0`.
[ "Up", "makes", "the", "drone", "gain", "altitude", ".", "speed", "can", "be", "a", "value", "from", "0", ".", "0", "to", "1", ".", "0", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_driver.go#L69-L71
156,181
hybridgroup/gobot
platforms/parrot/ardrone/ardrone_driver.go
Down
func (a *Driver) Down(speed float64) { a.adaptor().drone.Down(speed) }
go
func (a *Driver) Down(speed float64) { a.adaptor().drone.Down(speed) }
[ "func", "(", "a", "*", "Driver", ")", "Down", "(", "speed", "float64", ")", "{", "a", ".", "adaptor", "(", ")", ".", "drone", ".", "Down", "(", "speed", ")", "\n", "}" ]
// Down makes the drone reduce altitude. // speed can be a value from `0.0` to `1.0`.
[ "Down", "makes", "the", "drone", "reduce", "altitude", ".", "speed", "can", "be", "a", "value", "from", "0", ".", "0", "to", "1", ".", "0", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_driver.go#L75-L77
156,182
hybridgroup/gobot
platforms/parrot/ardrone/ardrone_driver.go
Left
func (a *Driver) Left(speed float64) { a.adaptor().drone.Left(speed) }
go
func (a *Driver) Left(speed float64) { a.adaptor().drone.Left(speed) }
[ "func", "(", "a", "*", "Driver", ")", "Left", "(", "speed", "float64", ")", "{", "a", ".", "adaptor", "(", ")", ".", "drone", ".", "Left", "(", "speed", ")", "\n", "}" ]
// Left causes the drone to bank to the left, controls the roll, which is // a horizontal movement using the camera as a reference point. // speed can be a value from `0.0` to `1.0`.
[ "Left", "causes", "the", "drone", "to", "bank", "to", "the", "left", "controls", "the", "roll", "which", "is", "a", "horizontal", "movement", "using", "the", "camera", "as", "a", "reference", "point", ".", "speed", "can", "be", "a", "value", "from", "0",...
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_driver.go#L82-L84
156,183
hybridgroup/gobot
platforms/parrot/ardrone/ardrone_driver.go
Right
func (a *Driver) Right(speed float64) { a.adaptor().drone.Right(speed) }
go
func (a *Driver) Right(speed float64) { a.adaptor().drone.Right(speed) }
[ "func", "(", "a", "*", "Driver", ")", "Right", "(", "speed", "float64", ")", "{", "a", ".", "adaptor", "(", ")", ".", "drone", ".", "Right", "(", "speed", ")", "\n", "}" ]
// Right causes the drone to bank to the right, controls the roll, which is // a horizontal movement using the camera as a reference point. // speed can be a value from `0.0` to `1.0`.
[ "Right", "causes", "the", "drone", "to", "bank", "to", "the", "right", "controls", "the", "roll", "which", "is", "a", "horizontal", "movement", "using", "the", "camera", "as", "a", "reference", "point", ".", "speed", "can", "be", "a", "value", "from", "0...
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_driver.go#L89-L91
156,184
hybridgroup/gobot
platforms/parrot/ardrone/ardrone_driver.go
Forward
func (a *Driver) Forward(speed float64) { a.adaptor().drone.Forward(speed) }
go
func (a *Driver) Forward(speed float64) { a.adaptor().drone.Forward(speed) }
[ "func", "(", "a", "*", "Driver", ")", "Forward", "(", "speed", "float64", ")", "{", "a", ".", "adaptor", "(", ")", ".", "drone", ".", "Forward", "(", "speed", ")", "\n", "}" ]
// Forward causes the drone go forward, controls the pitch. // speed can be a value from `0.0` to `1.0`.
[ "Forward", "causes", "the", "drone", "go", "forward", "controls", "the", "pitch", ".", "speed", "can", "be", "a", "value", "from", "0", ".", "0", "to", "1", ".", "0", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_driver.go#L95-L97
156,185
hybridgroup/gobot
platforms/parrot/ardrone/ardrone_driver.go
Backward
func (a *Driver) Backward(speed float64) { a.adaptor().drone.Backward(speed) }
go
func (a *Driver) Backward(speed float64) { a.adaptor().drone.Backward(speed) }
[ "func", "(", "a", "*", "Driver", ")", "Backward", "(", "speed", "float64", ")", "{", "a", ".", "adaptor", "(", ")", ".", "drone", ".", "Backward", "(", "speed", ")", "\n", "}" ]
// Backward causes the drone go backward, controls the pitch. // speed can be a value from `0.0` to `1.0`.
[ "Backward", "causes", "the", "drone", "go", "backward", "controls", "the", "pitch", ".", "speed", "can", "be", "a", "value", "from", "0", ".", "0", "to", "1", ".", "0", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_driver.go#L101-L103
156,186
hybridgroup/gobot
platforms/parrot/ardrone/ardrone_driver.go
Clockwise
func (a *Driver) Clockwise(speed float64) { a.adaptor().drone.Clockwise(speed) }
go
func (a *Driver) Clockwise(speed float64) { a.adaptor().drone.Clockwise(speed) }
[ "func", "(", "a", "*", "Driver", ")", "Clockwise", "(", "speed", "float64", ")", "{", "a", ".", "adaptor", "(", ")", ".", "drone", ".", "Clockwise", "(", "speed", ")", "\n", "}" ]
// Clockwise causes the drone to spin in clockwise direction // speed can be a value from `0.0` to `1.0`.
[ "Clockwise", "causes", "the", "drone", "to", "spin", "in", "clockwise", "direction", "speed", "can", "be", "a", "value", "from", "0", ".", "0", "to", "1", ".", "0", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_driver.go#L107-L109
156,187
hybridgroup/gobot
platforms/parrot/ardrone/ardrone_driver.go
CounterClockwise
func (a *Driver) CounterClockwise(speed float64) { a.adaptor().drone.Counterclockwise(speed) }
go
func (a *Driver) CounterClockwise(speed float64) { a.adaptor().drone.Counterclockwise(speed) }
[ "func", "(", "a", "*", "Driver", ")", "CounterClockwise", "(", "speed", "float64", ")", "{", "a", ".", "adaptor", "(", ")", ".", "drone", ".", "Counterclockwise", "(", "speed", ")", "\n", "}" ]
// CounterClockwise the drone to spin in counter clockwise direction // speed can be a value from `0.0` to `1.0`.
[ "CounterClockwise", "the", "drone", "to", "spin", "in", "counter", "clockwise", "direction", "speed", "can", "be", "a", "value", "from", "0", ".", "0", "to", "1", ".", "0", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/parrot/ardrone/ardrone_driver.go#L113-L115
156,188
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
Start
func (w *WiichuckDriver) Start() (err error) { bus := w.GetBusOrDefault(w.connector.GetDefaultBus()) address := w.GetAddressOrDefault(wiichuckAddress) w.connection, err = w.connector.GetConnection(address, bus) if err != nil { return err } go func() { for { if _, err := w.connection.Write([]byte{0x40, 0x00}); err != nil { w.Publish(w.Event(Error), err) continue } time.Sleep(w.pauseTime) if _, err := w.connection.Write([]byte{0x00}); err != nil { w.Publish(w.Event(Error), err) continue } time.Sleep(w.pauseTime) newValue := make([]byte, 6) bytesRead, err := w.connection.Read(newValue) if err != nil { w.Publish(w.Event(Error), err) continue } if bytesRead == 6 { if err = w.update(newValue); err != nil { w.Publish(w.Event(Error), err) continue } } time.Sleep(w.interval) } }() return }
go
func (w *WiichuckDriver) Start() (err error) { bus := w.GetBusOrDefault(w.connector.GetDefaultBus()) address := w.GetAddressOrDefault(wiichuckAddress) w.connection, err = w.connector.GetConnection(address, bus) if err != nil { return err } go func() { for { if _, err := w.connection.Write([]byte{0x40, 0x00}); err != nil { w.Publish(w.Event(Error), err) continue } time.Sleep(w.pauseTime) if _, err := w.connection.Write([]byte{0x00}); err != nil { w.Publish(w.Event(Error), err) continue } time.Sleep(w.pauseTime) newValue := make([]byte, 6) bytesRead, err := w.connection.Read(newValue) if err != nil { w.Publish(w.Event(Error), err) continue } if bytesRead == 6 { if err = w.update(newValue); err != nil { w.Publish(w.Event(Error), err) continue } } time.Sleep(w.interval) } }() return }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "bus", ":=", "w", ".", "GetBusOrDefault", "(", "w", ".", "connector", ".", "GetDefaultBus", "(", ")", ")", "\n", "address", ":=", "w", ".", "GetAddressOrD...
// Start initilizes i2c and reads from adaptor // using specified interval to update with new value
[ "Start", "initilizes", "i2c", "and", "reads", "from", "adaptor", "using", "specified", "interval", "to", "update", "with", "new", "value" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L88-L125
156,189
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
Joystick
func (w *WiichuckDriver) Joystick() map[string]float64 { val := make(map[string]float64) w.mtx.Lock() defer w.mtx.Unlock() val["sx_origin"] = w.joystick["sx_origin"] val["sy_origin"] = w.joystick["sy_origin"] return val }
go
func (w *WiichuckDriver) Joystick() map[string]float64 { val := make(map[string]float64) w.mtx.Lock() defer w.mtx.Unlock() val["sx_origin"] = w.joystick["sx_origin"] val["sy_origin"] = w.joystick["sy_origin"] return val }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "Joystick", "(", ")", "map", "[", "string", "]", "float64", "{", "val", ":=", "make", "(", "map", "[", "string", "]", "float64", ")", "\n", "w", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "w", ...
// Joystick returns the current value for the joystick
[ "Joystick", "returns", "the", "current", "value", "for", "the", "joystick" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L131-L138
156,190
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
update
func (w *WiichuckDriver) update(value []byte) (err error) { if w.isEncrypted(value) { return ErrEncryptedBytes } else { w.parse(value) w.adjustOrigins() w.updateButtons() w.updateJoystick() } return }
go
func (w *WiichuckDriver) update(value []byte) (err error) { if w.isEncrypted(value) { return ErrEncryptedBytes } else { w.parse(value) w.adjustOrigins() w.updateButtons() w.updateJoystick() } return }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "update", "(", "value", "[", "]", "byte", ")", "(", "err", "error", ")", "{", "if", "w", ".", "isEncrypted", "(", "value", ")", "{", "return", "ErrEncryptedBytes", "\n", "}", "else", "{", "w", ".", "par...
// update parses value to update buttons and joystick. // If value is encrypted, warning message is printed
[ "update", "parses", "value", "to", "update", "buttons", "and", "joystick", ".", "If", "value", "is", "encrypted", "warning", "message", "is", "printed" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L142-L152
156,191
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
setJoystickDefaultValue
func (w *WiichuckDriver) setJoystickDefaultValue(joystickAxis string, defaultValue float64) { w.mtx.Lock() defer w.mtx.Unlock() if w.joystick[joystickAxis] == -1 { w.joystick[joystickAxis] = defaultValue } }
go
func (w *WiichuckDriver) setJoystickDefaultValue(joystickAxis string, defaultValue float64) { w.mtx.Lock() defer w.mtx.Unlock() if w.joystick[joystickAxis] == -1 { w.joystick[joystickAxis] = defaultValue } }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "setJoystickDefaultValue", "(", "joystickAxis", "string", ",", "defaultValue", "float64", ")", "{", "w", ".", "mtx", ".", "Lock", "(", ")", "\n", "defer", "w", ".", "mtx", ".", "Unlock", "(", ")", "\n", "if...
// setJoystickDefaultValue sets default value if value is -1
[ "setJoystickDefaultValue", "sets", "default", "value", "if", "value", "is", "-", "1" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L155-L161
156,192
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
calculateJoystickValue
func (w *WiichuckDriver) calculateJoystickValue(axis float64, origin float64) float64 { return float64(axis - origin) }
go
func (w *WiichuckDriver) calculateJoystickValue(axis float64, origin float64) float64 { return float64(axis - origin) }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "calculateJoystickValue", "(", "axis", "float64", ",", "origin", "float64", ")", "float64", "{", "return", "float64", "(", "axis", "-", "origin", ")", "\n", "}" ]
// calculateJoystickValue returns distance between axis and origin
[ "calculateJoystickValue", "returns", "distance", "between", "axis", "and", "origin" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L164-L166
156,193
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
isEncrypted
func (w *WiichuckDriver) isEncrypted(value []byte) bool { if value[0] == value[1] && value[2] == value[3] && value[4] == value[5] { return true } return false }
go
func (w *WiichuckDriver) isEncrypted(value []byte) bool { if value[0] == value[1] && value[2] == value[3] && value[4] == value[5] { return true } return false }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "isEncrypted", "(", "value", "[", "]", "byte", ")", "bool", "{", "if", "value", "[", "0", "]", "==", "value", "[", "1", "]", "&&", "value", "[", "2", "]", "==", "value", "[", "3", "]", "&&", "value"...
// isEncrypted returns true if value is encrypted
[ "isEncrypted", "returns", "true", "if", "value", "is", "encrypted" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L169-L174
156,194
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
adjustOrigins
func (w *WiichuckDriver) adjustOrigins() { w.setJoystickDefaultValue("sy_origin", w.data["sy"]) w.setJoystickDefaultValue("sx_origin", w.data["sx"]) }
go
func (w *WiichuckDriver) adjustOrigins() { w.setJoystickDefaultValue("sy_origin", w.data["sy"]) w.setJoystickDefaultValue("sx_origin", w.data["sx"]) }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "adjustOrigins", "(", ")", "{", "w", ".", "setJoystickDefaultValue", "(", "\"", "\"", ",", "w", ".", "data", "[", "\"", "\"", "]", ")", "\n", "w", ".", "setJoystickDefaultValue", "(", "\"", "\"", ",", "w"...
// adjustOrigins sets sy_origin and sx_origin with values from data
[ "adjustOrigins", "sets", "sy_origin", "and", "sx_origin", "with", "values", "from", "data" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L182-L185
156,195
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
updateButtons
func (w *WiichuckDriver) updateButtons() { if w.data["c"] == 0 { w.Publish(w.Event(C), true) } if w.data["z"] == 0 { w.Publish(w.Event(Z), true) } }
go
func (w *WiichuckDriver) updateButtons() { if w.data["c"] == 0 { w.Publish(w.Event(C), true) } if w.data["z"] == 0 { w.Publish(w.Event(Z), true) } }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "updateButtons", "(", ")", "{", "if", "w", ".", "data", "[", "\"", "\"", "]", "==", "0", "{", "w", ".", "Publish", "(", "w", ".", "Event", "(", "C", ")", ",", "true", ")", "\n", "}", "\n", "if", ...
// updateButtons publishes "c" and "x" events if present in data
[ "updateButtons", "publishes", "c", "and", "x", "events", "if", "present", "in", "data" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L188-L195
156,196
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
updateJoystick
func (w *WiichuckDriver) updateJoystick() { joy := w.Joystick() w.Publish(w.Event(Joystick), map[string]float64{ "x": w.calculateJoystickValue(w.data["sx"], joy["sx_origin"]), "y": w.calculateJoystickValue(w.data["sy"], joy["sy_origin"]), }) }
go
func (w *WiichuckDriver) updateJoystick() { joy := w.Joystick() w.Publish(w.Event(Joystick), map[string]float64{ "x": w.calculateJoystickValue(w.data["sx"], joy["sx_origin"]), "y": w.calculateJoystickValue(w.data["sy"], joy["sy_origin"]), }) }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "updateJoystick", "(", ")", "{", "joy", ":=", "w", ".", "Joystick", "(", ")", "\n", "w", ".", "Publish", "(", "w", ".", "Event", "(", "Joystick", ")", ",", "map", "[", "string", "]", "float64", "{", "...
// updateJoystick publishes event with current x and y values for joystick
[ "updateJoystick", "publishes", "event", "with", "current", "x", "and", "y", "values", "for", "joystick" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L198-L204
156,197
hybridgroup/gobot
drivers/i2c/wiichuck_driver.go
parse
func (w *WiichuckDriver) parse(value []byte) { w.data["sx"] = w.decode(value[0]) w.data["sy"] = w.decode(value[1]) w.data["z"] = float64(uint8(w.decode(value[5])) & 0x01) w.data["c"] = float64(uint8(w.decode(value[5])) & 0x02) }
go
func (w *WiichuckDriver) parse(value []byte) { w.data["sx"] = w.decode(value[0]) w.data["sy"] = w.decode(value[1]) w.data["z"] = float64(uint8(w.decode(value[5])) & 0x01) w.data["c"] = float64(uint8(w.decode(value[5])) & 0x02) }
[ "func", "(", "w", "*", "WiichuckDriver", ")", "parse", "(", "value", "[", "]", "byte", ")", "{", "w", ".", "data", "[", "\"", "\"", "]", "=", "w", ".", "decode", "(", "value", "[", "0", "]", ")", "\n", "w", ".", "data", "[", "\"", "\"", "]"...
// parse sets driver values based on parsed value
[ "parse", "sets", "driver", "values", "based", "on", "parsed", "value" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/wiichuck_driver.go#L207-L212
156,198
hybridgroup/gobot
platforms/opencv/camera_driver.go
NewCameraDriver
func NewCameraDriver(source interface{}) *CameraDriver { c := &CameraDriver{ name: "Camera", Eventer: gobot.NewEventer(), Source: source, start: func(c *CameraDriver) (err error) { switch v := c.Source.(type) { case string: c.camera, _ = gocv.VideoCaptureFile(v) case int: c.camera, _ = gocv.VideoCaptureDevice(v) default: return errors.New("Unknown camera source") } return }, } c.AddEvent(Frame) return c }
go
func NewCameraDriver(source interface{}) *CameraDriver { c := &CameraDriver{ name: "Camera", Eventer: gobot.NewEventer(), Source: source, start: func(c *CameraDriver) (err error) { switch v := c.Source.(type) { case string: c.camera, _ = gocv.VideoCaptureFile(v) case int: c.camera, _ = gocv.VideoCaptureDevice(v) default: return errors.New("Unknown camera source") } return }, } c.AddEvent(Frame) return c }
[ "func", "NewCameraDriver", "(", "source", "interface", "{", "}", ")", "*", "CameraDriver", "{", "c", ":=", "&", "CameraDriver", "{", "name", ":", "\"", "\"", ",", "Eventer", ":", "gobot", ".", "NewEventer", "(", ")", ",", "Source", ":", "source", ",", ...
// NewCameraDriver creates a new driver with specified source. // It also creates a start function to either set camera as a File or Camera capture.
[ "NewCameraDriver", "creates", "a", "new", "driver", "with", "specified", "source", ".", "It", "also", "creates", "a", "start", "function", "to", "either", "set", "camera", "as", "a", "File", "or", "Camera", "capture", "." ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/opencv/camera_driver.go#L30-L51
156,199
hybridgroup/gobot
platforms/opencv/camera_driver.go
Start
func (c *CameraDriver) Start() (err error) { if err := c.start(c); err != nil { return err } img := gocv.NewMat() go func() { for { if ok := c.camera.Read(&img); ok { c.Publish(Frame, img) } } }() return }
go
func (c *CameraDriver) Start() (err error) { if err := c.start(c); err != nil { return err } img := gocv.NewMat() go func() { for { if ok := c.camera.Read(&img); ok { c.Publish(Frame, img) } } }() return }
[ "func", "(", "c", "*", "CameraDriver", ")", "Start", "(", ")", "(", "err", "error", ")", "{", "if", "err", ":=", "c", ".", "start", "(", "c", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "img", ":=", "gocv", ".", "NewM...
// Start initializes camera by grabbing frames
[ "Start", "initializes", "camera", "by", "grabbing", "frames" ]
58db149a40a113aec7d6068fb9418b7e05de1802
https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/opencv/camera_driver.go#L63-L76