Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Oleynikov committed Nov 27, 2019
2 parents d224768 + 680eea3 commit 8dbeae6
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 171 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.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Nightscout Watcher
The main purpose of the application is to show glucose level on your monitor in background mode to control glucose level in more convenient way. It`s especially convinent for office workers who spend a lot of time working on computer.
The main purpose of the application is to show glucose level on your monitor in background mode to control glucose level in more convenient way. It's especially convinent for office workers who spend a lot of time working on computer.

![N|Solid](https://raw.githubusercontent.com/SergeyRock/nightscout-watcher/master/screenshots/Main.jpg)

App receives TSV-data about blood sugar level by requesting url like this: http://oldexcom.herokuapp.com/api/v1/entries/sgv?count=3000&find[dateString][$gte]=2019-11-16T01:00:00

## Collaboration
You are allways welcome to connect to this open source project by helping of any kind (e.g. testing, programming, spelling and etc.).
Don`t be hesitating if you notice something that can help to improve this project. Just write me an issue.
PS. I`m not a native english speaker. I`ll be gratefull if you paticipate in correction of [mistakes](https://github.com/SergeyRock/nightscout-watcher/issues).
Don't be hesitating if you notice something that can help to improve this project. Just write me an issue.
PS. I'm not a native english speaker. I'll be gratefull if you paticipate in correction of [mistakes](https://github.com/SergeyRock/nightscout-watcher/issues).

## Prerequisites
1. The main prerequisite is availability of your own [nightscout site](https://github.com/nightscout/cgm-remote-monitor).
Expand Down
1 change: 0 additions & 1 deletion forms/ufMain.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ object fMain: TfMain
Width = 301
Align = alBottom
Position = 10
Smooth = True
TabOrder = 0
end
object pm: TPopupMenu
Expand Down
182 changes: 43 additions & 139 deletions forms/ufMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ TfMain = class(TForm)
Settings: TSettings;
DrawPanel: TDrawPanel;
Entries: TNightscoutEntryList;
OptionsFileName: string;
Connected: Boolean;
WasAlphaBlend: Boolean;
Wallpaper: TBitmap;
Expand All @@ -202,8 +201,6 @@ TfMain = class(TForm)
function LoadWallpaper(const FileName: string): Boolean;
procedure ResetWindowBoundsToDefault();
procedure ResizeWallpaper();
procedure SaveOptions();
procedure LoadOptions();
function LoadEntriesData: Boolean;
procedure SetActionCheckProperty(Action: TAction; Checked: Boolean; DrawStage: TDrawStage);
function GetArrowRect(Slope: string; ArrowAreaRect: TRect; var OutPoints: TRect): Boolean;
Expand All @@ -227,6 +224,7 @@ TfMain = class(TForm)
procedure SnoozeAlarms(Seconds: Integer);
procedure UpdateApplicationTitle();
procedure UpdateHint();
procedure UpdateSnoozeActionShortCut(Seconds: Integer);
end;

var
Expand All @@ -237,13 +235,13 @@ TfMain = class(TForm)
DebugMode: Boolean = False;
{$ENDIF}

resourcestring
sHideTaskbarIcon = '-hide-taskbar-icon';
const
cSnoozeAlarmsResetTag = 0;

implementation

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

procedure TfMain.Restart(Params: string = '');
Expand All @@ -260,7 +258,7 @@ procedure TfMain.Restart(Params: string = '');
aProcess.Execute;
finally
aProcess.Free;
SaveOptions();
Settings.SaveOptions();
Application.Terminate;
end;
end;
Expand Down Expand Up @@ -441,23 +439,39 @@ procedure TfMain.DrawApplicationIcon();
end;

procedure TfMain.SnoozeAlarms(Seconds: Integer);
begin
Settings.SnoozeAlarms(Seconds);
UpdateSnoozeActionShortCut(Seconds);
end;

procedure TfMain.UpdateSnoozeActionShortCut(Seconds: Integer);
var
i: Integer;
SnoozeAction: TAction;
ActionFound: Boolean;
begin
Settings.SnoozeAlarms(Seconds);
if Seconds = cSnoozeAlarmsResetTag then
Exit;

ActionFound := False;
// Reassign shortcut according to chosen snooze period
for i := 0 to miSnoozeAlarms.Count - 1 do
begin
SnoozeAction := TAction(miSnoozeAlarms.Items[i].Action);
if SnoozeAction = nil then
Continue;

if SnoozeAction.Tag = Seconds then
SnoozeAction.ShortCut := VK_Z
begin
SnoozeAction.ShortCut := VK_Z;
ActionFound := True;
end
else
SnoozeAction.ShortCut := VK_UNKNOWN;
end;

if not ActionFound then
actSnoozeAlarms10mins.ShortCut := VK_Z;
end;

procedure TfMain.actSetCheckIntervalExecute(Sender: TObject);
Expand Down Expand Up @@ -638,19 +652,31 @@ procedure TfMain.ShowIconInTaskbar(AVisible: Boolean);
procedure TfMain.FormCreate(Sender: TObject);
begin
Loaded := False;
Connected := False;
Settings := TSettings.Create(ExtractFilePath(ParamStr(0)) + 'Options.ini');
Wallpaper := TBitmap.Create();
WallpaperJPG := TJPEGImage.Create();
StaleAlarmBlinkTrigger := False;
GlucoseLevelAlarmBlinkTrigger := False;
Settings := TSettings.Create();

Connected := False;
OptionsFileName := ExtractFilePath(ParamStr(0)) + 'Options.ini';
Entries := TNightscoutEntryList.Create;

CreateDrawPanel();

LoadOptions();
Settings.LoadOptions();
actDrawAlertLines.Checked := Settings.IsInDrawStage(dsAlertLines);
actDrawGlucoseAvg.Checked := Settings.IsInDrawStage(dsGlucoseAvg);
actDrawGlucoseExtremePoints.Checked := Settings.IsInDrawStage(dsGlucoseExtremePoints);
actDrawGlucoseLevel.Checked := Settings.IsInDrawStage(dsGlucoseLevel);
actDrawGlucoseLevelDelta.Checked := Settings.IsInDrawStage(dsGlucoseLevelDelta);
actDrawGlucoseLevelPoints.Checked := Settings.IsInDrawStage(dsGlucoseLevelPoints);
actDrawGlucoseLines.Checked := Settings.IsInDrawStage(dsGlucoseLines);
actDrawGlucoseSlope.Checked := Settings.IsInDrawStage(dsGlucoseSlope);
actDrawHorzGuideLines.Checked := Settings.IsInDrawStage(dsHorzGuideLines);
actDrawLastGlucoseLevel.Checked := Settings.IsInDrawStage(dsLastGlucoseLevel);
actDrawLastGlucoseLevelDate.Checked := Settings.IsInDrawStage(dsLastGlucoseLevelDate);
actDrawVertGuideLines.Checked := Settings.IsInDrawStage(dsVertGuideLines);
actDrawWallpaper.Checked := Settings.IsInDrawStage(dsWallpaper);
UpdateSnoozeActionShortCut(Settings.LastSnoozeTimePeriod);

ShowIconInTray(Settings.ShowIconInTray);
ShowWindowBorder(Settings.ShowWindowBorder);
Expand All @@ -662,9 +688,9 @@ procedure TfMain.FormCreate(Sender: TObject);

procedure TfMain.FormDestroy(Sender: TObject);
begin
SaveOptions();
FreeAndNil(Entries);
Settings.SaveOptions();
FreeAndNil(Settings);
FreeAndNil(Entries);
FreeAndNil(WallpaperJPG);
FreeAndNil(Wallpaper);
end;
Expand Down Expand Up @@ -859,7 +885,7 @@ procedure TfMain.actShowIconOnTaskbarExecute(Sender: TObject);
ShowIconInTaskbar(TAction(Sender).Checked);
Msg := 'To apply setting you should restart application.' + #13#10 + 'Restart now?';
if MessageDlg(Msg, mtConfirmation, mbYesNo, -1) = mrYes then
Restart(sHideTaskbarIcon);
Restart();
end;

procedure TfMain.alUpdate(AAction: TBasicAction; var Handled: Boolean);
Expand Down Expand Up @@ -1066,129 +1092,7 @@ procedure TfMain.SetActionCheckProperty(Action: TAction; Checked: Boolean; DrawS
Action.Checked := Checked;
end;

procedure TfMain.LoadOptions();
var
ini: TIniFile;

procedure LoadDrawStageOption(const Ident: string; DrawStage: TDrawStage; Action: TAction);
var
DrawStageChecked: Boolean;
begin
DrawStageChecked := ini.ReadBool('Visual', Ident, Settings.IsInDrawStage(DrawStage));
SetActionCheckProperty(Action, DrawStageChecked, DrawStage);
end;

begin
ini := TIniFile.Create(OptionsFileName);
try
// Main settings
Settings.IsMmolL := ini.ReadBool('Main', 'IsMmolL', Settings.IsMmolL);
Settings.NightscoutUrl := ini.ReadString('Main', 'NightscoutUrl', Settings.NightscoutUrl);
Settings.CheckInterval := ini.ReadInteger('Main', 'CheckInterval', Settings.CheckInterval);
Settings.TimeZoneCorrection := ini.ReadInteger('Main', 'TimeZoneCorrection', Settings.TimeZoneCorrection);
Settings.HoursToRecive := ini.ReadInteger('Main', 'HoursToRecive', Settings.HoursToRecive);

// Visual settings
LoadDrawStageOption('dsLastGlucoseLevel', dsLastGlucoseLevel, actDrawLastGlucoseLevel);
LoadDrawStageOption('dsGlucoseLines', dsGlucoseLines, actDrawGlucoseLines);
LoadDrawStageOption('dsGlucoseLevel', dsGlucoseLevel, actDrawGlucoseLevel);
LoadDrawStageOption('dsHorzGuideLines', dsHorzGuideLines, actDrawHorzGuideLines);
LoadDrawStageOption('dsVertGuideLines', dsVertGuideLines, actDrawVertGuideLines);
LoadDrawStageOption('dsLastGlucoseLevelDate', dsLastGlucoseLevelDate, actDrawLastGlucoseLevelDate);
LoadDrawStageOption('dsGlucoseSlope', dsGlucoseSlope, actDrawGlucoseSlope);
LoadDrawStageOption('dsGlucoseExtremePoints', dsGlucoseExtremePoints, actDrawGlucoseExtremePoints);
LoadDrawStageOption('dsAlertLines', dsAlertLines, actDrawAlertLines);
LoadDrawStageOption('dsGlucoseLevelPoints', dsGlucoseLevelPoints, actDrawGlucoseLevelPoints);
LoadDrawStageOption('dsGlucoseLevelDelta', dsGlucoseLevelDelta, actDrawGlucoseLevelDelta);
LoadDrawStageOption('dsGlucoseAvg', dsGlucoseAvg, actDrawGlucoseAvg);
LoadDrawStageOption('dsWallpaper', dsWallpaper, actDrawWallpaper);

Settings.WindowRect.Left := ini.ReadInteger('Visual', 'WindowLeft', Settings.WindowRect.Left);
Settings.WindowRect.Top := ini.ReadInteger('Visual', 'WindowTop', Settings.WindowRect.Top);
Settings.WindowRect.Right := ini.ReadInteger('Visual', 'WindowRight', Settings.WindowRect.Right);
Settings.WindowRect.Bottom := ini.ReadInteger('Visual', 'WindowBottom', Settings.WindowRect.Bottom);

Settings.ShowCheckNewDataProgressBar := ini.ReadBool('Visual', 'ShowCheckNewDataProgressBar', Settings.ShowCheckNewDataProgressBar);
Settings.ShowWindowBorder := ini.ReadBool('Visual', 'ShowWindowBorder', Settings.ShowWindowBorder);
Settings.FullScreen := ini.ReadBool('Visual', 'FullScreen', Settings.FullScreen);
Settings.StayOnTop := ini.ReadBool('Visual', 'StayOnTop', Settings.StayOnTop);
Settings.ShowIconInTaskBar := ini.ReadBool('Visual', 'ShowIconInTaskBar', Settings.ShowIconInTaskBar);
Settings.ShowIconInTray := ini.ReadBool('Visual', 'ShowIconInTray', Settings.ShowIconInTray);
Settings.WallpaperFileName := ini.ReadString('Visual', 'WallpaperFileName', Settings.WallpaperFileName);
Settings.AlphaBlendValue := ini.ReadInteger('Visual', 'AlphaBlendValue', Settings.AlphaBlendValue);
Settings.ScaleIndex := ini.ReadInteger('Visual', 'ScaleIndex', Settings.ScaleIndex);

// Alarm settings
Settings.EnableGlucoseLevelAlarms := ini.ReadBool('Alarms', 'EnableGlucoseLevelAlarms', Settings.EnableGlucoseLevelAlarms);
Settings.EnableStaleDataAlarms := ini.ReadBool('Alarms', 'EnableStaleDataAlarms', Settings.EnableStaleDataAlarms);
Settings.HighGlucoseAlarm := ini.ReadInteger('Alarms', 'HighGlucoseAlarm', Settings.HighGlucoseAlarm);
Settings.LowGlucoseAlarm := ini.ReadInteger('Alarms', 'LowGlucoseAlarm', Settings.LowGlucoseAlarm);
Settings.UrgentHighGlucoseAlarm := ini.ReadInteger('Alarms', 'UrgentHighGlucoseAlarm', Settings.UrgentHighGlucoseAlarm);
Settings.UrgentLowGlucoseAlarm := ini.ReadInteger('Alarms', 'UrgentLowGlucoseAlarm', Settings.UrgentLowGlucoseAlarm);
Settings.StaleDataAlarm := ini.ReadInteger('Alarms', 'StaleDataAlarm', Settings.StaleDataAlarm);
Settings.UrgentStaleDataAlarm := ini.ReadInteger('Alarms', 'UrgentStaleDataAlarm', Settings.UrgentStaleDataAlarm);
finally
ini.Free;
end;
end;

procedure TfMain.SaveOptions();
var
ini: TIniFile;
begin
ini := TIniFile.Create(OptionsFileName);
try
ini.WriteBool('Main', 'IsMmolL', Settings.IsMmolL);
ini.WriteString('Main', 'NightscoutUrl', Settings.NightscoutUrl);
ini.WriteInteger('Main', 'HoursToRecive', Settings.HoursToRecive);
ini.WriteInteger('Main', 'TimeZoneCorrection', Settings.TimeZoneCorrection);
ini.WriteInteger('Main', 'CheckInterval', Settings.CheckInterval);

ini.WriteBool('Visual', 'dsLastGlucoseLevel', Settings.IsInDrawStage(dsLastGlucoseLevel));
ini.WriteBool('Visual', 'dsGlucoseLines', Settings.IsInDrawStage(dsGlucoseLines));
ini.WriteBool('Visual', 'dsGlucoseLevel', Settings.IsInDrawStage(dsGlucoseLevel));
ini.WriteBool('Visual', 'dsHorzGuideLines', Settings.IsInDrawStage(dsHorzGuideLines));
ini.WriteBool('Visual', 'dsVertGuideLines', Settings.IsInDrawStage(dsVertGuideLines));
ini.WriteBool('Visual', 'dsLastGlucoseLevelDate', Settings.IsInDrawStage(dsLastGlucoseLevelDate));
ini.WriteBool('Visual', 'dsGlucoseSlope', Settings.IsInDrawStage(dsGlucoseSlope));
ini.WriteBool('Visual', 'dsGlucoseExtremePoints', Settings.IsInDrawStage(dsGlucoseExtremePoints));
ini.WriteBool('Visual', 'dsAlertLines', Settings.IsInDrawStage(dsAlertLines));
ini.WriteBool('Visual', 'dsGlucoseLevelPoints', Settings.IsInDrawStage(dsGlucoseLevelPoints));
ini.WriteBool('Visual', 'dsGlucoseLevelDelta', Settings.IsInDrawStage(dsGlucoseLevelDelta));
ini.WriteBool('Visual', 'dsGlucoseAvg', Settings.IsInDrawStage(dsGlucoseAvg));
ini.WriteBool('Visual', 'dsWallpaper', Settings.IsInDrawStage(dsWallpaper));

ini.WriteString('Visual', 'WallpaperFileName', Settings.WallpaperFileName);

ini.WriteBool('Visual', 'ShowCheckNewDataProgressBar', Settings.ShowCheckNewDataProgressBar);
ini.WriteBool('Visual', 'ShowWindowBorder', Settings.ShowWindowBorder);
ini.WriteBool('Visual', 'FullScreen', Settings.FullScreen);
ini.WriteInteger('Visual', 'AlphaBlendValue', Settings.AlphaBlendValue);

// Save window position and size
ini.WriteInteger('Visual', 'WindowLeft', BoundsRect.Left);
ini.WriteInteger('Visual', 'WindowTop', BoundsRect.Top);
ini.WriteInteger('Visual', 'WindowRight', BoundsRect.Right);
ini.WriteInteger('Visual', 'WindowBottom', BoundsRect.Bottom);

ini.WriteInteger('Visual', 'ScaleIndex', Settings.ScaleIndex);
ini.WriteBool('Visual', 'StayOnTop', Settings.StayOnTop);
ini.WriteBool('Visual', 'ShowIconInTaskBar', Settings.ShowIconInTaskBar);
ini.WriteBool('Visual', 'ShowIconInTray', Settings.ShowIconInTray);

ini.WriteInteger('Alarms', 'HighGlucoseAlarm', Settings.HighGlucoseAlarm);
ini.WriteInteger('Alarms', 'LowGlucoseAlarm', Settings.LowGlucoseAlarm);
ini.WriteInteger('Alarms', 'UrgentHighGlucoseAlarm', Settings.UrgentHighGlucoseAlarm);
ini.WriteInteger('Alarms', 'UrgentLowGlucoseAlarm', Settings.UrgentLowGlucoseAlarm);

ini.WriteInteger('Alarms', 'StaleDataAlarm', Settings.StaleDataAlarm);
ini.WriteInteger('Alarms', 'UrgentStaleDataAlarm', Settings.UrgentStaleDataAlarm);
ini.WriteBool('Alarms', 'EnableGlucoseLevelAlarms', Settings.EnableGlucoseLevelAlarms);
ini.WriteBool('Alarms', 'EnableStaleDataAlarms', Settings.EnableStaleDataAlarms);
finally
ini.Free;
end;
end;

procedure TfMain.RefreshCheckInterval;
begin
Expand Down
12 changes: 6 additions & 6 deletions forms/ufSettings.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ object fSettings: TfSettings
Height = 432
Top = 0
Width = 600
ActivePage = tsHelp
ActivePage = tsVisual
Align = alTop
Anchors = [akTop, akLeft, akRight, akBottom]
TabIndex = 4
TabIndex = 1
TabOrder = 2
OnChange = pcChange
object tsMain: TTabSheet
Expand Down Expand Up @@ -316,8 +316,8 @@ object fSettings: TfSettings
Left = 277
Height = 23
Top = 137
Width = 171
Caption = 'Show window border'
Width = 248
Caption = 'Show window border (need OK)'
Font.Color = clWindowText
Font.Height = -16
Font.Name = 'Tahoma'
Expand Down Expand Up @@ -2011,7 +2011,7 @@ object fSettings: TfSettings
object odWallpaper: TOpenDialog
Filter = '*.jp*g|*.jp*g'
Options = [ofFileMustExist, ofEnableSizing, ofViewDetail, ofAutoPreview]
left = 509
top = 136
left = 528
top = 40
end
end
Binary file added screenshots/Main.3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8dbeae6

Please sign in to comment.