Argument type check


#1

Hi !

I work with arduino uno. I’m developping some new extensions.
Does anybody could give me some hint on how to implement type check (as advised in the coding standard).
For instance, if I have an integer parameter, the use may concatenate a string and my code would have to interpret String(“5”) + String(“0”) as 50. And of course, the same code as to work if an integer is provided.

I guess this could may be done using va_list but I did not find a way to get the type of the argument.

Did anybody succeed to implement this requirement in arduino ?


#2

The specify what type of input the block will allow the user to input. It can only be a string or float. Then in your lower level routine you will need to cast it to what you want.


#3

What code do you want to create arduino?


#4

I would like to create code for arduino.
I’ve got a block with a single paramter that is expected to be an integer.
=> My code works well when the user pass an integer as a parameter.
=>But it should also works when a string like “50” is passed. I do not know how to handle this

So I need to : (i) detect that the parameter is a string or an integer (ii) if it’s a string, convert it to the corresponding integer.

Any help is appreciated. Thanks


#5


arduino (1).zip (16.3 KB)


#6

I’m sorry I do not know english. Google Translate.

Does the problem continue?


#7

AS already posted you will design your block so it can only a take an integer or a float, it is not possible to have a block where the user can input both.


#8

Continuing the discussion from Argument type check:

My problem comes from the documentation:https://www.mblock.cc/doc/en/developer-documentation/design-blocks-5.html.


It seems to request that if the user pass a string, then the code should behave like if an integer was used. I do not know how to do this.


#9

At the beginning of this post you wanted an input of a integer. When you create the block if you set it up as a number input it will only allow the user to type in a float. If you set up your block with an input of a string it will add “” either side of what ever they user types.

So far my experience in make custom extension blocks is that the user can only input floats or strings and this id defined when you create the blocks.

Best thing to do is create a block then download the block you create and drag and drop it into the mblock5 PC software and use it with the ardunio window open and you can see exactly what code your block creates.