Skip to content
This repository was archived by the owner on May 15, 2019. It is now read-only.

Var Type

EtienneDx edited this page Apr 14, 2018 · 2 revisions

Var Type

ArduiNode's variables require some VarType objects to work properly. You can create manually some new variables, by following the examples in arduinode/src/Types/Vars, or by folllowing the structure defined here.

Structure

Here's how the flow type is defined :

type VarType = {
  name : string,
  imports : ?(Array<string> | string),
  pluggedImage : any,
  unpluggedImage : any,
  color : any,
  definition : string,
  setupDefinition ?: string,
  defaultValue : any,
  valueFormat : any,
}

Here's the meaning of each of those :

  • name : the name of the type (eg. Int, Servo, Bool, ...)
  • imports : the list of imports, formatted as follow : '"someImport.h"', '<anotherImport.h>'
  • pluggedImage : the image to use on the connector if it is connected
  • unpluggedImage : the image to use on the connector if it isn't connected
  • color : the color of the connection between nodes
  • definition : this is the global definition, see below
  • setupDefinition : this is the definition inside of the setup function
  • defaultValue : this is the 'default' default value
  • valueFormat : see below

Images

If your type is an object, you can use the object images and color :

import objUnplugged from '../../resources/Obj_Unplugged.png';
import objPlugged from '../../resources/Obj_Plugged.png';
const color = "#1969a6"

Definitions

Both definitions are templates, in which some strings are replaced :

<<name>>

Replaced by the name of the variable

<<value>>

Replaced by the value, if the value isn't an object

<<value:something>>

Replaced by value.something (if the value is an object, see valueFormat)

Value Format

This simply state the format of the default value, it is either a string, and the value won't be an object, or it can be an object of string, and the value will have 'subvalues'. Again, it may be easier to take a look at some examples. It can also take an array of string, to allow it to have any of those value (dropdown in details menu)

Here's what a simple value would look like :

valueFormat : "int",
defaultValue : 0

or

valueFormat : "bool",
defaultValue : true,

And here's what a more complex value would look like :

valueFormat : {
    someSubValue : "int",
    another : ["One Value", "Another Value"],
},
defaultValue : {
    someSubValue : 2,
    another : "One Value",
}

Example : Pin variable

Pin : {
  name : PIN,
  pluggedImage : pinPlugged,
  unpluggedImage : pinUnplugged,
  color : "grey",
  definition : `#define <<name>> <<value:pin>>
`,
  setupDefinition : `pinMode(<<name>>, <<value:mode>>);
`,
  defaultValue : {
    pin : "0",
    mode : "INPUT",
  },
  valueFormat : {
    pin : "string",
    mode : ["INPUT", "OUTPUT", "INPUT_PULLUP"],
  },
}

Clone this wiki locally