11using System ;
22using System . Collections . Generic ;
33using System . Text . RegularExpressions ;
4+ using System . Threading . Tasks ;
45using System . Windows . Forms ;
56using Windows . Devices . Bluetooth ;
67using Windows . Devices . Bluetooth . GenericAttributeProfile ;
@@ -19,21 +20,45 @@ public partial class Form1 : Form
1920
2021 private Regex regex = new Regex ( "^LHB-.{8}" ) ;
2122
22- public Form1 ( )
23+ public Form1 ( string [ ] args )
2324 {
2425 InitializeComponent ( ) ;
25- lbStatus . Text = "" ;
26- btnStart . Click += ( obj , e ) => SendOnLighthouse ( activateByte ) ;
27- btnStop . Click += ( obj , e ) => SendOnLighthouse ( deactivateByte ) ;
26+ lbStatus . Text = null ;
27+ btnStart . Click += ( obj , e ) => SendOnLighthouseAsync ( activateByte ) ;
28+ btnStop . Click += ( obj , e ) => SendOnLighthouseAsync ( deactivateByte ) ;
2829 btnStop . Enabled = btnStart . Enabled = false ;
30+
31+ if ( args . Length > 0 )
32+ {
33+ UseArgumentsAsync ( args ) ;
34+ }
35+ else
36+ {
37+ GetGattCharacteristicsAsync ( ) ;
38+ }
2939 }
3040
31- private void Form1_Load ( object sender , EventArgs e )
41+ private async void UseArgumentsAsync ( string [ ] args )
3242 {
33- GetGattCharacteristics ( ) ;
43+ await GetGattCharacteristicsAsync ( ) ;
44+ for ( int i = 0 ; i < args . Length ; ++ i )
45+ {
46+ Log ( args [ i ] + " " + listGattCharacteristics . Count . ToString ( ) ) ;
47+ if ( args [ i ] == "--powerOn" )
48+ {
49+ await SendOnLighthouseAsync ( activateByte ) ;
50+ break ;
51+ }
52+ else if ( args [ i ] == "--powerOff" )
53+ {
54+ await SendOnLighthouseAsync ( deactivateByte ) ;
55+ break ;
56+ }
57+ }
58+ Close ( ) ;
3459 }
3560
36- private async void GetGattCharacteristics ( )
61+ private async Task GetGattCharacteristicsAsync ( )
3762 {
3863 DeviceInformationCollection GatDevices = await DeviceInformation . FindAllAsync ( GattDeviceService . GetDeviceSelectorFromUuid ( service ) ) ;
3964 for ( int id = 0 ; id < GatDevices . Count ; id ++ )
@@ -71,7 +96,7 @@ private async void GetGattCharacteristics()
7196 }
7297 }
7398
74- private async void SendOnLighthouse ( byte byte4send )
99+ private async Task SendOnLighthouseAsync ( byte byte4send )
75100 {
76101 for ( int i = 0 ; i < listGattCharacteristics . Count ; ++ i )
77102 {
0 commit comments