/* Filename:    J014_PictureApp.js
 * Description: Picture Application Overload Demonstration
 * Copyright:   2006 The Code Corporation. Please see http://www.codecorp.com/jsLicensing.html for information regarding copyright and grant of license.
 * $Revision: 118 $
 * $Date: 2006-12-05 16:26:51 -0700 (Tue, 05 Dec 2006) $
 */
 
include(".crx.js");

//Places a right softkey on the "ready screen" of CodeViewer
ready.rightSoftkey = new gui.Softkey("Picture",  function() { gui.showMenu(menuPicture); });
ready.show();

function signaturePicture()//setting windowing parameters for taking picture of a signature
{
    reader.writeSetting(0xe2,1); //VGA on
    reader.writeSetting(0xe1, 0x64); //brightness
    reader.writeSetting(0x3a, 7); //Left Button Take Picture
    reader.writeSetting(0x39, 7); //Right Button Take Picture
    reader.writeSetting(0x64, 0); //Dot Off
    reader.writeSetting(0x122, 0); //Dot off
    reader.writeSetting(0xc4, 2); //Laser on continuously
    reader.writeSetting(0xac, 0x64); //Picture left position
    reader.writeSetting(0xad, 0x96); //Picture upper position
    reader.writeSetting(0xaf, 0xc8); //Picture upper position
    reader.writeSetting(0xab, 1); //AGC mode pictures
    
    
    var signaturePicture = new gui.Form();  //instructions for taking picture of a signature
    
    
   function rightSoftkeyOnClick()
   {
        //when the cancel softkey is pressed default settings are re-initialized
       reader.processCommand("J");
       reader.processCommand("W");
       gui.showMenu(menuPicture);
    }
    
    
   var right = new gui.Softkey("Cancel",  rightSoftkeyOnClick);
   gui.statusText = "Signature";
   gui.show(new gui.Text("Aim laser at signature with reader 8-10 in. away, press any red button"));
   gui.rightSoftkey = right;
   gui.leftSoftkey = null; //eliminates left softkey
}    

function licensePicture()//setting windowing parameters for taking picture for drivers licenses and license plates
{
    reader.writeSetting(0xe2,1); //VGA on
    reader.writeSetting(0xe1, 0x64); //brightness
    reader.writeSetting(0x3a, 7); //Left Button Take Picture
    reader.writeSetting(0x39, 7); //Right Button Take Picture
    reader.writeSetting(0x64, 0); //Dot Off
    reader.writeSetting(0x122, 0); //Dot off
    reader.writeSetting(0xc4, 2); //Laser on continuously
    reader.writeSetting(0xac, 0); //Picture left position
    reader.writeSetting(0xad, 0); //Picture upper position
    reader.writeSetting(0xaf, 0x280); //Picture upper position
    reader.writeSetting(0xab, 1); //AGC mode
    reader.writeSetting(0x36, 0xa); //# of frames before taking picture

   function rightSoftkeyOnClick()
   {
        //when the cancel softkey is pressed default settings are re-initialized
       reader.processCommand("J");
       reader.processCommand("W");
       gui.showMenu(menuPicture);
    }
    
    function dLicensePicture() //instructions for taking picture of drivers license
    {
        var dLicensePicture = new gui.Form();
        function rightSoftkeyOnClick()
        {
            //when the cancel softkey is pressed default settings are re-initialized
            reader.processCommand("J");
            reader.processCommand("W");
            gui.showMenu(menuPicture);
        }
        var right = new gui.Softkey("Cancel",  rightSoftkeyOnClick);
        gui.statusText = "Driver's License";
        gui.show(new gui.Text("Aim laser at license with reader 8-10 in. away, press any red button"));
        gui.rightSoftkey = right;
        gui.leftSoftkey = null;     //eliminates left softkey
    }
        
    function platePicture() //instructions for taking picture of a license plate
    {
        var platePicture = new gui.Form();
        
        function rightSoftkeyOnClick()
        {
            //when the cancel softkey is pressed default settings are re-initialized
            reader.processCommand("J");
            reader.processCommand("W");
            gui.showMenu(menuPicture);
        }
        
        var right = new gui.Softkey("Cancel",  rightSoftkeyOnClick);
        gui.statusText = "License Plate";
        gui.show(new gui.Text("Aim reader at license plate 5-6 ft. away, press any red button"));
        gui.rightSoftkey = right;
        gui.leftSoftkey = null;     //eliminates left softkey 
    }
        
    var licensePicture = new gui.Form();
    var dLicensePictureApp = new gui.MenuItem("Drivers License", dLicensePicture);
    var platePictureApp = new gui.MenuItem("License Plate", platePicture)
    licensePicture.append(dLicensePictureApp);
    licensePicture.append(platePictureApp);
    licensePicture.caption = "Choose Size";     
    gui.showMenu(licensePicture);
}


function sendPicture()  //send files stored on reader
{
    var show = !comm.isConnected;   //check for cable connection

    if( show )
    {
        reader.processCommand("#", "\3");
        gui.alert("Reader Not Connected, Connect cable and try again");
        return ok;
    }
    else
    {
        reader.processCommand("X"); //upload all files
        gui.alert("Files Sent");
        
        // Note:
        //     Using the 'X' command to upload pictures doesn't provide status feedback to the script.
        //     It could be rewritten to use storage.findFirst, findNext, and upload to send the files here and process the status.
    }
}


var menuPicture = new gui.Menu();//cancel softkey; resets reader back to factory defaults as well as starting up CodeViewer

// "Cancel" softkey function
menuPicture.onCancel = function ()
{    
    reader.processCommand("J");
    reader.processCommand("W");
    ready.show();
}

var sepHeight  = 1;

//Main Picture menu form

var signaturePictureApp = new gui.MenuItem("Signature", signaturePicture);
var licensePictureApp = new gui.MenuItem("License", licensePicture);
var btnuploadFile = new gui.Button("Send", sendPicture);
menuPicture.caption = "Picture Size";

menuPicture.append(signaturePictureApp);
menuPicture.append(licensePictureApp);
menuPicture.append( new gui.Separator(sepHeight , gui.separatorStyle.horizontalLine) );
menuPicture.append(btnuploadFile);


//EOF
