Skip navigation links

SMARTToolSenseBlock 0.1.0-SNAPSHOT API

SMART ToolSense™ Block SDK

See: Description

Packages 
Package Description
com.smarttech.toolsense.block
SMART ToolSense™ Block SDK core classes
com.smarttech.toolsense.block.protobuf
SMART ToolSense™ Block SDK protobuf generated classes

SMART ToolSense™ Block SDK

This SDK is part of a SDK suite to assist Android apps to integrate SMART ToolSense™ technology. The SDK is used in concert with the SMART ToolSense™ SDK to enable Android applications to retrieve fields in ToolSense™ Block Tool blob that is stored in ToolSense™ physical tool.

Introduction

The SDK enables Android apps to retrieve fields in ToolSense™ Block Tool blob that is stored in ToolSense™ physical tool.

ToolSense™ physical tool is identified "tool vendor id" and "tool product id". SMART Technologies ULC assigns unique "tool vendor id" to ToolSense™ physical tool vendor, and vendor is responsible to assign "tool product id" for classes of physical tool.

A class of physical tool consists of multiple kind of tools. For example, for English alphabet tool class, it consists of letter A-Z and a-z. In this case, 'tool product id" is not sufficient to represent all letters. Thus, Block Tool blob enables physical tool to contain additional fields to describe the Block.

Block Tool blob contains a Path Id field. Vendors of ToolSense™ physical tools are responsible for allocating Path Id's to identify their physical tools and vendor's applications are responsible for translating Block physical tool touch contacts into actions. For graphic apps, it may lookup SVG path by Path Id and render the SVG path as a digital representation of a physical tool. For educational games that teach English alphabet, Path Id may be mapped to arbitrary action in the games.

Block Path Id Allocations

In order to minimize Block physical tool touch contact detection latency, Block Tool blob SHOULD be keep as small as possible. Path Id value SHOULD be between 0 and 16383. Values outside the range MAY increase touch contact detection latency.

Build Instruction (Local AAR)

1. Copy SMARTToolSenseBlock-[VERSION]-release.aar to 'libs' directory

2. In your app build.gradle, add the followings:


    apply plugin: 'com.android.application'

    repositories {
        flatDir {
           dirs 'libs'
        }
    }

    android { //... }

    dependencies {
        implementation (name:'SMARTToolSenseBlock-[VERSION]-SNAPSHOT', ext:'aar')
        implementation "com.google.protobuf:protobuf-java:2.6.1"
    }
  

Access ToolSense Block record

Pseudo-code:

1. Obtain com.smarttech.boardtoolid.ToolSense object from com.smarttech.boardtoolid.PointerProperties

2. Check 'toolVendorId' and 'toolProductId' in ToolSense object. If they belong to your application, obtain the Tool blob from ToolSense object. Otherwise, your application MUST ignore the touch contact

3. Call com.smarttech.toolsense.block.BlockRecordParserFacade.parseFrom() and pass in the Tool blob. The function returns import com.smarttech.toolsense.block.protobuf.ToolSenseBlock.BlockRecord object

4. Lastly, access fields through ToolSenseBlock.BlockRecord object

Example Code:


    //
    // Define your ToolSense tool vendor id here
    //
    static final int MY_TOOLSENSE_VENDOR_ID = ;
    //
    // Define your ToolSense Tool Product Id here
    //   Your apps may handle more than one tool product id, but this example does not show it for brevity
    //
    static final int MY_TOOLSENSE_TOOL_PRODUCT_ID_1 = ;
    static final int MY_TOOLSENSE_TOOL_PRODUCT_ID_2 = ;
    //
    // Allocate Android MotionEvent.PointerProperties once and reuse the object for each MotionEvent
    //
    android.view.MotionEvent.PointerProperties _motionEventPointerProperties = new android.view.MotionEvent.PointerProperties();
    //
    // Allocate boardtoolid.PointerProperties once and reuse the object for each MotionEvent
    //
    com.smarttech.boardtoolid.PointerProperties _toolSensePointerProperties = new com.smarttech.boardtoolid.PointerProperties(motionEventPointerProperties);

    public boolean onTouchEvent(MotionEvent event) {
        boolean event_handled = false;
        //
        // Obtain the number of concurrent touch contact, and iterate each contact to look for ToolSense touch contacts
        //
        int pointerCount = event.getPointerCount();
        for (int idx = 0; idx < pointerCount; ++idx) {
            //
            // For each touch contact in MotionEvent, read extended ToolType in boardtoolid.PointerProperties
            //
            event.getPointerProperties(idx, _motionEventPointerProperties);
            ToolType extendedToolType = _toolSensePointerProperties.getExtendedToolType();
            //
            // If ToolType is ToolSense, extract ToolSense Tool blob
            //
            if (extendedToolType == ToolType.ToolSense) {
                com.smarttech.boardtoolid.ToolSense toolSense = _toolSensePointerProperties.getToolSense();
                //
                // Found a ToolSense touch contact, only proceed further if tool vendor id is mine
                //
                if (toolSense.getToolVendorId() == MY_TOOLSENSE_TOOL_VENDOR_ID) {
                    byte[] toolSenseBlob = toolSense.getToolBlob();
                    //
                    //  Check tool product id and only handle those my apps supported
                    //
                    switch(toolSense.getToolProductId()) {
                        case MY_TOOLSENSE_TOOL_PRODUCT_ID_1:
                            try {
                                //
                                // Parse the ToolSense BLOB into a more convenient form to obtain the Path Id
                                //
                                com.smarttech.toolsense.block.protobuf.ToolSenseBlock.BlockRecord blockRecord =
                                        com.smarttech.toolsense.block.BlockRecordParserFacade.parseFrom(toolSenseBlob);
                                int physicalToolBlockPathId = blockRecord.getPathId();
                                //
                                // Logic in your apps to act on physicalToolBlockPathId
                                //
                                event_handled = true;
                            } catch (com.google.protobuf.InvalidProtocolBufferException e) {
                                //
                                // Unable to parse ToolSense Tool Blob
                                //
                            }
                            break;
                        case MY_TOOLSENSE_TOOL_PRODUCT_ID_2:
                            //
                            // Logic in your apps to act on another Tool Product Id
                            //
                            break;
                    }
                }
            }
        }
        return event_handled;
    }

Generate ToolSense Block record

The SDK provides a python script to encode Path Id in binary format. The script name is genblock.py and it is located under "tools" directory in SMARTToolSenseBlock-artifacts.zip

Requirements

Requirements Installation

pip install protobuf
Or
pip3 install protobuf

Usage

python genblock.py --path_id <positive integer>
Writes the hexadecimal string representation of the block to stdout, formatted correctly for use in SMART Pen Programming Utility.

Skip navigation links