1+ /*************************************************************************************
2+ * This file is an example code on how to use MOZA Shifter device-related interfaces with MOZA SDK C#
3+ *
4+ * For other APIs in MOZA SDK, please refer to the example code file `sdk_api_test.cc` in the MOZA SDK C++ version.
5+ * You can also refer to the API documentation of the C++ version, located at `docsEng/index.html`.
6+ * The API in the MOZA SDK C# version is almost identical to the C++ version in terms of function names and input parameters.
7+ *************************************************************************************/
8+
9+ using mozaAPI ;
10+ using static mozaAPI . mozaAPI ;
11+
12+ MozaShifterTest ( ) ;
13+ Console . WriteLine ( "Program finished." ) ;
14+ return ;
15+
16+ void MozaShifterTest ( )
17+ {
18+ var devices = EnumShifterDevices ( out var error ) ;
19+ if ( error != ERRORCODE . NORMAL || devices . Count == 0 )
20+ {
21+ Console . WriteLine ( $ "No MOZA Shifter device found, error = { error } ") ;
22+ return ;
23+ }
24+
25+ var device = devices [ 0 ] ;
26+ if ( ! device . Open ( ) )
27+ {
28+ Console . WriteLine ( "Device open failed." ) ;
29+ return ;
30+ }
31+
32+ Console . WriteLine ( $ "MOZA Shifter device '{ device . Path } ' is opened.") ;
33+
34+ var gear = 0 ;
35+ while ( device . IsConnected )
36+ {
37+ // The `GetCurrentGear` function waits for the HID report while reading data, until valid data is received or an error occurs.
38+ // This means the execution time of this function may be relatively long, and it is not recommended to call it in the main thread.
39+ var currentGear = device . GetCurrentGear ( ) ;
40+ if ( gear == currentGear ) continue ;
41+ Console . WriteLine ( $ "The gear has been switched from { gear } to { currentGear } ") ;
42+ gear = currentGear ;
43+ }
44+
45+ Console . WriteLine ( "The device has been disconnected." ) ;
46+ }
0 commit comments