Updates and Bugfixes

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5583 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber
2017-01-02 10:55:49 +00:00
parent 935c054138
commit 0f650b444a
3 changed files with 92 additions and 52 deletions

View File

@ -3,14 +3,14 @@
<ProjectSession> <ProjectSession>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Version Value="10"/> <Version Value="10"/>
<BuildModes Active="linux64"/> <BuildModes Active="win32GTK2"/>
<Units Count="25"> <Units Count="25">
<Unit0> <Unit0>
<Filename Value="foobotmonitor.lpr"/> <Filename Value="foobotmonitor.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<EditorIndex Value="8"/> <EditorIndex Value="8"/>
<CursorPos X="33" Y="25"/> <CursorPos X="33" Y="25"/>
<UsageCount Value="72"/> <UsageCount Value="74"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
@ -20,9 +20,9 @@
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/> <IsVisibleTab Value="True"/>
<TopLine Value="23"/> <TopLine Value="591"/>
<CursorPos X="72" Y="39"/> <CursorPos X="58" Y="613"/>
<UsageCount Value="72"/> <UsageCount Value="74"/>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
</Unit1> </Unit1>
@ -34,7 +34,7 @@
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<EditorIndex Value="2"/> <EditorIndex Value="2"/>
<CursorPos X="2" Y="20"/> <CursorPos X="2" Y="20"/>
<UsageCount Value="62"/> <UsageCount Value="64"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
@ -44,7 +44,7 @@
<WindowIndex Value="-1"/> <WindowIndex Value="-1"/>
<TopLine Value="-1"/> <TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/> <CursorPos X="-1" Y="-1"/>
<UsageCount Value="54"/> <UsageCount Value="56"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
<Filename Value="..\foobot_objects.pas"/> <Filename Value="..\foobot_objects.pas"/>
@ -53,7 +53,7 @@
<WindowIndex Value="-1"/> <WindowIndex Value="-1"/>
<TopLine Value="-1"/> <TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/> <CursorPos X="-1" Y="-1"/>
<UsageCount Value="54"/> <UsageCount Value="56"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
<Filename Value="..\foobot_utility.pas"/> <Filename Value="..\foobot_utility.pas"/>
@ -61,7 +61,7 @@
<EditorIndex Value="5"/> <EditorIndex Value="5"/>
<TopLine Value="65"/> <TopLine Value="65"/>
<CursorPos X="18" Y="83"/> <CursorPos X="18" Y="83"/>
<UsageCount Value="72"/> <UsageCount Value="74"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
@ -71,21 +71,21 @@
<WindowIndex Value="-1"/> <WindowIndex Value="-1"/>
<TopLine Value="-1"/> <TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/> <CursorPos X="-1" Y="-1"/>
<UsageCount Value="54"/> <UsageCount Value="56"/>
</Unit6> </Unit6>
<Unit7> <Unit7>
<Filename Value="..\latest_stable\foobot_httpclient.pas"/> <Filename Value="..\latest_stable\foobot_httpclient.pas"/>
<EditorIndex Value="3"/> <EditorIndex Value="3"/>
<TopLine Value="43"/> <TopLine Value="43"/>
<CursorPos X="47" Y="13"/> <CursorPos X="47" Y="13"/>
<UsageCount Value="53"/> <UsageCount Value="54"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit7> </Unit7>
<Unit8> <Unit8>
<Filename Value="..\latest_stable\foobot_objects.pas"/> <Filename Value="..\latest_stable\foobot_objects.pas"/>
<EditorIndex Value="7"/> <EditorIndex Value="7"/>
<CursorPos X="32" Y="61"/> <CursorPos X="32" Y="61"/>
<UsageCount Value="53"/> <UsageCount Value="54"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit8> </Unit8>
<Unit9> <Unit9>
@ -121,7 +121,7 @@
<EditorIndex Value="4"/> <EditorIndex Value="4"/>
<TopLine Value="284"/> <TopLine Value="284"/>
<CursorPos X="38" Y="313"/> <CursorPos X="38" Y="313"/>
<UsageCount Value="33"/> <UsageCount Value="34"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit13> </Unit13>
<Unit14> <Unit14>
@ -191,16 +191,16 @@
<Unit23> <Unit23>
<Filename Value="C:\trunklatest\fpc\packages\rtl-objpas\src\inc\dateutil.inc"/> <Filename Value="C:\trunklatest\fpc\packages\rtl-objpas\src\inc\dateutil.inc"/>
<EditorIndex Value="6"/> <EditorIndex Value="6"/>
<TopLine Value="93"/> <TopLine Value="381"/>
<CursorPos X="19" Y="110"/> <CursorPos X="24" Y="409"/>
<UsageCount Value="22"/> <UsageCount Value="23"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit23> </Unit23>
<Unit24> <Unit24>
<Filename Value="..\latest_stable\udataform.pas"/> <Filename Value="..\latest_stable\udataform.pas"/>
<EditorIndex Value="1"/> <EditorIndex Value="1"/>
<TopLine Value="70"/> <TopLine Value="70"/>
<UsageCount Value="22"/> <UsageCount Value="23"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit24> </Unit24>
</Units> </Units>

