V0.2.2.0 work-in-progress. ToDo: Trigger config form

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5614 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
gbamber 2017-01-09 12:13:01 +00:00
parent c4ef4f5db2
commit e22989bb94
2 changed files with 156 additions and 104 deletions

View File

@ -8,9 +8,9 @@
<Unit0>
<Filename Value="foobotmonitor.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="12"/>
<EditorIndex Value="13"/>
<CursorPos Y="35"/>
<UsageCount Value="119"/>
<UsageCount Value="120"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
@ -20,9 +20,9 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<TopLine Value="1113"/>
<CursorPos X="86" Y="1135"/>
<UsageCount Value="119"/>
<TopLine Value="981"/>
<CursorPos X="43" Y="1035"/>
<UsageCount Value="120"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
@ -32,20 +32,20 @@
<ComponentName Value="configform"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<EditorIndex Value="7"/>
<EditorIndex Value="8"/>
<TopLine Value="33"/>
<CursorPos X="41" Y="45"/>
<UsageCount Value="109"/>
<UsageCount Value="110"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit2>
<Unit3>
<Filename Value="..\foobot_httpclient.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<TopLine Value="380"/>
<CursorPos X="35" Y="387"/>
<UsageCount Value="101"/>
<EditorIndex Value="1"/>
<CursorPos X="49" Y="20"/>
<UsageCount Value="102"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="..\foobot_objects.pas"/>
@ -54,15 +54,15 @@
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="101"/>
<UsageCount Value="102"/>
</Unit4>
<Unit5>
<Filename Value="..\foobot_utility.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="9"/>
<TopLine Value="123"/>
<EditorIndex Value="10"/>
<TopLine Value="129"/>
<CursorPos X="49" Y="212"/>
<UsageCount Value="119"/>
<UsageCount Value="120"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
@ -72,15 +72,15 @@
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="101"/>
<UsageCount Value="102"/>
</Unit6>
<Unit7>
<Filename Value="foobot_sensors.pas"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="4"/>
<EditorIndex Value="5"/>
<TopLine Value="299"/>
<CursorPos X="14" Y="321"/>
<UsageCount Value="53"/>
<UsageCount Value="54"/>
<Loaded Value="True"/>
</Unit7>
<Unit8>
@ -89,9 +89,9 @@
<ComponentName Value="splashform"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<EditorIndex Value="2"/>
<EditorIndex Value="3"/>
<CursorPos X="42" Y="25"/>
<UsageCount Value="48"/>
<UsageCount Value="49"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
@ -100,26 +100,26 @@
<ComponentName Value="triggersform"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<EditorIndex Value="1"/>
<EditorIndex Value="2"/>
<CursorPos X="41" Y="7"/>
<UsageCount Value="39"/>
<UsageCount Value="40"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit9>
<Unit10>
<Filename Value="..\latest_stable\foobot_httpclient.pas"/>
<EditorIndex Value="8"/>
<EditorIndex Value="9"/>
<TopLine Value="43"/>
<CursorPos X="47" Y="13"/>
<UsageCount Value="74"/>
<UsageCount Value="75"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
<Filename Value="..\latest_stable\foobot_objects.pas"/>
<EditorIndex Value="11"/>
<EditorIndex Value="12"/>
<TopLine Value="143"/>
<CursorPos X="35" Y="59"/>
<UsageCount Value="74"/>
<UsageCount Value="75"/>
<Loaded Value="True"/>
</Unit11>
<Unit12>
@ -187,10 +187,10 @@
<Unit21>
<Filename Value="C:\trunklatest\lazarus\ide\lazarus.pp"/>
<UnitName Value="Lazarus"/>
<EditorIndex Value="5"/>
<EditorIndex Value="6"/>
<TopLine Value="101"/>
<CursorPos Y="154"/>
<UsageCount Value="25"/>
<UsageCount Value="26"/>
<Loaded Value="True"/>
</Unit21>
<Unit22>
@ -216,17 +216,17 @@
</Unit24>
<Unit25>
<Filename Value="C:\trunklatest\fpc\packages\rtl-objpas\src\inc\dateutil.inc"/>
<EditorIndex Value="10"/>
<EditorIndex Value="11"/>
<TopLine Value="381"/>
<CursorPos X="13" Y="384"/>
<UsageCount Value="43"/>
<UsageCount Value="44"/>
<Loaded Value="True"/>
</Unit25>
<Unit26>
<Filename Value="..\latest_stable\udataform.pas"/>
<EditorIndex Value="6"/>
<EditorIndex Value="7"/>
<TopLine Value="70"/>
<UsageCount Value="43"/>
<UsageCount Value="44"/>
<Loaded Value="True"/>
</Unit26>
<Unit27>
@ -267,10 +267,10 @@
<Unit32>
<Filename Value="C:\trunklatest\lazarus\lcl\graphics.pp"/>
<UnitName Value="Graphics"/>
<EditorIndex Value="3"/>
<EditorIndex Value="4"/>
<TopLine Value="1811"/>
<CursorPos X="13" Y="1834"/>
<UsageCount Value="21"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
</Unit32>
<Unit33>
@ -285,123 +285,123 @@
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="umainform.pas"/>
<Caret Line="953" TopLine="920"/>
<Caret Line="938" Column="17" TopLine="930"/>
</Position1>
<Position2>
<Filename Value="umainform.pas"/>
<Caret Line="929" Column="17" TopLine="921"/>
<Caret Line="940" Column="17" TopLine="932"/>
</Position2>
<Position3>
<Filename Value="umainform.pas"/>
<Caret Line="930" Column="17" TopLine="922"/>
<Caret Line="942" Column="17" TopLine="934"/>
</Position3>
<Position4>
<Filename Value="umainform.pas"/>
<Caret Line="932" Column="17" TopLine="924"/>
<Caret Line="287" TopLine="250"/>
</Position4>
<Position5>
<Filename Value="umainform.pas"/>
<Caret Line="931" Column="17" TopLine="923"/>
<Caret Line="580" Column="32" TopLine="574"/>
</Position5>
<Position6>
<Filename Value="umainform.pas"/>
<Caret Line="932" Column="17" TopLine="924"/>
<Caret Line="581" Column="32" TopLine="575"/>
</Position6>
<Position7>
<Filename Value="umainform.pas"/>
<Caret Line="934" Column="17" TopLine="926"/>
<Caret Line="580" Column="32" TopLine="574"/>
</Position7>
<Position8>
<Filename Value="umainform.pas"/>
<Caret Line="936" Column="17" TopLine="928"/>
<Caret Line="973" Column="18" TopLine="934"/>
</Position8>
<Position9>
<Filename Value="umainform.pas"/>
<Caret Line="938" Column="17" TopLine="930"/>
<Caret Line="987" Column="17" TopLine="945"/>
</Position9>
<Position10>
<Filename Value="umainform.pas"/>
<Caret Line="940" Column="17" TopLine="932"/>
<Caret Line="580" Column="49" TopLine="575"/>
</Position10>
<Position11>
<Filename Value="umainform.pas"/>
<Caret Line="942" Column="17" TopLine="934"/>
<Caret Line="581" Column="49" TopLine="576"/>
</Position11>
<Position12>
<Filename Value="umainform.pas"/>
<Caret Line="287" TopLine="250"/>
<Caret Line="582" Column="49" TopLine="577"/>
</Position12>
<Position13>
<Filename Value="umainform.pas"/>
<Caret Line="580" Column="32" TopLine="574"/>
<Caret Line="583" Column="49" TopLine="578"/>
</Position13>
<Position14>
<Filename Value="umainform.pas"/>
<Caret Line="581" Column="32" TopLine="575"/>
<Caret Line="586" Column="49" TopLine="581"/>
</Position14>
<Position15>
<Filename Value="umainform.pas"/>
<Caret Line="580" Column="32" TopLine="574"/>
<Caret Line="589" Column="49" TopLine="584"/>
</Position15>
<Position16>
<Filename Value="umainform.pas"/>
<Caret Line="973" Column="18" TopLine="934"/>
<Caret Line="592" Column="49" TopLine="587"/>
</Position16>
<Position17>
<Filename Value="umainform.pas"/>
<Caret Line="987" Column="17" TopLine="945"/>
<Caret Line="595" Column="49" TopLine="590"/>
</Position17>
<Position18>
<Filename Value="umainform.pas"/>
<Caret Line="580" Column="49" TopLine="575"/>
<Caret Line="598" Column="49" TopLine="593"/>
</Position18>
<Position19>
<Filename Value="umainform.pas"/>
<Caret Line="581" Column="49" TopLine="576"/>
<Caret Line="402" Column="29" TopLine="369"/>
</Position19>
<Position20>
<Filename Value="umainform.pas"/>
<Caret Line="582" Column="49" TopLine="577"/>
<Caret Line="438" Column="37" TopLine="401"/>
</Position20>
<Position21>
<Filename Value="umainform.pas"/>
<Caret Line="583" Column="49" TopLine="578"/>
<Caret Line="415" Column="89" TopLine="393"/>
</Position21>
<Position22>
<Filename Value="umainform.pas"/>
<Caret Line="586" Column="49" TopLine="581"/>
<Caret Line="417" Column="66" TopLine="395"/>
</Position22>
<Position23>
<Filename Value="umainform.pas"/>
<Caret Line="589" Column="49" TopLine="584"/>
<Caret Line="1076" Column="38" TopLine="1035"/>
</Position23>
<Position24>
<Filename Value="umainform.pas"/>
<Caret Line="592" Column="49" TopLine="587"/>
<Caret Line="709" Column="8" TopLine="696"/>
</Position24>
<Position25>
<Filename Value="umainform.pas"/>
<Caret Line="595" Column="49" TopLine="590"/>
<Caret Line="462" Column="59" TopLine="411"/>
</Position25>
<Position26>
<Filename Value="umainform.pas"/>
<Caret Line="598" Column="49" TopLine="593"/>
<Caret Line="463" Column="44" TopLine="422"/>
</Position26>
<Position27>
<Filename Value="umainform.pas"/>
<Caret Line="402" Column="29" TopLine="369"/>
<Caret Line="408" Column="36" TopLine="382"/>
</Position27>
<Position28>
<Filename Value="umainform.pas"/>
<Caret Line="438" Column="37" TopLine="401"/>
<Caret Line="1001" Column="34" TopLine="974"/>
</Position28>
<Position29>
<Filename Value="umainform.pas"/>
<Caret Line="415" Column="89" TopLine="393"/>
<Caret Line="463" Column="44" TopLine="438"/>
</Position29>
<Position30>
<Filename Value="umainform.pas"/>
<Caret Line="417" Column="66" TopLine="395"/>
<Caret Line="346" Column="11" TopLine="6"/>
</Position30>
</JumpHistory>
</ProjectSession>

