Develop for the First NFC Game Controller: Flitchio

A guest blog by David Ferrand, SUPENTA

NFC is amazing. In its shortest definition, it’s a technology that allows communication between two nearby devices. It has been in our smartphones for years, and we are only starting to see very nice uses, like storing information in everyday objects or paying with your phone. When you think of it, NFC has the potential to be so much smarter, because it not only enables two devices to communicate, it can also wirelessly power a nearby circuit, whatever it is, as long as it has an antenna. NFC is both power and communication.

This combination opens a world of possibilities. We at SUPENTA realized the benefits of a device that would be battery-less, connector-free and always close to the user’s phone. We have built Flitchio, a smartphone case that has a built-in game controller, and it is entirely powered by NFC. You simply snap it on the back of your phone to use it. Since it has no battery, it is portable. It has two pressure-sensitive buttons and two analogue joysticks, and it connects to Android so you can play dozens of games and pilot drones out of the box. What’s more important: it is an open platform for developers, so you can implement your new ideas through the Flitchio Software Development Kit (SDK).

Flitchio is the first smartphone case with built-in game controller

The Flitchio SDK is a simple and lightweight Android library. It enables your app to communicate with Flitchio, receive events from it and poll its state at any time. In this blog post, I want to introduce you to development for Flitchio.

Basic initialization

The Flitchio SDK is no different than the libraries you are already used to as it is publicly available on JCenter. Simply follow the installation process on our GitHub page: it is straightforward. Once you have added it, the API is accessible from your Android activities and services. The FlitchioController is the object that you use to access Flitchio. Here is an example of a typical initialize/terminate cycle in an Activity:

public class MainActivity extends Activity {
    private FlitchioController mFlitchioController;

    protected void onCreate(Bundle savedInstanceState) {
        ...
        mFlitchioController = FlitchioController.getInstance(this);

        try {
            mFlitchioController.onCreate();
        } catch (final FlitchioManagerDependencyException e) {
            // Version incompatibility between SDK and Flitchio app
        }
    }

    public void onDestroy() {
        mFlitchioController.onDestroy();
        ...
    }
}
 Receiving events from Flitchio

To start receiving events, such as button press/release or joystick move, you simply need to register a FlitchioListener. In this example, the MainActivity itself implements the listener so it directly receives the event callbacks:

protected void onResume() {
    ...
    mFlitchioController.onResume(this); // Registration of the listener
}

protected void onPause() {
    mFlitchioController.onPause(); // Unregistration of the listener
    ...
}

public void onFlitchioButtonEvent(Button src, ButtonEvent event) {
    // src is BUTTON_TOP or BUTTON_BOTTOM
    // event has pressure between 0.0 and 1.0
}

public void onFlitchioJoystickEvent(Joystick src, JoystickEvent event) {
    // src is JOYSTICK_TOP or JOYSTICK_BOTTOM
    // event has X and Y coordinates
}

public void onFlitchioStatusChanged(boolean isConnected) {
    // Triggered when Flitchio has just connected or disconnected
}
 Polling the state of Flitchio

In some apps (and in a game, actually most of the time), you’d actively poll the state of Flitchio in a loop rather than wait for events. That is possible too, by retrieving the latest snapshot from FlitchioController:

FlitchioSnapshot snapshot = mFlitchioController.obtainSnapshot();

if (snapshot.getJoystickX(JOYSTICK_TOP) == 0.0 &&
    snapshot.getJoystickY(JOYSTICK_TOP) == 0.0) {
    // JOYSTICK_TOP is in central position
}

if (snapshot.getButtonPressure(BUTTON_BOTTOM) > 0.5) {
    // BUTTON_BOTTOM is halfway pressed
}
Conclusion

It literally takes less than one hour to integrate Flitchio SDK to your project: it is extremely lightweight and uses concepts that are common to any Android developer (e.g. event listening). I presented the Flitchio SDK for pure Android, but we also have a Flitchio Unity plug-in that makes it even easier for game developers working on the Unity engine.

The Flitchio SDK has recently been open-sourced on GitHub, with complete documentation and samples to come. You are now able to implement your novel game and app ideas, taking advantage of the tangible control and pressure-sensitivity features that this NFC case offers!

We can’t wait to see more smart uses of NFC like Flitchio– hoping that it’ll help to spread and strengthen the support of NFC on all smartphone platforms.

About our guest blogger:
David Ferrand is Software Engineer at SUPENTA, where he is in charge of the Android development. He’s passionate about the technical challenges and opportunities that NFC represents. His constant focus is to create intuitive user experiences to make the (IT) world a better place.

Share

Leave A Comment?

You must be logged in to post a comment.