Skip to content

Commit

Permalink
Updates to HW
Browse files Browse the repository at this point in the history
  • Loading branch information
djthorpe committed Dec 17, 2020
1 parent 1af6c4d commit 6c2d9d7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
7 changes: 5 additions & 2 deletions cmd/argonone/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ type app struct {
func (this *app) Define(cfg gopi.Config) error {
cfg.Command("daemon", "Start daemon", this.RunServe)
cfg.Command("version", "Server version", this.RunVersion)
cfg.Command("stream", "Stream events from Argonone", this.RunStream)
return nil
}

func (this *app) New(cfg gopi.Config) error {
if this.Command = cfg.GetCommand(cfg.Args()); this.Command == nil {
if cmd, err := cfg.GetCommand(nil); err != nil {
return err
} else if cmd == nil {
return gopi.ErrHelp
} else {
this.Command = cmd
}
return nil
}
Expand Down
26 changes: 15 additions & 11 deletions cmd/hw/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,44 @@ func (this *app) Define(cfg gopi.Config) error {
this.i2cbus = cfg.FlagUint("bus", 0, "I2C Bus", "i2c")
this.timeout = cfg.FlagDuration("timeout", time.Second, "Discovery timeout", "mdns")

// Define version command
// Define commands
cfg.Command("version", "Return information about the command", func(context.Context) error {
if err := this.PrintVersion(cfg); err != nil {
return err
} else {
return gopi.ErrHelp
}
})

// Define LIRC command
cfg.Command("lirc", "IR sending and receiving control", func(ctx context.Context) error {
return this.RunLIRC(ctx, cfg)
})
cfg.Command("lirc print", "Print LIRC Parameters", func(ctx context.Context) error {
return nil
})

// Define mDNS command
cfg.Command("mdns", "Service discovery", this.RunDiscovery)
/*
// Define mDNS command
cfg.Command("mdns", "Service discovery", this.RunDiscovery)
// Define other commands
cfg.Command("hw", "Return hardware platform information", this.RunHardware)
cfg.Command("i2c", "Return I2C interface parameters", this.RunI2C)
cfg.Command("gpio", "Control GPIO interface", this.RunGPIO)
cfg.Command("fonts", "Return Font faces", this.RunFonts) // Not yet implemented
// Define other commands
cfg.Command("hw", "Return hardware platform information", this.RunHardware)
cfg.Command("i2c", "Return I2C interface parameters", this.RunI2C)
cfg.Command("gpio", "Control GPIO interface", this.RunGPIO)
cfg.Command("fonts", "Return Font faces", this.RunFonts) // Not yet implemented
*/

// Return success
return nil
}

func (this *app) New(cfg gopi.Config) error {
// Set the command to run
if this.Command = cfg.GetCommand(nil); this.Command == nil {
if cmd, err := cfg.GetCommand(nil); err != nil {
return err
} else if cmd == nil {
return gopi.ErrHelp
} else {
this.Command = cmd
}

// Return success
Expand Down
6 changes: 0 additions & 6 deletions cmd/hw/lirc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ func (this *app) RunLIRC(ctx context.Context, cfg gopi.Config) error {
return fmt.Errorf("LIRC is not enabled")
}

if cmd := cfg.GetCommand(this.Args()); cmd == nil {
return gopi.ErrHelp
} else {
fmt.Println("command=", cmd)
}

// Return sucess
return nil
}
9 changes: 6 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,12 @@ func (this *config) usageAll() {
name := this.FlagSet.Name()

fmt.Fprintln(w, "Syntax:")
fmt.Fprintf(w, " %v (<flags>) <command> (<args>)\n", name)
fmt.Fprintf(w, " %v -help (<command>)\n", name)
if len(this.commands.commands) > 0 {
if len(this.commands.commands) == 0 {
fmt.Fprintf(w, " %v (<flags>) (<args>)\n", name)
fmt.Fprintf(w, " %v -help\n", name)
} else {
fmt.Fprintf(w, " %v (<flags>) <command> (<args>)\n", name)
fmt.Fprintf(w, " %v -help (<command>)\n", name)
fmt.Fprintln(w, "\nCommands:")
}
usageCommand(w, this.commands, nil)
Expand Down

0 comments on commit 6c2d9d7

Please sign in to comment.