Scriptel OmniScript Tutorial 06 - Sending Images to Device

From Scriptel Wiki
Jump to navigation Jump to search

Video tutorial

Scriptel OmniScript Tutorial 06 - Sending Images to Device

Instructions

In this video tutorial we'll make an application capable pushing images to your ScripTouch device.

Video instructions follow:

You'll need a couple tools.

  • You'll need a recent web-browser: Safari 6+, Chrome 16+, Explorer 10+, Firefox 11+, or Opera 12.10+.
  • Next you'll need a text editor: Notepad will work, but any text editor should work.
  • Make sure OmniScript is installed and running, and you have a ScripTouch capture device hooked up.

For this example, we're going to assume that you're going to be using OmniScript installed on your local computer.

Step 1: Creating the Example Files

We'll start by creating the files for the example.

  1. Open up a folder, create two files: an HTML file and a JS file.
  2. Open up the HTML file and make a skeleton document.
  3. Add the doctype tag because this is an HTML5 application.
  4. Then create the open and close html tags.
  5. Next, create the head and body tags.
  6. Give the document a title and create a script tag that references the new script file.
  7. Now we'll create a canvas tag we'll use to draw on later in our example.
  8. Now let's add an onload handler to our document body that calls a function we'll create in the JavaScript file in just a moment.
  9. Save the document and open up the JavaScript file.
  10. Create the function we just referenced in the onload handler in the html document.
  11. Double-check and make sure the function matches the one we're calling.

Once that's done we can start writing code.

Step 2: Writing the Code

  1. Let's start by creating a websocket along with a callback for the "connection established," "connection closed," and "data received" events.
  2. We'll put console.log() statements in each of the callbacks so we can verify they're being called when we run the application.
  3. Now, just like in the previous examples, we'll add handlers to our on message callback.
  4. We'll start by handling the "connection open" just like before, where we open the first device on the server as soon as we connect.
  5. Let's add a reference to our canvas and its drawing context at the top of our function, we'll need this in just a moment.
  6. Let's also set the stroke style to black while we're at it.
  7. Now let's add a handler for "device open" responses.
  8. We'll use the information we get from this object to set up the canvas, paint a simple X across the screen, and push the image to the device.
  9. We'll push the canvas to the device using a "push bitmap" request.
  10. These requests allow you to push any P&G data URL to the screen of your device provided the bitmap fits on the screen of your device and won't overflow any of the edges. The two data URL call converts your canvas into a PNG data URL, the bit depth specifies that the picture should be transferred in 4-bit grayscale.

Some devices may not support grayscale.

OmniScript will convert the image to black and white for your device, if this is the case.

Finally let's add a catch-all to make sure that OmniScript doesn't send us anything we aren't expecting.

Now let's try opening the application.

Step 3: Testing

  1. Open the HTML page and web browser.
  2. You should see the X drawn on your screen.
  3. That same X should also be displayed on your device.

You can use this to transfer any type of image that your browser supports.