forked from gerryd/ms213x-status
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
75 lines (61 loc) · 1.61 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"os"
"github.com/BertoldVdb/ms-tools/gohid"
"github.com/BertoldVdb/ms-tools/mshal"
"github.com/alecthomas/kong"
)
type Context struct {
dev gohid.HIDDevice
hal *mshal.HAL
}
var CLI struct {
VID int `optional type:"hex" help:"The USB Vendor ID." default:534d`
VID2 int `optional type:"hex" help:"The second USB Vendor ID." default:345f`
PID int `optional type:"hex" help:"The USB Product ID."`
Serial string `optional help:"The USB Serial."`
RawPath string `optional help:"The USB Device Path."`
ListDev ListHIDCmd `cmd help:"List devices."`
Status StatusCmd `cmd help:"Print status." default:1`
Firmware FirmwareCmd `cmd help:"Do firmware things."`
}
func main() {
k, err := kong.New(&CLI,
kong.NamedMapper("int", intMapper{}),
kong.NamedMapper("hex", intMapper{base: 16}))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
ctx, err := k.Parse(os.Args[1:])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
c := &Context{}
if ctx.Command() != "list-dev" && ctx.Command() != "firmware" {
dev, err := OpenDevice()
if err != nil {
fmt.Println("Failed to open device", err)
os.Exit(1)
}
defer dev.Close()
c.dev = dev
config := mshal.HALConfig{
// auto-assume EEPROM in mshal
PatchProbeEEPROM: true,
LogFunc: func(level int, format string, param ...interface{}) {
//str := fmt.Sprintf(format, param...)
//fmt.Printf("HAL(%d): %s\n", level, str)
},
}
c.hal, err = mshal.New(dev, config)
if err != nil {
fmt.Println("Failed to create HAL", err)
os.Exit(1)
}
}
err = ctx.Run(c)
ctx.FatalIfErrorf(err)
}