1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00

Merge pull request #290 from dgryski/gosimple

Code cleanups suggested by gosimple
This commit is contained in:
Ron Evans 2016-07-15 09:03:02 -06:00 committed by GitHub
commit 913e9371a7
11 changed files with 20 additions and 44 deletions

View File

@ -1019,10 +1019,8 @@ func RestoreAsset(dir, name string) error {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
return err
}
// RestoreAssets restores an asset under the given directory recursively

View File

@ -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)
}
})

View File

@ -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()
}
})
@ -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 {
@ -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)))
}
}

View File

@ -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()

View File

@ -62,7 +62,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
}
@ -78,7 +78,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
}

View File

@ -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]))
}
}

View File

@ -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) {

View File

@ -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 {

View File

@ -171,10 +171,7 @@ 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:
@ -182,10 +179,7 @@ func (m *MCP23017Driver) SetPullUp(pin uint8, val uint8, portStr string) error {
// 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

View File

@ -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]
@ -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)

View File

@ -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
}