Skip to content

Commit

Permalink
MainWIndow:
Browse files Browse the repository at this point in the history
- Property PollReserve removed.
- Buzzer1_DrawButton: Play sound for pressed button.
- Buzzer2_DrawButton: Play sound for pressed button.
- PollBuzzer_Tick(): Query  BuzzerDevices parallel.

BuzzerUI:
- SetBuzzer(): Thread safe for new PollBuzzer_Tick()
  • Loading branch information
gueggel committed May 28, 2021
1 parent a87994a commit 4a34645
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 35 deletions.
31 changes: 28 additions & 3 deletions SJ.Buzzer/Controls/BuzzerUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @link https://stefanjahn.de
*
* @date 21.05.2021
* @version 20210524
* @version 20210528
* @license http://www.gnu.org/copyleft/gpl.html
* ------------------------------------------------------------------------
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -41,6 +41,16 @@ namespace SJ.App.Buzzer.Controls
/// </summary>
public partial class BuzzerUI : UserControl
{
#region Delegates

/// <summary>
/// Aufruf von Methoden aus einem anderem Thread heraus.
/// </summary>
private delegate void CallMethodDelegate();

#endregion


#region Attribute

/// <summary>
Expand Down Expand Up @@ -240,17 +250,32 @@ public void SetButton( BuzzerButton buttonColor, bool pressed )
}
}



/// <summary>
/// Buzzerknopf ein-/ausscahlten.
/// Buzzerknopf ein-/ausschalten.
/// </summary>
/// <param name="pressed">True = Gedrueckt</param>
public void SetBuzzer( bool pressed )
{
BuzzerPressed = pressed;
DrawBuzzer( pnlBuzzer.CreateGraphics() );
pnlBuzzer.Refresh();

if( pnlBuzzer.InvokeRequired )
{
Invoke( new CallMethodDelegate( PollBuzzer ) );
}
else
{
pnlBuzzer.Refresh();
}
}

/// <summary>
/// Grafik Buzzerknopf aktualisieren.
/// </summary>
private void PollBuzzer() => pnlBuzzer.Refresh();

/// <summary>
/// Button-Objekt abfragen.
/// </summary>
Expand Down
58 changes: 26 additions & 32 deletions SJ.Buzzer/Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

using SharpDX.XAudio2;
Expand Down Expand Up @@ -63,10 +64,7 @@ public partial class MainWindow : Form
/// </summary>
private XAudio2 AudioDevice
{
get
{
return _AudioDevice;
}
get => _AudioDevice;
set
{
_AudioDevice = value;
Expand Down Expand Up @@ -124,16 +122,6 @@ private Dictionary<BuzzerNumber, BuzzerUI> ListBuzzer2UI
set;
}

/// <summary>
/// True = Buzzer in verkehrter Reihenfolge abfragen.
/// </summary>
private bool PollReverse
{
get;
set;
}


/// <summary>
/// Timer fuer die Abfrage des Buzzers.
/// </summary>
Expand Down Expand Up @@ -238,8 +226,6 @@ public MainWindow()
BuzzerNumber.Four
};


PollReverse = false;
LastWindowState = WindowState;
SetLanguage = string.Empty;

Expand Down Expand Up @@ -1127,6 +1113,16 @@ private void ChangeLanguage( string language )
/// <param name="buttonFound">True = Erster Button eines Buzzers wurde gedrueckt</param>
private void Buzzer1_DrawButton( object sender, BuzzerNumber buzzerNumber, BuzzerButton buzzerButton, bool isPressed, bool buzzerFound, bool buttonFound )
{
if( buzzerFound )
{
ListSounds[Soundfile.BuzzerPressed].Play();
}

if( buttonFound )
{
ListSounds[Soundfile.ButtonClick].Play();
}

if( buzzerButton == BuzzerButton.Buzzer )
{
ListBuzzer1UI[buzzerNumber].SetBuzzer( isPressed );
Expand All @@ -1137,7 +1133,6 @@ private void Buzzer1_DrawButton( object sender, BuzzerNumber buzzerNumber, Buzze
}
}


/// <summary>
/// Button auf dem Buzzer #2 zeichnen.
/// </summary>
Expand All @@ -1149,6 +1144,16 @@ private void Buzzer1_DrawButton( object sender, BuzzerNumber buzzerNumber, Buzze
/// <param name="buttonFound">True = Erster Button eines Buzzers wurde gedrueckt</param>
private void Buzzer2_DrawButton( object sender, BuzzerNumber buzzerNumber, BuzzerButton buzzerButton, bool isPressed, bool buzzerFound, bool buttonFound )
{
if( buzzerFound )
{
ListSounds[Soundfile.BuzzerPressed].Play();
}

if( buttonFound )
{
ListSounds[Soundfile.ButtonClick].Play();
}

if( buzzerButton == BuzzerButton.Buzzer )
{
ListBuzzer2UI[buzzerNumber].SetBuzzer( isPressed );
Expand All @@ -1175,21 +1180,10 @@ private void Buzzer2_DrawButton( object sender, BuzzerNumber buzzerNumber, Buzze
/// <summary>
/// Buzzer abfragen.
/// </summary>
private void PollBuzzer_Tick( object sender, EventArgs e )
{
if( PollReverse )
{
BuzzerDevice2.Poll();
BuzzerDevice1.Poll();
}
else
{
BuzzerDevice1.Poll();
BuzzerDevice2.Poll();
}

PollReverse = !PollReverse;
}
private void PollBuzzer_Tick( object sender, EventArgs e ) => Parallel.Invoke(
() => BuzzerDevice1.Poll(),
() => BuzzerDevice2.Poll()
);


/// <summary>
Expand Down

0 comments on commit 4a34645

Please sign in to comment.