@@ -87,16 +87,16 @@ enum LedState {
8787impl LedState {
8888 fn magic ( & self ) -> [ u8 ; 64 ] {
8989 match self {
90- Self :: On => hex ! ( "
90+ Self :: On => hex ! { "
9191 0478293800000000000002000000000000000000000000000000000000000000
9292 000000000000000000000000007a000000000000000000000000000000000000
93- " ) ,
94- Self :: Sleep => hex ! ( "
93+ " } ,
94+ Self :: Sleep => hex ! { "
9595 0478293800000000000002000000000000000000000000000000000000000000
9696 000000000000000000000000007b000000000000000000000000000000000000
9797 // ^- vive console also sends c here, but i see no difference between b and c
9898 // perhaps brightness, but hardware only supports 2 levels?
99- " ) ,
99+ " } ,
100100 // Also used on bootup, i see no effect
101101 // Self::Idk => hex!("
102102 // 0478293800000000000000000000000000000000000000000000000000000000
@@ -118,7 +118,7 @@ fn reset_dp(device: &HidDevice) -> Result<()> {
118118/// Hardcoded in official software too
119119#[ derive( Clone , Copy , ArgEnum ) ]
120120#[ repr( u8 ) ]
121- enum Mode {
121+ enum Resolution {
122122 R2448x1224f90 = 0 ,
123123 R2448x1224f120 = 1 ,
124124 R3264x1632f90 = 2 ,
@@ -127,13 +127,31 @@ enum Mode {
127127 R4896x2448f120 = 5 ,
128128}
129129
130- fn set_mode ( device : & HidDevice , mode : Mode ) -> Result < ( ) > {
130+ fn set_resolution ( device : & HidDevice , resolution : Resolution ) -> Result < ( ) > {
131131 // If not sent - something is wrong
132132 send_str_report ( & device, false , b"wireless,0" ) ?;
133- send_str_report ( & device, false , & format ! ( "dtd,{}" , mode as u8 ) . as_bytes ( ) ) ?;
133+ send_str_report (
134+ & device,
135+ false ,
136+ & format ! ( "dtd,{}" , resolution as u8 ) . as_bytes ( ) ,
137+ ) ?;
134138 Ok ( ( ) )
135139}
136140
141+ fn set_mode ( device : & HidDevice , mst : bool , dsc : bool , amdgpu : bool ) -> Result < ( ) > {
142+ send_str_report (
143+ & device,
144+ false ,
145+ & format ! (
146+ "mode,{},{},{}" ,
147+ if mst { '1' } else { '0' } ,
148+ if dsc { '1' } else { '0' } ,
149+ if amdgpu { '1' } else { '0' }
150+ )
151+ . as_bytes ( ) ,
152+ )
153+ }
154+
137155#[ derive( Clone , Copy , ArgEnum ) ]
138156enum NoiseCancelState {
139157 Disable ,
@@ -146,12 +164,18 @@ enum Args {
146164 /// Reconnect HMD
147165 ResetDp ,
148166 /// Restart HMD with new reported resolution
149- SetMode {
150- #[ clap( arg_enum) ]
151- mode : Mode ,
152- /// vive console does this, but dtd command already performs reset
167+ Mode {
168+ /// Multi-stream-transport
169+ #[ clap( long) ]
170+ mst : bool ,
171+ /// Display stream compression
172+ #[ clap( long) ]
173+ dsc : bool ,
174+ /// ?
153175 #[ clap( long) ]
154- reset : bool ,
176+ amdgpu : bool ,
177+ #[ clap( arg_enum) ]
178+ resolution : Resolution ,
155179 } ,
156180 /// Change display brightness
157181 SetBrightness {
@@ -167,6 +191,11 @@ enum Args {
167191 #[ clap( arg_enum) ]
168192 state : LedState ,
169193 } ,
194+ Payload {
195+ #[ clap( long) ]
196+ alt : bool ,
197+ value : String ,
198+ } ,
170199 /// Testing only, performs full initialization sequence (captured on windows)
171200 Magic ,
172201}
@@ -177,11 +206,16 @@ fn main() -> Result<()> {
177206 let device = manager. open ( 0x0bb4 , 0x0342 ) ?;
178207 match args {
179208 Args :: ResetDp => reset_dp ( & device) ?,
180- Args :: SetMode { mode, reset } => {
181- set_mode ( & device, mode) ?;
182- if reset {
183- reset_dp ( & device) ?;
184- }
209+ Args :: Mode {
210+ resolution,
211+ mst,
212+ dsc,
213+ amdgpu,
214+ } => {
215+ set_mode ( & device, mst, dsc, amdgpu) ?;
216+ set_resolution ( & device, resolution) ?;
217+ // set_mode does strage things without DP reset
218+ reset_dp ( & device) ?;
185219 // TODO: Wait for device to reappear?
186220 }
187221 Args :: SetBrightness { value } => {
@@ -193,56 +227,47 @@ fn main() -> Result<()> {
193227 Args :: Led { state } => {
194228 set_led ( & device, state) ?;
195229 }
230+ Args :: Payload { alt, value } => send_str_report ( & device, alt, value. as_bytes ( ) ) ?,
196231 Args :: Magic => {
197232 send_magic_report (
198233 & device,
199- & hex ! (
200- "
201- 0478293801000000000000000000000000000000000000000000000000000000
202- 0000000000000000000000000000000000000000000000000000000000000000
203- "
204- ) ,
234+ & hex ! { "
235+ 0478293801000000000000000000000000000000000000000000000000000000
236+ 0000000000000000000000000000000000000000000000000000000000000000
237+ " } ,
205238 ) ?;
206239 send_magic_report (
207240 & device,
208- & hex ! (
209- "
210- 0478293801000000000000000100000000000000000000000000000000000000
211- 0000000000000000000000000000000000000000000000000000000000000000
212- "
213- ) ,
241+ & hex ! { "
242+ 0478293801000000000000000100000000000000000000000000000000000000
243+ 0000000000000000000000000000000000000000000000000000000000000000
244+ " } ,
214245 ) ?;
215246 send_magic_report (
216247 & device,
217- & hex ! (
218- "
219- 04782938010000000000000001725f766976655fb2551e4d6ff1cf1188cb0011
220- 11000030686463fa9b020000b8dc63fa9b020000b2551e4d6ff1cf1100000000
221- "
222- ) ,
248+ & hex ! { "
249+ 04782938010000000000000001725f766976655fb2551e4d6ff1cf1188cb0011
250+ 11000030686463fa9b020000b8dc63fa9b020000b2551e4d6ff1cf1100000000
251+ " } ,
223252 ) ?;
224253 set_led ( & device, LedState :: On ) ?;
225254 set_brightness ( & device, Brightness ( 130 ) ) ?;
226255 send_magic_report (
227256 & device,
228- & hex ! (
229- "
230- 0478293808000000000000000000000100000000000000000000000000000000
231- 0000000000000000000000000000000000000000000000000000000000000000
232- "
233- ) ,
257+ & hex ! { "
258+ 0478293808000000000000000000000100000000000000000000000000000000
259+ 0000000000000000000000000000000000000000000000000000000000000000
260+ " } ,
234261 ) ?;
235262 toggle_mic_noise_cancel ( & device, false ) ?;
236263 send_magic_report (
237264 & device,
238- & hex ! (
239- "
240- 0478293800000000000000000000000000000000000000000000000000000000
241- 0000000000000000000000000000000000000000000000000000000000000000
242- "
243- ) ,
265+ & hex ! { "
266+ 0478293800000000000000000000000000000000000000000000000000000000
267+ 0000000000000000000000000000000000000000000000000000000000000000
268+ " } ,
244269 ) ?;
245- set_mode ( & device, Mode :: R2448x1224f90 ) ?;
270+ set_resolution ( & device, Resolution :: R2448x1224f90 ) ?;
246271 reset_dp ( & device) ?;
247272 }
248273 }
0 commit comments