Skip to content

Commit

Permalink
cmd: Make -hz argument coherent across tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
maruel committed Apr 9, 2017
1 parent 25208bc commit d9641df
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions cmd/apa102/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func mainImpl() error {
numLights := flag.Int("n", 150, "number of lights on the strip")
intensity := flag.Int("l", 127, "light intensity [1-255]")
temperature := flag.Int("t", 5000, "light temperature in °Kelvin [3500-7500]")
speed := flag.Int("s", 0, "speed in Hz")
hz := flag.Int("hz", 0, "SPI bus speed")
color := flag.String("color", "208020", "hex encoded color to show")
imgName := flag.String("img", "", "image to load")
lineMs := flag.Int("linems", 2, "number of ms to show each line of the image")
Expand Down Expand Up @@ -145,8 +145,8 @@ func mainImpl() error {
return err
}
defer bus.Close()
if *speed != 0 {
if err := bus.LimitSpeed(int64(*speed)); err != nil {
if *hz != 0 {
if err := bus.LimitSpeed(int64(*hz)); err != nil {
return err
}
}
Expand Down
13 changes: 10 additions & 3 deletions cmd/bme280/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func mainImpl() error {
i2cID := flag.String("i2c", "", "I²C bus to use")
i2cADDR := flag.Uint("ia", 0, "I²C bus address to use")
spiID := flag.String("spi", "", "SPI bus to use")
hz := flag.Int("hz", 0, "I²C/SPI bus speed")
sample1x := flag.Bool("s1", false, "sample at 1x")
sample2x := flag.Bool("s2", false, "sample at 2x")
sample4x := flag.Bool("s4", false, "sample at 4x")
Expand Down Expand Up @@ -115,9 +116,10 @@ func mainImpl() error {
printPin("MISO", p.MISO())
printPin("CS", p.CS())
}
// Slow down bus speed in case wires are too long.
if err := bus.LimitSpeed(100000); err != nil {
return err
if *hz != 0 {
if err := bus.LimitSpeed(int64(*hz)); err != nil {
return err
}
}
if dev, err = bme280.NewSPI(bus, &opts); err != nil {
return err
Expand All @@ -132,6 +134,11 @@ func mainImpl() error {
printPin("SCL", p.SCL())
printPin("SDA", p.SDA())
}
if *hz != 0 {
if err := bus.SetSpeed(int64(*hz)); err != nil {
return err
}
}
if dev, err = bme280.NewI2C(bus, &opts); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/i2c-io/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func mainImpl() error {
// TODO(maruel): This is not generic enough.
write := flag.Bool("w", false, "write instead of reading")
reg := flag.Int("r", -1, "register to address")
hz := flag.Int("hz", 0, "change the bus frequency (may require root)")
hz := flag.Int("hz", 0, "I²C bus speed (may require root)")
l := flag.Int("l", 1, "length of data to read; ignored if -w is specified")
flag.Parse()
if !*verbose {
Expand Down
11 changes: 8 additions & 3 deletions cmd/ssd1306/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func mainImpl() error {
i2cID := flag.String("i2c", "", "I²C bus to use")
spiID := flag.String("spi", "", "SPI bus to use")
dcName := flag.String("dc", "", "DC pin to use in 4-wire SPI mode")
speed := flag.Int("speed", 0, "specify SPI speed in Hz to use")
hz := flag.Int("hz", 0, "I²C/SPI bus speed")

h := flag.Int("h", 64, "display height")
w := flag.Int("w", 128, "display width")
Expand Down Expand Up @@ -169,8 +169,8 @@ func mainImpl() error {
return err
}
defer bus.Close()
if *speed != 0 {
if err := bus.LimitSpeed(int64(*speed)); err != nil {
if *hz != 0 {
if err := bus.LimitSpeed(int64(*hz)); err != nil {
return err
}
}
Expand All @@ -192,6 +192,11 @@ func mainImpl() error {
return err
}
defer bus.Close()
if *hz != 0 {
if err := bus.SetSpeed(int64(*hz)); err != nil {
return err
}
}
if p, ok := bus.(i2c.Pins); ok {
// TODO(maruel): Print where the pins are located.
log.Printf("Using pins SCL: %s SDA: %s", p.SCL(), p.SDA())
Expand Down

0 comments on commit d9641df

Please sign in to comment.