Component Creation

Moderator: Benj

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Component Creation

Postby mnf » Fri Jun 15, 2018 8:32 pm

A couple of queries on component creation:

I'm working on a simple component which has a couple of 'optional' connections:

If the user leaves these as 'unconnected' a warning is given that the unconnected pins may cause problems. Is there a 'correct' way to allow unconnected pins?

The component will allow one or optionally two controls to be used - is there a way to hide the second set of pins if the user deselects the second controller.

Is there a way to test for a unconnected pin in a macro (this is not an error - the pin can either be connected to a PWM pin or jumpered to 5V on the driver board)

Some FC components have properties with 'collapsible' subsections - I couldn't create these in my own component - how do you go about creating them?

Many thanks

Martin

User avatar
Benj
Matrix Staff
Posts: 13946
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4224 times
Been thanked: 3979 times
Contact:

Re: Component Creation

Postby Benj » Fri Jun 15, 2018 9:47 pm

Hi Martin

Hidden pins still generate code and so need to be connected to avoid the error. The easy fix is that when pins are hidden you take the value of a valid pin property and copy this value to your hidden pins in the property change event macro.

To add sections right click the properties window and select add category. This has a variable name just as the properties do and can be hidden in the same manner hiding any properties nested inside.

Hope this helps.
These users thanked the author Benj for the post:
mnf (Mon Jun 18, 2018 5:56 pm)
Rating: 5.88%
 

mnf
Valued Contributor
Valued Contributor
Posts: 429
Joined: Wed May 31, 2017 11:57 am
Has thanked: 48 times
Been thanked: 242 times
Contact:

Re: Component Creation

Postby mnf » Sat Jun 23, 2018 3:22 pm

Not having a lot of joy with this:

Importing the CAL_PWM component generates a heap of errors in v8 (though seems ok in v7)

Launching the compiler...
E:\Flowcode\Common\Compilers\avr\batchfiles\avra.bat atmega328p "C:\Users\Martin\DOWNLO~1\Flowcode1.elf" "C:\Users\Martin\DOWNLO~1\Flowcode1.c" "C:\Users\Martin\DOWNLO~1\Flowcode1.lst"

C:\Users\Martin\DOWNLO~1>"E:\Flowcode\Common\Compilers\avr\batchfiles\..\bin\avr-gcc.exe" -mmcu=atmega328p -Os -ffunction-sections -fdata-sections -funsigned-char -o "C:\Users\Martin\DOWNLO~1\Flowcode1.elf" "C:\Users\Martin\DOWNLO~1\Flowcode1.c" -lm -Wl,-gc-sections
In file included from C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\includes.c:484,
from C:\Users\Martin\DOWNLO~1\Flowcode1.c:100:
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:106:4: error: #error "PWM channel selected is greater then available PWM Channel Count"
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:477:3: warning: #warning "Period control register not available on target device, period will default to 255 + 1"
In file included from C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\includes.c:484,
from C:\Users\Martin\DOWNLO~1\Flowcode1.c:100:
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c: In function 'FC_CAL_PWM_Enable_1':
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:503: error: 'MX_TCCR_X' undeclared (first use in this function)
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:503: error: (Each undeclared identifier is reported only once
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:503: error: for each function it appears in.)
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:503: error: 'MX_PWM_COM0_X' undeclared (first use in this function)
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:508: error: 'MX_PWM_COM1_X' undeclared (first use in this function)
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c: In function 'FC_CAL_PWM_Disable_1':
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:534: error: 'MX_TCCR_X' undeclared (first use in this function)
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:534: error: 'MX_PWM_COM1_X' undeclared (first use in this function)
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c: In function 'FC_CAL_PWM_SetDuty8Bit_1':
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:554: error: 'MX_DUTY_REG_X' undeclared (first use in this function)
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c: In function 'FC_CAL_PWM_SetDuty10Bit_1':
C:\ProgramData\MatrixTSL\FlowcodeV8\CAL\/AVR\AVR_CAL_PWM.c:830: error: 'MX_DUTY_REG_X' undeclared (first use in this function)


This using an Arduino Nano as target. I've tried using different PWM channels. Transferring back to v7 and it seems to compile AOK. I only use Enable and SetDuty8Bit (at present) from the CAL_PWM.

I haven't managed a neat solution to the NC pin problem - do you have any examples of altering the properties at compile time?

Martin

User avatar
LeighM
Matrix Staff
Posts: 1749
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 414 times
Been thanked: 578 times
Contact:

Re: Component Creation

Postby LeighM » Mon Jun 25, 2018 1:37 pm

Hi Martin,
The errors you have are due to a bug in the PWM CAL component for Arduino
I have now fixed this and attached the component, to go into your C:\ProgramData\MatrixTSL\FlowcodeV8\Components directory,
This will hopefully get pushed out to the auto-update system tomorrow, if you want to wait for that instead.
Thanks
Leigh
Attachments
cal_pwm.fcpx
(9.99 KiB) Downloaded 44 times
These users thanked the author LeighM for the post:
mnf (Mon Jun 25, 2018 6:04 pm)
Rating: 5.88%
 

User avatar
LeighM
Matrix Staff
Posts: 1749
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 414 times
Been thanked: 578 times
Contact:

Re: Component Creation

Postby LeighM » Mon Jun 25, 2018 2:00 pm

do you have any examples of altering the properties at compile time?

We usually update properties when one of them changes, by adding code into an Ev_Property event macro

This can be done with sim icons,
such as this example that reads the CHANNEL property of a cal_uart component and sets the value of a panel property
sim_icon.jpg
sim_icon.jpg (17.7 KiB) Viewed 847 times

The SIM functions can also be called from a calculation icon
calc_icon.jpg
calc_icon.jpg (27.19 KiB) Viewed 847 times

Just in case the image is difficult to read, here is the calculation code for a property copy from cal_uart to our local panel property

Code: Select all

::Component .Property .SetValue (this,"MY_PORT", ::Component .Property .GetValue (cal_uart,"PORT"))


Although for the above operations we now have the Expose property feature, but at least they demonstrate how properties can be read and written.
Hope that helps
Leigh
These users thanked the author LeighM for the post:
mnf (Mon Jun 25, 2018 6:06 pm)
Rating: 5.88%