.. Alpha User manual
.. Author: Benjamin Vandendriessche
.. Version: 1.1 [January 2017]

.. STATUS: production

.. role:: bfred
.. role:: yellow
.. role:: green
.. role:: bfdarkblue

#################
Alpha User Manual
#################

This manual describes the operation of an early prototype version of the Byteflies Multi-Sensor Platform for wearable health development. Use of this system is prohibited unless the user has agreed to and signed an appropriate non-disclosure agreement. In case of questions or problems, use the `Slack team <https://bfalpha.slack.com>`_ (you should have received an invite). To file bug reports, use the ``#bug`` channel in the Slack team. Color highlights in the text refer to emphasis boxes in certain figures.

.. rubric:: Quick Navigation
.. contents::
   :local:
   :depth: 2

----

*******************
Known Issues & Bugs
*******************

.. attention:: This list is updated regularly, please consult it before starting a new test or experiment. This list assumes familiarity with the system as outlined :ref:`further <start>`.

#. Make only one recording at a time (i.e. sync any logged data and clear memory before starting a new recording).
#. If Bluetooth connection is lost while recording, simply keep :ref:`logging <logging>`. To stop the recording, reconnect via Bluetooth. Sync the logged data in the same ``app`` session.
#. Do not set the sampling frequency for the ``ECG node`` higher than 125 Hz.
#. Keeping the ``nodes`` connected to a powered ``dock`` when not in use is good practice for these early prototypes.
#. Currently the ``nodes`` should be used for maximum one hour recordings.

If you are told to **reset** a ``node``, use the programmer board as follows:

.. image:: images/jumper_reset.png
   :scale: 40%
   :align: left

#. Connect the programmer board to power via USB
#. Use one of the ``dock`` jumpers to bridge the 3\ :sup:`rd` pin on the side of the USB connector
#. Connect the node to the programmer board for about one second

.. Text block spacers to move next block underneath image

|
|
|
|
|
|
|
|
|
|
|
|
|
|

If you are told to **flash** a ``node``, use the programmer board and debugger probe as follows:

.. image:: images/flash.png
   :scale: 25%
   :align: left

#. Connect the debugger probe **correctly** to the programmer board
#. Connect the debugger probe to the computer via USB and the programmer board to power via USB
#. Connect the node to the programmer board
#. Download and install `Uniflash <http://www.ti.com/tool/UNIFLASH>`_
#. Open Uniflash and select ``CC2650F128`` in the Device list
#. Next, select ``Texas Instruments XDS2xx USB Debug Probe`` and click ``Start``
#. Load the appropriate ``.hex`` file(s) via the ``Browse`` menu
#. Click ``Load Image`` and wait for the process to complete
#. Reset the ``node`` to activate it as explained above

.. Text block spacers to move next block underneath image

|
|
|
|
|
|
|
|

----

.. _start:

*****************
What's in the Box
*****************

.. warning:: None of the components are currently waterproof or water resistant!

The prototype kit contains the following items:

* 1x Byteflies biopotential sensor node (``ECG node``)

.. image:: images/ecg.png
   :scale: 100%
   :align: center

* 20x round ECG electrodes (``ECG electrode``)

.. image:: images/electrode.png
   :scale: 60%
   :align: center

* 1x Byteflies photoplethysmography (PPG) sensor node (``PPG node``)

.. image:: images/ppg.png
   :scale: 15%
   :align: center

* 1x Byteflies docking station (``dock``)

.. image:: images/dock.png
   :scale: 80%
   :align: center

* 1x BLE112D Bluetooth dongle (``dongle``)

.. image:: images/dongle.png
   :scale: 15%
   :align: center

* Configuration software (``app``) and dependencies: the files and additional instructions can be found in the ``#files`` channel of the `Slack team <https://bfalpha.slack.com>`_

Not provided:

* Micro-USB cable
* Computer
* USB extension cord (optional)

----

*****************
Quick Start Guide
*****************

Initial setup
=============

.. warning:: Make sure the :bfred:`8-pin connector` is properly aligned when connecting the ``node`` to the ``dock`` to avoid damaging the pins.

#. Install the ``app`` and necessary dependencies on a personal computer (see :ref:`further <app>`)
#. Connect the ``dock`` to the computer via a micro-USB cable
#. Connect one or two sensor ``nodes`` to the ``dock`` via the :bfred:`8-pin connector(s)`
#. Ensure the battery of the ``node(s)`` is fully charged (see :ref:`Battery <battery>`)

ECG node
========

