diff --git a/NightscoutWatcher.dpr b/NightscoutWatcher.dpr index cd13582..08f8823 100644 --- a/NightscoutWatcher.dpr +++ b/NightscoutWatcher.dpr @@ -34,7 +34,7 @@ uses begin Application.Initialize; - Application.Title := 'Nightscout Watcher'; + Application.Title:='Nightscout Watcher'; Application.CreateForm(TfMain, fMain); Application.Run; end. diff --git a/NightscoutWatcher.lpi b/NightscoutWatcher.lpi index 0b7d935..4daa5b1 100644 --- a/NightscoutWatcher.lpi +++ b/NightscoutWatcher.lpi @@ -24,7 +24,8 @@ - + + diff --git a/forms/ufMain.lfm b/forms/ufMain.lfm index 65085d3..30157e0 100644 --- a/forms/ufMain.lfm +++ b/forms/ufMain.lfm @@ -18,6 +18,7 @@ object fMain: TfMain Font.Name = 'Tahoma' FormStyle = fsSystemStayOnTop KeyPreview = True + OnClose = FormClose OnCreate = FormCreate OnDblClick = actVisitNightscoutSiteExecute OnDestroy = FormDestroy @@ -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 diff --git a/forms/ufMain.pas b/forms/ufMain.pas index d67f235..149c4c6 100644 --- a/forms/ufMain.pas +++ b/forms/ufMain.pas @@ -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 @@ -29,8 +29,6 @@ TDrawPanel = class(TPanel) { TfMain } TfMain = class(TForm) - AudioOut: TAcsAudioOut; - AudioFileIn: TAcsFileIn; actDrawGlucoseLevelDelta: TAction; actDrawGlucoseAvg: TAction; actDrawWallpaper: TAction; @@ -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); @@ -182,6 +181,7 @@ TfMain = class(TForm) Loaded: Boolean; FPosX : Integer; FPosY : Integer; + LastAudioFileName: string; Settings: TSettings; DrawPanel: TDrawPanel; Entries: TNightscoutEntryList; @@ -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(); @@ -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 @@ -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); @@ -671,6 +687,7 @@ procedure TfMain.FormCreate(Sender: TObject); WallpaperJPG := TJPEGImage.Create(); StaleAlarmBlinkTrigger := False; GlucoseLevelAlarmBlinkTrigger := False; + LastAudioFileName := ''; Entries := TNightscoutEntryList.Create; @@ -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); @@ -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; @@ -1190,8 +1212,9 @@ procedure TfMain.tmrProgressBarTimer(Sender: TObject); CheckStaleDataAlarms(); CheckGlucoseLevelAlarms(); DrawTrayIcon(); + ShowTrayIconBaloonHint(); DrawApplicationIcon(); - ShowBaloonHint(); + PlayAlarm(); Invalidate(); end; @@ -1216,6 +1239,7 @@ procedure TfMain.tmrTimer(Sender: TObject); UpdateApplicationTitle(); DrawTrayIcon(); DrawApplicationIcon(); + PlayAlarm(); HardInvalidate(); end; @@ -1648,6 +1672,7 @@ procedure TfMain.DoUpdateCallerFormWithSettings; SetAlphaBlendValue(Settings.AlphaBlendValue); LoadWallpaper(Settings.WallpaperFileName); ShowIconInTray(Settings.ShowIconInTray); + PlayAlarm(); HardInvalidate; end; diff --git a/forms/ufSettings.lfm b/forms/ufSettings.lfm index 4b11a70..ccfc0a1 100644 --- a/forms/ufSettings.lfm +++ b/forms/ufSettings.lfm @@ -1,7 +1,7 @@ object fSettings: TfSettings - Left = 1271 + Left = 611 Height = 500 - Top = 431 + Top = 188 Width = 600 Caption = 'Settings' ClientHeight = 500 @@ -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 @@ -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' diff --git a/forms/ufSettings.pas b/forms/ufSettings.pas index 006bdc1..25fb800 100644 --- a/forms/ufSettings.pas +++ b/forms/ufSettings.pas @@ -20,6 +20,7 @@ TfSettings = class(TForm) btnLoadWallpaper: TButton; btnOK: TButton; btnCancel: TButton; + cbEnableAudioAlarms: TCheckBox; cbShowIconInTray: TCheckBox; cbStayOnTop: TCheckBox; cbDrawGlucoseLevelDelta: TCheckBox; @@ -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; @@ -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); @@ -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(); diff --git a/resources/InnoSetupScript.iss b/resources/InnoSetupScript.iss new file mode 100644 index 0000000..2a2fbe7 --- /dev/null +++ b/resources/InnoSetupScript.iss @@ -0,0 +1,48 @@ +; -- Installation script -- + +#define MyInstallerName "NightscoutWatcher" +#define MyAppExeName "NightscoutWatcher.exe" +#define MyAppName "Nightscout Watcher" +#define MyAppVersion "2.3.0" + +[Setup] +AppName=Nightscout Watcher +WizardStyle=modern +DefaultDirName={autopf}\Nightscout Watcher +DefaultGroupName=Nightscout Watcher +Compression=lzma2 +SolidCompression=yes +OutputDir=.\ +OutputBaseFilename={#MyInstallerName} +PrivilegesRequired=none +Uninstallable=yes +DisableReadyPage=True +AppCopyright=Sergey Oleynikov +SetupIconFile=NightScoutWatcher.ico +ShowUndisplayableLanguages=True +UninstallDisplayName=Nightscout Watcher +UninstallDisplayIcon={app}\{#MyAppExeName} +AppVersion={#MyAppVersion} + +[Files] +Source: "..\lib\i386-win32\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion +Source: "alarm.wav"; DestDir: "{app}"; Flags: ignoreversion +Source: "alarm2.wav"; DestDir: "{app}"; Flags: ignoreversion +Source: "libeay32.dll"; DestDir: "{app}"; Flags: ignoreversion +Source: "ssleay32.dll"; DestDir: "{app}"; Flags: ignoreversion + +[Icons] +Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\{#MyAppExeName}"; Tasks: "desktopicon" +Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\{#MyAppExeName}" + + +[Languages] +Name: "english"; MessagesFile: "compiler:Default.isl"; +Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl"; + +[Tasks] +Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked + + +[Run] +Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent diff --git a/resources/alarm.wav b/resources/alarm.wav new file mode 100644 index 0000000..8683eed Binary files /dev/null and b/resources/alarm.wav differ diff --git a/resources/alarm2.wav b/resources/alarm2.wav new file mode 100644 index 0000000..4db4739 Binary files /dev/null and b/resources/alarm2.wav differ diff --git a/units/uSettings.pas b/units/uSettings.pas index cc081dc..5cc6d63 100644 --- a/units/uSettings.pas +++ b/units/uSettings.pas @@ -69,11 +69,13 @@ TSettings = class function GetEntryMinsWithTimeZoneCorrection(DateFirst, DateLast: TDateTime): Integer; public AlphaBlendValue: Integer; - AudioAlarmFile: string; + AlarmAudioFile: string; + UrgentAlarmAudioFile: string; CheckInterval: Integer; DrawStages: TDrawStages; EnableGlucoseLevelAlarms: Boolean; EnableStaleDataAlarms: Boolean; + EnableAudioAlarms: Boolean; FullScreen: Boolean; HighGlucoseAlarm: Integer; HoursToRecive: Integer; @@ -113,6 +115,7 @@ TSettings = class function SetScaleIndex(Index: Integer): Boolean; function IsSnoozeAlarmsEndTimePassed(): Boolean; function GetOpacity(): Integer; + function GetAppropriateAlarmFile(Entry: TNightscoutEntry): string; function GetScale(): Integer; procedure AddDrawStage(DrawStage: TDrawStage); procedure Assign(Settings: TSettings); @@ -181,6 +184,7 @@ procedure TSettings.Assign(Settings: TSettings); DrawStages := Settings.DrawStages; EnableGlucoseLevelAlarms := Settings.EnableGlucoseLevelAlarms; EnableStaleDataAlarms := Settings.EnableStaleDataAlarms; + EnableAudioAlarms := Settings.EnableAudioAlarms; FullScreen := Settings.FullScreen; HighGlucoseAlarm := Settings.HighGlucoseAlarm; IsMmolL := Settings.IsMmolL; @@ -204,12 +208,15 @@ procedure TSettings.Assign(Settings: TSettings); function TSettings.Clone(): TSettings; begin Result := TSettings.Create(OptionsFileName); + Result.AlarmAudioFile := AlarmAudioFile; + Result.UrgentAlarmAudioFile := UrgentAlarmAudioFile; Result.AlphaBlendValue := AlphaBlendValue; Result.CheckInterval := CheckInterval; Result.HoursToRecive := HoursToRecive; Result.DrawStages := DrawStages; Result.EnableGlucoseLevelAlarms := EnableGlucoseLevelAlarms; Result.EnableStaleDataAlarms := EnableStaleDataAlarms; + Result.EnableAudioAlarms := EnableAudioAlarms; Result.FullScreen := FullScreen; Result.HighGlucoseAlarm := HighGlucoseAlarm; Result.IsMmolL := IsMmolL; @@ -234,13 +241,15 @@ constructor TSettings.Create(OptionsFileName: string); begin Self.OptionsFileName := OptionsFileName; DrawStages := [dsLastGlucoseLevel, dsGlucoseLines, dsHorzGuideLines, - dsVertGuideLines, dsLastGlucoseLevelDate, dsGlucoseSlope, + dsLastGlucoseLevelDate, dsGlucoseSlope, dsGlucoseExtremePoints, dsGlucoseLevelDelta, dsGlucoseAvg]; AlphaBlendValue := 200; - AudioAlarmFile := ''; + AlarmAudioFile := 'alarm.wav'; + UrgentAlarmAudioFile := 'alarm2.wav'; CheckInterval := 20; EnableGlucoseLevelAlarms := True; EnableStaleDataAlarms := True; + EnableAudioAlarms := False; FullScreen := False; HighGlucoseAlarm:= 9 * cMmolDenominator; HoursToRecive := 24; @@ -249,7 +258,7 @@ constructor TSettings.Create(OptionsFileName: string); LowGlucoseAlarm:= 4 * cMmolDenominator; NightscoutUrl := ''; NightscoutUrl := ''; - ScaleIndex := 5; + ScaleIndex := 12; ShowCheckNewDataProgressBar := True; ShowIconInTaskBar := True; ShowIconInTray := True; @@ -259,10 +268,10 @@ constructor TSettings.Create(OptionsFileName: string); StayOnTop := True; TimeZoneCorrection := 0; UrgentHighGlucoseAlarm:= 13 * cMmolDenominator; - UrgentLowGlucoseAlarm:= Round(3.3 * cMmolDenominator); - UrgentStaleDataAlarm:= 40; + UrgentLowGlucoseAlarm := Round(3.3 * cMmolDenominator); + UrgentStaleDataAlarm := 40; WallpaperFileName := ''; - WindowRect := Rect(Screen.Width div 2, Screen.Height div 2, Screen.Width, Screen.Height); + WindowRect := Rect(Screen.Width div 2, Screen.Height div 2, Screen.Width - 100, Screen.Height - 100); end; function TSettings.GetColorByGlucoseLevel(Glucose: Integer): TColor; @@ -355,6 +364,7 @@ procedure TSettings.SaveOptions(); ini.WriteInteger('Alarms', 'UrgentStaleDataAlarm', UrgentStaleDataAlarm); ini.WriteBool ('Alarms', 'EnableGlucoseLevelAlarms', EnableGlucoseLevelAlarms); ini.WriteBool ('Alarms', 'EnableStaleDataAlarms', EnableStaleDataAlarms); + ini.WriteBool ('Alarms', 'EnableAudioAlarms', EnableAudioAlarms); ini.WriteInteger('Alarms', 'LastSnoozeTime', LastSnoozeTimePeriod); finally ini.Free; @@ -419,6 +429,7 @@ procedure TSettings.LoadOptions(); // Alarm settings EnableGlucoseLevelAlarms := ini.ReadBool ('Alarms', 'EnableGlucoseLevelAlarms', EnableGlucoseLevelAlarms); EnableStaleDataAlarms := ini.ReadBool ('Alarms', 'EnableStaleDataAlarms', EnableStaleDataAlarms); + EnableAudioAlarms := ini.ReadBool ('Alarms', 'EnableAudioAlarms', EnableAudioAlarms); HighGlucoseAlarm := ini.ReadInteger('Alarms', 'HighGlucoseAlarm', HighGlucoseAlarm); LowGlucoseAlarm := ini.ReadInteger('Alarms', 'LowGlucoseAlarm', LowGlucoseAlarm); UrgentHighGlucoseAlarm := ini.ReadInteger('Alarms', 'UrgentHighGlucoseAlarm', UrgentHighGlucoseAlarm); @@ -468,6 +479,19 @@ function TSettings.GetOpacity(): Integer; Result := Round(AlphaBlendValue / 255 * 100); end; +function TSettings.GetAppropriateAlarmFile(Entry: TNightscoutEntry): string; +begin + Result := ''; + + if not EnableAudioAlarms or (Entry = nil) or not IsSnoozeAlarmsEndTimePassed() then + Exit; + + if IsUrgentGlucoseLevelAlarmExists(Entry) or IsUrgentStaleDataAlarmExists(Entry) then + Result := UrgentAlarmAudioFile + else if IsGlucoseLevelAlarmExists(Entry) or IsStaleDataAlarmExists(Entry) then + Result := AlarmAudioFile; +end; + function TSettings.GetScale(): Integer; begin Result := ScaleIndex * 10;