Tutorial: 06 - Forcing Calibration

06 - Forcing Calibration

Sometimes it may be desirable to force a device to recalibrate. This may be necessary if the pen isn't tracking well against the screen. The following example shows how to force a device to calibrate and to track the progress as the user goes through the process:

function tutorial() {
    var socket = new WebSocket("ws://localhost:8080");
    socket.onopen = function() {
        console.log("Web Socket Open");
    };
    socket.onclose = function() {
        console.log("Web Socket Closed");
    };
    socket.onmessage = function(evt) {
        var msg = JSON.parse(evt.data);
        if(msg._class==="ConnectionOpen") {
            //We've just connected to the server.
            if(msg.serverInfo.devices.length>0) {
                //Lets open the first available device:
                var device = msg.serverInfo.devices[0];
                console.log("Opening device",device.uuid,": ",device.manufacturer,device.product);
                var obj = {"_class":"DeviceOpenRequest","uuid":device.uuid};
                socket.send(JSON.stringify(obj));
            }
        } else if(msg._class==="DeviceOpenResponse") {
            socket.send(JSON.stringify({"_class":"ForceRecalibrate"}));
        } else if(msg._class==="CalibrationUpdate") {
            if(!msg.done) {
                console.log("Device is currently waiting for the user to press the ",msg.point,"point.");
            } else {
                console.log("Done!");
            }
        }
    };
}

When you connect to the device you can also determine if the device is currently in calibration mode. If the device is in calibration mode you won't receive events and some commands you issue may not execute correctly. To determine if the device is in calibration mode see the CalibrationMode object stored in the ScriptelDevice object returned with the DeviceOpenResponse you get when you open the device.