View File

@ -59,10 +59,10 @@ object mainform: Tmainform
ShowText = True ShowText = True
ShowLevel = True ShowLevel = True
Value = 10 Value = 10
ValueMin = 10 ValueMin = 0
ValueMax = 40 ValueMax = 40
ValueRed = 10 ValueRed = 0
ValueYellow = 10 ValueYellow = 30
AnalogKind = akAnalog AnalogKind = akAnalog
end end
object as_hum: TAnalogSensor object as_hum: TAnalogSensor
@ -132,7 +132,7 @@ object mainform: Tmainform
ShowLevel = True ShowLevel = True
Value = 0 Value = 0
ValueMin = 0 ValueMin = 0
ValueMax = 1000 ValueMax = 700
ValueRed = 0 ValueRed = 0
ValueYellow = 0 ValueYellow = 0
AnalogKind = akAnalog AnalogKind = akAnalog
@ -382,6 +382,7 @@ object mainform: Tmainform
end end
object lineseries_allpollu: TLineSeries object lineseries_allpollu: TLineSeries
LinePen.Color = clBlue LinePen.Color = clBlue
LinePen.Width = 2
end end
end end
end end

View File

@ -36,7 +36,7 @@ V0.0.5.0: ??
interface interface
uses uses
Classes, SysUtils, FileUtil, TAGraph, TAIntervalSources, TASeries, //TASources, Classes, SysUtils, FileUtil, TAGraph, TAIntervalSources, TASeries,
Sensors, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, Menus, Sensors, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, Menus,
lclIntf, foobot_utility, uCryptIni, Variants, dateutils, uconfigform; lclIntf, foobot_utility, uCryptIni, Variants, dateutils, uconfigform;
@ -50,12 +50,27 @@ const
TWENTYFOURHOURS = ONEHOUR * 24; TWENTYFOURHOURS = ONEHOUR * 24;
// Colours for guages and graph lines // Colours for guages and graph lines
COL_PM = clMaroon; COL_PM = clGreen;
COL_TMP = clRed; COL_TMP = clRed;
COL_HUM = clGreen; COL_HUM = clMaroon;
COL_CO2 = clLime; COL_CO2 = clLime;
COL_VOC = clNavy; COL_VOC = clBlue;
COL_ALLPOLLU = clBlue; COL_ALLPOLLU = clFuchsia;
// Sensor Gauge MINMAX Values
MIN_PM = 0;
MAX_PM = 1000;
MIN_TMP = 0;
MAX_TMP = 40;
MIN_HUM = 10;
MAX_HUM = 100;
MIN_CO2 = 450;
MAX_CO2 = 3000;
MIN_VOC = 125;
MAX_VOC = 1000;
MIN_ALLPOLLU = 0;
MAX_ALLPOLLU = 700;
type type
@ -143,12 +158,13 @@ type
sSecretKey, sFoobotUserName, sUUID: string; sSecretKey, sFoobotUserName, sUUID: string;
bShowMinimalDisplay: boolean; bShowMinimalDisplay: boolean;
iFudgeFactor: integer; iFudgeFactor: integer;
procedure SetUpColours; procedure SetUpSensorColours;
procedure SetUpSensorMinMax;
procedure DisplayReadings; procedure DisplayReadings;
procedure UpdateGuage(Sender: TAnalogSensor; SensorNumber: integer); procedure UpdateGuage(Sender: TAnalogSensor; SensorNumber: integer);
procedure UpdateHighLow(SensorNumber: integer); procedure UpdateHighLow(SensorNumber: integer);
procedure DrawGraphHistory; procedure GraphHistory;
procedure DrawGraph; procedure GraphCurrentReading;
public public
INI: TCryptINIfile; INI: TCryptINIfile;
end; end;
@ -186,7 +202,8 @@ begin
TrayIcon1.Icon := Application.Icon; TrayIcon1.Icon := Application.Icon;
TrayIcon1.Hint := Application.Title; TrayIcon1.Hint := Application.Title;
DateTimeIntervalChartSource1.DateTimeFormat := 'hh:nn'; DateTimeIntervalChartSource1.DateTimeFormat := 'hh:nn';
SetUpColours; SetUpSensorMinMax;
SetUpSensorColours;
end; end;
procedure Tmainform.FormActivate(Sender: TObject); procedure Tmainform.FormActivate(Sender: TObject);
@ -194,8 +211,7 @@ var
sTempFoobotUserName, sTempSecretKey: string; sTempFoobotUserName, sTempSecretKey: string;
begin begin
ClientHeight := grp_sensorDisplay.Height + grp_highlow.Height + ClientHeight := grp_sensorDisplay.Height + grp_highlow.Height + grp_chart.Height;
grp_chart.Height;
// Allow user to enter values in INIFile // Allow user to enter values in INIFile
sTempFoobotUserName := INI.ReadUnencryptedString('Config', 'Foobot User', 'unknown'); sTempFoobotUserName := INI.ReadUnencryptedString('Config', 'Foobot User', 'unknown');
@ -222,7 +238,7 @@ begin
mnu_optionsSaveHighLows.Checked := SaveLoadHighLows; mnu_optionsSaveHighLows.Checked := SaveLoadHighLows;
if SaveLoadHighLows then if SaveLoadHighLows then
LoadHighLows; LoadHighLows;
DrawGraphHistory; GraphHistory;
{$IFNDEF DEBUGMODE} {$IFNDEF DEBUGMODE}
mnu_optionsTakeReadingNow.Click; mnu_optionsTakeReadingNow.Click;
{$ENDIF} {$ENDIF}
@ -264,7 +280,7 @@ begin
FreeAndNil(INI); FreeAndNil(INI);
end; end;
procedure Tmainform.SetUpColours; procedure Tmainform.SetUpSensorColours;
begin begin
as_pm.ColorFore := COL_PM; as_pm.ColorFore := COL_PM;
lineSeries_pm.SeriesColor := COL_PM; lineSeries_pm.SeriesColor := COL_PM;
@ -280,6 +296,22 @@ begin
lineSeries_allpollu.SeriesColor := COL_ALLPOLLU; lineSeries_allpollu.SeriesColor := COL_ALLPOLLU;
end; end;
procedure Tmainform.SetUpSensorMinMax;
begin
as_pm.ValueMin := MIN_PM;
as_pm.ValueMax := MAX_PM;
as_tmp.ValueMin := MIN_TMP;
as_tmp.ValueMax := MAX_TMP;
as_hum.ValueMin := MIN_HUM;
as_hum.ValueMax := MAX_HUM;
as_co2.ValueMin := MIN_CO2;
as_co2.ValueMax := MAX_CO2;
as_voc.ValueMin := MIN_VOC;
as_voc.ValueMax := MAX_VOC;
as_allpollu.ValueMin := MIN_ALLPOLLU;
as_allpollu.ValueMax := MAX_ALLPOLLU;
end;
procedure Tmainform.FormWindowStateChange(Sender: TObject); procedure Tmainform.FormWindowStateChange(Sender: TObject);
begin begin
if mainform.WindowState = wsMinimized then if mainform.WindowState = wsMinimized then
@ -542,30 +574,35 @@ begin
for iCount := 1 to 6 do for iCount := 1 to 6 do
UpdateHighLow(iCount); UpdateHighLow(iCount);
end; end;
DrawGraph; GraphCurrentReading;
end; end;
end; end;
function AsPercent(aValue, aMax: double): double; function AsPercent(aValue, aMin, aMax: double): double;
begin begin
if aMax > 0 then if aMax > 0 then
Result := aValue / aMax * 100 Result := aValue / (aMax - aMin) * 100
else else
Result := 0; Result := 0;
end; end;
procedure Tmainform.DrawGraph; procedure Tmainform.GraphCurrentReading;
begin begin
lineseries_pm.AddXY(FoobotData_time[0], AsPercent(FoobotData_pm[0], as_pm.ValueMax)); lineseries_pm.AddXY(FoobotData_time[0],
lineseries_tmp.AddXY(FoobotData_time[0], AsPercent(FoobotData_tmp[0], as_tmp.ValueMax)); AsPercent(FoobotData_pm[0], as_pm.ValueMin, as_pm.ValueMax));
lineseries_hum.AddXY(FoobotData_time[0], AsPercent(FoobotData_hum[0], as_hum.ValueMax)); lineseries_tmp.AddXY(FoobotData_time[0], AsPercent(FoobotData_tmp[0],
lineseries_co2.AddXY(FoobotData_time[0], AsPercent(FoobotData_co2[0], as_co2.ValueMax)); as_tmp.ValueMin, as_tmp.ValueMax));
lineseries_voc.AddXY(FoobotData_time[0], AsPercent(FoobotData_voc[0], as_voc.ValueMax)); lineseries_hum.AddXY(FoobotData_time[0],
AsPercent(FoobotData_hum[0], as_hum.ValueMin, as_hum.ValueMax));
lineseries_co2.AddXY(FoobotData_time[0],
AsPercent(FoobotData_co2[0], as_co2.ValueMin, as_co2.ValueMax));
lineseries_voc.AddXY(FoobotData_time[0],
AsPercent(FoobotData_voc[0], as_voc.ValueMin, as_voc.ValueMax));
lineseries_allpollu.AddXY(FoobotData_time[0], lineseries_allpollu.AddXY(FoobotData_time[0],
AsPercent(FoobotData_allpollu[0], as_allpollu.ValueMax)); AsPercent(FoobotData_allpollu[0], as_allpollu.ValueMin, as_allpollu.ValueMax));
end; end;
procedure Tmainform.DrawGraphHistory; procedure Tmainform.GraphHistory;
// Fetch Hourly readings for the previous 2 days (AverageBy=3600) // Fetch Hourly readings for the previous 2 days (AverageBy=3600)
// Populate FoobotDataObjectToArrays // Populate FoobotDataObjectToArrays
var var
@ -573,7 +610,8 @@ var
iStartSeconds, iEndSeconds: int64; iStartSeconds, iEndSeconds: int64;
begin begin
iEndSeconds := DateTimeToUnix(Now) - 3600; iEndSeconds := DateTimeToUnix(Now) - 3600;
iStartSeconds := iEndSeconds - (2 * (24 * 3600)); iStartSeconds := iEndSeconds - (2 * (24 * 3600)); // 49 hours before Now
grp_chart.Caption:=Format('History from %s',[FormatDateTime('dd/mm/yyyy hh:nn',UnixToDateTime(iStartSeconds))]);
if FetchFoobotData(dfStartEnd, 0, 0, 3600, iStartSeconds, iEndSeconds, sSecretKey) = if FetchFoobotData(dfStartEnd, 0, 0, 3600, iStartSeconds, iEndSeconds, sSecretKey) =
False then False then
exit; exit;
@ -581,17 +619,18 @@ begin
for iCount := 0 to Pred(High(FoobotData_time)) do for iCount := 0 to Pred(High(FoobotData_time)) do
begin begin
lineseries_pm.AddXY(FoobotData_time[iCount], lineseries_pm.AddXY(FoobotData_time[iCount],
AsPercent(FoobotData_pm[iCount], as_pm.ValueMax)); AsPercent(FoobotData_pm[iCount], as_pm.ValueMin, as_pm.ValueMax));
lineseries_tmp.AddXY(FoobotData_time[iCount], lineseries_tmp.AddXY(FoobotData_time[iCount],
AsPercent(FoobotData_tmp[iCount], as_tmp.ValueMax)); AsPercent(FoobotData_tmp[iCount], as_tmp.ValueMin, as_tmp.ValueMax));
lineseries_hum.AddXY(FoobotData_time[iCount], lineseries_hum.AddXY(FoobotData_time[iCount],
AsPercent(FoobotData_hum[iCount], as_hum.ValueMax)); AsPercent(FoobotData_hum[iCount], as_hum.ValueMin, as_hum.ValueMax));
lineseries_co2.AddXY(FoobotData_time[iCount], lineseries_co2.AddXY(FoobotData_time[iCount],
AsPercent(FoobotData_co2[iCount], as_co2.ValueMax)); AsPercent(FoobotData_co2[iCount], as_co2.ValueMin, as_co2.ValueMax));
lineseries_voc.AddXY(FoobotData_time[iCount], lineseries_voc.AddXY(FoobotData_time[iCount],
AsPercent(FoobotData_voc[iCount], as_voc.ValueMax)); AsPercent(FoobotData_voc[iCount], as_voc.ValueMin, as_voc.ValueMax));
lineseries_allpollu.AddXY(FoobotData_time[iCount], lineseries_allpollu.AddXY(FoobotData_time[iCount],
AsPercent(FoobotData_allpollu[iCount], as_allpollu.ValueMax)); AsPercent(FoobotData_allpollu[iCount], as_allpollu.ValueMin,
as_allpollu.ValueMax));
end; end;
ResetArrays; // at end ResetArrays; // at end
end; end;