Arduino: The Visuino Project - Part 3 Page - 1/16 Create Your Own Components For Visuino
Arduino: The Visuino Project - Part 3 Page - 1/16 Create Your Own Components For Visuino
START DEVELOPING VISUINO COMPONENTS If you open the project group, you will discover
Before you start developing Visuino components, that it contains 2 projects.
you will need to install Visuino and the Visuino
components development SDK. Visuino.ExamplePackage.dproj
The SDK currently requires Delphi XE8 to be and
used for the component development. Visuino.ExamplePackage.Design.dproj.
The typical Visuino installation will place the
executable under C:\Program Visuino.ExamplePackage.dproj contains the
Files\Mitov\Visuino or C:\Program Files demo components, and the
(x86)\Mitov\Visuino, depending on the Visuino.ExamplePackage.Design.dproj
version of Windows you use. contains the component registration code.
The Visuino directory will contain the
executable Visuino.exe . There is also a Demos
sub-directory. There is another typically empty
directory called “Component Packages”.
This is the directory where additional component
packages can be installed.In addition to this folder
structure, Visuino also instals C++ Arduino files into
“Mitov” sub-directory of the Arduino library folder.
Typically the Arduino libraries folder is
“My Documents\Arduino\libraries”.
Each Visuino component consists of 2 parts.
The Arduino C++ c ode in the
“libraries\Mitov” directory,
or another “libraries\*” sub-directory,
and a corresponding Delphi component in a
package in the “Component Packages”
directory.
14
6 Issue Nr 4 2015 BLAISE PASCAL MAGAZINE
ARDUINO: THE VISUINO PROJECT - PART 3 PAGE - 4/16
CREATE YOUR OWN COMPONENTS FOR VISUINO
THIS TIME IF YOU TRY TO COMPILE THE CODE, THERE WILL BE NO ERRORS:
In the “Delphi Compiler” page set: “DCP output directory” and “Package output
directory” to : .\$(Platform)\$(Config)
requires
rtl,
vcl,
OpenWirePkgDXE8,
Mitov_Runtime_DXE8,
OpenWireBindingPkgDXE8,
SignalLabBasicPkgDXE8,
CommunicationLabBasicPkgDXE8,
Embedded.Arduino.Basic.DXE8;
requires
rtl,
vcl,
OpenWirePkgDXE8,
Mitov_Runtime_DXE8,
OpenWireBindingPkgDXE8,
SignalLabBasicPkgDXE8,
CommunicationLabBasicPkgDXE8,
Mitov.Embedded.Arduino.Basic.DXE8,
Visuino.MyVisuinoPackage;
Now that you have your packages ready, you can start
working on your component. You will add component
almost identical to the one in the included example, so
you can also copy and paste some of the code from
there.
Add new unit to the Visuino.MyVisuinoPackage:
The component however is not registered in any To add the desired user friendly names,
categories, does not have image, and does not add Mitov.Attributes to the uses, and
have user friendly name. Lets start fixing this. [CreateName( 'MyVisuinoComponent' )],
Add Mitov.Arduino.Categories.Basic and
to the uses clause, and [Category ( [Name( 'My First Visuino Component'
TArduinoMathFilterToolbarCategory )] )]
attribute to the component: attributes to the component:
uses System . Classes , Mitov . Design . Components ,
System . Classes , Mitov . Design . Components , Mitov . Arduino . Types ,
Mitov . Arduino . Types , Mitov.Arduino.Categories.Basic,
Mitov . Arduino . Categories . Basic ; Mitov.Attributes;
type type
[ Category ( TArduinoMathFilterToolbarCategory )] [Category(TArduinoMathFilterToolbarCategory)]
TVisuinoMyComponent = [CreateName( 'MyVisuinoComponent' )]
class ( TArduinoCommonAnalogFilter ) [Name( 'My First Visuino Component' )]
end ; TVisuinoMyComponent =
class( TArduinoCommonAnalogFilter )
end;
Now that you have a rudimentary Visuino This is enough to generate the proper code for
component that you can test, go back to the Arduino, however the MyComponent inherits
Delphi code, and instruct it how to generate code from Mitov::CommonEnableFilter which
for the component. contains abstract method virtual void
First you need to specify the header file that DoReceive( void *_Data ).
needs to be included in the Arduino project when You need to implement this method in your C++
you use the component. In this case code, and this is where our data processing will be
Visuino_MyComponent.h. You can do this by done. For now you can just do nothing with the
adding [ArduinoInclude( data, and send it to the output of the filter without
'Visuino_MyComponent' )] attribute. a change:
Second you need to specify the namespace and class MyComponent : public Mitov::CommonEnableFilter
the name of the C++ component. You can do this {
typedef Mitov::CommonEnableFilter inherited;
by adding [ArduinoComponent(
'MyVisuinoComponents::MyComponent' protected:
)] attribute: virtual void DoReceive( void *_Data )
{
type OutputPin.Notify( _Data );
[ArduinoInclude( 'Visuino_MyComponent' )] }
[Category( TArduinoMathFilterToolbarCategory )]
};
[ArduinoComponent( 'MyVisuinoComponents::MyComponent' )]
[CreateName( 'MyVisuinoComponent' )]
[Name( 'My First Visuino Component' )]
TVisuinoMyComponent = class( TArduinoCommonAnalogFilter
) DoReceive receives a pointer to the data,
end; and it just calls OutputPin.Notify passing
the same pointer to the data to be sent to
the next filter in the chain. If you generate
the code, and compile it in
the Arduino IDE, it will
succeed: see figure at left.
For the quadratic function you will need 3 properties containing the 3 coefficients A, B and C.
So lets declare them in the C++ code first:
class MyComponent : public Mitov :: CommonEnableFilter
{
typedef Mitov::CommonEnableFilter inherited;
public:
float A,B,C;
Next, you need to initialize them with their default values in the constructor:
class MyComponent : public Mitov :: CommonEnableFilter
{
typedef Mitov::CommonEnableFilter inherited;
public:
float A,B,C;
protected:
virtual void DoReceive( void *_Data )
{
OutputPin.Notify( _Data );
}
public:
MyComponent() :
A( 1.0 ), B( 2.0 ), C( 3.0 )
{
}
};
else
OutputPin.Notify( _Data );
In this case if the component is Enabled it will obtain the floating point value from the _Data pointer,
use it for the calculation, and then send the result trough the OutputPin .
If the component is not Enabled it will just send the data trough the OutputPin without changes.
The C++ code for the component is ready. Now lets add the properties in the Delphi code.
First you need to declare the 3 fields that will hold the properties:
TVisuinoMyComponent = class ( TArduinoCommonAnalogFilter )
protected
FA : Single; FB : Single; FC : Single;
end;
Next you need to declare the 3 properties, and specify the default values. The Visuino
component framework will initialize the fields automatically with the default values:
published
[DefaultSingle( 1.0 )] Your component is ready to
property A : Single read FA write FA; be used. If you deploy the
compiled *.bpl files
[DefaultSingle( 2.0 )] to the “Component
property B : Single read FB write FB;
Packages” sub-directory of
[DefaultSingle( 3.0 )] Visuino, and run Visuino,
property C : Single read FC write FC; you will have the
properties available, and
end; you can edit them:
Here is example Visuino connection diagram that you can use to test the new component:
If you compile and upload the Arduino code as described in the previous
articles, and then connect to it with Visuino, you will see the sine wave
deformed by the quadratic function plotted in the scope:
[DefaultSingle( 3.0 )]
[ValueRange( -1000, 1000 )]
property C : Single read FC write FC;
You can also add a suggested smaller range that will be used in the Visuino property editor when
showing the in-place track-bar value editor, by using the DesignRange attribute like this:
[DefaultSingle( 3.0 )]
[DesignRange( -100, 100 )]
[ValueRange( -1000, 1000 )]
property C : Single read FC write FC;
Any attempt to also enter manually value outside We are working hard to provide more resources
the -1000 to 1000 range will fail. and information on Visuino component
If the DesignRange attribute is not present, and development, and I hope you all will have many
ValueRange is present, the track-bar will use the joyful hours playing with Visuino and creating
ValueRange instead. If none of them is present, your own components for it.
In the next Visuino article we will show you how
the track-bar will offer the full range of floating
you can connect Delphi applications and Arduino
point values. boards over internet, and how you can make
different Arduino boards talk to each other. You
CONCLUSION
will be entering the exciting world of “Internet
In this article you learned the basics of
of Things”!
creating your own Visuino components. As you
have seen, it is very easy, and can be done by
almost anyone, even with limited programming
knowledge.
The component we demonstrated is very
simple, and yet already very useful. With the
component SDK you can create much more
complex and advanced components, with many
more features. All components included in
Visuino are written using this SDK, and you can
see the power they offer. It is not possible in a
single article to cover all aspects of Visuino
component development, but this is a very
good starting point.