11using System ;
2- using System . Collections . Generic ;
32using System . Runtime . InteropServices . WindowsRuntime ;
4- using System . Text ;
53using System . Threading ;
6- using System . Threading . Tasks ;
74using Windows . Devices . Bluetooth ;
85using Windows . Devices . Bluetooth . Advertisement ;
96using Windows . Devices . Enumeration ;
@@ -24,31 +21,34 @@ static void Main(string[] args)
2421 {
2522 int limit = 1 ;
2623 int timeout = 120 ;
27- Commands cmd = Commands . GetTemp ;
24+ Commands command = Commands . GetTemp ;
2825
2926 for ( var j = 0 ; j < args . Length ; j ++ )
3027 {
3128 switch ( args [ j ] )
3229 {
3330 case "--limit" :
34- if ( j + 1 >= args . Length ) throw new Exception ( "-limit のパラメータが足りません" ) ;
31+ if ( j + 1 >= args . Length ) throw new Exception ( "-- limit のパラメータが足りません" ) ;
3532 j ++ ;
3633 limit = int . Parse ( args [ j ] ) ;
3734 break ;
3835 case "--timeout" :
36+ if ( j + 1 >= args . Length ) throw new Exception ( "--timeout のパラメータがありません" ) ;
37+ j ++ ;
38+ timeout = int . Parse ( args [ j ] ) ;
3939 break ;
4040 case "--list" :
4141 case "-l" :
42- cmd = Commands . List ;
42+ command = Commands . List ;
4343 break ;
4444 case "--help" :
4545 case "-h" :
46- cmd = Commands . Help ;
46+ command = Commands . Help ;
4747 break ;
4848 }
4949 }
5050
51- switch ( cmd )
51+ switch ( command )
5252 {
5353 case Commands . GetTemp :
5454 GetTemp ( limit , timeout ) ;
@@ -64,7 +64,7 @@ static void Main(string[] args)
6464
6565 private static void Help ( )
6666 {
67- Console . WriteLine ( "Usage: SwitchbotThermometerApp [options...]\n "
67+ Console . WriteLine ( "Usage: SwitchBotMeter [options...]\n "
6868 + " Options:\n "
6969 + " --limit N Limit results (default: 1, unlimited: 0)\n "
7070 + " -t --timeout N Timeout seconds(default: 120, unlimited: 0)\n "
@@ -122,7 +122,8 @@ private static void GetTemp(int limit, int timeout)
122122 var data = ds . Data . ToArray ( 2 , 6 ) ;
123123 double temp = ( ( data [ 3 ] & 0x0f ) / 10.0 + ( data [ 4 ] & 0x7f ) ) * ( ( data [ 4 ] & 0x80 ) != 0 ? 1 : - 1 ) ;
124124 int humidity = data [ 5 ] & 0x7f ;
125- Console . WriteLine ( $ "{ args . BluetoothAddress : X} { temp : f1} { humidity : d} ") ;
125+ int battery = data [ 2 ] & 0x7f ;
126+ Console . WriteLine ( $ "{ args . BluetoothAddress : X} { temp : f1} { humidity : d} { battery : d} ") ;
126127 if ( limit > 0 ) countdownEvent . Signal ( ) ;
127128 }
128129 }
0 commit comments