API

Last updated: April 23th, 2020

About

This section describes EEDC API and it’s functions. All you need to start using EEDC API to communicate with your device is to include eedc-core.js file to html like in example below. Then add your custom js file (e.q. custom.js) and inside this file you can start using EEDC API.

index.html:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>...</title>
    <link rel="icon" href="data:;base64,=">
    <link rel="stylesheet" href="style.css">
    <script src="eedc-core.js" type="module"></script>
    <script src="custom.js" type="module"></script>
</head>
<body>
...
</body>
</html>
custom.js:
import EEDC from './eedc-core.js';

EEDC.init(function() {
    // device is connected
});

Functions

init(callback)

This function initializes connection between you script and android device. Argument passed is callback which is invoked as soon as device is successfully connected.

Note

Callback is invoked only when device state change is changed from DISCONNECTED to CONNECTED. If device was connected in previous initialization callback is not invoked.

Parameters

  • callback: callback invoked when device is successfully connected.
EEDC.init(function() {
    // device is connected
});

sendString(data)

This functions sends string to device.

Parameters

  • data: string data to send.
EEDC.sendString("data");

sendBytes(data, ch1, ch2)

This function send bytes to devices. Bytes must be type of Uint8Array.

Parameters

  • data: byte (Uint8Array) data to send.
  • ch1: (optional) ble service UUID, used only for ble devices
  • ch2: (optional) ble characteristic UUID, used only for ble devices
let data = new Uint8Array([0, 1]);
EEDC.sendBytes(data);
// for ble:
EEDC.sendBytes(data, 0x1826, 0x2AD9);

listenLines()

Start to listen data from device line by line. See: new_line event.

EEDC.listenLines();

listenBytes(bufferSize, ch1, ch2, ch3)

Start to listen byte data from device. See: new_bytes event.

Parameters

  • bufferSize: buffer size used for reading bytes from stream.
  • ch1: (optional) ble service UUID, used only for ble devices
  • ch2: (optional) ble characteristic UUID, used only for ble devices
  • ch3: (optional) ble descriptor UUID, used only for ble devices
EEDC.listenBytes(100);
// for ble:
EEDC.listenBytes(1, 0x1826, 0x2AD2, 0x2902);

stopListenLines()

Stops to listen line data from device.

EEDC.stopListenLines();

stopListenBytes(ch1, ch2, ch3)

Stops to listen byte data from device.

Parameters

  • ch1: (optional) ble service UUID, used only for ble devices
  • ch2: (optional) ble characteristic UUID, used only for ble devices
  • ch3: (optional) ble descriptor UUID, used only for ble devices
EEDC.stopListenBytes();
// for ble:
EEDC.stopListenBytes(0x1826, 0x2AD2, 0x2902);

readSingleLine()

Reads single line from device. See: new_line event.

EEDC.readSingleLine();

readSingleBytes(bufferSize, ch1, ch2)

Reads single byte data from device. See: new_bytes event.

Parameters

  • bufferSize: buffer size used for reading bytes from stream.
  • ch2: (optional) ble characteristic UUID, used only for ble devices
  • ch3: (optional) ble descriptor UUID, used only for ble devices
EEDC.readSingleBytes(100);
// for ble read from characteristic:
EEDC.readSingleBytes(1, 0x1826, 0x2AD2, 0x2902);

getDeviceInfo()

Returns info about current running device (phone) and connected device as json string (not object!).

EEDC.getDeviceInfo();

Informations

  • serial: hw serial number
  • model: end-user-visible name for the end product
  • id: a changelist number, or a label
  • manufacturer: manufacturer of the product/hardware
  • brand: consumer-visible brand
  • type: type of build, like "user" or "eng"
  • user: ro.build.user
  • base: The original, first, version of Android.
  • incremental: The internal value used by the underlying source control to represent this build
  • sdk: The SDK version of the software currently running on this hardware
  • board: name of the underlying board
  • host: ro.build.host
  • fingerprint: string that uniquely identifies this build.
  • version: an opaque string (ro.build.version.release)
  • name: device name
  • desc: device description
  • connection_type: bluettoth/wifi
  • address: (ip/mac) address
  • port: port
  • theme: theme color name

setFullScreen(fullScreen)

Enable or disable fullscreen mode.

Parameters

  • fullScreen: boolean value - enable/disable.
EEDC.setFullScreen(true);

isFullScreen()

Return tru if fullScreen mode is enabled else false

let fullScreen = EEDC.isFullScreen();

exit()

Disconnect from device and close webView

EEDC.exit();

Events

About

There are 4 event types you can listen to.

Events

  • connected: when device is first connected.
  • state_change: when device state changed.
  • new_line: when there is new line from device.
  • new_bytes: when there are new byte data from device.

connected

Invoked when device is first time connected. This event is auto registered inside init function.

let callback = function() {
    // device is first time connected
};
EEDC.on("connected", callback);
...
EEDC.off("connected", callback);

state_change

This event is invoked when device state change. New state is value of this event.

States

  • DEFAULT: default state of device before trying to first connect.
  • CONNECTING: device is connecting.
  • CONNECTED: device is connected.
  • DISCONNECTED: device is disconnected.
EEDC.on("state_change", function(newState) {
    // state changed
});

new_line

This event is invoked when there is new line. To be invoked this event you must call listenLines or readSingleLine

EEDC.on("new_line", function(line) {
    // new line
});

new_bytes

This event is invoked when there is new byte data .To be invoked this event you must call listenBytes or readSingleBytes. Value is object containing byte data and uuids for ble devices.

EEDC.on("new_bytes", function(data) {
    let bytes = data.data;
    let ch1 = data.ch1;
    let ch2 = data.ch2;
    let ch3 = data.ch3;
});
eedc-core.js