rob chohan: titanium+plus modules and javascript bridges: controlling hardware with a web language
DESCRIPTION
Javascript is a fantastic language and the lingua franca of the Web. But can you use Javascript to control hardware? Titanium already does a great job of supporting hardware over iOS & Android, such as the accelerometer and the camera. But what about other hardware? Can you use Titanium to turn on Wifi or Bluetooth radios? How about other sensors like the Barometer on the Motorola XOOM? It turns out that the flexibility of the Titanium+Plus allows all of this and more. This talk discusses the ups and down of developing Titanium+Plus modules specifically for hardware like Wifi and Bluetooth. We will also discuss some aspects of doing localization for Titanium+Plus in Android.TRANSCRIPT
![Page 1: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/1.jpg)
Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language
Rob ChohanChief Technologist, ePi Rational
(C) 2011 ePi Rational, LLC
![Page 2: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/2.jpg)
![Page 3: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/3.jpg)
2001: A Space OdysseyStart around 57'20''
![Page 4: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/4.jpg)
Streaming BBC Channel 12 to Space
![Page 5: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/5.jpg)
Sweet Spot = Hardware + Software + Content
![Page 6: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/6.jpg)
Mobile Architecture,extending Titanium example
Zxing or Zebra Crossing –Open source barcode library encode/decode
Titanium –Open source User Interface & Hardware API Library
Killer Barcode App = Camera +
iOS Android
One Barcode app idea to rule them all!!!
(Software to be written to tie these together)
![Page 7: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/7.jpg)
Libraries that are ripe for Titanium+Plus
• DropBox
• Airpush
• Square
• Networking
• Google Analytics*
• A cryptographically secure RNG that your app needs that Javascript can't provide (e.g., SecureRandom)
• My Tracks, Map or Lat/Long?-117.117203, 32.784180-117.116966, 32.784218-117.116501, 32.784386-117.116501, 32.784439-117.116341, 32.784527-117.116280, 32.784618
![Page 8: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/8.jpg)
How To:Appcelerator makes it easy
to get started
• Titanium generates stubs• From their it is up to you to fill in the blanks• Pull in your favorite JAR, Java, or Obj-C or C++ code• Build and distribute on the Appcelerator Marketplace
![Page 9: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/9.jpg)
Hardware that could beinteresting to Titanium
Developers
• Barometer
• WiFi
• Bluetooth
• Near Field Communications (NFC)
• ANT+
• GPS
![Page 10: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/10.jpg)
Barometer
• Motorola chose a Digital Pressure Sensor in their Motorola Xoom
What is a Barometer good for (courtesy of the chip manufacturer, Bosch)• Enhancement of GPS
navigation• Indoor and outdoor
navigation• Leisure and sports• Weather forecast• Vertical velocity indication
![Page 11: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/11.jpg)
Barometer,Javascript example
• This is a perfect example of how Titanium+Plus can be extended• Barometer usage (targeting Motorola XOOM)
var baro = require('epi.baro');data = baro.getBaro(); // in milliBars, of course
![Page 12: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/12.jpg)
Titanium+Module Implementation for a Barometer on Android
public void onSensorChanged(SensorEvent event) {long curTime = System.currentTimeMillis(); switch (event.sensor.getType()) { case Sensor.TYPE_PRESSURE: if (lastUpdate == -1 || (curTime - lastUpdate) > mTime){ float pressure = event.values[0]; } break; case Sensor.TYPE_ACCELEROMETER: if (lastUpdate == -1 || (curTime - lastUpdate) > mTime){ float x = event.values[0]; float y = event.values[1]; float z = event.values[2]; } break; }}
![Page 13: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/13.jpg)
Screen from Motorola Xoom, Native App by Noosters500+ Downloads as of Sep 2011
![Page 14: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/14.jpg)
Screen from Motorola Xoom, Native App by Guild Software5,000+ Downloads as of Sep 2011
![Page 15: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/15.jpg)
Screen from Motorola Xoom, Native App by David Momenso100+ Downloads as of Sep 2011
![Page 16: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/16.jpg)
Titanium+Plus Moduleshelps to lower the bar
![Page 17: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/17.jpg)
Data Mining on Android Bluetooth Hardware Apps,
Data mined from AndBOT.com, April 2011
• Bluetooth Samples• Bluetooth Bar Widget• Bluetooth Backport for pre-Android 2.0• Bluetooth Fileshare - Bluex• Bluetooth On/Off for Droid• Bluetooth Remote• Bluetooth text & paint Chat• Bluetooth Terminal• Bluetooth Widget
Very useful apps, but what else can be done?
![Page 18: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/18.jpg)
Bluetooth now becomes very interesting for
Titanium Users
var btLib = require('epi.bt');bt = btLib.turnOnRadio(); // discoverybt.discovery();// pairing// exchanging of data
What is a Bluetooth good for in the context of Titanium• Chat programs• Getting data from custom sensor
boards
![Page 19: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/19.jpg)
San Diego Based Fitness Startup
• San Diego based startup focusing on Bicycle fitness
• Patent pending nutrition and hydration algorithm for cyclists
• 100% bootstrapped• Developed a custom sensor
board witho wheel revolution counterso digital pressure barometero another type of pressure
sensoro Bluetooth 3 radio
Mobile Phone
Custom Devicecomm over Bluetooth
![Page 20: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/20.jpg)
San Diego Based Fitness Startupwhy Titanium worked for them
• 100% bootstrapped• team is comprised of
o 1 firmwareo 1 electrical engineer o 1 Titanium Dev o 1 Bluetooth Devo 1 Marketing
• Each team member was able to focus on their particular part
• Team currently at funding stage
Mobile Phone
Custom Devicecomm over Bluetooth
![Page 21: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/21.jpg)
Bluetooth on Android & Titanium+Plus
• Android module built for Android 1.6
• Relies on the Bluetooth Backport open source jar from Sosuke Masui, Japan
• Development was started back before Bluetooth was supported on Android 2.0
• Many pitfallso older firmware and Android
phones (wait for supported hardware!)
o building for Titanium required modifying the Python build scripts for both the Module and the Application
o Android resources!!!, created a two-step build process
o Port to iOS coming after funding
![Page 22: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/22.jpg)
Localization Notes on Titanium+Plus with Android
• Android res files for each locale (en, ja, es, ...)
![Page 23: Rob Chohan: Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language](https://reader034.vdocument.in/reader034/viewer/2022051818/549f3f08ac795906768b4977/html5/thumbnails/23.jpg)
Titanium+Plus Modules and Javascript Bridges: Controlling Hardware with a Web Language
Rob ChohanChief Technologist, ePi Rational
(C) 2011 ePi Rational, LLC