Skip to content

Commit

Permalink
Code cleanups suggested by gosimple
Browse files Browse the repository at this point in the history
  • Loading branch information
dgryski committed Jul 13, 2016
1 parent 67ff7da commit 977c878
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 44 deletions.
6 changes: 2 additions & 4 deletions api/robeaux/robeaux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/ardrone_face_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
var image *cv.IplImage
gobot.On(camera.Event("frame"), func(data interface{}) {
image = data.(*cv.IplImage)
if detect == false {
if !detect {
window.ShowImage(image)
}
})
Expand Down
10 changes: 5 additions & 5 deletions examples/sphero_conways.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ func main() {
})

gobot.Every(3*time.Second, func() {
if conway.alive == true {
if conway.alive {
conway.movement()
}
})

gobot.Every(10*time.Second, func() {
if conway.alive == true {
if conway.alive {
conway.birthday()
}
})
Expand Down Expand Up @@ -107,8 +107,8 @@ func (c *conway) birthday() {

fmt.Println("Happy birthday", c.cell.Name, "you are", c.age, "and had", c.contacts, "contacts.")

if c.enoughContacts() == true {
if c.alive == false {
if c.enoughContacts() {
if !c.alive {
c.rebirth()
}
} else {
Expand All @@ -119,7 +119,7 @@ func (c *conway) birthday() {
}

func (c *conway) movement() {
if c.alive == true {
if c.alive {
c.cell.Roll(100, uint16(gobot.Rand(360)))
}
}
2 changes: 1 addition & 1 deletion gobot.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (g *Gobot) Start() (errs []error) {
}

// waiting for interrupt coming on the channel
_ = <-c
<-c

// Stop calls the Stop method on each robot in its collection of robots.
g.Stop()
Expand Down
4 changes: 2 additions & 2 deletions platforms/digispark/digispark_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (d *DigisparkAdaptor) DigitalWrite(pin string, level byte) (err error) {

// PwmWrite writes the 0-254 value to the specified pin
func (d *DigisparkAdaptor) PwmWrite(pin string, value byte) (err error) {
if d.pwm == false {
if !d.pwm {
if err = d.littleWire.pwmInit(); err != nil {
return
}
Expand All @@ -87,7 +87,7 @@ func (d *DigisparkAdaptor) PwmWrite(pin string, value byte) (err error) {

// ServoWrite writes the 0-180 degree val to the specified pin.
func (d *DigisparkAdaptor) ServoWrite(pin string, angle uint8) (err error) {
if d.servo == false {
if !d.servo {
if err = d.littleWire.servoInit(); err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion platforms/firmata/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (b *Client) process() (err error) {
b.FirmwareName = string(name[:])
gobot.Publish(b.Event("FirmwareQuery"), b.FirmwareName)
case StringData:
str := currentBuffer[2:len(currentBuffer)]
str := currentBuffer[2:]
gobot.Publish(b.Event("StringData"), string(str[:len(str)-1]))
}
}
Expand Down
5 changes: 1 addition & 4 deletions platforms/gpio/motor_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ func (m *MotorDriver) Direction(direction string) (err error) {
}

func (m *MotorDriver) isDigital() bool {
if m.CurrentMode == "digital" {
return true
}
return false
return m.CurrentMode == "digital"
}

func (m *MotorDriver) changeState(state byte) (err error) {
Expand Down
5 changes: 1 addition & 4 deletions platforms/i2c/jhd1313m1_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ func (h *JHD1313M1Driver) Scroll(leftToRight bool) error {
func (h *JHD1313M1Driver) Halt() []error { return nil }

func (h *JHD1313M1Driver) setReg(command int, data int) error {
if err := h.connection.I2cWrite(h.rgbAddress, []byte{byte(command), byte(data)}); err != nil {
return err
}
return nil
return h.connection.I2cWrite(h.rgbAddress, []byte{byte(command), byte(data)})
}

func (h *JHD1313M1Driver) command(buf []byte) error {
Expand Down
10 changes: 2 additions & 8 deletions platforms/i2c/mcp23017_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,15 @@ func (m *MCP23017Driver) ReadGPIO(pin uint8, portStr string) (val uint8, err err
// val = 0 pull up disabled.
func (m *MCP23017Driver) SetPullUp(pin uint8, val uint8, portStr string) error {
selectedPort := m.getPort(portStr)
if err := m.write(selectedPort.GPPU, pin, val); err != nil {
return err
}
return nil
return m.write(selectedPort.GPPU, pin, val)
}

// SetGPIOPolarity will change a given pin's polarity based on the value:
// val = 1 opposite logic state of the input pin.
// val = 0 same logic state of the input pin.
func (m *MCP23017Driver) SetGPIOPolarity(pin uint8, val uint8, portStr string) (err error) {
selectedPort := m.getPort(portStr)
if err := m.write(selectedPort.IPOL, pin, val); err != nil {
return err
}
return nil
return m.write(selectedPort.IPOL, pin, val)
}

// write gets the value of the passed in register, and then overwrites
Expand Down
4 changes: 2 additions & 2 deletions platforms/sphero/sphero_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (s *SpheroDriver) Start() (errs []error) {
go func() {
for {
header := s.readHeader()
if header != nil && len(header) != 0 {
if len(header) > 0 {
body := s.readBody(header[4])
data := append(header, body...)
checksum := data[len(data)-1]
Expand Down Expand Up @@ -268,7 +268,7 @@ func (s *SpheroDriver) SetHeading(heading uint16) {
// SetStabilization enables or disables the built-in auto stabilizing features of the Sphero
func (s *SpheroDriver) SetStabilization(on bool) {
b := uint8(0x01)
if on == false {
if !on {
b = 0x00
}
s.packetChannel <- s.craftPacket([]uint8{b}, 0x02, 0x02)
Expand Down
14 changes: 2 additions & 12 deletions robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,8 @@ func (r *Robot) Start() (errs []error) {
// Stop stops a Robot's connections and Devices
func (r *Robot) Stop() (errs []error) {
log.Println("Stopping Robot", r.Name, "...")
if heers := r.Devices().Halt(); len(heers) > 0 {
for _, err := range heers {
errs = append(errs, err)
}
}

if ceers := r.Connections().Finalize(); len(ceers) > 0 {
for _, err := range ceers {
errs = append(errs, err)
}
}

errs = append(errs, r.Devices().Halt()...)
errs = append(errs, r.Connections().Finalize()...)
return errs
}

Expand Down

0 comments on commit 977c878

Please sign in to comment.