Flash and Hardware

28
Flash and Hardware Kevin Hoyt [email protected] Platform Evangelist Adobe Systems, Inc.

description

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

Transcript of Flash and Hardware

Page 1: Flash and Hardware

Flash and HardwareKevin Hoyt

[email protected] EvangelistAdobe Systems, Inc.

Page 2: Flash and Hardware

Agenda

•Why?

•Web Camera

•Socket Basics

•Phidgets

•WiiFlash

•Arduino

Page 3: Flash and Hardware
Page 4: Flash and Hardware

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!

Page 5: Flash and Hardware

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 );

Page 6: Flash and Hardware

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

Page 7: Flash and Hardware

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

Page 8: Flash and Hardware

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

Page 9: Flash and Hardware

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 ) );

}}

Page 10: Flash and Hardware

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

Page 11: Flash and Hardware

Barcode Reader Computer Vision

Page 12: Flash and Hardware

•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

Page 13: Flash and Hardware
Page 14: Flash and Hardware

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

Page 15: Flash and Hardware

Some Types of Phidgets

•Infrared distance

•Force

•Motion

•Temperature

•Light

•Sonar

•Linear touch

•Circular touch

•Accelerometer

•Ph

•Thermocouple input

•Encoder

Page 16: Flash and Hardware

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;}

Page 17: Flash and Hardware

Phidget Overload Inventory Manager

Page 18: Flash and Hardware
Page 19: Flash and Hardware

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)

Page 20: Flash and Hardware

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 );

}

Page 21: Flash and Hardware

Vision RevisitedEvent Charting

Page 22: Flash and Hardware
Page 23: Flash and Hardware

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

Page 24: Flash and Hardware

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

Page 25: Flash and Hardware

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

Page 26: Flash and Hardware

With FlashWithout Flash

Page 27: Flash and Hardware

Flash and HardwareKevin Hoyt

[email protected] EvangelistAdobe Systems, Inc.

Page 28: Flash and Hardware

References

•Barcode Reader

•Basic Computer Vision

•Socket Policy Files

•Phidgets

•WiiFlash

•Arduino