#. Attach two ``ECG electrodes`` to the ``node`` leads
#. Remove the adhesive film and apply at the same angle as an :ref:`Einthoven Lead II <ecg>`
#. Verify that high quality data is recorded via the :ref:`Streaming Mode <streaming>`

PPG node
========

#. Apply to desired location using a piece of double-sided tape
#. Take care to not obstruct the LED opening
#. Verify that high quality data is recorded via the :ref:`Streaming Mode <streaming>`

Dock
====

The ``dock`` is used for turning a ``node`` on, node :ref:`charging <battery>` and downloading of :ref:`logged <logging>` data. After installing the ``app`` by running the appropriate installer for your OS, connect the ``dock`` to your computer using a micro-USB cable. The :bfdarkblue:`blue power LED D4` should switch on to indicate the ``dock`` is receiving power. In addition, the following **status LEDs** can be found:

* :bfdarkblue:`D1 and D2`: ``node`` charging
* :yellow:`D5 and D6`: transfer of :ref:`logged <logging>` data

.. attention:: To turn on a ``node``, ensure the :yellow:`jumper` is set to the correct channel

.. _battery:

Battery
=======

The charging :bfdarkblue:`LEDs D1 and D2` will switch on when the ``dock`` is powered on or when the ``node`` connected to the accompanying bay is charging. :bfdarkblue:`D1 and D2` will dim when the connected node is fully charged. Expect a charging time of about 2 hours.

The ``nodes`` will automatically power down under the following conditions:

#. When reaching critical battery level
#. When disconnected from Bluetooth when :ref:`logging <logging>` is *not* enabled

.. hint:: The ``nodes`` have no physical on/off switch. A node can be turned on by connecting it to a ``dock`` (verify the :yellow:`jumper` is set to the correct channel). If a node is turned off while it is connected to a dock, disconnect and reconnect the node to turn it back on. If they powered down due to low battery level, charge them first with a ``dock``. As soon as the battery level is high enough, they will show up again in the ``app``. The battery level can be verified in the ``app``, and the ``dock`` can be powered over any USB power supply.

----

.. _app:

***
App
***

To install the ``app``, download the correct installer package for your OS from the ``#files`` channel on `Slack <https://bfalpha.slack.com>`_, extract it, and run ``main.exe``. All the dependencies should be taken care of in the package.

.. _streaming:

Streaming Mode
==============

Streaming Mode allows you to quickly verify the quality of the data generated by one or more sensor ``nodes``. In this mode, the ``nodes`` send data via a Bluetooth connection to the ``app``.

.. hint:: The bandwidth of Bluetooth is limited: if the stream starts lagging or showing artifacts, lower the number of enabled channels. Additionally, the Bluetooth signal strength is limited in the current node design. Keep the sensor node close the dongle. If needed, use a USB extension cord.

#. Connect the ``dongle`` to the computer and launch the ``app``
#. Apply the ``ECG`` and/or ``PPG node`` and click the :bfdarkblue:`+ button`; available ``nodes`` will populate the dropdown menu to the left

.. image:: images/interface_blank_annotated.png
   :scale: 40%
   :align: center

#. Select one of the ``nodes`` in the menu (they will show up as ``BF ECG ProjectX`` and ``BF PPG ProjectX``, where ``X`` is the identifier of the ``node``; the menu can be closed via the right-click menu)

.. image:: images/interface_select.png
   :scale: 50%
   :align: center

#. The :ref:`ECG <ecg>` (left) or :ref:`PPG <ppg>` (right) user interface will load:

    #. :bfdarkblue:`Battery and memory gauges`
    #. :bfred:`Channel switches`
    #. :yellow:`Sensor parameters`
    #. :green:`Logging and Bluetooth` (see :ref:`Logging Mode <logging>`)

.. image:: images/interface_menu.png
   :scale: 30%
   :align: center

.. _logging:

Logging Mode
============

Logging Mode enables long-term recording of data without the need for an active Bluetooth connection. To start logging on the onboard memory, switch :green:`Recording` on and select the desired channels from the popup menu. Currently, it is not possible to disable logging of the accelerometer channels.

To download the data stored on the onboard memory:

1. Connect the ``node(s)`` to the ``dock``
2. Select the appropriate ``node`` by moving the ``dock`` :yellow:`jumper`
3. Connect the ``dock`` to the computer with a micro-USB cable
4. Launch the ``app``, connect to the ``node``, and click :green:`Sync`
5. Choose folder where data will be downloaded
6. After download is completed check the HDF5 data integrity
7. Press the ``Clear memory`` button
8. :green:`Disconnect` the Bluetooth connection

