Skip to content

Commit 14087de

Browse files
authored
Merge pull request #13 from aurycat/identify
Add 'Identify' button to Lighthouse dropdown menu
2 parents e90dff8 + e37c88b commit 14087de

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

OVRLighthouseManager/Contracts/Services/ILighthouseGattService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ internal interface ILighthouseGattService
1313
public Task SleepAsync(Lighthouse lighthouse);
1414

1515
public Task StandbyAsync(Lighthouse lighthouse);
16+
17+
public Task IdentifyAsync(Lighthouse lighthouse);
1618
}

OVRLighthouseManager/Helpers/LighthouseCommands.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,48 @@ public class PowerAllCommandParameter
258258
public string Command { get; set; } = string.Empty;
259259
public IEnumerable<LighthouseObject> Lighthouses { get; set; } = Enumerable.Empty<LighthouseObject>();
260260
}
261+
262+
public class IdentifyCommand : AsyncCommandBase
263+
{
264+
public override event EventHandler? CanExecuteChanged;
265+
private Task? _task;
266+
private readonly ILogger _log = LogHelper.ForContext<IdentifyCommand>();
267+
268+
public override bool CanExecute(object? parameter)
269+
{
270+
var isV1 = parameter is LighthouseObject lighthouse && new Lighthouse { Name = lighthouse.Name }.Version == LighthouseVersion.V1;
271+
if (isV1)
272+
{
273+
return false;
274+
}
275+
return _task == null || _task.IsCompleted;
276+
}
277+
278+
public async override Task ExecuteAsync(object? parameter)
279+
{
280+
if (parameter is LighthouseObject lighthouse)
281+
{
282+
var notification = App.GetService<INotificationService>();
283+
try
284+
{
285+
_log.Information($"{lighthouse.Name} Identify");
286+
var l = new Lighthouse { Name = lighthouse.Name, BluetoothAddress = lighthouse.BluetoothAddress, Id = lighthouse.Id };
287+
_task = App.GetService<ILighthouseGattService>().IdentifyAsync(l);
288+
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
289+
await _task;
290+
_task = null;
291+
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
292+
notification.Success(string.Format("Notification_Identify".GetLocalized(), lighthouse.Name));
293+
}
294+
catch (Exception ex)
295+
{
296+
_log.Error(ex, $"{lighthouse.Name} Failed to identify");
297+
notification.Error(string.Format("Notification_CommunicationError".GetLocalized(), lighthouse.Name) + "\n" + ex.Message);
298+
}
299+
}
300+
else
301+
{
302+
throw new ArgumentException("Invalid parameter");
303+
}
304+
}
305+
}

OVRLighthouseManager/Services/LighthouseGattService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class LighthouseGattService : ILighthouseGattService
1616

1717
private static readonly Guid V2ControlService = new("00001523-1212-efde-1523-785feabcd124");
1818
private static readonly Guid V2PowerCharacteristic = new("00001525-1212-efde-1523-785feabcd124");
19+
private static readonly Guid V2IdentifyCharacteristic = new("00008421-1212-efde-1523-785feabcd124");
1920

2021
private static readonly ILogger _log = LogHelper.ForContext<LighthouseGattService>();
2122

@@ -59,6 +60,15 @@ public async Task StandbyAsync(Lighthouse lighthouse)
5960
await WriteV2PowerCharacteristic(lighthouse, 0x02);
6061
}
6162

63+
public async Task IdentifyAsync(Lighthouse lighthouse)
64+
{
65+
if (lighthouse.Version == LighthouseVersion.V1)
66+
{
67+
throw new LighthouseGattException("Identify is not supported for V1 lighthouses");
68+
}
69+
await WritePowerCharacteristicAsync(lighthouse, V2ControlService, V2IdentifyCharacteristic, new byte[] { 0x01 });
70+
}
71+
6272
private async Task ControlV1Async(Lighthouse lighthouse, bool powerOn)
6373
{
6474
byte[] bytes;

OVRLighthouseManager/Strings/en-us/Resources.resw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@
162162
<data name="Menu_Standby.Text" xml:space="preserve">
163163
<value>Standby</value>
164164
</data>
165+
<data name="Menu_Identify.Text" xml:space="preserve">
166+
<value>Identify</value>
167+
</data>
165168
<data name="Shell_Main_BaseStationsLabel.Text" xml:space="preserve">
166169
<value>Base Stations</value>
167170
</data>
@@ -189,6 +192,9 @@
189192
<data name="Notification_Standby" xml:space="preserve">
190193
<value>{0} has been put to standby.</value>
191194
</data>
195+
<data name="Notification_Identify" xml:space="preserve">
196+
<value>{0} is identifying itself.</value>
197+
</data>
192198
<data name="Shell_Main_PowerManagementDescription.Text" xml:space="preserve">
193199
<value>When you start SteamVR, they wake up from standby, and when you exit SteamVR, they go to standby. Neither HTC VIVE nor Valve Index required.</value>
194200
</data>

OVRLighthouseManager/Strings/ja-jp/Resources.resw

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@
162162
<data name="Menu_Standby.Text" xml:space="preserve">
163163
<value>スタンバイ</value>
164164
</data>
165+
<data name="Menu_Identify.Text" xml:space="preserve">
166+
<value />
167+
</data>
165168
<data name="Shell_Main_BaseStationsLabel.Text" xml:space="preserve">
166169
<value>ベースステーション</value>
167170
</data>
@@ -189,6 +192,9 @@
189192
<data name="Notification_Standby" xml:space="preserve">
190193
<value>{0}をスタンバイ状態にしました。</value>
191194
</data>
195+
<data name="Notification_Identify" xml:space="preserve">
196+
<value>{0}</value>
197+
</data>
192198
<data name="Shell_Main_PowerManagementDescription.Text" xml:space="preserve">
193199
<value>SteamVRを起動するとスタンバイ状態から復帰し、SteamVRを終了するとスタンバイ状態にします。HTC VIVEおよびValve Indexは必要ありません。</value>
194200
</data>

OVRLighthouseManager/Views/LighthouseControl.xaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<helpers:PowerOnCommand x:Key="powerOnCommand" />
1414
<helpers:SleepCommand x:Key="sleepCommand" />
1515
<helpers:StandbyCommand x:Key="standbyCommand" />
16+
<helpers:IdentifyCommand x:Key="identifyCommand" />
1617
<helpers:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
1718
</UserControl.Resources>
1819

@@ -111,6 +112,12 @@
111112
CommandParameter="{x:Bind LighthouseObject, Mode=OneWay}"
112113
/>
113114
<MenuFlyoutSeparator />
115+
<MenuFlyoutItem
116+
x:Uid="Menu_Identify"
117+
Command="{StaticResource identifyCommand}"
118+
CommandParameter="{x:Bind LighthouseObject, Mode=OneWay}"
119+
/>
120+
<MenuFlyoutSeparator />
114121
<MenuFlyoutItem
115122
x:Uid="Menu_EditId"
116123
Command="{x:Bind LighthouseObject.EditIdCommand, Mode=OneWay}"

0 commit comments

Comments
 (0)