> For the complete documentation index, see [llms.txt](https://cavedu.gitbook.io/linkit-7697/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cavedu.gitbook.io/linkit-7697/linkit-7697-development-guide-for-arduino-ide/developer-guide/using-mcs-library/mcs-library-api-reference/mcsdatachannel-classes.md).

# MCSDataChannel Classes

The following classes extend MCSDataChannel, which is used to create a **data channel** instance mapping to the one created on the MCS server and provide operations on a data channel, including getting and uploading data points.

For example, an ON/OFF controller channel shown below:

![](https://3972650740-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FY4gduUSLWOCI23CXUWej%2Fuploads%2F6K71UDcrzlsmWRR8QLQ2%2Fimage2017-6-2%2B11_58_24.png?alt=media\&token=c0eed262-96a6-486e-a63d-8e3561a7a778)

This channel can be represented by an instance of the class **MCSControllerOnOff**, as shown below:

```
MCSControllerOnOff channelOnOff("channel_id_1");
device.addChannel(channelOnOff);	// device is an instance of MCSDevice or MCSLiteDevice.
 
device.connect();
bool controllerValue = channel.value();
```

&#x20;Data channel classes provide **set()** and **value()** methods for each data channel as they have different formats. Use the following extended classes in your sketch to create a specific type of data channels.

There are 2 major sub-class categories, **controller channel** and **display channel**. Controller channels, such as MCSController*OnOff* and MCSController*Integer*, represents controller channels on MCS. Display channels such as MCSDisplay*Float* and MCSDisplay*String* maps to display channels instead.&#x20;

### Constructors <a href="#mcsdatachannelclasses-constructors" id="mcsdatachannelclasses-constructors"></a>

&#x20;MCSDataChannel()

{% tabs %}
{% tab title="MCSDataChannel()" %}
Creates a *data channel* that can be added to a *device* that is an instance of MCSDevice or MCSLiteDevice.

**Syntax**

MCSControllerOnOff *dataChannel*(data\_channel\_ID)

MCSDisplayOnOff *dataChannel*(data\_channel\_ID)

MCSControllerCategory *dataChannel*(data\_channel\_ID)

MCSDisplayCategory *dataChannel*(data\_channel\_ID)

MCSControllerInteger *dataChannel*(data\_channel\_ID)

MCSDisplayInteger *dataChannel*(data\_channel\_ID)

MCSControllerFloat *dataChannel*(data\_channel\_ID)

MCSDisplayFloat *dataChannel*(data\_channel\_ID)

MCSControllerHex *dataChannel*(data\_channel\_ID)

MCSDisplayHex *dataChannel*(data\_channel\_ID)

MCSControllerString *dataChannel*(data\_channel\_ID)

MCSDisplayString *dataChannel*(data\_channel\_ID)

MCSControllerGPS *dataChannel*(data\_channel\_ID)

MCSDisplayGPS *dataChannel*(data\_channel\_ID)

MCSControllerGPIO *dataChannel*(data\_channel\_ID)

MCSDisplayGPIO *dataChannel*(data\_channel\_ID)

MCSControllerPWM *dataChannel*(data\_channel\_ID)

MCSDisplayPWM *dataChannel*(data\_channel\_ID)

MCSControllerAnalog *dataChannel*(data\_channel\_ID)

**Parameters**

data\_channel\_ID: The data channel id of the data channel you created on MCS.

**Returns**

*dataChannel* is an instance of the subclass of the **MCSDataChannel** class.
{% endtab %}
{% endtabs %}

### MCSDataChannel Methods <a href="#mcsdatachannelclasses-mcsdatachannelmethods" id="mcsdatachannelclasses-mcsdatachannelmethods"></a>

For each type of data channel:

updated()&#x20;

valid()&#x20;

value()

{% tabs %}
{% tab title="updated()" %}
To check if there is updated data point received for a specified data channel. To check if channels are updated, users must call *device.*&#x70;rocess() first, which checks if there any incoming command update from MCS server. If there are multiple updated values happened, only the last value will be kept.

**Syntax**

*dataChannel*.updated()

**Parameters**

none

**Returns**

boolean true if there is an updated data point received for this data channel, false if there isn't.
{% endtab %}

{% tab title="valid()" %}
To check if there is valid value received or set from a specified data channel.

**Syntax**

dataChannel.valid()

**Parameters**

none

**Returns**

boolean true if there is a valid value received or set for this data channel, false if there isn't.
{% endtab %}

{% tab title="value()" %}
To get the current value of a specified data channel except MCSControllerGPS and MCSDisplayGPS.

**Syntax**

*dataChannel*.value()

**Parameters**

none

**Returns**

The value of specified data channel and the data type of value is based on data channel, including float, integer long or string.
{% endtab %}
{% endtabs %}

### Display Channel Methods <a href="#mcsdatachannelclasses-displaychannelmethods" id="mcsdatachannelclasses-displaychannelmethods"></a>

&#x20;set()

{% tabs %}
{% tab title="set()" %}
To set the value to a specified display data channel.

**Syntax**

dataChannel.set(value)

MCSDisplayPWM.set(value, period)

MCSDisplayGPS.set(latitude, longitude, altitude)

**Parameters**

dataChannel: an instance of the MCSDataChannel extended classes, like MCSControllerOnOff, MCSControllerCategory...

MCSDisplayPWM: an instance of MCSDisplayPWM class

MCSDisplayGPS: an instance of MCSDisplayGPS class

value: the value you are going to set for a specified data channel and the data type of value is various according to data channel, like float, integer, long or string.

period: a specific integer parameter for PWM type of data channel. This period is the inverse of the PWM frequency.

latitude, longitude, altitude: specific float parameters for GPS type of data channel to present the GPS coordinate.

**Returns**

boolean true if the value is set and uploaded to MCS server successfully, false if it fails.
{% endtab %}
{% endtabs %}

### Controller Channel Methods <a href="#mcsdatachannelclasses-controllerchannelmethods" id="mcsdatachannelclasses-controllerchannelmethods"></a>

&#x20;setServerValue()

{% tabs %}
{% tab title="setServerValue()" %}
To set the value to a specified display data channel.

**Syntax**

controllerChannel.setServerValue(value)

**Parameters**

dataChannel: an instance of the MCSDataChannel extended classes, like MCSControllerOnOff, MCSControllerCategory...

| Channel Class         | Value Type  |
| --------------------- | ----------- |
| MCSControllerOnOff    | bool        |
| MCSControllerFloat    | float       |
| MCSControllerInteger  | int         |
| MCSControllerAnalog   | int         |
| MCSControllerGPIO     | int         |
| MCSControllerHex      | long        |
| MCSControllerCategory | String      |
| MCSControllerString   | String      |
| MCSControllerPWM      | MCSPWMValue |
| MCSControllerGPS      | MCSGPSValue |

latitude, longitude, altitude: specific float parameters for GPS type of data channel to present the GPS coordinate.

**Returns**

boolean true if the value is set and uploaded to MCS server successfully, false if it fails.
{% endtab %}
{% endtabs %}

### MCSControllerPWM Methods <a href="#mcsdatachannelclasses-mcscontrollerpwmmethods" id="mcsdatachannelclasses-mcscontrollerpwmmethods"></a>

For **PWM controller** data channel, we provide

dutyCycle()&#x20;

period()

{% tabs %}
{% tab title="dutyCycle()" %}
To get the current dutyCycle(value) setting of a specified PWM controller data channel.

**Syntax**

MCSControllerPWM.dutyCycle()

**Parameters**

MCSControllerPWM: an instance of MCSControllerPWM class

**Returns**

The duty cycle setting of specified PWM controller data channel (labeled as "value" in MCS UI) and the data type is integer.
{% endtab %}

{% tab title="period()" %}
To get the current period setting of a specified PWM controller data channel.

**Syntax**

MCSControllerPWM.period()

**Parameters**

MCSControllerPWM: an instance of MCSControllerPWM class

**Returns**

The period setting of specified PWM controller data channel and the data type is integer.
{% endtab %}
{% endtabs %}

### GPS Channel Methods <a href="#mcsdatachannelclasses-gpschannelmethods" id="mcsdatachannelclasses-gpschannelmethods"></a>

For **GPS controller** and **GPS display** data channel, we provide additional helper functions to parse the latitude, longitude and altitude fields.

latitude()&#x20;

longitude()&#x20;

altitude()

{% tabs %}
{% tab title="latitude()" %}
To get the current value of latitude of a specified GPS controller data channel.

**Syntax**

MCSControllerGPS.latitude()

**Parameters**

MCSControllerGPS: an instance of MCSControllerGPS class

**Returns**

The latitude of specified GPS controller data channel and the data type is float.
{% endtab %}

{% tab title="longitude() " %}
To get the current value of longitude of a specified GPS controller data channel.

**Syntax**

MCSControllerGPS.longitude()

**Parameters**

MCSControllerGPS: an instance of MCSControllerGPS class

**Returns**

The longitude of specified GPS controller data channel and the data type is float.
{% endtab %}

{% tab title="altitude()" %}
To get the current value of altitude of a specified GPS controller data channel.

**Syntax**

MCSControllerGPS.altitude()

**Parameters**

MCSControllerGPS: an instance of MCSControllerGPS class

**Returns**

The altitude of specified GPS controller data channel and the data type is float.
{% endtab %}
{% endtabs %}

### Gamepad Controller Channel Methods <a href="#mcsdatachannelclasses-gamepadcontrollerchannelmethods" id="mcsdatachannelclasses-gamepadcontrollerchannelmethods"></a>

A **Gamepad** controller channel's value is an event with two fields:

* which button(**BTN\_UP, BTN\_DOWN, BTN\_LEFT, BTN\_RIGHT, BTN\_A, BTN\_B**) is pressed or released.
* The event is a **BTN\_PRESSED** event or a **BTN\_RELEASED** event.

The buttons are represented by the enumeration below:

```
enum MCSGamePadButton{
    BTN_UP = 1,
    BTN_DOWN,
    BTN_LEFT,
    BTN_RIGHT,
    BTN_A,
    BTN_B,
    BTN_INVALID
};
```

and the events are represented by another enumeration:

```
enum MCSGamePadButtonEvent{
    BTN_PRESSED = 1,
    BTN_RELEASED = 0,
    BTN_NO_EVENT = -1
};
```

So the object returned by the value() method can be read by accessing these two fields:

```
if(BTN_UP == gamepadChannel.value().button &&
   BTN_PRESSED == gamepadChannel.value().event)
{
   // Do something when the "UP" key is pressed...
}
```

Following helper methods are also provided to easily access the button and event fields:

button()&#x20;

event()

{% tabs %}
{% tab title="button() " %}
Returns a MCSGamePadButton enumeration representing the buttons being pressed or released

**Syntax**

MCSControllerGamePad.button()

**Parameters**

MCSControllerGamePad: an instance of MCSControllerGamePad class

**Returns**

Returns a **MCSGamePadButton** enumeration representing the buttons being pressed or released. The possible values are:

```
enum MCSGamePadButton{
    BTN_UP = 1,
    BTN_DOWN,
    BTN_LEFT,
    BTN_RIGHT,
    BTN_A,
    BTN_B,
    BTN_INVALID
};
```

<br>
{% endtab %}

{% tab title="event()" %}
Returns a MCSGamePadButtonEvent that denote a key pressed or key released event.

**Syntax**

MCSControllerGamePad.button()

**Parameters**

MCSControllerGamePad: an instance of MCSControllerGamePad class

**Returns**

Returns a **MCSGamePadButtonEvent** enumeration representing a pressed or released event. The possible values are:

```
enum MCSGamePadButtonEvent{
    BTN_PRESSED = 1,
    BTN_RELEASED = 0,
    BTN_NO_EVENT = -1
};
```

{% endtab %}
{% endtabs %}