.. warning:: Currently, USB transmission between the node and the PC is fairly unstable. This can result in corrupt data being saved in the HDF5 file. Repeating the ``sync`` procedure should allow you to retrieve the recording on the ``node``.

.. warning:: Currently, data from only one ``node`` at a time can be downloaded. While downloading data, the ``app`` will crash if another sensor ``node`` is still connected via Bluetooth.

6. The data will be downloaded as an `HDF5 file <https://support.hdfgroup.org/HDF5/>`_ which is organized as follows:

    a) The root contains one HDF Group per recording, combination of parameters, or sensor ``nodes``
    b) Each HDF Group contains one channel for each dataset (see :ref:`further <logging>`)
    c) The metadata associated with each HDF Group specifies the type of sensor. The sampling frequency is stored as an attribute of the dataset.

.. hint:: Point 6a implies that a new HDF Group will be created every time a new configuration is used to start a recording.

----

************
Sensor Nodes
************

Node-specific parameters can be configured through the ``app``. Remember that interrupting an ongoing recording to change one or more parameters will create a new HDF Group in the root of the HDF5 file.

.. _ecg:

ECG node
========

The ``ECG node`` is a single lead bipolar biopotential sensor. A high quality ECG waveform is characterized by a clear P-wave, R-wave and T-wave, even in the presence of high frequency noise and/or baseline drift. Various angles can be used to attach the ECG electrodes.

.. figure:: images/ecg_annotation_leads.png
   :scale: 80%
   :align: center

For the sake of reproducibility, it is good practice to use an angle that corresponds to an Einthoven Lead II, with the negative electrode (black or white) placed centrally on the chest, and the positive electrode (brown or green) near the apex of the heart (i.e. to the left from the users point-of-view).

.. image:: images/interface_ecg_annotated.png
   :scale: 80%
   :align: center

.. hint:: The current prototypes have short ECG leads. This is by design as the leads mimic the electrode distance that will be available in a future patch design, but consequently it is not possible to use the same distance between the electrodes as in a strict Lead II configuration.

The ECG parameters in the ``app`` are limited to :bfred:`channel switches` and the :yellow:`sampling frequency`. One bipolar biopotential lead is available, in addition to the accelerometer XYZ axes. The sampling frequency for the latter cannot be changed in the app and is 125 Hz for each channel.

.. _ppg:

PPG node
========

The ``PPG node`` is a triple (green (channel 1), infrared (IR, channel 2), red (channel 3)) wavelength blood pulse flow sensor. Using double-sided tape, the ``node`` can be attached to any patch of skin that is large enough (e.g. the forehead, upper-arm, wrist, lower-leg, ...). When deciding on one or more LED colors, keep in mind that red and IR penetrate deeper into tissue than green light, which will have an influence on the reflected signal and artifacts. A high quality PPG waveform is characterized by clear systole (max blood flow), diastole (min blood flow), and dicrotic notch (reflected wave) features.

.. image:: images/ppg_annotated.png
   :scale: 40%
   :align: center

The sampling frequency for the different LED channels is 100 Hz, and 125 Hz for the accelerometer channels. In addition to the 3 LED channels, there is a self-explanatory ambient channel.

.. image:: images/interface_ppg_annotated.png
   :scale: 80%
   :align: center

The following :bfred:`PPG-specific parameters` are available in the app:

#. LED1-3 current: set strength of LED
#. LED1-3 offset: set DC offset
#. Resistance (RF gain): set DAC gain

The LED strength and RF gain are positively correlated with signal quality, and the DC offset is used to set an optimal range for the DAC (i.e. avoid signal saturation). To find a good set of parameters, use the following workflow:

#. Set LED strength to 5
#. Use DC offset to bring signal as close as possible to 0
#. Increase RF gain step-by-step while keeping it centered around 0 ± 220
#. Increase LED strength step-by-step, while compensating for DC offset, until reaching a satisfactory signal quality

----

******************
Potential Problems
******************

#. If too many channels are accessed via :ref:`Streaming Mode <streaming>`, lag or artifacts may occur. Reduce the number of enabled channels.
#. When trying to download :ref:`logged data <logging>` from one ``node``, while another is still connected via Bluetooth, the ``app`` will crash. Disconnect the other ``node`` first.
#. The Bluetooth connection has a limited range, especially for the PPG ``node``. Keep the dongle in close proximity to maintain the connection. If needed, use a USB extension cord.
#. In case of other issues, let us know via the ``#bug`` channel in `Slack <https://bfalpha.slack.com>`_.
