Component Creation

Moderator: Benj

Post Reply
mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Component Creation

Post by mnf »

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: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Component Creation

Post by Benj »

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.

mnf
Valued Contributor
Valued Contributor
Posts: 1188
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Component Creation

Post by mnf »

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: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Component Creation

Post by LeighM »

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 336 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Component Creation

Post by LeighM »

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 6221 times
The SIM functions can also be called from a calculation icon
calc_icon.jpg
calc_icon.jpg (27.18 KiB) Viewed 6221 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

Post Reply