Difference between revisions of "Device (Java)"

From Neurotech Software Development Kit
Jump to: navigation, search
(See also)
 
(26 intermediate revisions by the same user not shown)
Line 16: Line 16:
  
 
==Class definition==
 
==Class definition==
<code><span style="color:#0066FF;">'''public class'''</span>Device</code>
+
<code><span style="color:#0066FF;">'''public class'''</span> Device</code>
  
 
The Device class is an abstraction for NeuroMD BLE devices. This abstraction provides functions for changing of device state by executing commands and setting parameters. Each device have different sets of supported commands and parameters, Device class has functions designed to get information about these sets. Callibri and Braibit devices has different parameters sets and provides different ways to access them. Device class hides all differences behind its interface and provides universal way to read and write parameters, execute commands and receive biopotential signals.
 
The Device class is an abstraction for NeuroMD BLE devices. This abstraction provides functions for changing of device state by executing commands and setting parameters. Each device have different sets of supported commands and parameters, Device class has functions designed to get information about these sets. Callibri and Braibit devices has different parameters sets and provides different ways to access them. Device class hides all differences behind its interface and provides universal way to read and write parameters, execute commands and receive biopotential signals.
 
  
 
==Fields Summary==
 
==Fields Summary==
Line 27: Line 26:
 
|'''Field and Description'''
 
|'''Field and Description'''
 
|- valign="top"
 
