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:

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();

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 MCSControllerOnOff and MCSControllerInteger, represents controller channels on MCS. Display channels such as MCSDisplayFloat and MCSDisplayString maps to display channels instead.

Constructors

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.

MCSDataChannel Methods

For each type of data channel:

updated()

valid()

value()

To check if there is updated data point received for a specified data channel. To check if channels are updated, users must call device.process() 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.

Display Channel Methods

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.

Controller Channel Methods

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 ClassValue 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.

MCSControllerPWM Methods

For PWM controller data channel, we provide

dutyCycle()

period()

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.

GPS Channel Methods

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

latitude()

longitude()

altitude()

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.

Gamepad Controller Channel Methods

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()

event()

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
};

Last updated