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.
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>
import EEDC from './eedc-core.js';
EEDC.init(function() {
// device is connected
});
This function initializes connection between you script and android device. Argument passed is callback which is invoked as soon as device is successfully connected.
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.
EEDC.init(function() {
// device is connected
});
This functions sends string to device.
EEDC.sendString("data");
This function send bytes to devices. Bytes must be type of Uint8Array.
let data = new Uint8Array([0, 1]);
EEDC.sendBytes(data);
// for ble:
EEDC.sendBytes(data, 0x1826, 0x2AD9);
Start to listen data from device line by line. See: new_line event.
EEDC.listenLines();
Start to listen byte data from device. See: new_bytes event.
EEDC.listenBytes(100);
// for ble:
EEDC.listenBytes(1, 0x1826, 0x2AD2, 0x2902);
Stops to listen line data from device.
EEDC.stopListenLines();
Stops to listen byte data from device.
EEDC.stopListenBytes();
// for ble:
EEDC.stopListenBytes(0x1826, 0x2AD2, 0x2902);
Reads single byte data from device. See: new_bytes event.
EEDC.readSingleBytes(100);
// for ble read from characteristic:
EEDC.readSingleBytes(1, 0x1826, 0x2AD2, 0x2902);
Returns info about current running device (phone) and connected device as json string (not object!).
EEDC.getDeviceInfo();
Enable or disable fullscreen mode.
EEDC.setFullScreen(true);
Return tru if fullScreen mode is enabled else false
let fullScreen = EEDC.isFullScreen();
Disconnect from device and close webView
EEDC.exit();
There are 4 event types you can listen to.
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);
This event is invoked when device state change. New state is value of this event.
EEDC.on("state_change", function(newState) {
// state changed
});
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
});
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;
});