|- valign="top"
|[[SubscribersNotifier Class|SubscribersNotifier]]&lt;'''[[DeviceState (Java)|DeviceState]]'''&gt;
+
|[[SubscribersNotifier Class|SubscribersNotifier]]&lt;'''[[ParameterName (Java)|ParameterName]]'''&gt;
|[[#parameterChanged|'''deviceStateChanged''']]
+
|[[#parameterChanged|'''parameterChanged''']]
Subscribe this event to get notifications about device state
+
Subscribe this event to receive notifications about changes of device parameters
 
|}
 
|}
  
 
==Constructor Summary==
 
==Constructor Summary==
You are not able to create Device directly. Use .[[DeviceScanner (Java)|DeviceScanner]] to find and create devices
+
You are not able to create Device directly. Use [[DeviceScanner (Java)|DeviceScanner]] to find and create devices
  
 
==Methods Summary==
 
==Methods Summary==
Line 40: Line 39:
 
|'''Modifier and Type'''
 
|'''Modifier and Type'''
 
|'''Method and Description'''
 
|'''Method and Description'''
|- valign="top"
 
|style="color:#0066FF;" |'''void'''
 
|[[#close|close]]()
 
Close device and free all resources
 
 
|- valign="top"
 
|- valign="top"
 
|style="color:#0066FF;" |'''void'''
 
|style="color:#0066FF;" |'''void'''
Line 53: Line 48:
 
Disconnects from device
 
Disconnects from device
 
|- valign="top"
 
|- valign="top"
|style="color:#0066FF;" |'''void'''
+
|[[ChannelInfo (java)|ChannelInfo]][]
|[[#finalize|finalize]]()
+
|[[#channels|channels]]()
|- valign="top"
+
Returns information about supported channels.
|java.lang.String
+
Check this information before creation of channel. If device does not support channel,
|[[#getAddress|getAddress]]()
+
channel object won't be initialized.
Returns Bluetooth LE MAC address
 
|- valign="top"
 
|style="color:#0066FF;" |'''int'''
 
|[[#getBatteryLevel|getBatteryLevel]]()
 
Returns battery charge level in percents
 
 
|- valign="top"
 
|- valign="top"
|[[NeuroDeviceError Enumeration|NeuroDeviceError]]
+
|[[Command (java)|Command]][]
|[[#getError|getError]]()
+
|[[#commands|commands]]()
Returns device error state information
+
Returns supported commands of a device
 
|- valign="top"
 
|- valign="top"
|[[DeviceFeature Enumeration|DeviceFeature]][]
+
|[[Parameter (Java)|Parameter]][]
|[[#getFeature|getFeature]]()
+
|[[#parameters|parameters]]()
Returns supported device features
+
Returns all available parameters of device, their types and access rights
 
|- valign="top"
 
|- valign="top"
|java.lang.String
+
|style="color:#0066FF;" |'''boolean'''
|[[#getName|getName]]()
+
|[[#execute|execute]]()
Returns name of BLE device
+
Tries to execute command and returns value indicating operation success.
 
|- valign="top"
 
|- valign="top"
|style="color:#0066FF;" |[[NeuroDevice Class#Android|NeuroDevice]]
+
|style="color:#0066FF;" |'''boolean'''
|[[#getNeuroDevice|getNeuroDevice]]()
+
|[[#setParam|setParam]]()
Returns this object
+
Sets value for specified parameter and returns value indicating success of operation.
 
|- valign="top"
 
|- valign="top"
|style="color:#0066FF;" |[[SignalSubsystem Class#Android|SignalSubsystem]]
+
|style="color:#0066FF;" |<ParamType>
|[[#getSignalSubsystem|getSignalSubsystem]]()
+
ParamType
Returns subsystem for SIGNAL device feature
+
|[[#readParam|readParam]]()
|- valign="top"
+
Return value of specified parameter of device.
|style="color:#0066FF;" |[[NeuroDeviceState Enumeration#Android|NeuroDeviceState]]
 
|[[#getState|getState]]()
 
Returns common device state
 
|- valign="top"
 
|style="color:#0066FF;" |[[StimulationSubsystem Class#Android|StimulationSubsystem]]
 
|[[#getStimulationSubsystem|getStimulationSubsystem]]()
 
Returns subsystem for STIMUL device feature
 
 
|}
 
|}
  
 
==Field Detail==
 
==Field Detail==
<h3>deviceStateChanged</h3>
+
<h3>parameterChanged</h3>
<code><span style="color:#0066FF;">'''public final'''</span> [[SubscribersNotifier Class|SubscribersNotifier]]&lt;[[NeuroDeviceState Enumeration|NeuroDeviceState]]&gt; deviceStateChanged</code>
+
<code><span style="color:#0066FF;">'''public final'''</span> [[SubscribersNotifier Class|SubscribersNotifier]]&lt;[[ParameterName (java)|ParameterName]]&gt; parameterChanged</code>
  
Subscribe this event to get notifications about device state
+
Subscribe this event to receive notifications about changes of device parameters
 
 
==Constructor Detail==
 
 
 
<h3>NeuroDevice</h3>
 
<code><span style="color:#0066FF;">'''public'''</span> NeuroDevice(<span style="color:#0066FF;">'''long'''</span> nativeObjPtr)</code>
 
  
 
==Method Detail==
 
==Method Detail==
 +
<h3>connect</h3>
 +
<code><span style="color:#0066FF;">'''public void'''</span> connect()</code>
  
<h3>finalize</h3>
+
Tries to establish connection with device. Check DeviceState parameter or subscribe parameterChanged event for operation result.
<code><span style="color:#0066FF;">'''public void'''</span> finalize() <span style="color:#0066FF;">throws</span> java.lang.Throwable</code>
 
<dl>
 
<dt>Overrides:</dt>
 
<dd><code>finalize</code>&nbsp;in class&nbsp;<code>java.lang.Object</code></dd>
 
<dt>Throws:</dt>
 
<dd><code>java.lang.Throwable</code></dd>
 
</dl>
 
  
 +
<h3>disconnect</h3>
 +
<code><span style="color:#0066FF;">'''public void'''</span> disconnect()</code>
  
<h3>close</h3>
+
Disconnects from device. Check DeviceState parameter or subscribe parameterChanged event for operation result
<code><span style="color:#0066FF;">'''public void'''</span> close()</code>
 
  
 +
<h3>channels</h3>
 +
<code><span style="color:#0066FF;">'''public'''</span> [[ChannelInfo (Java)|ChannelInfo]][] channels()</code>
  
<h3>getState</h3>
+
Returns information about supported channels.
<code><span style="color:#0066FF;">'''public'''</span> [[NeuroDeviceState Enumeration|NeuroDeviceState]] getState()</code>
 
  
Returns NeuroDevice state
+
Check this information before creation of channel. If device does not support channel,
 +
channel object won't be initialized with it.
 
<dl>
 
<dl>
 
<dt><span>Returns:</span></dt>
 
<dt><span>Returns:</span></dt>
<dd>Device state</dd>
+
<dd>Array of channel info objects</dd>
 
</dl>
 
</dl>
  
<h3>getError</h3>
+
<h3>commands</h3>
<code><span style="color:#0066FF;">'''public'''</span> [[NeuroDeviceError Enumeration|NeuroDeviceError]] getError()</code>
+
<code><span style="color:#0066FF;">'''public'''</span> [[Command (Java)|Command]][] commands()</code>
  
Returns error type if device is in error state
+
Returns supported commands of device
 
<dl>
 
<dl>
 
<dt><span>Returns:</span></dt>
 
<dt><span>Returns:</span></dt>
<dd>Error type for device error state</dd>
+
<dd>Array of supported commands</dd>
 
</dl>
 
</dl>
  
<h3>getName</h3>
+
<h3>parameters</h3>
<code><span style="color:#0066FF;">'''public'''</span> java.lang.String getName()</code>
+
<code><span style="color:#0066FF;">'''public'''</span> [[Parameter (Java)|Parameter]][] parameters()</code>
 
 
<span>'''Description copied from class: '''</span>[[VisualizableDevice Class#getName|VisualizableDevice]]
 
  
Returns name of BLE device
+
Returns all available parameters of device, their types and access rights
 
<dl>
 
<dl>
<dt><span class="overrideSpecifyLabel">Specified by:</span></dt>
 
<dd><code>[[VisualizableDevice Class#getName|VisualizableDevice.getName()]]</code> in class VisualizableDevice</dd>
 
 
<dt><span>Returns:</span></dt>
 
<dt><span>Returns:</span></dt>
<dd>BLE device name</dd>
+
<dd>Array of available parameters</dd>
 
</dl>
 
</dl>
  
<h3>getAddress</h3>
+
<h3>execute</h3>
<code><span style="color:#0066FF;">'''public'''</span>&nbsp;java.lang.String&nbsp;getAddress()</code>
+
<code><span style="color:#0066FF;">'''public boolean'''</span>&nbsp;execute([[Command (Java)|Command]] cmd)</code>
  
<span>'''Description copied from class:''' [[VisualizableDevice Class|VisualizableDevice]]</span>
+
Tries to execute command and returns value indicating operations success.
  
<div class="block">Returns Bluetooth LE MAC address
+
Will throw if device does not support specified command. To get supported commands call commands() method.
 
<dl>
 
<dl>
<dt><span class="overrideSpecifyLabel">Specified by:</span></dt>
+
<dt><span>Parameters:</span></dt>
<dd><code>[[VisualizableDevice Class#getDeviceAddress|VisualizableDevice.getAddress()]]</code> in class VisualizableDevice</dd>
+
<dd>cmd - Command to execute</dd>
 
<dt><span>Returns:</span></dt>
 
<dt><span>Returns:</span></dt>
<dd>device unique address</dd>
+
<dd>Operation success indicator</dd>
 +
<dt><span>Throws:</span></dt>
 +
<dd>java.lang.UnsupportedOperationException</dd>
 
</dl>
 
</dl>
  
<h3>getBatteryLevel</h3>
+
<h3>readParam</h3>
<code><span style="color:#0066FF;">'''public int'''</span> getBatteryLevel()</code>
+
<code><span style="color:#0066FF;">'''public'''</span><ParamType> ParamType readParam([[ParameterName (Java)|ParameterName]] param)</code>
  
<span>'''Description copied from class:''' [[VisualizableDevice Class|VisualizableDevice]]</span>
+
Return value of specified parameter of device.
  
Returns battery state
+
Will throw if parameter does not present in device. To get supported parameters and type information for parameter call parameters()
 +
method. It returns Parameter object which consists of parameter name, type and access mode.
  
 
<dl>
 
<dl>
<dt><span class="overrideSpecifyLabel">Specified by:</span></dt>
+
<dt><span>Parameters:</span></dt>
<dd><code>[[VisualizableDevice Class#getBatteryLevel|VisualizableDevice.getBatteryLevel()]]</code>&nbsp;in class&nbsp;VisualizableDevice</dd>
+
<dd>param - ParameterName to read</dd>
<dt><span class="returnLabel">Returns:</span></dt>
+
<dt><span>Returns:</span></dt>
<dd>battery charge level in percents</dd>
+
<dd>Parameter value</dd>
 +
<dt><span>Throws:</span></dt>
 +
<dd>java.lang.UnsupportedOperationException</dd>
 
</dl>
 
</dl>
  
<h3>getNeuroDevice</h3>
+
<h3>setParam</h3>
<code><span style="color:#0066FF;">'''public'''</span> [[NeuroDevice Class|NeuroDevice]]&nbsp;getNeuroDevice()</code>
+
<code><span style="color:#0066FF;">'''public boolean'''</span>&nbsp;setParam([[ParameterName (Java)|ParameterName]] param, Object value)</code>
  
<span>'''Description copied from class:'''&nbsp;[[VisualizableDevice Class|VisualizableDevice]]</span>
+
Sets value for specified parameter and returns value indicating success of operation.  
Returns this object. This method is for comapatability with VisualizableDevice class interface, inherited to use NeuroDevice in scopes where VisualizableDevice is needed
 
<dl>
 
<dt><span class="overrideSpecifyLabel">Specified by:</span></dt>
 
<dd><code>[[VisualizableDevice Class#getNeuroDevice|VisualizableDevice.getNeuroDevice()]]</code>&nbsp;in class&nbsp;VisualizableDevice</dd>
 
<dt><span class="returnLabel">Returns:</span></dt>
 
<dd>This NeuroDevice object</dd>
 
</dl>
 
 
 
 
 
<h3>getSignalSubsystem</h3>
 
<code><span style="color:#0066FF;">'''public'''</span> [[SignalSubsystem Class|SignalSubsystem]]&nbsp;getSignalSubsystem()</code>
 
 
 
Returns subsystem for SIGNAL device feature
 
  
 +
Will throw if parameter does not present in device or has only Read access mode. To get supported
 +
parameters and type information for parameter call parameters() method. It returns Parameter
 +
object which consists of parameter name, type and access mode
 
<dl>
 
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
+
<dt><span>Parameters:</span></dt>
<dd>Signal subsystem of device. Null if is not supported</dd>
+
<dd>param - Name of parameter to set</dd>
</dl>
+
<dd>value - Parameter value</dd>
 
+
<dt><span>Returns:</span></dt>
<h3>getStimulationSubsystem</h3>
+
<dd>Operation success indicator</dd>
<code><span style="color:#0066FF;">'''public'''</span> [[StimulationSubsystem Class|StimulationSubsystem]]&nbsp;getStimulationSubsystem()</code>
+
<dt><span>Throws:</span></dt>
 
+
<dd>java.lang.UnsupportedOperationException</dd>
Returns subsystem for STIMUL device feature
 
 
 
<dl>
 
<dt><span class="returnLabel">Returns:</span></dt>
 
<dd>Stimulation subsystem of device. Null if is not supported</dd>
 
 
</dl>
 
</dl>
  
<h3>getFeatures</h3>
+
==Example==
<code><span style="color:#0066FF;">'''public'''</span> [[DeviceFeature Enumeration|DeviceFeature]][]&nbsp;getFeatures()</code>
+
This example shows how to find devices and list their features
  
Returns supported device features
+
<syntaxhighlight lang="java">
 +
import com.neuromd.common.INotificationCallback;
 +
import com.neuromd.neurosdk.Device;
 +
import com.neuromd.neurosdk.DeviceScanner;
 +
import com.neuromd.neurosdk.channels.ChannelInfo;
 +
import com.neuromd.neurosdk.parameters.Command;
 +
import com.neuromd.neurosdk.parameters.Parameter;
 +
import com.neuromd.neurosdk.parameters.ParameterName;
 +
import com.neuromd.neurosdk.parameters.types.DeviceState;
  
<dl>
+
public class DeviceInfoActivity extends AppCompatActivity
<dt><span class="returnLabel">Returns:</span></dt>
+
{
<dd>Device features</dd>
+
    private DeviceScanner mScanner;
</dl>
+
    @Override
 +
    protected void onCreate(Bundle savedInstanceState)
 +
    {
 +
        super.onCreate(savedInstanceState);
 +
        setContentView(R.layout.activity_device_info);
 +
   
 +
        requestPermissions();
 +
        enableBtAndGeolocation();
 +
        initScanner();
 +
        initButtons();
 +
    }
 +
   
 +
    private void initScanner()
 +
    {
 +
        mScanner = new DeviceScanner(getApplicationContext());
 +
        mScanner.scanStateChanged.subscribe(new INotificationCallback<Boolean>()
 +
        {
 +
            @Override
 +
            public void onNotify(Object o, final Boolean isScanning)
 +
            {
 +
                runOnUiThread(new Runnable()
 +
                {
 +
                    @Override
 +
                    public void run()
 +
                    {
 +
                        Button startButton = findViewById(R.id.startScanButton);
 +
                        Button stopButton = findViewById(R.id.stopScanButton);
 +
                        startButton.setEnabled(!isScanning);
 +
                        stopButton.setEnabled(isScanning);
 +
                    }
 +
                });
 +
            }
 +
        });
 +
        mScanner.deviceFound.subscribe(new INotificationCallback<Device>()
 +
        {
 +
            @Override
 +
            public void onNotify(Object o, Device device)
 +
            {
 +
                onDeviceFound(device);
 +
            }
 +
        });
 +
    }
 +
   
 +
    private void requestPermissions(){
 +
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
 +
        {
 +
            requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
 +
        }
 +
    }
 +
   
 +
    private void enableBtAndGeolocation(){
 +
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
 +
        startActivityForResult(enableBtIntent, 1);
 +
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
 +
            final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
 +
            if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
 +
                Intent enableGeoIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
 +
                startActivityForResult(enableGeoIntent, 1);
 +
            }
 +
        }
 +
    }
 +
   
 +
    private void initButtons()
 +
    {
 +
        Button startButton = findViewById(R.id.startScanButton);
 +
        startButton.setEnabled(true);
 +
        startButton.setOnClickListener(new View.OnClickListener()
 +
        {
 +
            @Override
 +
            public void onClick(View v)
 +
            {
 +
                mScanner.startScan(0); //zero is for infinity
 +
            }
 +
        });
 +
   
 +
        Button stopButton = findViewById(R.id.stopScanButton);
 +
        stopButton.setEnabled(false);
 +
        stopButton.setOnClickListener(new View.OnClickListener()
 +
        {
 +
            @Override
 +
            public void onClick(View v)
 +
            {
 +
                mScanner.stopScan();
 +
            }
 +
        });
 +
    }
 +
   
 +
    private void onDeviceFound(final Device device)
 +
    {
 +
        device.parameterChanged.subscribe(new INotificationCallback<ParameterName>()
 +
        {
 +
            @Override
 +
            public void onNotify(Object o, ParameterName parameterName)
 +
            {
 +
                if (parameterName == ParameterName.State){
 +
                    DeviceState state = device.readParam(ParameterName.State);
 +
                    if (state == DeviceState.Connected){
 +
                        runOnUiThread(new Runnable()
 +
                        {
 +
                            @Override
 +
                            public void run()
 +
                            {
 +
                                onDeviceConnected(device);
 +
                            }
 +
                        });
 +
                    }
 +
                }
 +
            }
 +
        });
 +
        device.connect();
 +
    }
 +
   
 +
    private void onDeviceConnected(Device device)
 +
    {
 +
        EditText deviceInfoText = findViewById(R.id.infoText);
 +
       
 +
        String deviceName = device.readParam(ParameterName.Name);
 +
        String deviceAddress = device.readParam(ParameterName.Address);
 +
        deviceInfoText.append(String.format("Found device: %s [%s]\n", deviceName, deviceAddress));
 +
   
 +
        deviceInfoText.append("Supported params:\n");
 +
        Parameter[] deviceParams = device.parameters();
 +
        for (Parameter param : deviceParams)
 +
        {
 +
            String paramName = param.getName().toString();
 +
            String accessMode = param.getAccess().toString();
 +
            deviceInfoText.append(String.format("-%s {%s}\n", paramName, accessMode));
 +
        }
 +
   
 +
        deviceInfoText.append("\nSupported commands:\n");
 +
        Command[] deviceCommands = device.commands();
 +
        for (Command cmd : deviceCommands)
 +
        {
 +
            deviceInfoText.append(String.format("-%s \n", cmd.toString()));
 +
        }
 +
   
 +
        deviceInfoText.append("\nSupported channels:\n");
 +
        ChannelInfo[] deviceChannels = device.channels();
 +
        for (ChannelInfo channel : deviceChannels)
 +
        {
 +
            String channelName = channel.getName();
 +
            deviceInfoText.append(String.format("-%s \n", channelName));
 +
        }
 +
    }
 +
}
 +
</syntaxhighlight>
  
<h3>connect</h3>
+
Possible output:
<code><span style="color:#0066FF;">'''public void'''</span> connect()</code>
 
  
Establishes connection with device services
+
[[File:android_deviceinfo_example_1.png]]
  
<h3>disconnect</h3>
+
==See also==
<code><span style="color:#0066FF;">'''public void'''</span> disconnect()</code>
+
[[NeuroMD SDK Manual]]
  
Disconnects from device
+
[[Device (C++)]]

Latest revision as of 03:42, 1 May 2018

ru.neuromd.neurosdk

Class Device

Related Classes

ru.neuromd.neurosdk.DeviceScanner

Classes hierarchy

  • java.lang.Object
    • ru.neuromd.neurosdk.Device

Class definition

public class Device

The Device class is an abstraction for NeuroMD BLE devices. This abstraction provides functions for changing of device state by executing commands and setting parameters. Each device have different sets of supported commands and parameters, Device class has functions designed to get information about these sets. Callibri and Braibit devices has different parameters sets and provides different ways to access them. Device class hides all differences behind its interface and provides universal way to read and write parameters, execute commands and receive biopotential signals.

Fields Summary

Modifier and Type Field and Description
SubscribersNotifier<ParameterName> parameterChanged

Subscribe this event to receive notifications about changes of device parameters

Constructor Summary

You are not able to create Device directly. Use DeviceScanner to find and create devices

Methods Summary

Modifier and Type Method and Description
void connect()

Establishes connection with device services

void disconnect()

Disconnects from device

ChannelInfo[] channels()

Returns information about supported channels. Check this information before creation of channel. If device does not support channel, channel object won't be initialized.

Command[] commands()

Returns supported commands of a device

Parameter[] parameters()

Returns all available parameters of device, their types and access rights

boolean execute()

Tries to execute command and returns value indicating operation success.

boolean setParam()

Sets value for specified parameter and returns value indicating success of operation.

<ParamType>

ParamType

readParam()

Return value of specified parameter of device.

Field Detail

parameterChanged

public final SubscribersNotifier<ParameterName> parameterChanged

Subscribe this event to receive notifications about changes of device parameters

Method Detail

connect

public void connect()

Tries to establish connection with device. Check DeviceState parameter or subscribe parameterChanged event for operation result.

disconnect

public void disconnect()

Disconnects from device. Check DeviceState parameter or subscribe parameterChanged event for operation result

channels

public ChannelInfo[] channels()

Returns information about supported channels.

Check this information before creation of channel. If device does not support channel, channel object won't be initialized with it.

Returns:
Array of channel info objects

commands

public Command[] commands()

Returns supported commands of device

Returns:
Array of supported commands

parameters

public Parameter[] parameters()

Returns all available parameters of device, their types and access rights

Returns:
Array of available parameters

execute

public boolean execute(Command cmd)

Tries to execute command and returns value indicating operations success.

Will throw if device does not support specified command. To get supported commands call commands() method.

Parameters:
cmd - Command to execute
Returns:
Operation success indicator
Throws:
java.lang.UnsupportedOperationException

readParam

public<ParamType> ParamType readParam(ParameterName param)

Return value of specified parameter of device.

Will throw if parameter does not present in device. To get supported parameters and type information for parameter call parameters() method. It returns Parameter object which consists of parameter name, type and access mode.

Parameters:
param - ParameterName to read
Returns:
Parameter value
Throws:
java.lang.UnsupportedOperationException

setParam

public boolean setParam(ParameterName param, Object value)

Sets value for specified parameter and returns value indicating success of operation.

Will throw if parameter does not present in device or has only Read access mode. To get supported parameters and type information for parameter call parameters() method. It returns Parameter object which consists of parameter name, type and access mode

Parameters:
param - Name of parameter to set
value - Parameter value
Returns:
Operation success indicator
Throws:
java.lang.UnsupportedOperationException

Example

This example shows how to find devices and list their features

import com.neuromd.common.INotificationCallback;
import com.neuromd.neurosdk.Device;
import com.neuromd.neurosdk.DeviceScanner;
import com.neuromd.neurosdk.channels.ChannelInfo;
import com.neuromd.neurosdk.parameters.Command;
import com.neuromd.neurosdk.parameters.Parameter;
import com.neuromd.neurosdk.parameters.ParameterName;
import com.neuromd.neurosdk.parameters.types.DeviceState;

public class DeviceInfoActivity extends AppCompatActivity
{
    private DeviceScanner mScanner;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_info);
    
        requestPermissions();
        enableBtAndGeolocation();
        initScanner();
        initButtons();
    }
    
    private void initScanner()
    {
        mScanner = new DeviceScanner(getApplicationContext());
        mScanner.scanStateChanged.subscribe(new INotificationCallback<Boolean>()
        {
            @Override
            public void onNotify(Object o, final Boolean isScanning)
            {
                runOnUiThread(new Runnable()
                {
                    @Override
                    public void run()
                    {
                        Button startButton = findViewById(R.id.startScanButton);
                        Button stopButton = findViewById(R.id.stopScanButton);
                        startButton.setEnabled(!isScanning);
                        stopButton.setEnabled(isScanning);
                    }
                });
            }
        });
        mScanner.deviceFound.subscribe(new INotificationCallback<Device>()
        {
            @Override
            public void onNotify(Object o, Device device)
            {
                onDeviceFound(device);
            }
        });
    }
    
    private void requestPermissions(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        {
            requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
        }
    }
    
    private void enableBtAndGeolocation(){
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, 1);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE );
            if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
                Intent enableGeoIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivityForResult(enableGeoIntent, 1);
            }
        }
    }
    
    private void initButtons()
    {
        Button startButton = findViewById(R.id.startScanButton);
        startButton.setEnabled(true);
        startButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                mScanner.startScan(0); //zero is for infinity
            }
        });
    
        Button stopButton = findViewById(R.id.stopScanButton);
        stopButton.setEnabled(false);
        stopButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                mScanner.stopScan();
            }
        });
    }
    
    private void onDeviceFound(final Device device)
    {
        device.parameterChanged.subscribe(new INotificationCallback<ParameterName>()
        {
            @Override
            public void onNotify(Object o, ParameterName parameterName)
            {
                if (parameterName == ParameterName.State){
                    DeviceState state = device.readParam(ParameterName.State);
                    if (state == DeviceState.Connected){
                        runOnUiThread(new Runnable()
                        {
                            @Override
                            public void run()
                            {
                                onDeviceConnected(device);
                            }
                        });
                    }
                }
            }
        });
        device.connect();
    }
    
    private void onDeviceConnected(Device device)
    {
        EditText deviceInfoText = findViewById(R.id.infoText);
        
        String deviceName = device.readParam(ParameterName.Name);
        String deviceAddress = device.readParam(ParameterName.Address);
        deviceInfoText.append(String.format("Found device: %s [%s]\n", deviceName, deviceAddress));
    
        deviceInfoText.append("Supported params:\n");
        Parameter[] deviceParams = device.parameters();
        for (Parameter param : deviceParams)
        {
            String paramName = param.getName().toString();
            String accessMode = param.getAccess().toString();
            deviceInfoText.append(String.format("-%s {%s}\n", paramName, accessMode));
        }
    
        deviceInfoText.append("\nSupported commands:\n");
        Command[] deviceCommands = device.commands();
        for (Command cmd : deviceCommands)
        {
            deviceInfoText.append(String.format("-%s \n", cmd.toString()));
        }
    
        deviceInfoText.append("\nSupported channels:\n");
        ChannelInfo[] deviceChannels = device.channels();
        for (ChannelInfo channel : deviceChannels)
        {
            String channelName = channel.getName();
            deviceInfoText.append(String.format("-%s \n", channelName));
        }
    }
}

Possible output:

Android deviceinfo example 1.png

See also

NeuroMD SDK Manual

Device (C++)