<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jeffrey Sambells &#187; development</title>
	<atom:link href="http://jeffreysambells.com/category/development/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeffreysambells.com</link>
	<description>Geek out AFK</description>
	<lastBuildDate>Mon, 14 May 2012 16:04:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>&#9734; fun.js [Updated]</title>
		<link>http://jeffreysambells.com/posts/2012/01/15/fun-js/</link>
		<comments>http://jeffreysambells.com/posts/2012/01/15/fun-js/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 15:13:54 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=1405</guid>
		<description><![CDATA[There&#8217;s been a plethora of great little JavaScripts coming out lately. I&#8217;ve been collecting a few of them to use on various projects so I though I&#8217;d make a list (yes! a list!) and share what I&#8217;ve found. I haven&#8217;t included any big all encompassing libraries since I assume you already know about jQuery and [...]<p><a href="http://jeffreysambells.com/posts/2012/01/15/fun-js/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s been a plethora of great little JavaScripts coming out lately. I&#8217;ve been collecting a few of them to use on various projects so I though I&#8217;d make a list (yes! a list!) and share what I&#8217;ve found. I haven&#8217;t included any big all encompassing libraries since I assume you already know about <a href="http://jquery.com">jQuery</a> and the rest.</p>

<h2><a href="http://www.modernizr.com/">modernizer.js</a></h2>

<p>If you&#8217;re working with HTML5 and CSS3&#8211;and you should be&#8211;you&#8217;re probably wasting a lot of time if you&#8217;re not using <a href="http://www.modernizr.com/">Modernizer</a>. Modernizer gives you a quick and easy way to check exactly what browser or device features your visitors use using. I&#8217;d suggest reading <a href="http://www.alistapart.com/articles/taking-advantage-of-html5-and-css3-with-modernizr/">Taking Advantage of HTML5 and CSS3 with Modernizr</a> or <a href="http://webdesignernotebook.com/css/how-to-use-modernizr/">How to use Modernizr</a> and the <a href="http://www.modernizr.com/docs/">check out the documentation</a>.</p>

<h2><a href="http://filamentgroup.com/lab/respondjs_fast_css3_media_queries_for_internet_explorer_6_8_and_more/">respond.js</a></h2>

<p>Respond provides faster css3 media queries for internet explorer 6+. This will help you out when you&#8217;re following your <a href="http://www.abookapart.com/products/mobile-first">mobile first</a> <a href="http://www.alistapart.com/articles/responsive-web-design/">responsive design</a> techniques (you&#8217;re doing that too right? right?). Get the <a href="https://github.com/scottjehl/Respond">source here on GitHub</a> and then check out <a href="https://github.com/scottjehl/Respond#readme">the documentation</a>.</p>

<h2><a href="http://yepnopejs.com/">yepnope.js</a></h2>

<p>yepnope is a nice little script loader but I&#8217;d only recommend using it if you have a lot of scripts and each one is rarely used. A much better idea is to combine all your JavaScript&#8217;s into one compressed file so that you only need one http request to download everything (especially on mobile devices).</p>

<h2><a href="https://github.com/bartaz/impress.js">impress.js</a></h2>

<p>While impress may not help improve your site, this CSS3 powered interactive presentation tool will definitely help make client pitches rock. But, what about (Prezi)[prezi.com] you say? Go <a href="http://bartaz.github.com/impress.js">try the impress demo</a>. You&#8217;ll understand why it&#8217;s called &#8220;impress&#8221; (though I have a soft spot for <a href="http://vimeo.com/channels/kinetictypography">kinetic typography</a>). For another example and some excellent reading check out <a href="http://johnpolacek.github.com/WhatTheHeckIsResponsiveWebDesign-impressjs/">What The Heck Is Responsive Web Design</a>.</p>

<h2><a href="http://fgnass.github.com/spin.js/">spin.js</a></h2>

<p>Now here&#8217;s a great idea. How often do you need a nice little &#8220;spinner&#8221; loading animation? Gifs are so last decade so try this configurable, cross-browser JavaScript spinner with no images! Set a few properties and you&#8217;ll be loading in no time.</p>

<h2><a href="http://videojs.com/">video.js</a></h2>

<p>Again with the HTML5 scripts but now focused on video. You may or may not agree with <a href="http://www.apple.com/hotnews/thoughts-on-flash/">thoughts on flash</a> but you&#8217;ll probably like this impressive HTML5 video player. <a href="http://videojs.com/docs/">Drop it into</a> your <strike>simple</strike> html5 video markup and you&#8217;ll get a nice cross-browser ui&#8211;with a fallback to Flash just in case.</p>

<h2><a href="http://gildas-lormeau.github.com/zip.js/">zip.js</a></h2>

<p>A JavaScript library to zip and unzip files. Now you can confuse non-savvy computer users right in teh browser!</p>

<h2><a href="http://meltingice.github.com/psd.js/">psd.js</a></h2>

<p>Parse the Adobe Photoshop PSD files right in your browser. NOt sure what I&#8217;d do with it but it&#8217;s pretty neat. Drop a psd on <a href="http://meltingice.github.com/psd.js/">the demo page</a> and you&#8217;ll get a lit of all the layers in the file.</p>

<h2><a href="http://lab.hakim.se/zoom-js/">zoom.js</a></h2>

<p>zoom.js is a just an early experiment that allow you to quickly zoom in on DOM elements or points on a page. For example, click on any element on the <a href="http://lab.hakim.se/zoom-js/">demo page</a> to zoom in.</p>

<h1>jQuery Plugins</h1>

<p>Here&#8217;s a few more that are great but also require jQuery.</p>

<h2><a href="http://johnpolacek.github.com/scrollorama/">scrollorama.js</a></h2>

<p>Scrollorama is a fun plugin that helps you with &#8220;scrolly stuff&#8221; as the web site says. Scroll down <a href="http://johnpolacek.github.com/scrollorama/">the demo page</a> to see various example of transitions, pinning, parallax and more. But, remember, use this responsibly. Don&#8217;t make scrolling the <code>&lt;blink&gt;</code> tag of 2012.</p>

<h2><a href="http://letteringjs.com/">lettering.js</a></h2>

<p>I&#8217;m a bit of a typophile (yes, I know the current iteration of this blog design needs work) and I love tools that make web typography easier. Lettering provides fine grained control for properties like kerning, layout and more. The <a href="http://letteringjs.com/">gallery</a> on the site is better seen than described so after you&#8217;re impressed check out the <a href="https://github.com/davatron5000/Lettering.js/wiki">documentation here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2012/01/15/fun-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9734; Android ADK Resources</title>
		<link>http://jeffreysambells.com/posts/2011/05/18/android-adk-resources/</link>
		<comments>http://jeffreysambells.com/posts/2011/05/18/android-adk-resources/#comments</comments>
		<pubDate>Wed, 18 May 2011 16:00:55 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[How-To]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=1288</guid>
		<description><![CDATA[So, I&#8217;ve been playing with the Android Open Accessory Development Kit (ADK) and have realized there&#8217;s mot much out there in terms of available resources. Here&#8217;s the list of what I&#8217;ve found so far, I&#8217;ll add to it as I find more: Official Android ADK Guides Official Google Android ADK page ADK Components Getting Started [...]<p><a href="http://jeffreysambells.com/posts/2011/05/18/android-adk-resources/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;ve been playing with the Android Open Accessory Development Kit (ADK) and have realized there&#8217;s mot much out there in terms of available resources. Here&#8217;s the list of what I&#8217;ve found so far, I&#8217;ll add to it as I find more:</p>

<h2>Official Android ADK Guides</h2>

<ul>
<li><a href="http://developer.android.com/guide/topics/usb/adk.html">Official Google Android ADK page</a>

<ul>
<li><a href="http://developer.android.com/guide/topics/usb/adk.html#components">ADK Components</a></li>
<li><a href="http://developer.android.com/guide/topics/usb/adk.html#getting-started">Getting Started with the ADK</a></li>
<li><a href="http://developer.android.com/guide/topics/usb/adk.html#how">How an Accessory Communicates with an Android-powered Device in Accessory Mode</a></li>
<li><a href="http://developer.android.com/guide/topics/usb/adk.html#firmware">How the ADK board communicates with an Android-powered Device in Accessory Mode</a></li>
</ul></li>
</ul>

<h2>Related Android Guides</h2>

<ul>
<li><a href="http://developer.android.com/guide/topics/usb/accessory.html">USB Accessory Dev Guide</a></li>
<li><a href="http://developer.android.com/sdk/win-usb.html">Android USB driver</a></li>
</ul>

<h2>Videos</h2>

<ul>
<li><a href="http://www.youtube.com/watch?v=s7szcpXf2rE">Google I/O Session Video: Android Open Accessory API and Development Kit (ADK)</a></li>
</ul>

<h2>Arduino</h2>

<ul>
<li><a href="http://arduino.cc/en/Reference/HomePage">Arduino Language Reference</a></li>
<li><a href="http://arduino.cc/en/Reference/Libraries">Arduino Library Reference</a></li>
<li><a href="http://blog.makezine.com/arduino">Makezine Arduino Page</a></li>
</ul>

<h2>Hardware</h2>

<h3>Android Specific Components</h3>

<ul>
<li><a href="http://www.rt-net.jp/shop/index.php?main_page=product_info&amp;cPath=3_4&amp;products_id=1">RT Corp</a></li>
<li><a href="http://www.microchip.com/android">Microchip</a></li>
<li><a href="https://store.diydrones.com/ProductDetails.asp?ProductCode=BR-PhoneDrone">DIY Drones</a></li>
</ul>

<h3>Arduino Components</h3>

<ul>
<li><a href="http://arduino.cc/en/Main/Hardware">Boards</a></li>
<li><a href="http://www.makershed.com/SearchResults.asp?Cat=43">Maker Shed</a></li>
</ul>

<h2>Examples</h2>

<ul>
<li><a href="http://www.youtube.com/watch?v=Ub7newiu930">Robot from Google IO</a></li>
<li><a href="http://www.youtube.com/watch?v=GrE_JO5rXKA">5,000-pound labyrinth from Google IO</a></li>
<li><a href="http://www.youtube.com/watch?v=XEe3dYBj7RE">ADK Components</a></li>
</ul>

<p>Have any more that I missed? Add a comment and I&#8217;ll update the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2011/05/18/android-adk-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9734; Understanding the demokit.pde Arduino Sketch</title>
		<link>http://jeffreysambells.com/posts/2011/05/17/understanding-the-demokit-pde-arduino-sketch/</link>
		<comments>http://jeffreysambells.com/posts/2011/05/17/understanding-the-demokit-pde-arduino-sketch/#comments</comments>
		<pubDate>Tue, 17 May 2011 15:31:23 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=1274</guid>
		<description><![CDATA[Examples are great ways to learn a new language or technology. To demonstrate the functionality of the Android Open Accessory ADK, the kit comes with a demo Arduino Sketch that demonstrates how the device communicates with the Arduino Base Board and Android Demo Shield. Unfortunately I have yet to find any good documentation on the [...]<p><a href="http://jeffreysambells.com/posts/2011/05/17/understanding-the-demokit-pde-arduino-sketch/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p>Examples are great ways to learn a new language or technology. To demonstrate the functionality of the Android Open Accessory ADK, the kit comes with a demo Arduino Sketch that demonstrates how the device communicates with the Arduino Base Board and Android Demo Shield. Unfortunately I have yet to find any good documentation on the example and how it works so I thought I&#8217;d comment on the file for those that may not understand.</p>

<p>The post is in &#8220;blog&#8221; format with paragraphs shoved into the middle of code. For reference you can <a href="https://gist.github.com/975769">find the original <code>demokit.pde</code> file over in this Gist</a>.</p>

<h2>demokit.pde</h2>

<p>The Arduino language is based on C/C++ so the file starts off with the typical headers you&#8217;ll need for the various libraries used in the sketch (servos, LEDs, capacitive touch, USB, etc).</p>

<pre><code>#include &lt;Wire.h&gt;
#include &lt;Servo.h&gt;
#include &lt;Max3421e.h&gt;
#include &lt;Usb.h&gt;
</code></pre>

<p>These two are the ones you added to the Arduino application libraries <a href="http://a.arduino.com">when you set up your system for ADK development</a>.</p>

<pre><code>#include &lt;AndroidAccessory.h&gt;
#include &lt;CapSense.h&gt;
</code></pre>

<p>Next, you&#8217;ll  see several &#8216;#define&#8217; constants. These indicate which pins are attached to which features on the Android Demo Shield. If you look at the shield, you&#8217;ll notice each pin has a corresponding number. For example <code>#define LED3_RED 2</code> indicates that the third LED&#8217;s red component pin is using #2 on the shield.</p>

<p><figure><img src="http://jeffreysambells.com/wordpress/wp-content/uploads/2011/05/LED3_RED.png" alt="LED3 Red pin location" title="LED3_RED" /></figure></p>

<p>Technically you don&#8217;t need to do this and you could just use <code>2</code> throughout your code but defining a constant makes it much easier to read and understand the code when you use <code>LED3_RED</code> instead of referring to the board to see what pin <code>2</code> is.</p>

<pre><code>#define  LED3_RED       2
#define  LED3_GREEN     4
#define  LED3_BLUE      3

#define  LED2_RED       5
#define  LED2_GREEN     7
#define  LED2_BLUE      6

#define  LED1_RED       8
#define  LED1_GREEN     10
#define  LED1_BLUE      9

#define  SERVO1         11
#define  SERVO2         12
#define  SERVO3         13

#define  TOUCH_RECV     14
#define  TOUCH_SEND     15

#define  RELAY1         A0
#define  RELAY2         A1

#define  LIGHT_SENSOR   A2
#define  TEMP_SENSOR    A3

#define  BUTTON1        A6
#define  BUTTON2        A7
#define  BUTTON3        A8

#define  JOY_SWITCH     A9      // pulls line down when pressed
#define  JOY_nINT       A10     // active low interrupt input
#define  JOY_nRESET     A11     // active low reset output
</code></pre>

<p>Now it&#8217;s time to identify the actual accessory. Read my previous post on <a href="http://jeffreysambells.com/posts/2011/05/15/identifying-your-android-usb-accessory/">&#8220;Identifying Your Android USB Accessory
&#8220;</a> for more information but you can see here that the <code>demokit.pde</code> file identifies itself as version 1.0 of the Google DemoKit accessory.</p>

<pre><code>AndroidAccessory acc("Google, Inc.",
             "DemoKit",
             "DemoKit Arduino Board",
             "1.0",
             "http://www.android.com",
             "0000000012345678");
</code></pre>

<p>Now, all that&#8217;s left to do is initialize a few variables, setup the environment and then start the loop that will continuously run to evaluate the IO for the Arduion board.</p>

<pre><code>// Define an array for the servos
Servo servos[3];

// Initiate the touch sensor
// 10M ohm resistor on demo shield
CapSense   touch_robot = CapSense(TOUCH_SEND, TOUCH_RECV);

// Run the initial setup on the board
void setup();

// Loop and check for IO 
void loop();
</code></pre>

<h3>Initialization</h3>

<p>The <code>pinMode()</code> method is used to initialize the input and output pins on the Android Demo Shield. It configures the specified pin to behave either as an <code>INPUT</code> or an <code>OUTPUT</code>. Arduino pins default to <code>INPUT</code> so the mode doesn&#8217;t need to be explicitly set but its usually a good idea to do it anyway so that your code is clear and understandable.</p>

<p>For example, the <code>init_buttons</code> function identifies the pins for <code>BUTTON1</code>, <code>BUTTON2</code>, <code>BUTTON3</code> and <code>JOY_SWITCH</code> as input connections.</p>

<pre><code>void init_buttons()
{

    pinMode(BUTTON1, INPUT);
    pinMode(BUTTON2, INPUT);
    pinMode(BUTTON3, INPUT);
    pinMode(JOY_SWITCH, INPUT);
</code></pre>

<p>To identify the state of the buttons, a pin configured as an INPUT can have a <code>HIGH</code> or <code>LOW</code> value. Writing a <code>HIGH</code> value with will enable an internal 20K pullup resistor. Writing LOW will disable the pullup. The pullup resistor acts as a known value when no other input is present (such as when pressing the button). Later you can use <code>digitalRead()</code> to check the value to determine if the button has been pressed or not.</p>

<pre><code>    digitalWrite(BUTTON1, HIGH);
    digitalWrite(BUTTON2, HIGH);
    digitalWrite(BUTTON3, HIGH);
    digitalWrite(JOY_SWITCH, HIGH);
}
</code></pre>

<p>Output pins, such as the relays in <code>init_relays()</code> are also configured using the <code>pinMode()</code> function however no default value needs to be written to the relays because it is always told to be either on or off.</p>

<pre><code>// Initializes the relays as outputs
void init_relays()
{
    pinMode(RELAY1, OUTPUT);
    pinMode(RELAY2, OUTPUT);
}
</code></pre>

<p>The <code>digitalWrite()</code> method can also take varying values as inputs. For example, you may want to write an integer between 1 and 255 to represent the brightness of an LED. The <code>init_leds()</code> function sets all the LED pins as outputs and presets their output value to 1 (or bright).</p>

<pre><code>// Initialize the LED outputs
void init_leds()
{

    digitalWrite(LED1_RED, 1);
    digitalWrite(LED1_GREEN, 1);
    digitalWrite(LED1_BLUE, 1);

    pinMode(LED1_RED, OUTPUT);
    pinMode(LED1_GREEN, OUTPUT);
    pinMode(LED1_BLUE, OUTPUT);

    digitalWrite(LED2_RED, 1);
    digitalWrite(LED2_GREEN, 1);
    digitalWrite(LED2_BLUE, 1);

    pinMode(LED2_RED, OUTPUT);
    pinMode(LED2_GREEN, OUTPUT);
    pinMode(LED2_BLUE, OUTPUT);

    digitalWrite(LED3_RED, 1);
    digitalWrite(LED3_GREEN, 1);
    digitalWrite(LED3_BLUE, 1);

    pinMode(LED3_RED, OUTPUT);
    pinMode(LED3_GREEN, OUTPUT);
    pinMode(LED3_BLUE, OUTPUT);
}
</code></pre>

<p>The joystick controls are little tricker so I&#8217;m not going to go into it in this post. If you&#8217;re interested see the <code>init_joystick()</code> and related functions at the bottom of the <a href="https://gist.github.com/975769"><code>demokit.pde</code> file that comes with the kit</a>.</p>

<pre><code>void init_joystick(int threshold);
</code></pre>

<h3>Setup</h3>

<p>Now that all the necessary helper functions are defined we can look at the setup function. The <code>setup()</code> function begins serial communications with the device and then calls all the initialization methods you saw earlier.</p>

<pre><code>// These are a few variables to hold the state of the buttons.
byte b1, b2, b3, b4, c;

// Setup the board
void setup()
{
    // Begin communications.
    Serial.begin(115200);
    Serial.print("\r\nStart");

    init_leds();
    init_relays();
    init_buttons();
    init_joystick( 5 );
</code></pre>

<p>Next, <code>setup()</code> calibrates the capacitive touch sensor and sets the servos to their initial positions of 90 degrees.</p>

<pre><code>    // autocalibrate OFF
    touch_robot.set_CS_AutocaL_Millis(0xFFFFFFFF);

    servos[0].attach(SERVO1);
    servos[0].write(90);
    servos[1].attach(SERVO2);
    servos[1].write(90);
    servos[2].attach(SERVO3);
    servos[2].write(90);
</code></pre>

<p>Lastly, <code>setup()</code> assigns the current <code>HIGH</code> or <code>LOW</code> value of the buttons to <code>b1</code>, <code>b2</code>, <code>b3</code> and  <code>b4</code>. During the <code>loop</code> execution, these values will be compared to the values in the loop and used to determine if the button&#8217;s state has changed since the last loop.</p>

<pre><code>    b1 = digitalRead(BUTTON1);
    b2 = digitalRead(BUTTON2);
    b3 = digitalRead(BUTTON3);
    b4 = digitalRead(JOY_SWITCH);
    c = 0;
</code></pre>

<p>Now the setup power&#8217;s on the accessory.</p>

<pre><code>    acc.powerOn();
}
</code></pre>

<h3>Loop</h3>

<p>The <code>loop()</code> function is the heart beat of the Arduino Base Board. After creating and executing the <code>setup()</code> function, which is responsible for initializing the initial values, the loop begins it&#8217;s magic and loops consecutively, allowing the sketch to analyze and respond accordingly.</p>

<p>The loop in <code>demokit.pde</code> has two main responsibilities. First, if the device is connected, it will read any input and write output to the device as necessary. Second, if no device is connected it will reset all the initial values to await a new device connection.</p>

<pre><code>void loop()
{
    byte err;
    byte idle;
    static byte count = 0;
    byte msg[3];
    long touchcount;
</code></pre>

<p>Here it looks for a connection.</p>

<pre><code>    if (acc.isConnected()) {

        int len = acc.read(msg, sizeof(msg), 1);
        int i;
        byte b;
        uint16_t val;
        int x, y;
        char c0;
</code></pre>

<p>If the length of the input buffer from the attached Android device is greater than zero, the loop process the input command to determine what it should do.</p>

<pre><code>        if (len &gt; 0) {
</code></pre>

<p>The message format can be seen in the DemoKit Android App that also comes with the kit. If you take a look at the <code>sendCommand()</code> method in the <code>com.google.android.DemoKit.DemoKitActivity</code> class.  You&#8217;ll see something like this:</p>

<pre><code>...
buffer[0] = command;
buffer[1] = target;
buffer[2] = (byte) value; 
...
</code></pre>

<p>In the case of a LED or Servo command, the <code>command</code>&#8216;s value is <code>2</code> (<code>DemoKitActivity.LED_SERVO_COMMAND</code>), followed by the <code>target</code> and the <code>value</code> to associate with the target.</p>

<p>For example, you can see in the following code that the red, green and blue pins for each LED are updated, but only when <code>msg[0]</code> is 2 (<code>0x2</code>). The LED pin to update is defined in <code>msg[1]</code> (<code>0x0</code> thru <code>0x8</code> respectively) and the value is set using <code>msg[2]</code> and <code>analogWrite()</code>.</p>

<p>In the case of the value for a LED, the lower the value the brighter the light (or the higher the value the more black and darker the light). The DemoKit app on the Android device sends 255 when it wants a full bright light so the value is subtracted from  255 to set the appropriate value for &#8220;bright&#8221;.</p>

<pre><code>            // Assumes only one command per packet.
            if (msg[0] == 0x2) {
                if (msg[1] == 0x0)
                    analogWrite(LED1_RED, 255 - msg[2]);
                else if (msg[1] == 0x1)
                    analogWrite(LED1_GREEN, 255 - msg[2]);
                else if (msg[1] == 0x2)
                    analogWrite(LED1_BLUE, 255 - msg[2]);
                else if (msg[1] == 0x3)
                    analogWrite(LED2_RED, 255 - msg[2]);
                else if (msg[1] == 0x4)
                    analogWrite(LED2_GREEN, 255 - msg[2]);
                else if (msg[1] == 0x5)
                    analogWrite(LED2_BLUE, 255 - msg[2]);
                else if (msg[1] == 0x6)
                    analogWrite(LED3_RED, 255 - msg[2]);
                else if (msg[1] == 0x7)
                    analogWrite(LED3_GREEN, 255 - msg[2]);
                else if (msg[1] == 0x8)
                    analogWrite(LED3_BLUE, 255 - msg[2]);
</code></pre>

<p>The servo output uses the same <code>command</code> and is processed in the same if condition however setting the servo position is a little different. You can read more in the <a href="http://www.arduino.cc/en/Reference/Servo">Servo library</a> but the basics here are that the servo&#8217;s <a href="http://arduino.cc/en/Reference/ServoWrite"><code>write()</code> method</a> takes an angle for the servo and the <a href="http://www.arduino.cc/en/Reference/Map"><code>map()</code> method</a> is used to re-map the input value from one range (0-255) to another (0-180).</p>

<pre><code>                else if (msg[1] == 0x10)
                    servos[0].write(map(msg[2], 0, 255, 0, 180));
                else if (msg[1] == 0x11)
                    servos[1].write(map(msg[2], 0, 255, 0, 180));
                else if (msg[1] == 0x12)
                    servos[2].write(map(msg[2], 0, 255, 0, 180));

            } else if (msg[0] == 0x3) {
</code></pre>

<p>For the two relays on the Android Demo Shield, <code>msg[2]</code> is simply compared for a <code>HIGH</code> or <code>LOW</code> value and the board is updated accordingly.</p>

<pre><code>                if (msg[1] == 0x0)
                    digitalWrite(RELAY1, msg[2] ? HIGH : LOW);
                else if (msg[1] == 0x1)
                    digitalWrite(RELAY2, msg[2] ? HIGH : LOW);

            }

        }
</code></pre>

<p>At this point in the loop, all the input messages have been processed so the loop switches to checking all the output pins and sending any necessary messages to the device.  The message type for output is set to 1 and each individual output is checked.</p>

<pre><code>        msg[0] = 0x1;
</code></pre>

<p>For example, in the following code the state of <code>BUTTON1</code> is read into <code>b</code> and compared to <code>b1</code>. Earlier you saw how the read value of the pin associated with <code>BUTTON1</code> could be either <code>HIGH</code> or <code>LOW</code>. If the value of <code>b</code> differs from the value of <code>b1</code> (defined in <code>setup()</code> or in the previous run of the loop) then the state of the button has changed and the appropriate message is sent back to the connected Android device. At the same time, <code>b</code> is assigned to <code>b1</code> to indicate the new state for the next loop.</p>

<pre><code>        b = digitalRead(BUTTON1);
        if (b != b1) {
            msg[1] = 0;
            msg[2] = b ? 0 : 1;
            acc.write(msg, 3);
            b1 = b;
        }

        // Check button 2
        b = digitalRead(BUTTON2);
        if (b != b2) {
            msg[1] = 1;
            msg[2] = b ? 0 : 1;
            acc.write(msg, 3);
            b2 = b;
        }

        // Check button 3
        b = digitalRead(BUTTON3);
        if (b != b3) {
            msg[1] = 2;
            msg[2] = b ? 0 : 1;
            acc.write(msg, 3);
            b3 = b;
        }

        // Check for a press on the joystick button.
        b = digitalRead(JOY_SWITCH);
        if (b != b4) {
            msg[1] = 4;
            msg[2] = b ? 0 : 1;
            acc.write(msg, 3);
            b4 = b;
        }
</code></pre>

<p>Once all the digital reads for the buttons have completed, the demokit uses an <code>analogRead()</code> to determine the current values of the temperature sensor, the light sensor, the joystick and the capacitive touch sensor. At first I was confused by the use of a switch statement here until I realized the expense of an analog read. It takes about 100 microseconds to read an analog input, so the maximum reading rate is 10,000 times a second. That&#8217;s pretty good but we don&#8217;t want to slow things down unnecessarily, especially when environmental variables such as temperature and ambient light are not changing dramatically at a rapid pace. The <code>switch</code> and <code>count++ % 0x10</code> condition allows the loop to reduce the frequency of analog reads and only sample one analog read per loop.</p>

<pre><code>        switch (count++ % 0x10) {
        case 0:
            val = analogRead(TEMP_SENSOR);
            msg[0] = 0x4;
            msg[1] = val &gt;&gt; 8;
            msg[2] = val &amp; 0xff;
            acc.write(msg, 3);
            break;

        case 0x4:
            val = analogRead(LIGHT_SENSOR);
            msg[0] = 0x5;
            msg[1] = val &gt;&gt; 8;
            msg[2] = val &amp; 0xff;
            acc.write(msg, 3);
            break;

        case 0x8:
            read_joystick(&amp;x, &amp;y);
            msg[0] = 0x6;
            msg[1] = constrain(x, -128, 127);
            msg[2] = constrain(y, -128, 127);
            acc.write(msg, 3);
            break;

        case 0xc:
            touchcount = touch_robot.capSense(5);

            c0 = touchcount &gt; 750;

            if (c0 != c) {
                msg[0] = 0x1;
                msg[1] = 3;
                msg[2] = c0;
                acc.write(msg, 3);
                c = c0;
            }

            break;
        }
    } else {
</code></pre>

<p>As mentioned earlier, when a device is not connected (or was disconnected) the loop resets the outputs to the default values.</p>

<pre><code>        analogWrite(LED1_RED, 255);
        analogWrite(LED1_GREEN, 255);
        analogWrite(LED1_BLUE, 255);
        analogWrite(LED2_RED, 255);
        analogWrite(LED2_GREEN, 255);
        analogWrite(LED2_BLUE, 255);
        analogWrite(LED3_RED, 255);
        analogWrite(LED3_GREEN, 255);
        analogWrite(LED3_BLUE, 255);
        servos[0].write(90);
        servos[0].write(90);
        servos[0].write(90);
        digitalWrite(RELAY1, LOW);
        digitalWrite(RELAY2, LOW);
    }
</code></pre>

<p>Then the loop ends by delaying for a few milliseconds.</p>

<pre><code>    delay(10);
}
</code></pre>

<p>The <a href="https://gist.github.com/975769">remainder of the file</a> deals with the IO of the joystick. You can just take it as is and I&#8217;ll leave it until another post.</p>

<p>Hopefully this was a little helpful getting you started with the ADK and the demokit example.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2011/05/17/understanding-the-demokit-pde-arduino-sketch/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#9734; Identifying Your Android USB Accessory</title>
		<link>http://jeffreysambells.com/posts/2011/05/15/identifying-your-android-usb-accessory/</link>
		<comments>http://jeffreysambells.com/posts/2011/05/15/identifying-your-android-usb-accessory/#comments</comments>
		<pubDate>Mon, 16 May 2011 03:49:07 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=1260</guid>
		<description><![CDATA[When you create your first Android USB Accessory with the Android ADK, one of the first things you&#8217;ll need to do is identify your accessory when you connect it to your Android device. Within the Arduino sketch for your accessory, you identify your accessory in the AndroidAccessory object. AndroidAccessory(const char *manufacturer, const char *model, const [...]<p><a href="http://jeffreysambells.com/posts/2011/05/15/identifying-your-android-usb-accessory/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p>When you create your first Android USB Accessory with the Android ADK, one of the first things you&#8217;ll need to do is identify your accessory when you connect it to your Android device. Within the Arduino sketch for your accessory, you identify your accessory in the <code>AndroidAccessory</code> object.</p>

<pre><code>AndroidAccessory(const char *manufacturer,
                 const char *model,
                 const char *description,
                 const char *version,
                 const char *uri,
                 const char *serial);
</code></pre>

<p>For example, the DemoKit app that comes with the ADK identifies itself as version 1.0 of the Google DemoKit accessory:</p>

<pre><code>AndroidAccessory acc("Google, Inc.",
                 "DemoKit",
                 "DemoKit Arduino Board",
                 "1.0",
                 "http://www.android.com",
                 "0000000012345678");
</code></pre>

<p>You&#8217;re own app might looks something like this:</p>

<pre><code>AndroidAccessory acc("My App Company",
                 "CoolAccessory",
                 "CoolAccessory Arduino Board",
                 "1.0",
                 "http://www.example.com/CoolAccessory",
                 "0000000012345678");
</code></pre>

<p>The three key one&#8217;s you&#8217;ll need to remember are <code>manufacturer</code>, <code>model</code> and <code>version</code> as you&#8217;ll need to define these in you&#8217;re Android app so that the device can notify your app when your accessory is connected.</p>

<p>When you create your Android app, there&#8217;s a few steps you need to take. First, not every Android-powered device supports the USB accessory APIs. In fact, the Android Open Accessory ADK is only supported by Android OS 3.1 and 2.3.4 platforms. To identify that your app has USB features, you need to include a <code>&lt;uses-feature&gt;</code> element in your manifest to declare that your application uses the <code>android.hardware.usb.accessory</code> feature.</p>

<pre><code> &lt;uses-feature android:name="android.hardware.usb.accessory" /&gt;
</code></pre>

<p>Next, if you&#8217;re using the add-on library, add a <code>&lt;uses-library&gt;</code> element with <code>com.android.future.usb.accessory</code> for the USB accessory library.</p>

<pre><code>&lt;uses-library android:name="com.android.future.usb.accessory" /&gt;
</code></pre>

<p>and set the minimum SDK of the application to API Level 10. If you&#8217;re using <code>theandroid.hardware.usb package</code> then the <code>&lt;uses-library&gt;</code> isn&#8217;t necessary and you only need to set the minimum SDK to 12 .</p>

<p>Lastly, you&#8217;ll want your application to be notified when your accessory is attached. Specify an <code>&lt;intent-filter&gt;</code> and <code>&lt;meta-data&gt;</code> element pair for the <code>android.hardware.usb.action.USB_ACCESSORY_ATTACHED</code> intent in your main activity. Overall your manifest should look something like this:</p>

<pre><code>&lt;manifest ...&gt;
Â  Â  &lt;uses-feature android:name="android.hardware.usb.accessory" /&gt; 
Â  Â  &lt;uses-sdk android:minSdkVersion="&lt;version&gt;" /&gt;
Â  Â  ...
Â  Â  &lt;application&gt;
Â  Â  Â    &lt;uses-library android:name="com.android.future.usb.accessory" /&gt;
Â  Â  Â  Â  &lt;activity ...&gt;
Â  Â  Â  Â  Â  Â  ...
Â  Â  Â  Â  Â  Â  &lt;intent-filter&gt;
Â  Â  Â  Â  Â  Â  Â  Â  &lt;action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" /&gt;
Â  Â  Â  Â  Â  Â  &lt;/intent-filter&gt;
Â  Â  Â  Â  Â  Â  &lt;meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
Â  Â  Â  Â  Â  Â  Â  Â  android:resource="@xml/accessory_filter" /&gt;
Â  Â  Â  Â  &lt;/activity&gt;
Â  Â  &lt;/application&gt;
&lt;/manifest&gt;
</code></pre>

<p>The <code>&lt;meta-data&gt;</code> element references an XML resource file that includes the <code>manufacturer</code>, <code>model</code> and <code>version</code> you defined earlier in your Arduino sketch. Create an <code>accessory_filter.xml</code> resource file in the <code>res/xml/</code> directory with a <code>&lt;usb-accessory&gt;</code> element to identify your accessory.</p>

<pre><code>&lt;resources&gt;
    &lt;usb-accessory model="CoolAccessory" manufacturer="My App Company" version="1.0"/&gt;
&lt;/resources&gt;
</code></pre>

<p>Now, when you connect your accessory to the device android will send an intent to open an appropriate application. The best part is that more than one application can respond to a given intent so multiple apps could optionally respond for the same accessory.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2011/05/15/identifying-your-android-usb-accessory/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#9734; Android Open Accessory API and Development Kit</title>
		<link>http://jeffreysambells.com/posts/2011/05/13/android-open-accessory-api-and-development-kit/</link>
		<comments>http://jeffreysambells.com/posts/2011/05/13/android-open-accessory-api-and-development-kit/#comments</comments>
		<pubDate>Sat, 14 May 2011 02:21:05 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[How-To]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=1248</guid>
		<description><![CDATA[<p><figure title=""><img src="http://jeffreysambells.com/wordpress/wp-content/uploads/2011/05/IMG_2026-600x448.jpg" class="attachment-h5bp-post-image wp-post-image" alt="The parts of the Android ADK" title="Google IO Android ADK Arduino and Shield" /></figure></p>A co-worker was lucky enough to be invited to Google IO this year to promote our Lozzal Android app. That went great but while there, he snagged me one of the Android Open Accessory API and Development Kits (ADK)! Though he got to keep the sweet, sweet tablet which kills my idea of a home [...]<p><a href="http://jeffreysambells.com/posts/2011/05/13/android-open-accessory-api-and-development-kit/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p><figure title=""><img src="http://jeffreysambells.com/wordpress/wp-content/uploads/2011/05/IMG_2026-600x448.jpg" class="attachment-h5bp-post-image wp-post-image" alt="The parts of the Android ADK" title="Google IO Android ADK Arduino and Shield" /></figure></p><p>A co-worker was lucky enough to be invited to <a href="http://www.google.com/events/io/2011/">Google IO</a> this year to promote our <a href="https://market.android.com/details?id=com.lozzal">Lozzal Android app</a>. That went great but while there, he snagged me one of the <a href="http://a.android.com">Android Open Accessory API and Development Kits (ADK)</a>! Though he got to <a href="http://news.cnet.com/8301-30685_3-20061487-264.html">keep the sweet, sweet tablet</a> which kills my idea of a home automation panel on the kitchen wall.</p>

<p>I&#8217;m pretty excited about the Android ADK, especially since it&#8217;s based on one of the Maker&#8217;s favourite platform&#8212;Arduino. If you&#8217;re not sure why this is so awesome, I suggest reading the Makezine post on <a href="http://blog.makezine.com/archive/2011/05/why-google-choosing-arduino-matters-and-the-end-of-made-for-ipod-tm.html">Why Google Choosing Arduino Matters</a>. I looked into building external devices with iOS a few moths back but quickly discovered Apple requires special chipsets&#8211;which can&#8217;t be easily obtained by little indy hardware developers like myself. Now, with an easily accessible platform and relatively cheap hardware components, I have lots of projects I want to dive right into.</p>

<p>For those that didn&#8217;t get one, here&#8217;s a quick demo of what the Android ADK hardware includes (Sorry about the audio, didn&#8217;t have a mic):</p>

<iframe width="600" height="480" src="http://www.youtube.com/embed/XEe3dYBj7RE" frameborder="0" allowfullscreen></iframe>

<p>Included in the kit:</p>

<ul>
<li>A USB micro-controller board that is based on the Arduino Mega2560</li>
<li>Android Accessory demo Shield

<ul>
<li>Joystick</li>
<li>3 Buttons</li>
<li>3 RGB LEDs</li>
<li>Temperature Sensor</li>
<li>Light Sensor</li>
<li>Capacitive touch sensor</li>
<li>2 relays (24 VOC, 1A max)</li>
<li>2 servos (though the board has three connectors)</li>
</ul></li>
<li>AC Adapter</li>
<li>USB cable</li>
</ul>

<p>Before creating this demo video I only spent about 10 min <a href="http://developer.android.com/guide/topics/usb/adk.html">installing and setting up</a> the Arduino software, Android ADK components and the DemoKit app on the phone.  The initial setup is quite easy and you can be playing in minutes.</p>

<p>My only complaint (if you can call it that) is it would have been awesome to have more IO sensors, maybe IR (tv remote!), sound, or NFC on there. I guess it&#8217;s time I investigate all the other great <a href="http://www.arduino.cc/en/Main/ArduinoShields">Arduino shields</a> and see what else I can do.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2011/05/13/android-open-accessory-api-and-development-kit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#9734; Fun with iPhone Tracking Logs and Chrome WebGL Experiment</title>
		<link>http://jeffreysambells.com/posts/2011/05/12/fun-with-iphone-tracking-logs-and-chrome-webgl-experiment/</link>
		<comments>http://jeffreysambells.com/posts/2011/05/12/fun-with-iphone-tracking-logs-and-chrome-webgl-experiment/#comments</comments>
		<pubDate>Fri, 13 May 2011 03:26:06 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Maps]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=1236</guid>
		<description><![CDATA[I was a little intrigued by the then Google Chrome WebGL experiments demoed at Google I/O this past week so I grabbed some of the source code to play with it a little. After poking around I thought it might be fun to map out some of that infamous iPhone Location Tracking Data in the [...]<p><a href="http://jeffreysambells.com/posts/2011/05/12/fun-with-iphone-tracking-logs-and-chrome-webgl-experiment/">&#9734; Permalink</a></p>]]></description>
			<content:encoded><![CDATA[<p>I was a little intrigued by the then <a href="http://www.chromeexperiments.com/webgl">Google Chrome WebGL experiments</a> demoed at Google I/O this past week so I grabbed some of the source code to play with it a little.</p>

<p>After poking around I thought it might be fun to map out some of that infamous <a href="http://petewarden.github.com/iPhoneTracker/">iPhone Location Tracking Data</a> in the WebGL globe so I grabbed my <code>consolidated.db</code> file, exported the <code>CellLocation</code> table and ran it through this quick PHP script:</p>

<pre><code>&lt;?php

$data = explode("\n",file_get_contents("CellLocation.data"));

$magnitudes = array();

// Group like towers
$c = count($data);
for ($i = 0 ; $i &lt; $c ; $i++) {
    $ll = $data[$i];
    list($lat,$lng) = explode('|',$ll);
    $key = round($lat,2) . ',' . round($lng,2);

    if (array_key_exists($key, $magnitudes)) {
        $magnitudes[$key]++;
    }   else {
        $magnitudes[$key] = 1;
    }   
}

$json = '';
while (list($ll,$count) = each($magnitudes)) {
    $json .= str_replace('|',',', $ll);
    $json .= ',';
    $json .= $count / 100;
    $json .= ',';
    $json .= 11;
    $json .= ',';
}

echo '['.trim($json,',').']';
</code></pre>

<p>Dropping the output of the script in the place of the search results json file presented me with this:</p>

<p><figure><a href="http://jeffreysambells.com/wordpress/wp-content/uploads/2011/05/Screen-shot-2011-05-12-at-11.10.54-PM.png"><img src="http://jeffreysambells.com/wordpress/wp-content/uploads/2011/05/Screen-shot-2011-05-12-at-11.10.54-PM.png" alt="Visual of the iPhone tracking data on a globe." title="iPhone Tracking on WebGL Globe"/></a><figcaption>iPhone Tracking Data on the Google Chrome Experiment WebGL Globe</figcaption></figure></p>

<p>You can <a href="http://jeffreysambells.com/experiments/webgl-globe/globe-iphone/">play with the live WebGL version here if you want</a>. Now I just have to learn a little more WebGL to make the map zoom in and out.</p>

<p>UPDATE: Looking at the <code>globe.js</code> source, apparently you can zoom if you have a mouse with a wheel though it&#8217;s very pixelated.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2011/05/12/fun-with-iphone-tracking-logs-and-chrome-webgl-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9734; Breaking through the firewall with SSH</title>
		<link>http://jeffreysambells.com/posts/2010/09/17/breaking-through-the-firewall-with-ssh/</link>
		<comments>http://jeffreysambells.com/posts/2010/09/17/breaking-through-the-firewall-with-ssh/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 14:04:02 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=820</guid>
		<description><![CDATA[With mobile development I often find myself out-of-the-office away from the development resources I need on a daily basis. I was recently out-of-the-office (OK, I was at home sitting on my couch but close enough) and I needed to access a Windows machine at the office via Remote Desktop. The only problem was it was [...]]]></description>
			<content:encoded><![CDATA[<p>With mobile development I often find myself out-of-the-office away from the development resources I need on a daily basis. I was recently out-of-the-office (OK, I was at home sitting on my couch but close enough) and I needed to access a Windows machine at the office via Remote Desktop.  The only problem was it was behind a firewall in our companies internal 192.x.x.x network. Surprisingly, accessing it from home was quite simple.</p>

<p>I have a MacBook so I opened up the Terminal app and entered this:</p>

<pre><code>ssh -l jsambells -L 3390:192.168.1.100:3389 example.dev.box cat -
</code></pre>

<p>Then all I had to do on my MacBook was enter <code>localhost:3390</code> into Microsoft&#8217;s Remote Desktop Connection app and login to the Remote Desktop.</p>

<p>Huh?</p>

<p>This is what&#8217;s know as an <a href="http://en.wikipedia.org/wiki/Tunneling_protocol">SSH tunnel</a>. Basically it creates a secure connection that forwards a port on one machine to another. My above command contains several components:</p>

<ul>
<li><code>3390</code> is the local port on my MacBook that I&#8217;ll be using to connect to the Remote Desktop in the office. This could be any port above 1024 and below 32768. Doesn&#8217;t matter.</li>
<li><code>192.168.1.100</code> is the example IP address of the machine I want to access on the internal network. This IP must be accessible by the machine at <code>example.dev.box</code>.</li>
<li><code>3389</code> is the standard port number for Remote Desktop connections. </li>
<li><code>example.dev.box</code> is a publicly accessible machine that can also connect to the internal machine. </li>
<li><code>cat -</code> is a command that won&#8217;t finish so the connection stays alive.</li>
</ul>

<p>The trick here is that I needed a machine that could connect both the the internet at large and to the internal company network (which I happen to have at example.dev.box). The command uses an SSH tunnel to forward the traffic between <code>localhost:3390</code> and any connections to <code>192.168.1.100</code> on port <code>3389</code> of <code>example.dev.box</code>. Connecting locally at home to <code>localhost:3390</code> is the same as connecting to <code>192.168.1.100:3389</code> from <code>example.dev.box</code>.</p>

<p>You can use similar techniques to secure any traffic, such as your <a href="http://stopdesign.com/archive/2005/02/07/secure-email.html">email</a> or bypass firewall restrictions.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2010/09/17/breaking-through-the-firewall-with-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9734; A little bit of Git-Fu</title>
		<link>http://jeffreysambells.com/posts/2010/09/13/a-little-bit-of-git-fu/</link>
		<comments>http://jeffreysambells.com/posts/2010/09/13/a-little-bit-of-git-fu/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 02:53:21 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=791</guid>
		<description><![CDATA[I&#8217;m working on a Git project where I have several different repositories as submodules of another. I&#8217;ve decide that submodules are way too annoying to maintain (damn detached heads) and they&#8217;re not supported by the eclipse plugin so instead, I&#8217;m merging all the repos into one. Googling around I found several straight forward references for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a Git project where I have several different repositories as submodules of another. I&#8217;ve decide that submodules are way too annoying to maintain (damn <a href="http://sitaramc.github.com/concepts/detached-head.html">detached heads</a>) and they&#8217;re <a href="http://dev.eclipse.org/mhonarc/lists/egit-dev/msg01047.html">not supported by the eclipse plugin</a> so instead, I&#8217;m merging all the repos into one.</p>

<p>Googling around I found several straight forward <a href="http://stackoverflow.com/questions/277029/combining-multiple-git-repositories">references for doing just that</a>. The basic process is to modify your repo so that everything is in a sub-directory using this command:</p>

<pre><code>git filter-branch --index-filter 'git ls-files -s | sed "s-\t-&amp;newdir/-" |
    GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
    git update-index --index-info &amp;&amp;
    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
</code></pre>

<p>and then merge the various sub directories into one project. Perfect. Just what I needed. However, I spent a few hours trying to do so and ran into a few problems which I thought I&#8217;d share.</p>

<p>First, I was using Mac OS X and unbeknownst to me the <code>sed</code> command doesn&#8217;t support <code>\t</code> from the command line so <code>sed "s-\t-&amp;newdir/-"</code> in the above command was searching for a literal <code>t</code> instead of a tab. This messed up the new file paths in the <code>git ls-files -s</code> output so I had to find a workaround. Apparently the <code>\t</code> issue is due to posix or something and I tried several variations without luck so I moved to a Debian box that didn&#8217;t have this issue (I&#8217;d love to know how to fix it).</p>

<p>Second, the git repositories I&#8217;m working from were created from a large SVN import. In SVN, you can commit an empty directory to the repository so in several cases the commit in my repo didn&#8217;t have any files associated with it (this was always the case with the first commit that created the initial SVN repository). Git doesn&#8217;t allow you to commit empty directories&#8212;it must contain at least one file&#8212;so the above command&#8217;s <code>mv</code> portion failed when a file didn&#8217;t exists. I <a href="http://stackoverflow.com/questions/435646/how-do-i-combine-the-first-two-commits-of-a-git-repository">tried to remove or squash the offending commits</a> several different ways but always ran into more problems with conflicts or strange trees. Sitting back and trying to see the big picture, I broke down the command and realized that I could just check if the file existed before it was moved. This made a lot more sense:</p>

<pre><code>git filter-branch --index-filter 'git ls-files -s | sed "s-\t-&amp;newdir/-" |
    GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
    git update-index --index-info &amp;&amp;
    if test -f "$GIT_INDEX_FILE.new"; then mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE; fi' HEAD
</code></pre>

<p>That did the trick and I could proceed with merging my repos as I pleased.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2010/09/13/a-little-bit-of-git-fu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9734; Project: iPad Kiosk</title>
		<link>http://jeffreysambells.com/posts/2010/09/11/project-ipad-kiosk/</link>
		<comments>http://jeffreysambells.com/posts/2010/09/11/project-ipad-kiosk/#comments</comments>
		<pubDate>Sat, 11 Sep 2010 14:00:58 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[iPad]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=773</guid>
		<description><![CDATA[Recently, I was discussing the possibility of using an iPad as a kiosk to interact with a new online service we&#8217;re developing. The idea is very interesting as the touch screen device would offer us a great user experience that most people could easily understand. After doing a little research it seems that it&#8217;s physically [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I was discussing the possibility of using an iPad as a kiosk to interact with a new online service we&#8217;re developing. The idea is very interesting as the touch screen device would offer us a great user experience that most people could easily understand. After doing a little research it seems that it&#8217;s physically easy to get an iPad into a kiosk but the problems are in the software, not the hardware.</p>

<p>Like the iPhone, the iPad has only one primary button on the front of the device and a few buttons on the sides (for volume and on/off). The logistics of a kiosk mean people shouldn&#8217;t be allowed to randomly quit the app so you have to disable the iPad buttons by jailbreaking&#8212;and installing the appropriate software&#8212;or by disabling them physically (by covering them up). For physical barriers, there are a number of existing products such as the nice looking <a href="http://www.beyondkiosks.com/product.php?id=64">Beyond Kiosks</a>, the more portable <a href="http://www.gravityswitch.com/ibracket/">iBracket</a> or simple DIY projects like this <a href="http://www.flickriver.com/photos/ymbiont/4487329902/">wooden kiosk stand</a>. I&#8217;m not sure how the wooden kiosk stand would hold up to abuse but, hardware aside, it comes down to the software problems.</p>

<p>To run successfully as a kiosk, the kiosk app needs to be the only app running on the device without the ability to exit the app in any way (at least without removing the iPad from its enclosure). The iPad doesn&#8217;t offer an easy way to force an app to stay open but you can be sneaky and do things like launching the app again whenever it happens to close:</p>

<pre><code>-(void)applicationWillTerminate:(UIApplication *)application {
    [application openURL:[NSURL URLWithString:@"mykioskapp://"]];
}
</code></pre>

<p>Note: Doing this would probably get an app rejected from the App Store.</p>

<p>Care must also be taken not to include any way for a user to accidentally jump into another application, such as the web browser or the email app. If someone gets out of the kiosk application they&#8217;ll probably be confused but, more importantly, they&#8217;ll be stuck with no way to get back because the only buttons that would return them to the kiosk application have been disabled or covered up.</p>

<p>The other software problem is dealing with the Apple App Store submission process. Running in a kiosk could initially be great since a kiosk app probably isn&#8217;t going to be distributed through the app store. Instead, it will be easily loaded on each kiosk directly. Both a development distribution or an over-the-air Ad-Hoc distribution would work but each come with their own problems. Anyone who has dealt with Ad-Hoc or development distributions knows that the certificate process isn&#8217;t fun and just when you think you have it sorted out, the provisioning profiles on the devices expire and you have to repeat the process. It would be great to bypass the burden of the Apple App Store rules and regulations but to do so someone will need to be on-site to update the app on a regular (monthly) basis as the development or Ad-Hoc distributions expire or the app itself needs updates.</p>

<p>The idea of an iPad kiosk is obviously possible and there are a few existing companies already using it for things such as <a href="http://mhkiosk.malaysiaairlines.com/">ticket sales</a> or <a href="http://www.pointabout.com/2010/07/09/new-disney-store-opens-with-pointabouts-destination-disney-ipad-kiosk-experience">product information</a>.  If I get any further into the project I&#8217;ll post some updates and let you know how it goes.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2010/09/11/project-ipad-kiosk/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>&#9734; Android vs iPhone development decisions</title>
		<link>http://jeffreysambells.com/posts/2010/05/20/android-vs-iphone-development-decisions/</link>
		<comments>http://jeffreysambells.com/posts/2010/05/20/android-vs-iphone-development-decisions/#comments</comments>
		<pubDate>Fri, 21 May 2010 04:34:15 +0000</pubDate>
		<dc:creator>Jeffrey Sambells</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mobile]]></category>

		<guid isPermaLink="false">http://jeffreysambells.com/?p=646</guid>
		<description><![CDATA[Release early, release often (sometimes abbreviated RERO) is a software development philosophy that emphasizes the importance of early and frequent releases in creating a tight feedback loop between developers and users. &#8212; Wikipedia To begin let me say that I&#8217;m both a web developer and a mobile application developer and I LOVE the &#8220;release early, [...]]]></description>
			<content:encoded><![CDATA[<blockquote>
  <p>Release early, release often (sometimes abbreviated RERO) is a software development philosophy that emphasizes the importance of early and frequent releases in creating a tight feedback loop between developers and users.</p>
</blockquote>

<p>&#8212; Wikipedia</p>

<p>To begin let me say that I&#8217;m both a web developer and a mobile application developer and I LOVE the &#8220;release early, release often&#8221; philosophy for web development. RERO allows me to make quick updates and improvements and add great new features for all my users. RERO is great. It&#8217;s awesome. It works and all the developers and users using the application are happy.</p>

<p>On the other hand, I loath RERO when it comes to SDK&#8217;s. It&#8217;s just a flawed and utterly terrible idea when there&#8217;s no clear and very accessible upgrade path for end users. As a web developer, I would not be happy if Microsoft decided to release IE9, IE10 and IE11 in the span of a year. My workload would more than triple, my user base would fragment and I&#8217;d be endlessly adding kludges for each new version. Unfortunately this is what&#8217;s starting to happen with the Android SDK and, as a mobile developer, I&#8217;m starting to get worried.</p>

<h2>Android OS</h2>

<p>To understand how RERO can harm adoption let&#8217;s take a look at the <em>public</em> Android SDK release schedule:</p>

<ul>
<li>API Level 2, Android 1.1 &#8212; February 2009</li>
<li>API Level 3, Android 1.5 &#8212; April 2009</li>
<li>API Level 4, Android 1.6 &#8212; September 2009</li>
<li>API Level 5, Android 2.0 &#8212; October 2009</li>
<li>
<ul>
<li>API Level 6, Android 2.01 &#8212; December 2009</li>
</ul></li>
<li>API Level 7, Android 2.1 &#8212; January 2009</li>
<li>API Level 8, Android 2.2 &#8212; May 2009</li>
</ul>

<p>Wow. In the past fifteen months (a little over a year) there have been seven public releases of different versions of the Android SDK. That doesn&#8217;t include carrier or manufacturer revisions with different user interfaces. It&#8217;s not that I&#8217;m not happy with the advancements of the SDK. They&#8217;re all wonderful and obviously the Android team is working really hard but there&#8217;s a problem. If we take a look at Google&#8217;s published Platform Versions stats and we can see where developers have a tough decision:</p>

<p><img src="http://jeffreysambells.com/wordpress/wp-content/uploads/2010/05/chart.png" alt="" title="Android Platform Chart" width="460" height="250" class="aligncenter size-full wp-image-648" />
&#8212; <a href="http://developer.android.com/resources/dashboard/platform-versions.html">Source</a></p>

<p>More than 50% of the Android install base is still using version 1.6 or less. As a developer what should I do? If I choose to take advantage of the latest and greatest SDK I get less than half of the devices! But still, the bigger problem is there is no clear and easy upgrade path for those bottom 50% to get the newer OS version. Neither of my Google supplied development phones (which are only a year old) can be upgraded without a lot of illicit hacking and deep developer knowledge.</p>

<p>The Android OS is in deep trouble until there&#8217;s an easy way to upgrade the OS on every device that runs it.</p>

<h2>iPhone OS</h2>

<p>Now contrast this situation with iPhone OS. Apple has been lambasted by developers for their tight control and strict NDA rules regarding beta releases but in comparison to the situation with Android isn&#8217;t it better? The NDA period allows the SDK to be flushed out, before it is &#8220;publicly&#8221; available so that there is one complete well oiled version that all developers can target across a large set of devices.</p>

<p>The <em>public</em> iPhone SDK release timeline is also much longer:</p>

<ul>
<li>SDK 1.0 &#8211; June 2007 (not public)</li>
<li>SDK 2.0 &#8211; July 2008</li>
<li>SDK 3.0 &#8211; June 2009</li>
<li>
<ul>
<li>SDK 3.1 &#8211; September 2009</li>
</ul></li>
<li>
<ul>
<li>
<ul>
<li>SDK 3.1.2 &#8211; October 2009</li>
</ul></li>
</ul></li>
<li>
<ul>
<li>
<ul>
<li>SDK 3.1.3 &#8211; February 2010</li>
</ul></li>
</ul></li>
<li>SDK 3.2 &#8211; April 2010</li>
</ul>

<p>Major iPhone releases are spaced a year apart (with a few minor releases in-between) allowing developers to actually develop and release an app before the SDK changes.</p>

<p>The iPhone has another big advantage and it solves the problem of distribution as I alluded to earlier. iPhone users use iTunes to sync their devices and add content. The process of syncing the device also checks for updates and allows <em>all</em> iPhone OS devices (iPhones, iPod Touches, iPads) to download the latests version of the OS. As a result the March 2010 iPhone Platform Versions stats look very developer friendly:</p>

<p><img src="http://jeffreysambells.com/wordpress/wp-content/uploads/2010/05/Screen-shot-2010-05-20-at-4.01.22-PM.png" alt="" title="iPhone Platform Chart" width="439" height="310" class="aligncenter size-full wp-image-650" />
&#8212; <a href="http://metrics.admob.com/wp-content/uploads/2010/04/AdMob-Mobile-Metrics-Mar-10.pdf">Source</a></p>

<p>That&#8217;s only 5% of users who have NOT upgraded to at least 3.0 and 86% who are using one of the latest two (as of March) 3.1 minor versions. How great is that? Not only does 3.1 contain great features, I can actually use them and hit 86% of my users right away.</p>

<h2>The Result</h2>

<p>Recent trends are showing that Android OS based devices are passing Appleâ€™s iPhone OS devices to be the No. 2 smartphone operating system in the U.S.&#8212;After RIM&#8217;s Blackberry OS:</p>

<ul>
<li>RIMâ€™s BlackBerry OS at 36 percent;</li>
<li>Android at 28 percent;</li>
<li>Apple at 21 percent.</li>
</ul>

<p>&#8212;<a href="http://www.npd.com/press/releases/press_100510.html">source</a></p>

<p>I say as a developer I don&#8217;t care. The number of devices per OS is a great marketing number for Google and Apple to fight over but as a developer&#8212;who wants to get the most out of the SDK&#8212;I care about the <em>version</em> of the OS on the devices. If I want to use the latest and greatest SDK&#8217;s I&#8217;ll take Apple&#8217;s 80% of 21% over Google&#8217;s 30% of 28%.</p>
]]></content:encoded>
			<wfw:commentRss>http://jeffreysambells.com/posts/2010/05/20/android-vs-iphone-development-decisions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

