Passcode Lock Screen for iOS

I have designed a small library (with its test project) that lets you implement a passcode lock screen on iOS. The library is compatible with iPod Touch, iPhone and iPad. And it is very easy to use.
EAPasscodeLock* passcodeManager = [[EAPasscodeLock alloc] init];
UIViewController* plViewController = [passcodeManager passcodeViewControllerWithCode:@"1234" cancellable:YES hintText:nil maxRetries:4 delegate:self];
[self presentModalViewController:plViewController animated:NO];

There is a protocol you should implement, with only one obligatory method, that sends messages to the main view.
@protocol EAPasscodeLockProtocol
@required
// Called when the passcode is entered correctly after dismissing the passcode View Controller
-(void)passcodeDidUnlockedSuccessfully;
@optional
// Called when the passcode is entered correctly before dismissing the passcode View Controller
-(void)passcodeWillUnlockedSuccessfully;
// Called when a passcode entered is incorrect
-(void)passcodeFailedToUnlock;
// Called when the cancel button was pressed and after the passcode View Controller is dismissed
-(void)passcodeLockWillBeCancelled;
// Called when the passcode was entered incorrectly too many times
-(void)passcodeFailedWithTooManyAttempts;
@end
Here a few screenshots of the iPad UI

Empty passcode screen

Typing the code

Wrong passcode message

Find the lastest version on GitHub: https://github.com/eaceto/EAPasscodeLock

Android USB Host + USB VCP Driver [Part 3]

The Abstraction Layer

Once the prototype works and could establish a great communication between the Xoom and the FT232 IC, I decided to separate the project in order to let anyone creates a VCP Driver adding just a few methods.
The Abstraction Layer is present in the USB VCP Library for Android. It consists of 5 classes as you can see in the following picture:

VCPDriver

It is the main class. It represents the driver which lets the user connect and disconnect from the device. It also handles the low level connection and disconnection from the USB Device, and provides 5 abstract methods.

The user should call “connect” with a valid RS232 Configuration and a (may be null) object that implements the Async. Receveiver Interface. The “disconnect” method should be used in order to de-initialize variables but must call VCPDriver.closeDevice() in order to release all the USB stack.

 
“transfer” is a generic method that lets the user do synchronised transactions. The user can call this method in order to send and/or receive a package from the device.
“initialize” should be called from “connect” and will perform several controlTransfer commands in order to setup the device (including the RS232 configuration).

Finally, the AsyncReceiver is an interface with a very simple method. If your class implements this interface, you will receive async information from the driver.
As the VCPDriver has some abstract methods, all the class is abstract. So for every IC manufacturer, you should create a specialised Driver class, as I have created the FT232Driver class.
 
 

Android USB Host + USB VCP Driver [Part 2]

(Un)fortunately I have just signed a NDA (Non-Disclosure Agreement) with FTDI Chip in order to develop the Android version of their FT(2)232 chip.

This agreement was approved by FTDI so I cannot publish either the documentation I have just received, or the source code I develop based on that documentation.
I will go on writing about my experience developing the USB VCP driver for Android entirely on Java, and  may be as a result of the project an obfuscate binary will be published in order to communicate with the FT(2)232 family.
One more thing to mention: FTDI writes very clear and nice documentation.

Android USB Host + USB VCP Driver [Part 1]

I have connected a USB device that creates a USB VCP profile to my Motorola Xoom in order to enable my Xoom apps to interface with RS232 devices.
My small test program shows the following details for the USB device:

Model: /dev/bus/usb/002/002
Id: 2002
Class: 0
SubClass: 0
Protocol: 0
VendorId: 1659
ProductId: 8963
Number of Interfaces: 1
>> Interface 0 -> 3 Endpoints

With all the information we can tell the device to open a custom application when the USB device is attached. To do so, the following information should be added to the ‘activity’ tag in the Manifest.

<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/usb_device_filter" />

