Skip to content

Commit

Permalink
Sound alarms, installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Oleynikov committed Nov 28, 2019
1 parent 9ac0158 commit ca07e20
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 101 deletions.
2 changes: 1 addition & 1 deletion NightscoutWatcher.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ uses

begin
Application.Initialize;
Application.Title := 'Nightscout Watcher';
Application.Title:='Nightscout Watcher';
Application.CreateForm(TfMain, fMain);
Application.Run;
end.
3 changes: 2 additions & 1 deletion NightscoutWatcher.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<UseVersionInfo Value="True"/>
<AutoIncrementBuild Value="True"/>
<MajorVersionNr Value="2"/>
<MinorVersionNr Value="2"/>
<MinorVersionNr Value="3"/>
<RevisionNr Value="1"/>
<BuildNr Value="110"/>
</VersionInfo>
<BuildModes Count="3">
Expand Down
17 changes: 1 addition & 16 deletions forms/ufMain.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ object fMain: TfMain
Font.Name = 'Tahoma'
FormStyle = fsSystemStayOnTop
KeyPreview = True
OnClose = FormClose
OnCreate = FormCreate
OnDblClick = actVisitNightscoutSiteExecute
OnDestroy = FormDestroy
Expand Down Expand Up @@ -595,20 +596,4 @@ object fMain: TfMain
left = 137
top = 61
end
object AudioFileIn: TAcsFileIn
StartSample = 0
EndSample = -1
Loop = False
left = 137
top = 120
end
object AudioOut: TAcsAudioOut
BufferSize = 16384
PrefetchMode = pmAuto
Device = 0
Volume = 0
Delay = -1
left = 176
top = 120
end
end
47 changes: 36 additions & 11 deletions forms/ufMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface
uses
LCLIntf, LCLType, uSettings, SysUtils, Variants, Classes, Graphics, Controls,
Forms, Dialogs, DateUtils, Contnrs, ExtCtrls, Menus, uNightscout, ComCtrls,
ActnList, acs_file, acs_audio;
ActnList;

type

Expand All @@ -29,8 +29,6 @@ TDrawPanel = class(TPanel)
{ TfMain }

