See: Description
| Package | Description |
|---|---|
| com.smarttech.toolsense.block |
SMART ToolSense™ Block SDK core classes
|
| com.smarttech.toolsense.block.protobuf |
SMART ToolSense™ Block SDK protobuf generated classes
|
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.
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"
}
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
//
// 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;
}
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
pip install protobuf
Or
pip3 install protobuf
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.