The XML file is a resource file that contains information about the USB Device, that should be placed in /res/xml

<resources>
<usb-device vendor-id="1659" product-id="8963" class="0" subclass="0"
 protocol="0"/>
</resources>

When the activity starts, it can retrieve the USB Device information by calling:

device = (UsbDevice)getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE);

If the device is not null, then you can open an UsbInterface and get the UsbEndpoint in order to read and write information.

How Android sees an attached USB Device

In the long way that my project must walk, I decided to start testing some small things in order to understand how the Android USB Host API and Open Accessory API (two different things) work.
Basically the USB Host API lets your Android device acts as a computer. With this API you can connect from a Bluetooth USB adapter to any standard USB device that you can find in a store. The Open Accessory API works the other way, your Android acts as a device, so you have to connect a USB Host controller in the other side. I don’t find this second approach very useful. First because not all the microcontrollers in the world support USB Host (Remember, your Android is a Device for the Open Accessory API) Second because it does not allow seemless development of a product using a computer and a natural port to Android using the USB Host API. I still cannot find three nice examples of when I will prefer to use my Tablet as a USB Device, but I can find millions of application for my Tablet (and Phone) to be a USB Host.
So in this short post, I will show you how it a USB Device attached to a  Honeycomb-enabled device looks like. Take special attention to the fact that even though Android 2.x has an option USB toolkit, and the classes have the same name, they belong to a different package (so the imports are not the same).
The Motorola Xoom with Android 3.2 is USB Host capable, and even thought I connected a USB keyboard and it didn’t work in the OS, the following short example demonstrates that the Motorola Xoom detects a USB Bluetooth adapter.

When attaching the USB Bluetooth adapter the following message can be seen using “logcat” (connected via TCP as the USB port is busy with the adapter)



 

Debugging Android wirelessly

Recently I flashed my Motorola Xoom with Android 3.2 in order to start playing with USB Host API and Open Accessory API, but both functionalities are implemented on the unique USB port that the Xoom has. This is not a problem when you own a Dock, or you own a Acer A500 which has one USB host and one USB device. Debugging an Android application using abd can be done wirelessly over WiFi using the followings instructions.

When debugging applications that use USB accessory or host features, you most likely will have USB hardware connected to your Android-powered device. This will prevent you from having an adb connection to the Android-powered device via USB. You can still access adb over a network connection. To enable adb over a network connection:

  1. Connect the Android-powered device via USB to your computer.
  2. From your SDK platform-tools/ directory, enter adb tcpip 5555 at the command prompt.
  3. Enter adb connect <device-ip-address>:5555 You should now be connected to the Android-powered device and can issue the usual adb commands like adb logcat.
  4. To set your device to listen on USB, enter adb usb.

 

webOS template project + Python + PyGame = Happy Developers

So I have created a sample C project for webOS 2 that bundles all your python files into an ipk (so you can distribute this app using the App Catalog) and also launched the Python interpreter when you click on it!
The only condition is that you have to copy all the Python interpreter + WebOS API + PyGame into /media/internal. You can do this just following this simple steps
1] Download this compressed files that contains: Python, PyGame and WebOS API to your computer
Python + PyGame for WebOS (Binaries)
2] Unpack and copy “python” directory to the root directory of your SD Card (must previously mount the phone as Mass Storage Device)
3] Download PDL-Python Template
PDL Template Project
4] Modify, add source code…. IMPORTANT: modify app name, package name
5] Copy the binary to “release”
6] Copy all python source code to “release” (or just work in that directory
7] Create a package with palm-package
8] Install it with palm-install
Have fun!
 

A picture is worth a thousand words…

Running Python from a SSH session on the Pre2

The python program…

 
 
 
 
 
 
 
Running a simple Python program on the Mac

Running the same simple Python program on the Pre2

The C code that launches the Python script (this code was embedded into a ipk file with the Python code)