Skip to content

Commit

Permalink
* Make Sony camera optional
Browse files Browse the repository at this point in the history
* Improve speech if loosing kissing pair during countdown
  • Loading branch information
andijakl committed Sep 23, 2016
1 parent ec7f369 commit 599fb53
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions KissMachineKinect/KissMachineKinect.Windows/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private void Init()

private void InitCamera()
{
if (!UseSonyCamera) return;
if (_sonyCameraService == null)
{
_sonyCameraService = new SonyCameraService();
Expand Down Expand Up @@ -274,7 +275,10 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
DataContext = this;

InitCamera();
_sonyCameraService?.ForceRestart();
if (UseSonyCamera)
{
_sonyCameraService?.ForceRestart();
}

if (_speechService == null)
{
Expand All @@ -291,8 +295,11 @@ protected override void OnNavigatedFrom(NavigationEventArgs e)

_speechService?.Suspend();

_sonyCameraService?.StopCameraSearch();
_sonyCameraService?.Suspend();
if (UseSonyCamera)
{
_sonyCameraService?.StopCameraSearch();
_sonyCameraService?.Suspend();
}

// Body is IDisposables
if (_bodies != null)
Expand Down Expand Up @@ -604,14 +611,15 @@ private async Task RemovePlayer(ulong trackingId, int bodyNum)
var playerToRemove = _players.FirstOrDefault(playerInfo => playerInfo.BodyNum == bodyNum);
if (playerToRemove != null)
{
var speakRemovedMinPairPlayerHint = false;
Debug.WriteLine("Remove player: " + playerToRemove.BodyNum + " / id: " + playerToRemove.TrackingId);
if (_minPair != null && (_minPair.Player1TrackingId == playerToRemove.TrackingId ||
_minPair.Player2TrackingId == playerToRemove.TrackingId))
{
// Removing one of the players that is part of the minimum pair!
if (IsInCountdownPhase() && _speechService != null)
if (IsInCountdownPhase())
{
await _speechService.SpeakTextAsync(_resourceLoader.GetString("RemovedMinPairPlayerHint"));
speakRemovedMinPairPlayerHint = true;
}
_minPair = null;
_minPlayerLine?.SetVisibility(false);
Expand All @@ -623,6 +631,14 @@ private async Task RemovePlayer(ulong trackingId, int bodyNum)
_photoTaken = false;
await StopKissPhotoTimer();
}
if (speakRemovedMinPairPlayerHint)
{
// Do not await this statement, as it would cause Kinect to call this
// Method many times until the speech service is finished.
#pragma warning disable 4014
_speechService?.SpeakTextAsync(_resourceLoader.GetString("RemovedMinPairPlayerHint"));
#pragma warning restore 4014
}
}
}

Expand Down Expand Up @@ -981,7 +997,19 @@ private async Task StopKissPhotoTimer(bool setToInvisible = true)
{
// Set to invisible
await SetCountdown((int)KissCountdownStatusService.SpecialKissTexts.Invisible);
await _sonyCameraService.PutCameraToSleep();
if (UseSonyCamera)
{
try
{
await _sonyCameraService.PutCameraToSleep();
}
catch (Exception ex)
{
// Ignore this error for the self-service use case. Doesn't matter so much
// if camera doesn't go to sleep in one case, if it succeeds taking photos.
Debug.WriteLine("Failed putting camera to sleep: " + ex);
}
}
}
}

Expand Down

0 comments on commit 599fb53

Please sign in to comment.