Added NightAlert project for travel kit
This commit is contained in:
16
NightScout/Alerters/Alerter.cs
Normal file
16
NightScout/Alerters/Alerter.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NightScout
|
||||
{
|
||||
public abstract class Alerter : IAlerter
|
||||
{
|
||||
public abstract void StartAlert();
|
||||
public abstract void StartStaleDataAlert();
|
||||
public abstract void StartUrgentAlert();
|
||||
public abstract void StopAlerts();
|
||||
}
|
||||
}
|
||||
32
NightScout/Alerters/ConsoleAlerter.cs
Normal file
32
NightScout/Alerters/ConsoleAlerter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NightScout
|
||||
{
|
||||
public class ConsoleAlerter : IAlerter
|
||||
{
|
||||
|
||||
public void StartAlert()
|
||||
{
|
||||
Console.WriteLine("Alerting");
|
||||
}
|
||||
|
||||
public void StartUrgentAlert()
|
||||
{
|
||||
Console.WriteLine("Urgent Alerting");
|
||||
}
|
||||
|
||||
public void StartStaleDataAlert()
|
||||
{
|
||||
Console.WriteLine("Stale Data Alerting");
|
||||
}
|
||||
|
||||
public void StopAlerts()
|
||||
{
|
||||
Console.WriteLine("Alerts stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
81
NightScout/Alerters/MultiAlerter.cs
Normal file
81
NightScout/Alerters/MultiAlerter.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NightScout
|
||||
{
|
||||
public class MultiAlerter : IAlerter
|
||||
{
|
||||
public List<IAlerter> Alerters { get; set; }
|
||||
|
||||
public MultiAlerter(IEnumerable<IAlerter> alerters)
|
||||
{
|
||||
Alerters = new List<IAlerter>(alerters);
|
||||
}
|
||||
public void StartAlert()
|
||||
{
|
||||
Alerters.ForEach(a =>
|
||||
{
|
||||
try
|
||||
{
|
||||
a.StartAlert();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void StartUrgentAlert()
|
||||
{
|
||||
Alerters.ForEach(a =>
|
||||
{
|
||||
try
|
||||
{
|
||||
a.StartUrgentAlert();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void StartStaleDataAlert()
|
||||
{
|
||||
Alerters.ForEach(a =>
|
||||
{
|
||||
try
|
||||
{
|
||||
a.StartStaleDataAlert();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void StopAlerts()
|
||||
{
|
||||
|
||||
Alerters.ForEach(a =>
|
||||
{
|
||||
try
|
||||
{
|
||||
a.StopAlerts();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
81
NightScout/Alerters/RaspberryPiAudioAlert.cs
Normal file
81
NightScout/Alerters/RaspberryPiAudioAlert.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NightScout.Interfaces;
|
||||
|
||||
namespace NightScout
|
||||
{
|
||||
public class RaspberryPiAudioAlert : IAlerter
|
||||
{
|
||||
public String PlayerCommandLine { get; set; }
|
||||
public String KillCommand { get; set; }
|
||||
public String AlertFileName { get; set; }
|
||||
|
||||
protected IRaspberryPiButtonSource ButtonSource;
|
||||
|
||||
private Boolean playing = false;
|
||||
|
||||
|
||||
public RaspberryPiAudioAlert()
|
||||
{
|
||||
this.PlayerCommandLine = "\"mpg123 -q {0}\"";
|
||||
this.KillCommand = "pkill mpg123";
|
||||
this.AlertFileName = "~/ratm.mp3";
|
||||
}
|
||||
|
||||
public RaspberryPiAudioAlert(String playerCommandline)
|
||||
: base()
|
||||
{
|
||||
this.PlayerCommandLine = playerCommandline;
|
||||
}
|
||||
|
||||
public RaspberryPiAudioAlert(String playerCommandline, IRaspberryPiButtonSource buttonSource)
|
||||
: this(playerCommandline)
|
||||
{
|
||||
this.ButtonSource = buttonSource;
|
||||
this.ButtonSource.ButtonStateChange += ButtonSource_ButtonStateChange;
|
||||
}
|
||||
|
||||
public RaspberryPiAudioAlert(IRaspberryPiButtonSource buttonSource)
|
||||
: this()
|
||||
{
|
||||
this.ButtonSource = buttonSource;
|
||||
this.ButtonSource.ButtonStateChange += ButtonSource_ButtonStateChange;
|
||||
}
|
||||
|
||||
private void ButtonSource_ButtonStateChange(bool obj)
|
||||
{
|
||||
Console.WriteLine("Button state change: {0}", obj);
|
||||
if(obj)
|
||||
StopAlerts();
|
||||
}
|
||||
|
||||
public void StartAlert()
|
||||
{
|
||||
if (!playing)
|
||||
{
|
||||
playing = true;
|
||||
Process.Start("/bin/bash", String.Format("-c {0}", String.Format(PlayerCommandLine,AlertFileName )));
|
||||
}
|
||||
}
|
||||
|
||||
public void StartUrgentAlert()
|
||||
{
|
||||
StartAlert();
|
||||
}
|
||||
|
||||
public void StartStaleDataAlert()
|
||||
{
|
||||
StartAlert();
|
||||
}
|
||||
|
||||
public void StopAlerts()
|
||||
{
|
||||
Process.Start("/bin/bash", "-c \"pkill mpg123\"");
|
||||
playing = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user