Skip to content

Commit 9e89e18

Browse files
committed
launch arguments
close #1
1 parent 8a57635 commit 9e89e18

4 files changed

Lines changed: 42 additions & 14 deletions

File tree

LighthouseV2PowerControl/Form1.Designer.cs

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LighthouseV2PowerControl/Form1.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text.RegularExpressions;
4+
using System.Threading.Tasks;
45
using System.Windows.Forms;
56
using Windows.Devices.Bluetooth;
67
using 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
{

LighthouseV2PowerControl/Program.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ namespace LighthouseV2PowerControl
88
{
99
static class Program
1010
{
11-
/// <summary>
12-
/// Главная точка входа для приложения.
13-
/// </summary>
1411
[STAThread]
15-
static void Main()
12+
static void Main(string[] args)
1613
{
1714
Application.EnableVisualStyles();
1815
Application.SetCompatibleTextRenderingDefault(false);
19-
Application.Run(new Form1());
16+
Application.Run(new Form1(args));
2017
}
2118
}
2219
}

README.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
* Connect the lighthouses to your pc via Bluetooth;
66
* Enjoy.
77
> Open the program, it will find all the paired base stations, then you can use the buttons to turn on and off the base stations.
8+
9+
Launch arguments
10+
| Argument | Description |
11+
|------------|--------------------------------------------------------------|
12+
| `--powerOn` | Wakes up all available base stations. |
13+
| `--powerOff` | Transfers into a sleep mode are all available base stations. |
14+
815
***
916
## Potential problem ##
1017
* Loss of connection with Windows Mixed Reality controllers;

0 commit comments

Comments
 (0)