View File

@ -233,7 +233,7 @@ type
procedure SaveConfig;
procedure LoadConfig;
procedure SetMinMaxTriggers;
procedure SetTrafficLightStats;
procedure SetTrafficLightStats(iSensorNum: integer; HIGHLOW: integer);
procedure DoHighTriggerAlert(const iSensorNum: integer; const aValue: variant);
procedure DoLowTriggerAlert(const iSensorNum: integer; const aValue: variant);
procedure RestoreNormalColour(const iSensorNum: integer);
@ -301,7 +301,7 @@ end;
procedure Tmainform.FormActivate(Sender: TObject);
var
sTempFoobotUserName, sTempSecretKey: string;
iCount: integer;
begin
ClientHeight := grp_sensorDisplay.Height + grp_highlow.Height +
grp_health.Height + grp_chart.Height;
@ -343,7 +343,8 @@ begin
LoadTriggers; // This can only be done if we have a Foobot Identity
// as each Foobot has its own trigger values
SetMinMaxTriggers; // Adjust if necesarry for Guage High/Low limits
SetTrafficLightStats;
for iCount := C_PM to C_ALLPOLLU do
SetTrafficLightStats(iCount, C_HIGH);
Show;
{$IFNDEF DEBUGMODE}
mnu_optionsTakeReadingNow.Click;
@ -396,46 +397,87 @@ begin
mnu_optionsTakeReadingNow.Click;
end;
procedure Tmainform.SetTrafficLightStats;
procedure Tmainform.SetTrafficLightStats(iSensorNum: integer; HIGHLOW: integer);
begin
lbl_redlightpm.Caption := Format('> %.1f %s', [double(FooBotTriggerArray[C_HIGH, C_PM]),
FoobotDataObject.Units[C_PM]]);
lbl_yellowlightpm.Caption := Format('> %.1f %s', [double(REC_PM),
FoobotDataObject.Units[C_PM]]);
lbl_greenlightpm.Caption := Format('< %.1f %s', [double(REC_PM),
FoobotDataObject.Units[C_PM]]);
if iSensorNum = C_PM then
if (HIGHLOW = C_HIGH) then
lbl_redlightpm.Caption :=
Format('> %.1f %s', [double(FooBotTriggerArray[C_HIGH, C_PM]),
FoobotDataObject.Units[C_PM]])
else
lbl_redlightpm.Caption :=
Format('< %.1f %s', [double(FooBotTriggerArray[C_LOW, C_PM]),
FoobotDataObject.Units[C_PM]]);
lbl_yellowlightpm.Caption :=
Format('> %.1f %s', [double(REC_PM), FoobotDataObject.Units[C_PM]]);
lbl_greenlightpm.Caption :=
Format('< %.1f %s', [double(REC_PM), FoobotDataObject.Units[C_PM]]);
lbl_redlighttmp.Caption := Format('> %.1f %s', [double(FooBotTriggerArray[C_HIGH, C_TMP]),
FoobotDataObject.Units[C_TMP]]);
if iSensorNum = C_TMP then
if (HIGHLOW = C_HIGH) then
lbl_redlighttmp.Caption :=
Format('> %.1f %s', [double(FooBotTriggerArray[C_HIGH, C_TMP]),
FoobotDataObject.Units[C_TMP]])
else
lbl_redlighttmp.Caption :=
Format('< %.1f %s', [double(FooBotTriggerArray[C_LOW, C_TMP]),
FoobotDataObject.Units[C_TMP]]);
lbl_yellowlighttmp.Caption :=
Format('> %.1f %s', [double(REC_TMP), FoobotDataObject.Units[C_TMP]]);
lbl_greenlighttmp.Caption := Format('< %.1f %s', [double(REC_TMP),
FoobotDataObject.Units[C_TMP]]);
lbl_greenlighttmp.Caption :=
Format('< %.1f %s', [double(REC_TMP), FoobotDataObject.Units[C_TMP]]);
lbl_redlighthum.Caption := Format('> %.1f %s', [double(FooBotTriggerArray[C_HIGH, C_HUM]),
FoobotDataObject.Units[C_HUM]]);
if iSensorNum = C_HUM then
if (HIGHLOW = C_HIGH) then
lbl_redlighthum.Caption :=
Format('> %.1f %s', [double(FooBotTriggerArray[C_HIGH, C_HUM]),
FoobotDataObject.Units[C_HUM]])
else
lbl_redlighthum.Caption :=
Format('< %.1f %s', [double(FooBotTriggerArray[C_LOW, C_HUM]),
FoobotDataObject.Units[C_HUM]]);
lbl_yellowlighthum.Caption :=
Format('> %.1f %s', [double(REC_HUM), FoobotDataObject.Units[C_HUM]]);
lbl_greenlighthum.Caption := Format('< %.1f %s', [double(REC_HUM),
FoobotDataObject.Units[C_HUM]]);
lbl_greenlighthum.Caption :=
Format('< %.1f %s', [double(REC_HUM), FoobotDataObject.Units[C_HUM]]);
lbl_redlightco2.Caption := Format('> %.0f %s', [double(FooBotTriggerArray[C_HIGH, C_CO2]),
FoobotDataObject.Units[C_CO2]]);
if iSensorNum = C_CO2 then
if (HIGHLOW = C_HIGH) then
lbl_redlightco2.Caption :=
Format('> %.0f %s', [double(FooBotTriggerArray[C_HIGH, C_CO2]),
FoobotDataObject.Units[C_CO2]])
else
lbl_redlightco2.Caption :=
Format('< %.0f %s', [double(FooBotTriggerArray[C_LOW, C_CO2]),
FoobotDataObject.Units[C_CO2]]);
lbl_yellowlightco2.Caption :=
Format('> %.0f %s', [double(REC_CO2), FoobotDataObject.Units[C_CO2]]);
lbl_greenlightco2.Caption := Format('< %.0f %s', [double(REC_CO2),
FoobotDataObject.Units[C_CO2]]);
lbl_greenlightco2.Caption :=
Format('< %.0f %s', [double(REC_CO2), FoobotDataObject.Units[C_CO2]]);
lbl_redlightvoc.Caption := Format('> %.0f %s', [double(FooBotTriggerArray[C_HIGH, C_VOC]),
FoobotDataObject.Units[C_VOC]]);
if iSensorNum = C_VOC then
if (HIGHLOW = C_HIGH) then
lbl_redlightvoc.Caption :=
Format('> %.0f %s', [double(FooBotTriggerArray[C_HIGH, C_VOC]),
FoobotDataObject.Units[C_VOC]])
else
lbl_redlightvoc.Caption :=
Format('< %.0f %s', [double(FooBotTriggerArray[C_LOW, C_VOC]),
FoobotDataObject.Units[C_VOC]]);
lbl_yellowlightvoc.Caption :=
Format('> %.0f %s', [double(REC_VOC), FoobotDataObject.Units[C_VOC]]);
lbl_greenlightvoc.Caption := Format('< %.0f %s', [double(REC_VOC),
FoobotDataObject.Units[C_VOC]]);
lbl_greenlightvoc.Caption :=
Format('< %.0f %s', [double(REC_VOC), FoobotDataObject.Units[C_VOC]]);
lbl_redlightallpollu.Caption :=
Format('> %.1f %s', [double(FooBotTriggerArray[C_HIGH, C_ALLPOLLU]),
FoobotDataObject.Units[C_ALLPOLLU]]);
if iSensorNum = C_ALLPOLLU then
if (HIGHLOW = C_HIGH) then
lbl_redlightallpollu.Caption :=
Format('> %.1f %s', [double(FooBotTriggerArray[C_HIGH, C_ALLPOLLU]),
FoobotDataObject.Units[C_ALLPOLLU]])
else
lbl_redlightallpollu.Caption :=
Format('< %.1f %s', [double(FooBotTriggerArray[C_LOW, C_ALLPOLLU]),
FoobotDataObject.Units[C_ALLPOLLU]]);
lbl_yellowlightallpollu.Caption :=
Format('> %.1f %s', [double(REC_ALLPOLLU), FoobotDataObject.Units[C_ALLPOLLU]]);
lbl_greenlightallpollu.Caption :=
@ -470,8 +512,8 @@ end;
procedure Tmainform.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
SaveConfig; // to .cfg file
if (FoobotIdentityObject.FoobotIdentityList.Count > 0) then
SaveTriggers;
if UseTriggers then
SaveTriggers; // To .ini file
CloseAction := caFree;
end;
@ -586,9 +628,10 @@ begin
as_allpollu.ValueMax := INI.ReadFloat('Config', 'allpolluMaxValue', MAX_ALLPOLLU);
// Triggers
UseTriggers := INI.ReadBool('Config', 'UseTriggers', False);
HighTriggerColor := StringToColor(INI.ReadString('Config', 'HighTriggerColour',
'clYellow'));
LowTriggerColor := StringToColor(INI.ReadString('Config', 'LowTriggerColour', 'clAqua'));
HighTriggerColor := StringToColor(INI.ReadString('Config',
'HighTriggerColour', 'clYellow'));
LowTriggerColor := StringToColor(INI.ReadString('Config',
'LowTriggerColour', 'clAqua'));
INI.PlainTextMode := False;
end;
@ -702,6 +745,8 @@ begin
end;
procedure Tmainform.mnu_options_triggersActivateTriggersClick(Sender: TObject);
var
icount: integer;
begin
mnu_options_triggersActivateTriggers.Checked :=
not mnu_options_triggersActivateTriggers.Checked;
@ -711,9 +756,14 @@ begin
mnu_options_triggersActivateTriggers.Caption := 'Set Triggers Off';
LoadTriggers;
SetMinMaxTriggers;
DisplayReadings;
end
else
begin
mnu_options_triggersActivateTriggers.Caption := 'Set Triggers On';
for iCount := C_PM to C_ALLPOLLU do
RestoreNormalColour(iCount);
end;
end;
procedure Tmainform.mnu_options_triggersSetTriggersClick(Sender: TObject);
@ -969,6 +1019,7 @@ begin
C_VOC: as_voc.Color := HighTriggerColor;
C_ALLPOLLU: as_allpollu.Color := HighTriggerColor;
end;
SetTrafficLightStats(iSensorNum, C_HIGH);
end;
procedure Tmainform.DoLowTriggerAlert(const iSensorNum: integer; const aValue: variant);
@ -981,6 +1032,7 @@ begin
C_VOC: as_voc.Color := LowTriggerColor;
C_ALLPOLLU: as_allpollu.Color := LowTriggerColor;
end;
SetTrafficLightStats(iSensorNum, C_LOW);
end;
procedure Tmainform.RestoreNormalColour(const iSensorNum: integer);
@ -997,32 +1049,32 @@ end;
procedure Tmainform.UpdateHealth;
begin
if (as_pm.Value > REC_PM) then
if (as_pm.Value >= REC_PM) then
sls_pm.State := slYELLOW
else
sls_pm.State := slGREEN;
if (as_tmp.Value > REC_TMP) then
if (as_tmp.Value >= REC_TMP) then
sls_tmp.State := slYELLOW
else
sls_tmp.State := slGREEN;
if (as_hum.Value > REC_HUM) then
if (as_hum.Value >= REC_HUM) then
sls_hum.State := slYELLOW
else
sls_hum.State := slGREEN;
if (as_co2.Value > REC_CO2) then
if (as_co2.Value >= REC_CO2) then
sls_co2.State := slYELLOW
else
sls_co2.State := slGREEN;
if (as_voc.Value > REC_VOC) then
if (as_voc.Value >= REC_VOC) then
sls_voc.State := slYELLOW
else
sls_voc.State := slGREEN;
if (as_allpollu.Value > REC_ALLPOLLU) then
if (as_allpollu.Value >= REC_ALLPOLLU) then
sls_allpollu.State := slYELLOW
else
sls_allpollu.State := slGREEN;