You've already forked lazarus-ccr
Industrial: Add demo for TAnalogSensor
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8776 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="analogsensor_demo"/>
|
||||
<Scaled Value="True"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<XPManifest>
|
||||
<DpiAware Value="True"/>
|
||||
</XPManifest>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<RequiredPackages>
|
||||
<Item>
|
||||
<PackageName Value="industrial"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item>
|
||||
</RequiredPackages>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="analogsensor_demo.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="AnalogSensor_Demo"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="analogsensor_unit.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="AnalogSensor_Unit"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="analogsensor_demo"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf3"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
@ -0,0 +1,25 @@
|
||||
program AnalogSensor_Demo;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}
|
||||
cthreads,
|
||||
{$ENDIF}
|
||||
{$IFDEF HASAMIGA}
|
||||
athreads,
|
||||
{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, AnalogSensor_Unit
|
||||
{ you can add units after this };
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource:=True;
|
||||
Application.Scaled:=True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
@ -0,0 +1,297 @@
|
||||
object Form1: TForm1
|
||||
Left = 261
|
||||
Height = 279
|
||||
Top = 130
|
||||
Width = 590
|
||||
AutoSize = True
|
||||
Caption = 'AnalogSensor Demo'
|
||||
ClientHeight = 279
|
||||
ClientWidth = 590
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '2.3.0.0'
|
||||
object AnalogSensor1: TAnalogSensor
|
||||
AnchorSideLeft.Control = SettingsPanel
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 324
|
||||
Height = 150
|
||||
Top = 8
|
||||
Width = 250
|
||||
BorderSpacing.Around = 8
|
||||
BevelInner = bvRaised
|
||||
BevelOuter = bvLowered
|
||||
ClientHeight = 150
|
||||
ClientWidth = 250
|
||||
Color = clSilver
|
||||
ParentBackground = False
|
||||
ParentColor = False
|
||||
ParentShowHint = False
|
||||
ShowHint = True
|
||||
TabOrder = 1
|
||||
VerticalAlignment = taAlignTop
|
||||
ShowText = True
|
||||
ShowLevel = True
|
||||
ColorFore = clGreen
|
||||
ColorBack = clLime
|
||||
Value = 40
|
||||
ValueMax = 100
|
||||
ValueRed = 30
|
||||
ValueYellow = 60
|
||||
AnalogKind = akAnalog
|
||||
end
|
||||
object SettingsPanel: TPanel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 255
|
||||
Top = 12
|
||||
Width = 300
|
||||
Align = alLeft
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 12
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 255
|
||||
ClientWidth = 300
|
||||
Constraints.MinWidth = 300
|
||||
TabOrder = 0
|
||||
object cbAnalogKind: TComboBox
|
||||
AnchorSideTop.Control = GroupBox1
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = SettingsPanel
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 104
|
||||
Height = 23
|
||||
Top = 148
|
||||
Width = 196
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 8
|
||||
ItemHeight = 15
|
||||
ItemIndex = 0
|
||||
Items.Strings = (
|
||||
'akAnalog'
|
||||
'akHorizontal'
|
||||
'akVertical'
|
||||
)
|
||||
OnChange = cbAnalogKindChange
|
||||
Style = csDropDownList
|
||||
TabOrder = 1
|
||||
Text = 'akAnalog'
|
||||
end
|
||||
object lblAnalogKind: TLabel
|
||||
AnchorSideTop.Control = cbAnalogKind
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 0
|
||||
Height = 15
|
||||
Top = 152
|
||||
Width = 65
|
||||
Caption = 'Analog Kind'
|
||||
end
|
||||
object lblCaption: TLabel
|
||||
AnchorSideLeft.Control = SettingsPanel
|
||||
AnchorSideTop.Control = edCaption
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 0
|
||||
Height = 15
|
||||
Top = 183
|
||||
Width = 42
|
||||
Caption = 'Caption'
|
||||
end
|
||||
object edCaption: TEdit
|
||||
AnchorSideLeft.Control = cbAnalogKind
|
||||
AnchorSideTop.Control = cbAnalogKind
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = cbAnalogKind
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 104
|
||||
Height = 23
|
||||
Top = 179
|
||||
Width = 196
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 8
|
||||
OnChange = edCaptionChange
|
||||
TabOrder = 2
|
||||
end
|
||||
object cbShowText: TCheckBox
|
||||
AnchorSideLeft.Control = SettingsPanel
|
||||
AnchorSideTop.Control = edCaption
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 0
|
||||
Height = 19
|
||||
Top = 210
|
||||
Width = 72
|
||||
BorderSpacing.Top = 8
|
||||
Caption = 'Show Text'
|
||||
Checked = True
|
||||
OnChange = cbShowTextChange
|
||||
State = cbChecked
|
||||
TabOrder = 3
|
||||
end
|
||||
object cbShowLevel: TCheckBox
|
||||
AnchorSideLeft.Control = cbShowText
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = cbShowText
|
||||
Left = 104
|
||||
Height = 19
|
||||
Top = 210
|
||||
Width = 77
|
||||
BorderSpacing.Left = 32
|
||||
Caption = 'Show Level'
|
||||
Checked = True
|
||||
OnChange = cbShowLevelChange
|
||||
State = cbChecked
|
||||
TabOrder = 4
|
||||
end
|
||||
object GroupBox1: TGroupBox
|
||||
Left = 0
|
||||
Height = 140
|
||||
Top = 0
|
||||
Width = 300
|
||||
Align = alTop
|
||||
AutoSize = True
|
||||
Caption = 'Values'
|
||||
ClientHeight = 120
|
||||
ClientWidth = 296
|
||||
TabOrder = 0
|
||||
object sbValue: TScrollBar
|
||||
AnchorSideLeft.Control = clbValueFore
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = clbValueFore
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = GroupBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 120
|
||||
Height = 17
|
||||
Top = 4
|
||||
Width = 168
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 4
|
||||
BorderSpacing.Right = 8
|
||||
PageSize = 0
|
||||
Position = 20
|
||||
TabOrder = 0
|
||||
OnChange = sbValueChange
|
||||
end
|
||||
object sbValueRed: TScrollBar
|
||||
AnchorSideLeft.Control = clbValueRed
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = clbValueRed
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = GroupBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 120
|
||||
Height = 17
|
||||
Top = 33
|
||||
Width = 168
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Right = 8
|
||||
PageSize = 0
|
||||
Position = 30
|
||||
TabOrder = 1
|
||||
OnChange = sbValueRedChange
|
||||
end
|
||||
object sbValueYellow: TScrollBar
|
||||
AnchorSideLeft.Control = clbValueYellow
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = clbValueYellow
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = GroupBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 120
|
||||
Height = 17
|
||||
Top = 62
|
||||
Width = 168
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 6
|
||||
BorderSpacing.Right = 8
|
||||
BorderSpacing.Bottom = 8
|
||||
PageSize = 0
|
||||
Position = 60
|
||||
TabOrder = 2
|
||||
OnChange = sbValueYellowChange
|
||||
end
|
||||
object clbValueFore: TColorButton
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideTop.Control = GroupBox1
|
||||
AnchorSideRight.Control = GroupBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 25
|
||||
Top = 0
|
||||
Width = 100
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Right = 8
|
||||
BorderWidth = 2
|
||||
ButtonColorAutoSize = False
|
||||
ButtonColorSize = 16
|
||||
ButtonColor = clGreen
|
||||
Caption = 'Value'
|
||||
Margin = 4
|
||||
OnColorChanged = clbValueForeColorChanged
|
||||
end
|
||||
object clbValueRed: TColorButton
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideTop.Control = clbValueFore
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 25
|
||||
Top = 29
|
||||
Width = 100
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Top = 4
|
||||
BorderSpacing.Right = 8
|
||||
BorderWidth = 2
|
||||
ButtonColorAutoSize = False
|
||||
ButtonColorSize = 16
|
||||
ButtonColor = clRed
|
||||
Caption = 'Value Red'
|
||||
Margin = 4
|
||||
OnColorChanged = clbValueRedColorChanged
|
||||
end
|
||||
object clbValueYellow: TColorButton
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideTop.Control = clbValueRed
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 25
|
||||
Top = 58
|
||||
Width = 100
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Top = 4
|
||||
BorderSpacing.Right = 8
|
||||
BorderWidth = 2
|
||||
ButtonColorAutoSize = False
|
||||
ButtonColorSize = 16
|
||||
ButtonColor = clYellow
|
||||
Caption = 'Value Yellow'
|
||||
OnColorChanged = clbValueYellowColorChanged
|
||||
end
|
||||
object clbBack: TColorButton
|
||||
AnchorSideLeft.Control = GroupBox1
|
||||
AnchorSideTop.Control = clbValueYellow
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = GroupBox1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 12
|
||||
Height = 25
|
||||
Top = 87
|
||||
Width = 100
|
||||
BorderSpacing.Left = 12
|
||||
BorderSpacing.Top = 4
|
||||
BorderSpacing.Bottom = 8
|
||||
BorderWidth = 2
|
||||
ButtonColorAutoSize = False
|
||||
ButtonColorSize = 16
|
||||
ButtonColor = clLime
|
||||
Caption = 'ColorBack'
|
||||
Margin = 4
|
||||
OnClick = clbBackClick
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,143 @@
|
||||
unit AnalogSensor_Unit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
|
||||
Sensors;
|
||||
|
||||
type
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
AnalogSensor1: TAnalogSensor;
|
||||
cbAnalogKind: TComboBox;
|
||||
cbShowText: TCheckBox;
|
||||
cbShowLevel: TCheckBox;
|
||||
clbValueFore: TColorButton;
|
||||
clbValueYellow: TColorButton;
|
||||
clbValueRed: TColorButton;
|
||||
clbBack: TColorButton;
|
||||
edCaption: TEdit;
|
||||
GroupBox1: TGroupBox;
|
||||
lblAnalogKind: TLabel;
|
||||
lblCaption: TLabel;
|
||||
SettingsPanel: TPanel;
|
||||
sbValue: TScrollBar;
|
||||
sbValueYellow: TScrollBar;
|
||||
sbValueRed: TScrollBar;
|
||||
procedure cbAnalogKindChange(Sender: TObject);
|
||||
procedure cbShowLevelChange(Sender: TObject);
|
||||
procedure cbShowTextChange(Sender: TObject);
|
||||
procedure clbValueForeColorChanged(Sender: TObject);
|
||||
procedure clbValueRedColorChanged(Sender: TObject);
|
||||
procedure clbValueYellowColorChanged(Sender: TObject);
|
||||
procedure clbBackClick(Sender: TObject);
|
||||
procedure edCaptionChange(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure sbValueYellowChange(Sender: TObject);
|
||||
procedure sbValueChange(Sender: TObject);
|
||||
procedure sbValueRedChange(Sender: TObject);
|
||||
private
|
||||
procedure UpdateColorState;
|
||||
|
||||
public
|
||||
|
||||
end;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.cbAnalogKindChange(Sender: TObject);
|
||||
const
|
||||
lWIDTH: array[TAnalogKind] of Integer = (250, 250, 60);
|
||||
lHEIGHT: array[TAnalogKind] of Integer = (150, 70, 250);
|
||||
begin
|
||||
AnalogSensor1.AnalogKind := TAnalogKind(cbAnalogKind.ItemIndex);
|
||||
AnalogSensor1.Width := lWIDTH[AnalogSensor1.AnalogKind];
|
||||
AnalogSensor1.Height := lHEIGHT[AnalogSensor1.AnalogKind];
|
||||
end;
|
||||
|
||||
procedure TForm1.cbShowLevelChange(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.ShowLevel := cbShowLevel.Checked;
|
||||
end;
|
||||
|
||||
procedure TForm1.cbShowTextChange(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.ShowText := cbShowText.Checked;
|
||||
end;
|
||||
|
||||
procedure TForm1.clbBackClick(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.ColorBack := clbBack.ButtonColor;
|
||||
end;
|
||||
|
||||
procedure TForm1.clbValueForeColorChanged(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.ColorFore := clbValueFore.ButtonColor;
|
||||
UpdateColorState;
|
||||
end;
|
||||
|
||||
procedure TForm1.clbValueRedColorChanged(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.ColorRed := clbValueRed.ButtonColor;
|
||||
UpdateColorState;
|
||||
end;
|
||||
|
||||
procedure TForm1.clbValueYellowColorChanged(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.ColorYellow := clbValueYellow.ButtonColor;
|
||||
UpdateColorState;
|
||||
end;
|
||||
|
||||
procedure TForm1.edCaptionChange(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.Caption := edCaption.Text;
|
||||
UpdateColorState;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
UpdateColorState;
|
||||
end;
|
||||
|
||||
procedure TForm1.sbValueChange(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.Value := sbValue.Position;
|
||||
UpdateColorState;
|
||||
end;
|
||||
|
||||
procedure TForm1.sbValueRedChange(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.ValueRed := sbValueRed.Position;
|
||||
UpdateColorState;
|
||||
end;
|
||||
|
||||
procedure TForm1.sbValueYellowChange(Sender: TObject);
|
||||
begin
|
||||
AnalogSensor1.ValueYellow := sbValueYellow.Position;
|
||||
UpdateColorState;
|
||||
end;
|
||||
|
||||
procedure TForm1.UpdateColorState;
|
||||
begin
|
||||
if AnalogSensor1.Value < AnalogSensor1.ValueRed then
|
||||
AnalogSensor1.SetColorState(slRED)
|
||||
else if AnalogSensor1.Value > AnalogSensor1.ValueYellow then
|
||||
AnalogSensor1.SetColorState(slYELLOW)
|
||||
else
|
||||
AnalogSensor1.SetColorState(slUNKNOWN);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -211,6 +211,7 @@ begin
|
||||
begin
|
||||
FShowText := AValue;
|
||||
FlblShowText.Visible := FShowText;
|
||||
Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -268,8 +269,11 @@ begin
|
||||
if (AValue <> FValueRed) then
|
||||
begin
|
||||
if (AValue < FValueMin) or (AValue > FValueMax) then
|
||||
exit;
|
||||
{
|
||||
if not (csLoading in ComponentState) then
|
||||
raise EInvalidOperation.CreateFmt('SOutOfRange', [Round(FValueMin), Round(FValueMax)]);
|
||||
}
|
||||
FValueRed := AValue;
|
||||
Invalidate;
|
||||
end;
|
||||
@ -280,8 +284,11 @@ begin
|
||||
if (AValue <> FValueYellow) then
|
||||
begin
|
||||
if (AValue < FValueRed) or (AValue > FValueMax) then
|
||||
exit;
|
||||
{
|
||||
if not (csLoading in ComponentState) then
|
||||
raise EInvalidOperation.CreateFmt('SOutOfRange', [Round(FValueRed), Round(FValueMax)]);
|
||||
}
|
||||
FValueYellow := AValue;
|
||||
Invalidate;
|
||||
end;
|
||||
|
Reference in New Issue
Block a user