Flash and Hardware

Post on 05-Dec-2014

3.454 views 2 download

description

A walk through the various hardware integration touch points one might make from Adobe Flash Player.

Transcript of Flash and Hardware

Flash and HardwareKevin Hoyt

khoyt@adobe.comPlatform EvangelistAdobe Systems, Inc.

Agenda

•Why?

•Web Camera

•Socket Basics

•Phidgets

•WiiFlash

•Arduino

Why?

•Programmers work really hard

•All our work lives in this shiny box

•Turn off the box and all of our work is gone

•We’ve got nothing to show for our effort

•Sorry, that’s frustrating!

import flash.display.BitmapData;import flash.media.Camera;import flash.media.Video;

...

public var video:Video = new Video( 320, 240 );video.attachCamera( Camera.getCamera() );addChild( video );

...

var bmp:BitmapData = new BitmapData( 320, 240 );bmp.draw( video );

Using a Web Camera

•Hardware already on your machine

•Import the required libraries

•Create the video object

•Attach the web camera

•Use BitmapData.draw() to access pixels

•Process to your hearts content

0 = 32111 = 22212 = 21223 = 14114 = 11325 = 12316 = 11147 = 13128 = 12139 = 3112

Reading Barcodes

•Sharpen and extract sample rows (1 pixel)

•The first lines serve as segment markers

•Extract seven segments per number

•Segment colors alternate for each digit

•Check sum at the end

•Try line variations to maximize success

for( var h:Number = 0; h < video.height; h++ ) {

for( var w:Number = 0; w < video.width; w++ ) {

average = bmpd.getPixel( w, h );

r2 = ( average >> 16 ) & 0xFF;g2 = ( average >> 8 ) & 0xFF;b2 = average & 0xFF;

distance = Math.sqrt( Math.pow( r2 - r1, 2 ) + Math.pow( g2 - g1, 2 ) + Math.pow( b2 - b1, 2 ) );

}}

Color Intensity

•Get a sample color (triggered by user input)

•Iterate through all the pixels at desired rate

•Determine color distance from sample

•Track pixel position with least distance

•Rotate sprite based on distance from center

Barcode Reader Computer Vision

•Flash Player 9 and before (9.0.124)

•Policy file served independently

•Sockets can connect to 1024 or higher

•Flash Player 10 and forward

•Port 843 or the specific destination port

•Prevents DNS rebinding attacks

•Adobe AIR doesn’t care about policy files

Phidgets

•Plug and play USB prototyping

•Numerous sensors as well as motor control

•Support for multiple operating systems

•Support for multiple languages (inc. AS3)

•Phidgets service is a proxy socket server

•AS3 library available for sensors and events

Some Types of Phidgets

•Infrared distance

•Force

•Motion

•Temperature

•Light

•Sonar

•Linear touch

•Circular touch

•Accelerometer

•Ph

•Thermocouple input

•Encoder

public var phidget = new PhidgetInterfaceKit();phidget.addEventListener(

PhidgetDataEvent.SENSOR_CHANGE, doSensor );

phidget.open( "localhost", 5001 );

...

public function doSensor( event:PhidgetDataEvent ):void {

picture.alpha = Number( event.Data ) / MAX_RANGE;}

Phidget Overload Inventory Manager

WiiFlash

•Open source project by Thibault Imbert

•Integrates Wii Remote and Flash via Bluetooth

•Provides socket server for various OSs

•Provides AS3 library for server interaction

•Drives events for most Wii Remote changes

•No support for sensor bar (really an emitter)

wiimote = new Wiimote();wiimote.addEventListener( ButtonEvent.A_PRESS, doAButton );wiimote.addEventListener( ButtonEvent.A_RELEASE, doAButton );wiimote.addEventListener( WiimoteEvent.UPDATE, doUpdate );wiimote.connect();

...

public function doAButton( event:ButtonEvent ):void {trace( event.type );

}

public function doUpdate( event:WiimoteEvent ):void {trace( wiimote.pivot );

}

Vision RevisitedEvent Charting

Arduino

•Open source prototyping platform

•Primarily targeted at hobbyists

•Processing/Wiring language/IDE

•Can be connected to a PC or standalone

•Purchasing pre-assembled costs about $65

Sample Project

•Connect the board to your computer

•Connect an LED to the board

•Run the development environment

•Write and upload a program to the board

•Watch your Arduino go to work for you

•Countless “shields” offer infinite possibilities

Flash Integration

•Install Firmata on the Arduino for serial access

•Use serial proxy (SerProxy) to create a socket

•Use a socket library to communicate out

•Glue documented well by Protolab

With FlashWithout Flash

Flash and HardwareKevin Hoyt

khoyt@adobe.comPlatform EvangelistAdobe Systems, Inc.

References

•Barcode Reader

•Basic Computer Vision

•Socket Policy Files

•Phidgets

•WiiFlash

•Arduino