diff --git a/applications/foobot/foobot_utility.pas b/applications/foobot/foobot_utility.pas index 9ad816279..03a782a7b 100644 --- a/applications/foobot/foobot_utility.pas +++ b/applications/foobot/foobot_utility.pas @@ -145,7 +145,10 @@ var sFoobotName: string; begin if SaveLoadHighLows = False then - Exit(False); + begin + ShowMessage('Unable to load All-Time stats'); + Exit(False); + end; sFoobotName := FoobotIdentityObject.FoobotIdentityList[TheCurrentFoobot].Name; if not Assigned(HLINI) then HLINI := TIniFile.Create(ChangeFileExt(GetAppConfigFile(False), '.ini')); diff --git a/applications/foobot/monitor/foobotmonitor.lpi b/applications/foobot/monitor/foobotmonitor.lpi index ecf886452..22fdc3996 100644 --- a/applications/foobot/monitor/foobotmonitor.lpi +++ b/applications/foobot/monitor/foobotmonitor.lpi @@ -19,8 +19,8 @@ - - + + @@ -78,6 +78,11 @@ + + + + + @@ -179,16 +184,19 @@ - + - + - + - + + + + @@ -262,6 +270,13 @@ + + + + + + diff --git a/applications/foobot/monitor/foobotmonitor.lpr b/applications/foobot/monitor/foobotmonitor.lpr index d8464d656..023fcbfc1 100644 --- a/applications/foobot/monitor/foobotmonitor.lpr +++ b/applications/foobot/monitor/foobotmonitor.lpr @@ -15,7 +15,7 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, umainform, uconfigform + Forms, tachartlazaruspkg, umainform, uconfigform { you can add units after this }; {$R *.res} diff --git a/applications/foobot/monitor/foobotmonitor.lps b/applications/foobot/monitor/foobotmonitor.lps index 59bc7cede..84486b54b 100644 --- a/applications/foobot/monitor/foobotmonitor.lps +++ b/applications/foobot/monitor/foobotmonitor.lps @@ -4,13 +4,13 @@ - + - + - + @@ -20,9 +20,9 @@ - - - + + + @@ -32,9 +32,9 @@ - + - + @@ -44,7 +44,7 @@ - + @@ -53,14 +53,15 @@ - + - - - + + + + @@ -70,21 +71,21 @@ - + - + - + - + - + @@ -93,12 +94,12 @@ - + - + @@ -106,21 +107,21 @@ - + - + - - - - + + + + @@ -129,148 +130,203 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + - + - + - + - + - + diff --git a/applications/foobot/monitor/foobotmonitor.res b/applications/foobot/monitor/foobotmonitor.res index 7d4bce483..36ba30e0f 100644 Binary files a/applications/foobot/monitor/foobotmonitor.res and b/applications/foobot/monitor/foobotmonitor.res differ diff --git a/applications/foobot/monitor/innosetup/foobotmonitor.iss b/applications/foobot/monitor/innosetup/foobotmonitor.iss index a191a8d9e..d728b09b6 100644 --- a/applications/foobot/monitor/innosetup/foobotmonitor.iss +++ b/applications/foobot/monitor/innosetup/foobotmonitor.iss @@ -9,7 +9,7 @@ [Setup] AppName=Foobot Monitor -AppVersion=0.0.3.0 +AppVersion=0.0.4.0 DefaultDirName={pf}\foobotmonitor DefaultGroupName=Foobot UninstallDisplayIcon={app}\foobotmonitor.exe diff --git a/applications/foobot/monitor/innosetup/setup_foobotmonitor.exe b/applications/foobot/monitor/innosetup/setup_foobotmonitor.exe index 112c7f6a7..f67981606 100644 Binary files a/applications/foobot/monitor/innosetup/setup_foobotmonitor.exe and b/applications/foobot/monitor/innosetup/setup_foobotmonitor.exe differ diff --git a/applications/foobot/monitor/linuxbinaries/foobotmonitor.zip b/applications/foobot/monitor/linuxbinaries/foobotmonitor.zip index 9c6ed17c7..06f1ef19c 100644 Binary files a/applications/foobot/monitor/linuxbinaries/foobotmonitor.zip and b/applications/foobot/monitor/linuxbinaries/foobotmonitor.zip differ diff --git a/applications/foobot/monitor/umainform.lfm b/applications/foobot/monitor/umainform.lfm index 72657bbfa..18ea8a88a 100644 --- a/applications/foobot/monitor/umainform.lfm +++ b/applications/foobot/monitor/umainform.lfm @@ -1,19 +1,18 @@ object mainform: Tmainform - Left = 614 - Height = 262 - Top = 109 - Width = 782 + Left = 583 + Height = 451 + Top = 174 + Width = 784 BorderIcons = [biSystemMenu, biMinimize] BorderStyle = bsSingle Caption = 'mainform' - ClientHeight = 242 - ClientWidth = 782 + ClientHeight = 431 + ClientWidth = 784 DefaultMonitor = dmDesktop Menu = MainMenu1 OnActivate = FormActivate OnCreate = FormCreate OnDestroy = FormDestroy - OnShow = FormShow OnWindowStateChange = FormWindowStateChange Position = poWorkAreaCenter ShowInTaskBar = stNever @@ -23,12 +22,12 @@ object mainform: Tmainform Left = 0 Height = 120 Top = 0 - Width = 782 + Width = 784 Align = alTop Caption = 'Current Values' ChildSizing.ControlsPerLine = 6 ClientHeight = 100 - ClientWidth = 778 + ClientWidth = 780 TabOrder = 0 object as_pm: TAnalogSensor Left = 0 @@ -43,7 +42,7 @@ object mainform: Tmainform ShowLevel = True Value = 0 ValueMin = 0 - ValueMax = 300 + ValueMax = 1000 ValueRed = 0 ValueYellow = 0 AnalogKind = akAnalog @@ -59,11 +58,11 @@ object mainform: Tmainform TabOrder = 1 ShowText = True ShowLevel = True - Value = 0 - ValueMin = 0 + Value = 10 + ValueMin = 10 ValueMax = 40 - ValueRed = 0 - ValueYellow = 0 + ValueRed = 10 + ValueYellow = 10 AnalogKind = akAnalog end object as_hum: TAnalogSensor @@ -77,11 +76,11 @@ object mainform: Tmainform TabOrder = 2 ShowText = True ShowLevel = True - Value = 0 - ValueMin = 0 + Value = 10 + ValueMin = 10 ValueMax = 100 - ValueRed = 0 - ValueYellow = 0 + ValueRed = 10 + ValueYellow = 10 AnalogKind = akAnalog end object as_co2: TAnalogSensor @@ -95,11 +94,11 @@ object mainform: Tmainform TabOrder = 3 ShowText = True ShowLevel = True - Value = 0 - ValueMin = 0 + Value = 450 + ValueMin = 450 ValueMax = 3000 - ValueRed = 0 - ValueYellow = 0 + ValueRed = 450 + ValueYellow = 450 AnalogKind = akAnalog end object as_voc: TAnalogSensor @@ -113,11 +112,11 @@ object mainform: Tmainform TabOrder = 4 ShowText = True ShowLevel = True - Value = 0 - ValueMin = 0 + Value = 125 + ValueMin = 125 ValueMax = 1000 - ValueRed = 0 - ValueYellow = 0 + ValueRed = 125 + ValueYellow = 125 AnalogKind = akAnalog end object as_allpollu: TAnalogSensor @@ -133,7 +132,7 @@ object mainform: Tmainform ShowLevel = True Value = 0 ValueMin = 0 - ValueMax = 300 + ValueMax = 1000 ValueRed = 0 ValueYellow = 0 AnalogKind = akAnalog @@ -143,14 +142,14 @@ object mainform: Tmainform Left = 0 Height = 119 Top = 120 - Width = 782 + Width = 784 Align = alTop Caption = 'All-time Highs and Lows' ChildSizing.EnlargeHorizontal = crsHomogenousChildResize ChildSizing.EnlargeVertical = crsScaleChilds ChildSizing.ControlsPerLine = 6 ClientHeight = 99 - ClientWidth = 778 + ClientWidth = 780 TabOrder = 1 object grp_pm: TGroupBox Left = 0 @@ -166,16 +165,16 @@ object mainform: Tmainform Left = 8 Height = 15 Top = 8 - Width = 60 - Caption = 'lbl_pmhigh' + Width = 43 + Caption = 'No stats' ParentColor = False end object lbl_pmlow: TLabel Left = 8 Height = 15 Top = 40 - Width = 55 - Caption = 'lbl_pmlow' + Width = 44 + Caption = 'No Stats' ParentColor = False end end @@ -193,16 +192,16 @@ object mainform: Tmainform Left = 8 Height = 15 Top = 8 - Width = 64 - Caption = 'lbl_tmphigh' + Width = 44 + Caption = 'No Stats' ParentColor = False end object lbl_tmplow: TLabel Left = 8 Height = 15 Top = 40 - Width = 59 - Caption = 'lbl_tmplow' + Width = 44 + Caption = 'No Stats' ParentColor = False end end @@ -220,16 +219,16 @@ object mainform: Tmainform Left = 8 Height = 15 Top = 8 - Width = 67 - Caption = 'lbl_humhigh' + Width = 44 + Caption = 'No Stats' ParentColor = False end object lbl_humlow: TLabel Left = 8 Height = 15 Top = 40 - Width = 62 - Caption = 'lbl_humlow' + Width = 44 + Caption = 'No Stats' ParentColor = False end end @@ -247,16 +246,16 @@ object mainform: Tmainform Left = 8 Height = 15 Top = 8 - Width = 61 - Caption = 'lbl_co2high' + Width = 44 + Caption = 'No Stats' ParentColor = False end object lbl_co2low: TLabel Left = 8 Height = 15 Top = 40 - Width = 56 - Caption = 'lbl_co2low' + Width = 44 + Caption = 'No Stats' ParentColor = False end end @@ -274,16 +273,16 @@ object mainform: Tmainform Left = 8 Height = 15 Top = 8 - Width = 61 - Caption = 'lbl_vochigh' + Width = 44 + Caption = 'No Stats' ParentColor = False end object lbl_voclow: TLabel Left = 8 Height = 15 Top = 40 - Width = 56 - Caption = 'lbl_voclow' + Width = 44 + Caption = 'No Stats' ParentColor = False end end @@ -301,20 +300,91 @@ object mainform: Tmainform Left = 8 Height = 15 Top = 8 - Width = 81 - Caption = 'lbl_allpolluhigh' + Width = 44 + Caption = 'No Stats' ParentColor = False end object lbl_allpollulow: TLabel Left = 8 Height = 15 Top = 40 - Width = 76 - Caption = 'lbl_allpollulow' + Width = 44 + Caption = 'No Stats' ParentColor = False end end end + object grp_chart: TGroupBox + Left = 0 + Height = 179 + Top = 239 + Width = 784 + Align = alTop + Caption = 'History' + ClientHeight = 159 + ClientWidth = 780 + TabOrder = 2 + object Chart1: TChart + Left = 0 + Height = 159 + Top = 0 + Width = 780 + AxisList = < + item + Marks.Format = '%2:s' + Marks.Style = smsLabel + Minors = <> + Title.LabelFont.Orientation = 900 + end + item + Grid.Visible = False + Intervals.Count = 24 + Intervals.Options = [aipGraphCoords, aipUseNiceSteps] + Alignment = calBottom + Arrow.Length = 24 + Marks.Distance = 0 + Marks.Format = '%2:s' + Marks.OverlapPolicy = opHideNeighbour + Marks.Range.Max = 24 + Marks.Source = DateTimeIntervalChartSource1 + Marks.Style = smsLabel + Minors = <> + Range.Max = 24 + Range.UseMax = True + end> + ExtentSizeLimit.UseXMax = True + ExtentSizeLimit.XMax = 24 + Foot.Brush.Color = clBtnFace + Foot.Font.Color = clBlue + Foot.Text.Strings = ( + 'Today' + ) + Title.Brush.Color = clBtnFace + Title.Font.Color = clBlue + Title.Text.Strings = ( + 'Foobot History' + ) + Align = alClient + object lineseries_pm: TLineSeries + LinePen.Color = clMaroon + end + object lineseries_tmp: TLineSeries + LinePen.Color = clRed + end + object lineseries_hum: TLineSeries + LinePen.Color = clGreen + end + object lineseries_co2: TLineSeries + LinePen.Color = clLime + end + object lineseries_voc: TLineSeries + LinePen.Color = clNavy + end + object lineseries_allpollu: TLineSeries + LinePen.Color = clBlue + end + end + end object tmr_foobot: TTimer Enabled = False Interval = 3600 @@ -375,11 +445,10 @@ object mainform: Tmainform object mnu_optionsSeperator1: TMenuItem Caption = '-' end - object mnu_optionsShowHighsAndLows: TMenuItem + object mnu_optionsShowMinimalDisplay: TMenuItem AutoCheck = True - Caption = 'Show All-time Highs and Lows' - Checked = True - OnClick = mnu_optionsShowHighsAndLowsClick + Caption = 'Only show guages' + OnClick = mnu_optionsShowMinimalDisplayClick end object mnu_optionsSaveHighLows: TMenuItem AutoCheck = True @@ -419,4 +488,8 @@ object mainform: Tmainform OnClick = mnu_fileExitClick end end + object DateTimeIntervalChartSource1: TDateTimeIntervalChartSource + Left = 174 + Top = 325 + end end diff --git a/applications/foobot/monitor/umainform.pas b/applications/foobot/monitor/umainform.pas index 4b652a49f..5e95fd227 100644 --- a/applications/foobot/monitor/umainform.pas +++ b/applications/foobot/monitor/umainform.pas @@ -1,4 +1,5 @@ unit umainform; + { Foobot Monitor Copyright (C)2016 Gordon Bamber minsadorada@charcodelvalle.com @@ -23,19 +24,24 @@ VERSION HISTORY V0.0.1.0: Initial commit V0.0.2.0: Trayicon added V0.0.3.0: Added Help menu. Updated Options menu -V0.0.4.0: ?? +V0.0.4.0: Graph added +V0.0.5.0: ?? } +{$ifopt D+} +// Debug mode +{$ENDIF} {$mode objfpc}{$H+} interface uses - Classes, SysUtils, FileUtil, Sensors, Forms, Controls, Graphics, Dialogs, - ExtCtrls, StdCtrls, Menus, lclIntf,foobot_utility, uCryptIni, Variants, dateutils, - uconfigform; + Classes, SysUtils, FileUtil, TAGraph, TAIntervalSources, TASeries, //TASources, + Sensors, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, Menus, + lclIntf, foobot_utility, uCryptIni, Variants, dateutils, uconfigform; -CONST +const + // Timer milliseconds ONEMINUTE = 60000; ONEHOUR = ONEMINUTE * 60; TWOHOURS = ONEHOUR * 2; @@ -43,6 +49,13 @@ CONST EIGHTHOURS = ONEHOUR * 8; TWENTYFOURHOURS = ONEHOUR * 24; + // Colours for guages and graph lines + COL_PM = clMaroon; + COL_TMP = clRed; + COL_HUM = clGreen; + COL_CO2 = clLime; + COL_VOC = clNavy; + COL_ALLPOLLU = clBlue; type @@ -55,6 +68,15 @@ type as_pm: TAnalogSensor; as_tmp: TAnalogSensor; as_voc: TAnalogSensor; + Chart1: TChart; + DateTimeIntervalChartSource1: TDateTimeIntervalChartSource; + lineseries_allpollu: TLineSeries; + lineseries_voc: TLineSeries; + lineseries_co2: TLineSeries; + lineseries_hum: TLineSeries; + lineseries_tmp: TLineSeries; + lineseries_pm: TLineSeries; + grp_chart: TGroupBox; grp_pm: TGroupBox; grp_tmp: TGroupBox; grp_hum: TGroupBox; @@ -91,7 +113,7 @@ type mnu_SampleEvery1Hour: TMenuItem; mnu_optionsSampleEvery: TMenuItem; mnu_optionsTakeReadingNow: TMenuItem; - mnu_optionsShowHighsAndLows: TMenuItem; + mnu_optionsShowMinimalDisplay: TMenuItem; mnu_options: TMenuItem; mnu_fileExit: TMenuItem; mnu_file: TMenuItem; @@ -101,7 +123,6 @@ type procedure FormActivate(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); - procedure FormShow(Sender: TObject); procedure FormWindowStateChange(Sender: TObject); procedure mnupopup_fileRestoreClick(Sender: TObject); procedure mnu_fileExitClick(Sender: TObject); @@ -109,7 +130,7 @@ type procedure mnu_optionsMinimiseToTrayClick(Sender: TObject); procedure mnu_optionsOnlineHelpClick(Sender: TObject); procedure mnu_optionsSaveHighLowsClick(Sender: TObject); - procedure mnu_optionsShowHighsAndLowsClick(Sender: TObject); + procedure mnu_optionsShowMinimalDisplayClick(Sender: TObject); procedure mnu_optionsTakeReadingNowClick(Sender: TObject); procedure mnu_SampleEvery1HourClick(Sender: TObject); procedure mnu_SampleEvery24HoursClick(Sender: TObject); @@ -120,12 +141,14 @@ type procedure TrayIcon1Click(Sender: TObject); private sSecretKey, sFoobotUserName, sUUID: string; - bShowHighsAndLows: boolean; + bShowMinimalDisplay: boolean; iFudgeFactor: integer; - iSampleInterval:Integer; + procedure SetUpColours; procedure DisplayReadings; procedure UpdateGuage(Sender: TAnalogSensor; SensorNumber: integer); procedure UpdateHighLow(SensorNumber: integer); + procedure DrawGraphHistory; + procedure DrawGraph; public INI: TCryptINIfile; end; @@ -156,28 +179,33 @@ begin FreeAndNil(INI); Application.Terminate; end; - INI.SectionHashing:=FALSE; + INI.SectionHashing := False; ResetHighLows; - iFudgeFactor := 20; - ClientHeight := grp_sensorDisplay.Height + grp_highlow.Height + iFudgeFactor; - bShowHighsAndLows := True; - TrayIcon1.Icon:=Application.Icon; - TrayIcon1.Hint:=Application.Title; + iFudgeFactor := 20; // only needed if height set here + bShowMinimalDisplay := False; + TrayIcon1.Icon := Application.Icon; + TrayIcon1.Hint := Application.Title; + DateTimeIntervalChartSource1.DateTimeFormat := 'hh:nn'; + SetUpColours; end; procedure Tmainform.FormActivate(Sender: TObject); -Var sTempFoobotUserName,sTempSecretKey:String; +var + sTempFoobotUserName, sTempSecretKey: string; begin + ClientHeight := grp_sensorDisplay.Height + grp_highlow.Height + + grp_chart.Height; + // Allow user to enter values in INIFile - sTempFoobotUserName:=INI.ReadUnencryptedString('Config','Foobot User','unknown'); - sTempSecretKey:=INI.ReadUnencryptedString('Config', 'Secret Key', 'unknown'); + sTempFoobotUserName := INI.ReadUnencryptedString('Config', 'Foobot User', 'unknown'); + sTempSecretKey := INI.ReadUnencryptedString('Config', 'Secret Key', 'unknown'); if ((sTempFoobotUserName <> 'unknown') and (sTempSecretKey <> 'unknown')) then begin INI.WriteString('Foobot', 'Foobot User', sTempFoobotUserName); - INI.DeleteKey('Config','Foobot User'); + INI.DeleteKey('Config', 'Foobot User'); INI.WriteString('Foobot', 'Secret Key', sTempSecretKey); - INI.DeleteKey('Config','Secret Key'); + INI.DeleteKey('Config', 'Secret Key'); end; // Fetch Username and API_KEY sFoobotUserName := INI.ReadString('Foobot', 'Foobot User', 'unknown'); @@ -190,17 +218,24 @@ begin if FoobotIdentityObject.FoobotIdentityList.Count > 0 then begin sUUID := FoobotIdentityObject.FoobotIdentityList.Items[0].uuid; - SaveLoadHighLows:=INI.ReadBool('Foobot','SaveLoadHighLows',TRUE); - mnu_optionsSaveHighLows.Checked:=SaveLoadHighLows; - If SaveLoadHighLows then LoadHighLows; + SaveLoadHighLows := INI.ReadBool('Foobot', 'SaveLoadHighLows', True); + mnu_optionsSaveHighLows.Checked := SaveLoadHighLows; + if SaveLoadHighLows then + LoadHighLows; + DrawGraphHistory; + {$IFNDEF DEBUGMODE} mnu_optionsTakeReadingNow.Click; +{$ENDIF} // Switch off for testing - tmr_foobot.Interval:=ONEHOUR; - tmr_foobot.Enabled:=TRUE; + tmr_foobot.Interval := ONEHOUR; + {$IFNDEF DEBUGMODE} + tmr_foobot.Enabled := True; +{$ENDIF} Show; end; end - else Close; + else + Close; end else begin @@ -209,7 +244,7 @@ begin Application.ProcessMessages; configform.ShowModal; // If user quit without data, then bail out - If NOT configform.bValid then + if not configform.bValid then begin Close; end; @@ -218,7 +253,8 @@ begin INI.WriteString('Foobot', 'Secret Key', configform.FoobotSecretKey); //sFoobotUserName := INI.ReadString('Foobot', 'Foobot User', 'unknown'); //sSecretKey := INI.ReadString('Foobot', 'Secret Key', 'unknown'); - ShowMessage('Click OK to store settings and close the app.' + LineEnding + 'New settings are applied on resart.'); + ShowMessage('Click OK to store settings and close the app.' + + LineEnding + 'New settings are applied on resart.'); Close; end; end; @@ -228,23 +264,35 @@ begin FreeAndNil(INI); end; -procedure Tmainform.FormShow(Sender: TObject); +procedure Tmainform.SetUpColours; begin + as_pm.ColorFore := COL_PM; + lineSeries_pm.SeriesColor := COL_PM; + as_tmp.ColorFore := COL_TMP; + lineSeries_tmp.SeriesColor := COL_TMP; + as_hum.ColorFore := COL_HUM; + lineSeries_hum.SeriesColor := COL_HUM; + as_co2.ColorFore := COL_CO2; + lineSeries_co2.SeriesColor := COL_CO2; + as_voc.ColorFore := COL_VOC; + lineSeries_voc.SeriesColor := COL_VOC; + as_allpollu.ColorFore := COL_ALLPOLLU; + lineSeries_allpollu.SeriesColor := COL_ALLPOLLU; end; procedure Tmainform.FormWindowStateChange(Sender: TObject); begin if mainform.WindowState = wsMinimized then begin - mainform.WindowState := wsNormal; - mainform.Hide; - mainform.ShowInTaskBar := stNever; + mainform.WindowState := wsNormal; + mainform.Hide; + mainform.ShowInTaskBar := stNever; end; end; procedure Tmainform.mnupopup_fileRestoreClick(Sender: TObject); begin - mainform.show; + mainform.Show; end; procedure Tmainform.mnu_fileExitClick(Sender: TObject); @@ -273,9 +321,10 @@ begin MessageDlg('About ' + Application.Title, s, mtInformation, [mbOK], 0); end; + procedure Tmainform.mnu_optionsMinimiseToTrayClick(Sender: TObject); begin - mainform.WindowState:=wsMinimized; + mainform.WindowState := wsMinimized; mainform.FormWindowStateChange(Self); end; @@ -286,17 +335,18 @@ end; procedure Tmainform.mnu_optionsSaveHighLowsClick(Sender: TObject); begin - SaveLoadHighLows:=mnu_optionsSaveHighLows.Checked; - INI.WriteBool('Foobot','SaveLoadHighLows',SaveLoadHighLows); + SaveLoadHighLows := mnu_optionsSaveHighLows.Checked; + INI.WriteBool('Foobot', 'SaveLoadHighLows', SaveLoadHighLows); end; -procedure Tmainform.mnu_optionsShowHighsAndLowsClick(Sender: TObject); +procedure Tmainform.mnu_optionsShowMinimalDisplayClick(Sender: TObject); begin - if mnu_optionsShowHighsAndLows.Checked then - mainform.ClientHeight := grp_sensorDisplay.Height + grp_highlow.Height + iFudgeFactor + if mnu_optionsShowMinimalDisplay.Checked then + mainform.ClientHeight := grp_sensorDisplay.Height// + iFudgeFactor else - mainform.ClientHeight := grp_sensorDisplay.Height;// + iFudgeFactor; - bShowHighsAndLows := mnu_optionsShowHighsAndLows.Checked; + mainform.ClientHeight := grp_sensorDisplay.Height + grp_chart.Height + + grp_highlow.Height;// + iFudgeFactor; + bShowMinimalDisplay := mnu_optionsShowMinimalDisplay.Checked; end; procedure Tmainform.mnu_optionsTakeReadingNowClick(Sender: TObject); @@ -312,37 +362,37 @@ end; procedure Tmainform.mnu_SampleEvery1HourClick(Sender: TObject); begin - tmr_foobot.Enabled:=FALSE; - tmr_foobot.Interval:=ONEHOUR; - tmr_foobot.Enabled:=TRUE; + tmr_foobot.Enabled := False; + tmr_foobot.Interval := ONEHOUR; + tmr_foobot.Enabled := True; end; procedure Tmainform.mnu_SampleEvery24HoursClick(Sender: TObject); begin - tmr_foobot.Enabled:=FALSE; - tmr_foobot.Interval:=TWENTYFOURHOURS; - tmr_foobot.Enabled:=TRUE; + tmr_foobot.Enabled := False; + tmr_foobot.Interval := TWENTYFOURHOURS; + tmr_foobot.Enabled := True; end; procedure Tmainform.mnu_SampleEvery2HoursClick(Sender: TObject); begin - tmr_foobot.Enabled:=FALSE; - tmr_foobot.Interval:=TWOHOURS; - tmr_foobot.Enabled:=TRUE; + tmr_foobot.Enabled := False; + tmr_foobot.Interval := TWOHOURS; + tmr_foobot.Enabled := True; end; procedure Tmainform.mnu_SampleEvery4HoursClick(Sender: TObject); begin - tmr_foobot.Enabled:=FALSE; - tmr_foobot.Interval:=FOURHOURS; - tmr_foobot.Enabled:=TRUE; + tmr_foobot.Enabled := False; + tmr_foobot.Interval := FOURHOURS; + tmr_foobot.Enabled := True; end; procedure Tmainform.mnu_SampleEvery8HoursClick(Sender: TObject); begin - tmr_foobot.Enabled:=FALSE; - tmr_foobot.Interval:=EIGHTHOURS; - tmr_foobot.Enabled:=TRUE; + tmr_foobot.Enabled := False; + tmr_foobot.Interval := EIGHTHOURS; + tmr_foobot.Enabled := True; end; procedure Tmainform.tmr_foobotTimer(Sender: TObject); @@ -353,7 +403,7 @@ end; procedure Tmainform.TrayIcon1Click(Sender: TObject); begin - mainform.show; + mainform.Show; end; procedure Tmainform.UpdateHighLow(SensorNumber: integer); @@ -361,61 +411,56 @@ begin case SensorNumber of 1: begin - lbl_pmhigh.Caption := Format( - 'High: %f %s', [double(FoobotDataHighs[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + - FormatDateTime('dd/mm tt', TDateTime(FoobotDataHighTimes[SensorNumber])); - lbl_pmLow.Caption := Format( - 'Low: %f %s', [double(FoobotDataLows[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + + lbl_pmhigh.Caption := Format('High: %f %s', + [double(FoobotDataHighs[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + + LineEnding + 'on ' + FormatDateTime('dd/mm tt', + TDateTime(FoobotDataHighTimes[SensorNumber])); + lbl_pmLow.Caption := Format('Low: %f %s', + [double(FoobotDataLows[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + FormatDateTime('dd/mm tt', TDateTime( FoobotDataLowTimes[SensorNumber])); end; 2: begin - lbl_tmphigh.Caption := Format( - 'High: %f %s', [double(FoobotDataHighs[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + - FormatDateTime('dd/mm tt', TDateTime(FoobotDataHighTimes[SensorNumber])); - lbl_tmpLow.Caption := Format( - 'Low: %f %s', [double(FoobotDataLows[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + + lbl_tmphigh.Caption := Format('High: %f %s', + [double(FoobotDataHighs[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + + LineEnding + 'on ' + FormatDateTime('dd/mm tt', + TDateTime(FoobotDataHighTimes[SensorNumber])); + lbl_tmpLow.Caption := Format('Low: %f %s', + [double(FoobotDataLows[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + FormatDateTime('dd/mm tt', TDateTime( FoobotDataLowTimes[SensorNumber])); end; 3: begin - lbl_humhigh.Caption := Format( - 'High: %f %s', [double(FoobotDataHighs[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + - FormatDateTime('dd/mm tt', TDateTime(FoobotDataHighTimes[SensorNumber])); - lbl_humLow.Caption := Format( - 'Low: %f %s', [double(FoobotDataLows[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + + lbl_humhigh.Caption := Format('High: %f %s', + [double(FoobotDataHighs[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + + LineEnding + 'on ' + FormatDateTime('dd/mm tt', + TDateTime(FoobotDataHighTimes[SensorNumber])); + lbl_humLow.Caption := Format('Low: %f %s', + [double(FoobotDataLows[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + FormatDateTime('dd/mm tt', TDateTime( FoobotDataLowTimes[SensorNumber])); end; 4: begin - lbl_co2high.Caption := Format( - 'High: %f %s', [double(FoobotDataHighs[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + - FormatDateTime('dd/mm tt', TDateTime(FoobotDataHighTimes[SensorNumber])); - lbl_co2Low.Caption := Format( - 'Low: %f %s', [double(FoobotDataLows[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + + lbl_co2high.Caption := Format('High: %f %s', + [double(FoobotDataHighs[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + + LineEnding + 'on ' + FormatDateTime('dd/mm tt', + TDateTime(FoobotDataHighTimes[SensorNumber])); + lbl_co2Low.Caption := Format('Low: %f %s', + [double(FoobotDataLows[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + FormatDateTime('dd/mm tt', TDateTime( FoobotDataLowTimes[SensorNumber])); end; 5: begin - lbl_vochigh.Caption := Format( - 'High: %f %s', [double(FoobotDataHighs[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + - FormatDateTime('dd/mm tt', TDateTime(FoobotDataHighTimes[SensorNumber])); - lbl_vocLow.Caption := Format( - 'Low: %f %s', [double(FoobotDataLows[SensorNumber]), - FoobotDataObject.Units[SensorNumber]]) + + lbl_vochigh.Caption := Format('High: %f %s', + [double(FoobotDataHighs[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + + LineEnding + 'on ' + FormatDateTime('dd/mm tt', + TDateTime(FoobotDataHighTimes[SensorNumber])); + lbl_vocLow.Caption := Format('Low: %f %s', + [double(FoobotDataLows[SensorNumber]), FoobotDataObject.Units[SensorNumber]]) + LineEnding + 'on ' + FormatDateTime('dd/mm tt', TDateTime( FoobotDataLowTimes[SensorNumber])); end; @@ -483,7 +528,7 @@ var begin if FoobotDataObjectToArrays = True then begin - mainform.Caption := Format('Foobot "%s" - ', + mainform.Caption := Format('Foobot "%s" - Last reading: ', [FoobotIdentityObject.FoobotIdentityList[0].Name]) + FormatDateTime('dd/mm/yyyy - tt', FoobotData_time[0]); UpdateGuage(as_pm, 1); @@ -492,10 +537,63 @@ begin UpdateGuage(as_co2, 4); UpdateGuage(as_voc, 5); UpdateGuage(as_allpollu, 6); - if bShowHighsAndLows then + if not bShowMinimalDisplay then + begin for iCount := 1 to 6 do UpdateHighLow(iCount); + end; + DrawGraph; end; end; +function AsPercent(aValue, aMax: double): double; +begin + if aMax > 0 then + Result := aValue / aMax * 100 + else + Result := 0; +end; + +procedure Tmainform.DrawGraph; +begin + lineseries_pm.AddXY(FoobotData_time[0], AsPercent(FoobotData_pm[0], as_pm.ValueMax)); + lineseries_tmp.AddXY(FoobotData_time[0], AsPercent(FoobotData_tmp[0], as_tmp.ValueMax)); + lineseries_hum.AddXY(FoobotData_time[0], AsPercent(FoobotData_hum[0], as_hum.ValueMax)); + lineseries_co2.AddXY(FoobotData_time[0], AsPercent(FoobotData_co2[0], as_co2.ValueMax)); + lineseries_voc.AddXY(FoobotData_time[0], AsPercent(FoobotData_voc[0], as_voc.ValueMax)); + lineseries_allpollu.AddXY(FoobotData_time[0], + AsPercent(FoobotData_allpollu[0], as_allpollu.ValueMax)); +end; + +procedure Tmainform.DrawGraphHistory; +// Fetch Hourly readings for the previous 2 days (AverageBy=3600) +// Populate FoobotDataObjectToArrays +var + iCount: integer; + iStartSeconds, iEndSeconds: int64; +begin + iEndSeconds := DateTimeToUnix(Now) - 3600; + iStartSeconds := iEndSeconds - (2 * (24 * 3600)); + if FetchFoobotData(dfStartEnd, 0, 0, 3600, iStartSeconds, iEndSeconds, sSecretKey) = + False then + exit; + if FoobotDataObjectToArrays then + for iCount := 0 to Pred(High(FoobotData_time)) do + begin + lineseries_pm.AddXY(FoobotData_time[iCount], + AsPercent(FoobotData_pm[iCount], as_pm.ValueMax)); + lineseries_tmp.AddXY(FoobotData_time[iCount], + AsPercent(FoobotData_tmp[iCount], as_tmp.ValueMax)); + lineseries_hum.AddXY(FoobotData_time[iCount], + AsPercent(FoobotData_hum[iCount], as_hum.ValueMax)); + lineseries_co2.AddXY(FoobotData_time[iCount], + AsPercent(FoobotData_co2[iCount], as_co2.ValueMax)); + lineseries_voc.AddXY(FoobotData_time[iCount], + AsPercent(FoobotData_voc[iCount], as_voc.ValueMax)); + lineseries_allpollu.AddXY(FoobotData_time[iCount], + AsPercent(FoobotData_allpollu[iCount], as_allpollu.ValueMax)); + end; + ResetArrays; // at end +end; + end.