-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
175 lines (152 loc) · 3.75 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package main
import (
"flag"
"fmt"
"log"
"os"
)
var (
cliShowDisplay bool
cliGetDisplay bool
cliSetDisplay bool
cliDisplayHandle int
cliUseHandle bool = false
cliUseAll bool = false
cliVCPCode int
cliVCPValue int
cliDemo bool
cliHelp bool
cliVersion bool
)
func init() {
// 对显示器执行的操作
flag.BoolVar(&cliShowDisplay, "show", false, "show display infos")
flag.BoolVar(&cliGetDisplay, "get", false, "get display data")
flag.BoolVar(&cliSetDisplay, "set", false, "set display data")
// 按特征值选择显示器
flag.IntVar(&cliDisplayHandle, "handle", -1, "Display Handle")
flag.BoolVar(&cliUseAll, "all", false, "All Display(default)")
// VCP Code 相关
flag.IntVar(&cliVCPCode, "vcp", -1, "VCP Code")
flag.IntVar(&cliVCPValue, "value", -1, "VCP Value")
// cli基础
flag.BoolVar(&cliDemo, "demo", false, "brightness setting demo")
flag.BoolVar(&cliHelp, "h", false, "show help")
flag.BoolVar(&cliVersion, "v", false, "show version")
flag.Parse()
// 重写显示用法函数
flag.Usage = func() {
var helpInfo = `Usage:
dccli [Command] [Arguments]
Command:
-show : show display monitor info
-get : get vcp feature value from select display monitors
-set : set vcp feature value for select display monitors
-demo : simple demo to control brightness
-h : show help
-v : show version
Arguments:
-handle <int_number> : select display monitor by handle
-all : select all display monitor
-vcp <vcp_code> : specify vcp code
-value <vcp_feature_value> : specify vcp feature value
Example:
1) run brightness demo: dccli -demo
2) show all display monitor info: dccli -show
3) get brightness from monitor 0: dccli -get -handle 0 -vcp 0x10
4) set monitor 0's brightness to 50% : dccli -set -handle 0 -vcp 0x10 -value 50
5) power off monitor 1: dccli -set -handle 1 -vcp 0xD6 -value 05`
fmt.Println(helpInfo)
}
// demo控制亮度
if len(os.Args) == 1 || cliDemo {
err := runDemo()
if err != nil {
log.Fatalln(err)
}
os.Exit(0)
}
// help
if cliHelp {
flag.Usage()
os.Exit(0)
}
// 打印版本信息
if cliVersion {
fmt.Println("v1.01")
os.Exit(0)
}
// 显示器 handle 指定
if cliDisplayHandle != -1 {
cliUseHandle = true
} else {
cliUseAll = true
}
// get 功能检测
if cliGetDisplay {
// vcp 代码需要指定
if cliVCPCode == -1 {
log.Fatalln("no specify vcp code")
}
}
// set 功能检测
if cliSetDisplay {
// vcp 代码需要指定
if cliVCPCode == -1 {
log.Fatalln("no specify vcp code")
}
// vcp 功能值需要指定
if cliVCPValue == -1 {
log.Fatalln("no specify vcp feature value")
}
}
}
func showChangelog() {
var versionInfo = `Changelog:
1.00:
- First release
1.0.1:
- Compatible to displayController v1.01`
fmt.Println(versionInfo)
}
func main() {
if cliShowDisplay {
if cliUseHandle {
err := showDisplayByHandle(cliDisplayHandle)
if err != nil {
log.Fatalln(err)
}
} else if cliUseAll {
err := showAllDisplay()
if err != nil {
log.Fatalln(err)
}
}
}
if cliGetDisplay {
if cliUseHandle {
err := getDisplayByHandle(cliDisplayHandle, byte(cliVCPCode))
if err != nil {
log.Fatalln(err)
}
} else if cliUseAll {
err := getAllDisplay(byte(cliVCPCode))
if err != nil {
log.Fatalln(err)
}
}
}
if cliSetDisplay {
if cliUseHandle {
err := setDisplayByHandle(cliDisplayHandle, byte(cliVCPCode), cliVCPValue)
if err != nil {
log.Fatalln(err)
}
} else if cliUseAll {
err := setAllDisplay(byte(cliVCPCode), cliVCPValue)
if err != nil {
log.Fatalln(err)
}
}
}
}