TfMain = class(TForm)
AudioOut: TAcsAudioOut;
AudioFileIn: TAcsFileIn;
actDrawGlucoseLevelDelta: TAction;
actDrawGlucoseAvg: TAction;
actDrawWallpaper: TAction;
Expand Down Expand Up @@ -143,6 +141,7 @@ TfMain = class(TForm)
procedure DoSnoozeAlarmsExecute(Sender: TObject);
procedure actStayOnTopExecute(Sender: TObject);
procedure DoScaleIndexClick(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
Expand Down Expand Up @@ -182,6 +181,7 @@ TfMain = class(TForm)
Loaded: Boolean;
FPosX : Integer;
FPosY : Integer;
LastAudioFileName: string;
Settings: TSettings;
DrawPanel: TDrawPanel;
Entries: TNightscoutEntryList;
Expand All @@ -199,7 +199,7 @@ TfMain = class(TForm)
function GetHintText(): string;
procedure PlayAlarm();
procedure Restart(Params: string = '');
procedure ShowBaloonHint;
procedure ShowTrayIconBaloonHint;
procedure ShowIconInTaskbar(AVisible: Boolean);
function LoadWallpaper(const FileName: string): Boolean;
procedure ResetWindowBoundsToDefault();
Expand Down Expand Up @@ -245,7 +245,7 @@ implementation

uses
ufSettings, ufTimerDialog, UrlMon, Wininet, Math, StrUtils, Types, graphtype,
intfgraphics, fpimage, process, ButtonPanel;
intfgraphics, fpimage, process, ButtonPanel, mmsystem;

procedure TfMain.Restart(Params: string = '');
var
Expand Down Expand Up @@ -280,13 +280,29 @@ procedure TDrawPanel.Paint;
{ TfMain }

procedure TfMain.PlayAlarm();
var
AudioFileName: string;
begin
if not FileExists(Settings.AudioAlarmFile) then
AudioFileName := Settings.GetAppropriateAlarmFile(Entries.Last);
if (AudioFileName = '') or not FileExists(AudioFileName) then
begin
PlaySound(0, 0, SND_PURGE);
// sndPlaySound(nil, 0); // Stop playing
Exit;
end;

AudioFileIn.FileName := Settings.AudioAlarmFile;
AudioOut.Input := AudioFileIn;
AudioOut.Run();
if LastAudioFileName <> AudioFileName then
PlaySound(0, 0, SND_PURGE);
PlaySound(PChar(AudioFileName), 0, SND_ASYNC or SND_LOOP or SND_PURGE or SND_NOSTOP);
LastAudioFileName := AudioFileName;
// sndPlaySound(PChar(AudioFileName), SND_ASYNC or SND_LOOP);
//
// if AudioOut.Status = tosPlaying then
// Exit;
//
// if AudioFileIn.FileName <> AudioFileName then
// AudioFileIn.FileName := AudioFileName;
// AudioOut.Run();
end;

procedure TfMain.SetSystemStayOnTop(StayOnTop: Boolean);
Expand Down Expand Up @@ -671,6 +687,7 @@ procedure TfMain.FormCreate(Sender: TObject);
WallpaperJPG := TJPEGImage.Create();
StaleAlarmBlinkTrigger := False;
GlucoseLevelAlarmBlinkTrigger := False;
LastAudioFileName := '';

Entries := TNightscoutEntryList.Create;

Expand Down Expand Up @@ -859,6 +876,11 @@ procedure TfMain.DoScaleIndexClick(Sender: TObject);
SetScaleIndex(TComponent(Sender).Tag);
end;

procedure TfMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
sndPlaySound(nil, 0); // Stop playing
end;

procedure TfMain.actStayOnTopExecute(Sender: TObject);
begin
SetSystemStayOnTop(TAction(Sender).Checked);
Expand Down Expand Up @@ -995,7 +1017,7 @@ procedure TfMain.FormShow(Sender: TObject);
tmrTimer(tmr); // Load data from nightscout site and start monitoring
end;

procedure TfMain.ShowBaloonHint;
procedure TfMain.ShowTrayIconBaloonHint;
var
BaloonHint: string;
LastEntry: TNightscoutEntry;
Expand Down Expand Up @@ -1190,8 +1212,9 @@ procedure TfMain.tmrProgressBarTimer(Sender: TObject);
CheckStaleDataAlarms();
CheckGlucoseLevelAlarms();
DrawTrayIcon();
ShowTrayIconBaloonHint();
DrawApplicationIcon();
ShowBaloonHint();
PlayAlarm();
Invalidate();
end;

Expand All @@ -1216,6 +1239,7 @@ procedure TfMain.tmrTimer(Sender: TObject);
UpdateApplicationTitle();
DrawTrayIcon();
DrawApplicationIcon();
PlayAlarm();
HardInvalidate();
end;

Expand Down Expand Up @@ -1648,6 +1672,7 @@ procedure TfMain.DoUpdateCallerFormWithSettings;
SetAlphaBlendValue(Settings.AlphaBlendValue);
LoadWallpaper(Settings.WallpaperFileName);
ShowIconInTray(Settings.ShowIconInTray);
PlayAlarm();
HardInvalidate;
end;

Expand Down
20 changes: 16 additions & 4 deletions forms/ufSettings.lfm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object fSettings: TfSettings
Left = 1271
Left = 611
Height = 500
Top = 431
Top = 188
Width = 600
Caption = 'Settings'
ClientHeight = 500
Expand Down Expand Up @@ -42,10 +42,10 @@ object fSettings: TfSettings
Height = 432
Top = 0
Width = 600
ActivePage = tsVisual
ActivePage = tsAlerts
Align = alTop
Anchors = [akTop, akLeft, akRight, akBottom]
TabIndex = 1
TabIndex = 2
TabOrder = 2
OnChange = pcChange
object tsMain: TTabSheet
Expand Down Expand Up @@ -693,6 +693,18 @@ object fSettings: TfSettings
ParentFont = False
TabOrder = 2
end
object cbEnableAudioAlarms: TCheckBox
Left = 293
Height = 23
Top = 200
Width = 163
Caption = 'Enable audio alarms'
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Tahoma'
ParentFont = False
TabOrder = 4
end
end
object tsAbout: TTabSheet
Caption = 'About'
Expand Down
126 changes: 65 additions & 61 deletions forms/ufSettings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TfSettings = class(TForm)
btnLoadWallpaper: TButton;
btnOK: TButton;
btnCancel: TButton;
cbEnableAudioAlarms: TCheckBox;
cbShowIconInTray: TCheckBox;
cbStayOnTop: TCheckBox;
cbDrawGlucoseLevelDelta: TCheckBox;
Expand Down Expand Up @@ -187,6 +188,7 @@ constructor TfSettings.CreateSpecial(AOwner: TComponent; Settings: TSettings; Ac

procedure TfSettings.AssignComponentsOnChangeEvent;
begin
cbEnableAudioAlarms.OnClick := DoChange;
cbEnableGlucoseLevelAlarms.OnClick := DoChange;
cbEnableStaleDataAlarms.OnClick := DoChange;
cbIsMmolL.OnClick := DoChange;
Expand Down Expand Up @@ -275,42 +277,43 @@ procedure TfSettings.DoChange(Sender: TObject);

procedure TfSettings.AssignSettingsToComponents();
begin
cbDrawHorzGuideLines.Checked := NewSettings.IsInDrawStage(dsHorzGuideLines);
cbDrawLastGlucoseLevel.Checked := NewSettings.IsInDrawStage(dsLastGlucoseLevel);
cbDrawHorzGuideLines.Checked := NewSettings.IsInDrawStage(dsHorzGuideLines);
cbDrawLastGlucoseLevel.Checked := NewSettings.IsInDrawStage(dsLastGlucoseLevel);
cbDrawLastGlucoseLevelDate.Checked := NewSettings.IsInDrawStage(dsLastGlucoseLevelDate);
cbDrawGlucoseExtremePoints.Checked := NewSettings.IsInDrawStage(dsGlucoseExtremePoints);
cbDrawGlucoseLevel.Checked := NewSettings.IsInDrawStage(dsGlucoseLevel);
cbDrawGlucoseLines.Checked := NewSettings.IsInDrawStage(dsGlucoseLines);
cbDrawGlucoseSlope.Checked := NewSettings.IsInDrawStage(dsGlucoseSlope);
cbDrawVertGuideLines.Checked := NewSettings.IsInDrawStage(dsVertGuideLines);
cbDrawAlertLines.Checked := NewSettings.IsInDrawStage(dsAlertLines);
cbDrawGlucoseLevelPoints.Checked := NewSettings.IsInDrawStage(dsGlucoseLevelPoints);
cbDrawGlucoseLevelDelta.Checked := NewSettings.IsInDrawStage(dsGlucoseLevelDelta);
cbDrawGlucoseAvg.Checked := NewSettings.IsInDrawStage(dsGlucoseAvg);
cbDrawWallpaper.Checked := NewSettings.IsInDrawStage(dsWallpaper);
eWallpaper.Text := NewSettings.WallpaperFileName;

cbEnableGlucoseLevelAlarms.Checked := NewSettings.EnableGlucoseLevelAlarms;
cbEnableStaleDataAlarms.Checked := NewSettings.EnableStaleDataAlarms;
cbIsMmolL.Checked := NewSettings.IsMmolL;
cbDrawGlucoseLevel.Checked := NewSettings.IsInDrawStage(dsGlucoseLevel);
cbDrawGlucoseLines.Checked := NewSettings.IsInDrawStage(dsGlucoseLines);
cbDrawGlucoseSlope.Checked := NewSettings.IsInDrawStage(dsGlucoseSlope);
cbDrawVertGuideLines.Checked := NewSettings.IsInDrawStage(dsVertGuideLines);
cbDrawAlertLines.Checked := NewSettings.IsInDrawStage(dsAlertLines);
cbDrawGlucoseLevelPoints.Checked := NewSettings.IsInDrawStage(dsGlucoseLevelPoints);
cbDrawGlucoseLevelDelta.Checked := NewSettings.IsInDrawStage(dsGlucoseLevelDelta);
cbDrawGlucoseAvg.Checked := NewSettings.IsInDrawStage(dsGlucoseAvg);
cbDrawWallpaper.Checked := NewSettings.IsInDrawStage(dsWallpaper);
eWallpaper.Text := NewSettings.WallpaperFileName;

cbEnableAudioAlarms.Checked := NewSettings.EnableAudioAlarms;
cbEnableGlucoseLevelAlarms.Checked := NewSettings.EnableGlucoseLevelAlarms;
cbEnableStaleDataAlarms.Checked := NewSettings.EnableStaleDataAlarms;
cbIsMmolL.Checked := NewSettings.IsMmolL;
cbShowCheckNewDataProgressBar.Checked := NewSettings.ShowCheckNewDataProgressBar;
cbShowWindowBorder.Checked := NewSettings.ShowWindowBorder;
cbStayOnTop.Checked := NewSettings.StayOnTop;
cbShowIconOnTaskbar.Checked := NewSettings.ShowIconInTaskBar;
cbShowIconInTray.Checked := NewSettings.ShowIconInTray;
sbAlphaBlend.Position := NewSettings.AlphaBlendValue;
sbScale.Max := Length(cDrawStageSizes[1]);
sbScale.Position := NewSettings.ScaleIndex;
seCheckInterval.Value := NewSettings.CheckInterval;
seHoursToReceive.Value := NewSettings.HoursToRecive;
seHighGlucoseAlarm.Value := NewSettings.HighGlucoseAlarm;
seLowGlucoseAlarm.Value := NewSettings.LowGlucoseAlarm;
seStaleDataAlarm.Value := NewSettings.StaleDataAlarm;
cbShowWindowBorder.Checked := NewSettings.ShowWindowBorder;
cbStayOnTop.Checked := NewSettings.StayOnTop;
cbShowIconOnTaskbar.Checked := NewSettings.ShowIconInTaskBar;
cbShowIconInTray.Checked := NewSettings.ShowIconInTray;
sbAlphaBlend.Position := NewSettings.AlphaBlendValue;
sbScale.Max := Length(cDrawStageSizes[1]);
sbScale.Position := NewSettings.ScaleIndex;
seCheckInterval.Value := NewSettings.CheckInterval;
seHoursToReceive.Value := NewSettings.HoursToRecive;
seHighGlucoseAlarm.Value := NewSettings.HighGlucoseAlarm;
seLowGlucoseAlarm.Value := NewSettings.LowGlucoseAlarm;
seStaleDataAlarm.Value := NewSettings.StaleDataAlarm;
seUrgentHighGlucoseAlarm.Value := NewSettings.UrgentHighGlucoseAlarm;
seUrgentLowGlucoseAlarm.Value := NewSettings.UrgentLowGlucoseAlarm;
seUrgentStaleDataAlarm.Value := NewSettings.UrgentStaleDataAlarm;
seTimeZoneCorrection.Value := NewSettings.TimeZoneCorrection;
eNightscoutSite.Text := NewSettings.NightscoutUrl;
seUrgentLowGlucoseAlarm.Value := NewSettings.UrgentLowGlucoseAlarm;
seUrgentStaleDataAlarm.Value := NewSettings.UrgentStaleDataAlarm;
seTimeZoneCorrection.Value := NewSettings.TimeZoneCorrection;
eNightscoutSite.Text := NewSettings.NightscoutUrl;

AssignGlucoseAlertInMmolL(seUrgentHighGlucoseAlarm);
AssignGlucoseAlertInMmolL(seHighGlucoseAlarm);
Expand All @@ -326,41 +329,42 @@ procedure TfSettings.AssignComponentsToSettings;
NewSettings.CheckInterval := seCheckInterval.Value;
NewSettings.HoursToRecive := seHoursToReceive.Value;

NewSettings.HighGlucoseAlarm := seHighGlucoseAlarm.Value;
NewSettings.LowGlucoseAlarm := seLowGlucoseAlarm.Value;
NewSettings.UrgentHighGlucoseAlarm := seUrgentHighGlucoseAlarm.Value;
NewSettings.UrgentLowGlucoseAlarm := seUrgentLowGlucoseAlarm.Value;
NewSettings.IsMmolL := cbIsMmolL.Checked;
NewSettings.StaleDataAlarm := seStaleDataAlarm.Value;
NewSettings.UrgentStaleDataAlarm := seUrgentStaleDataAlarm.Value;
NewSettings.EnableAudioAlarms := cbEnableAudioAlarms.Checked;
NewSettings.EnableGlucoseLevelAlarms := cbEnableGlucoseLevelAlarms.Checked;
NewSettings.EnableStaleDataAlarms := cbEnableStaleDataAlarms.Checked;

NewSettings.SwitchDrawStage(dsHorzGuideLines, cbDrawHorzGuideLines.Checked);
NewSettings.SwitchDrawStage(dsLastGlucoseLevel, cbDrawLastGlucoseLevel.Checked);
NewSettings.EnableStaleDataAlarms := cbEnableStaleDataAlarms.Checked;
NewSettings.HighGlucoseAlarm := seHighGlucoseAlarm.Value;
NewSettings.IsMmolL := cbIsMmolL.Checked;
NewSettings.LowGlucoseAlarm := seLowGlucoseAlarm.Value;
NewSettings.StaleDataAlarm := seStaleDataAlarm.Value;
NewSettings.UrgentHighGlucoseAlarm := seUrgentHighGlucoseAlarm.Value;
NewSettings.UrgentLowGlucoseAlarm := seUrgentLowGlucoseAlarm.Value;
NewSettings.UrgentStaleDataAlarm := seUrgentStaleDataAlarm.Value;

NewSettings.SwitchDrawStage(dsHorzGuideLines, cbDrawHorzGuideLines.Checked);
NewSettings.SwitchDrawStage(dsLastGlucoseLevel, cbDrawLastGlucoseLevel.Checked);
NewSettings.SwitchDrawStage(dsLastGlucoseLevelDate, cbDrawLastGlucoseLevelDate.Checked);
NewSettings.SwitchDrawStage(dsGlucoseExtremePoints, cbDrawGlucoseExtremePoints.Checked);
NewSettings.SwitchDrawStage(dsGlucoseLevel, cbDrawGlucoseLevel.Checked);
NewSettings.SwitchDrawStage(dsGlucoseLines, cbDrawGlucoseLines.Checked);
NewSettings.SwitchDrawStage(dsGlucoseSlope, cbDrawGlucoseSlope.Checked);
NewSettings.SwitchDrawStage(dsVertGuideLines, cbDrawVertGuideLines.Checked);
NewSettings.SwitchDrawStage(dsAlertLines, cbDrawAlertLines.Checked);
NewSettings.SwitchDrawStage(dsGlucoseLevelPoints, cbDrawGlucoseLevelPoints.Checked);
NewSettings.SwitchDrawStage(dsGlucoseLevelDelta, cbDrawGlucoseLevelDelta.Checked);
NewSettings.SwitchDrawStage(dsGlucoseAvg, cbDrawGlucoseAvg.Checked);
NewSettings.SwitchDrawStage(dsWallpaper, cbDrawWallpaper.Checked);
NewSettings.SwitchDrawStage(dsGlucoseLevel, cbDrawGlucoseLevel.Checked);
NewSettings.SwitchDrawStage(dsGlucoseLines, cbDrawGlucoseLines.Checked);
NewSettings.SwitchDrawStage(dsGlucoseSlope, cbDrawGlucoseSlope.Checked);
NewSettings.SwitchDrawStage(dsVertGuideLines, cbDrawVertGuideLines.Checked);
NewSettings.SwitchDrawStage(dsAlertLines, cbDrawAlertLines.Checked);
NewSettings.SwitchDrawStage(dsGlucoseLevelPoints, cbDrawGlucoseLevelPoints.Checked);
NewSettings.SwitchDrawStage(dsGlucoseLevelDelta, cbDrawGlucoseLevelDelta.Checked);
NewSettings.SwitchDrawStage(dsGlucoseAvg, cbDrawGlucoseAvg.Checked);
NewSettings.SwitchDrawStage(dsWallpaper, cbDrawWallpaper.Checked);

NewSettings.ShowCheckNewDataProgressBar := cbShowCheckNewDataProgressBar.Checked;
NewSettings.ShowWindowBorder := cbShowWindowBorder.Checked;
NewSettings.StayOnTop := cbStayOnTop.Checked;
NewSettings.ShowIconInTaskBar := cbShowIconOnTaskbar.Checked;
NewSettings.ShowIconInTray := cbShowIconInTray.Checked;
NewSettings.NightscoutUrl := eNightscoutSite.Text;

NewSettings.ScaleIndex := sbScale.Position;
NewSettings.AlphaBlendValue := sbAlphaBlend.Position;
NewSettings.ShowWindowBorder := cbShowWindowBorder.Checked;
NewSettings.StayOnTop := cbStayOnTop.Checked;
NewSettings.ShowIconInTaskBar := cbShowIconOnTaskbar.Checked;
NewSettings.ShowIconInTray := cbShowIconInTray.Checked;
NewSettings.NightscoutUrl := eNightscoutSite.Text;

NewSettings.ScaleIndex := sbScale.Position;
NewSettings.AlphaBlendValue := sbAlphaBlend.Position;
NewSettings.TimeZoneCorrection := seTimeZoneCorrection.Value;
NewSettings.WallpaperFileName := eWallpaper.Text;
NewSettings.WallpaperFileName := eWallpaper.Text;

UpdateOpacityLabel();
UpdateScaleLabel();
Expand Down
Loading

0 comments on commit ca07e20

Please sign in to comment.