Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions FreePIE.Core.Plugins/BeepPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Threading; // bip
using System.Runtime.InteropServices; //bip dllimport
using System.Collections.Generic;
using FreePIE.Core.Contracts;

namespace FreePIE.Core.Plugins
{
[GlobalType(Type = typeof (BeepGlobal))]
public class BeepPlugin : Plugin
{
public override object CreateGlobal()
{
return new BeepGlobal(this);
}
public override string FriendlyName
{
get { return "Beep"; }
}
// Beep Function
public class BackgroundBeep
{
static Thread _beepThread;
static AutoResetEvent _signalBeep;
static int frequency;
static int duration;
static BackgroundBeep()
{
_signalBeep = new AutoResetEvent(false);
_beepThread = new Thread(() =>
{
for (; ; )
{
_signalBeep.WaitOne();
if (duration != 0)
Console.Beep(frequency, duration);
}
}, 1);

_beepThread.IsBackground = true;
_beepThread.Start();
}
public static void Beep(int f, int d)
{
if (d == 0) return;
duration = d;
frequency = f;
_signalBeep.Set();
}
public static void Beep(IList<int> bip)
{
if (bip == null) return;
duration = bip[1];
frequency = bip[0];
_signalBeep.Set();
}
}
// End Beep function
}

[Global(Name = "beep")]
public class BeepGlobal
{
private readonly BeepPlugin plugin;

public BeepGlobal(BeepPlugin plugin)
{
this.plugin = plugin;
}

public void play(int frequency, int duration = 300)
{
BeepPlugin.BackgroundBeep.Beep(frequency, duration);
}
public void play(bool value, IList<int> bip1 = null, IList<int> bip2 = null)
{
if (value)
BeepPlugin.BackgroundBeep.Beep(bip1);
else
BeepPlugin.BackgroundBeep.Beep(bip2);
}
}
}