C# – XBox 360 Controller library with a sample application

Created an easy to use XBox 360 Controller library in C# (with a sample application) using the SharpDX.XInput managed .NET wrapper of the DirectX API.

 https://github.com/okmer/XBoxController

Screenshot of the sample application.
Screenshot of the sample application.

A BUG in SharpDX.XInput ci-ci217, resulting in issues with the  left Thumb Stick, Left Trigger, and Right Trigger! Please stick to SharpDX.XInput v4.1.0-ci184 for now.

using System;
 
using Com.Okmer.GameController;
 
namespace XBoxSampleConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            XBoxController controller = new XBoxController();
 
            Console.WriteLine("XBox 360 Controller (Press ENTER to exit...)");
 
            //Connection
            controller.Connection.ValueChanged += (s, e) => Console.WriteLine($"Connection state: {e.Value}");
 
            //Battery
            controller.Battery.ValueChanged += (s, e) => Console.WriteLine($"Battery level: {e.Value}");
 
            //Buttons A, B, X, Y
            controller.A.ValueChanged += (s, e) => Console.WriteLine($"A state: {e.Value}");
            controller.B.ValueChanged += (s, e) => Console.WriteLine($"B state: {e.Value}");
            controller.X.ValueChanged += (s, e) => Console.WriteLine($"X state: {e.Value}");
            controller.Y.ValueChanged += (s, e) => Console.WriteLine($"Y state: {e.Value}");
 
            //Buttons Start, Back
            controller.Start.ValueChanged += (s, e) => Console.WriteLine($"Start state: {e.Value}");
            controller.Back.ValueChanged += (s, e) => Console.WriteLine($"Back state: {e.Value}");
 
            //Buttons D-Pad Up, Down, Left, Right
            controller.Up.ValueChanged += (s, e) => Console.WriteLine($"Up state: {e.Value}");
            controller.Down.ValueChanged += (s, e) => Console.WriteLine($"Down state: {e.Value}");
            controller.Left.ValueChanged += (s, e) => Console.WriteLine($"Left state: {e.Value}");
            controller.Right.ValueChanged += (s, e) => Console.WriteLine($"Right state: {e.Value}");
 
            //Buttons Shoulder Left, Right
            controller.LeftShoulder.ValueChanged += (s, e) => Console.WriteLine($"Left shoulder state: {e.Value}");
            controller.RightShoulder.ValueChanged += (s, e) => Console.WriteLine($"Right shoulder state: {e.Value}");
 
            //Buttons Thumb Left, Right
            controller.LeftThumbclick.ValueChanged += (s, e) => Console.WriteLine($"Left thumb state: {e.Value}");
            controller.RightThumbclick.ValueChanged += (s, e) => Console.WriteLine($"Right thumb state: {e.Value}");
 
            //Trigger Position Left, Right 
            controller.LeftTrigger.ValueChanged += (s, e) => Console.WriteLine($"Left trigger position: {e.Value}");
            controller.RightTrigger.ValueChanged += (s, e) => Console.WriteLine($"Right trigger position: {e.Value}");
 
            //Thumb Positions Left, Right
            controller.LeftThumbstick.ValueChanged += (s, e) => Console.WriteLine($"Left thumb X: {e.Value.X}, Y: {e.Value.Y}");
            controller.RightThumbstick.ValueChanged += (s, e) => Console.WriteLine($"Right thumb X: {e.Value.X}, Y: {e.Value.Y}");
 
            //Rumble Left, Right
            controller.LeftRumble.ValueChanged += (s, e) => Console.WriteLine($"Left rumble speed: {e.Value}");
            controller.RightRumble.ValueChanged += (s, e) => Console.WriteLine($"Right rumble speed: {e.Value}");
 
            //Rumble 0.25f speed for 500 milliseconds when the A or B button is pushed
            controller.A.ValueChanged += (s, e) => controller.LeftRumble.Rumble(0.25f, 500);
            controller.B.ValueChanged += (s, e) => controller.RightRumble.Rumble(0.25f, 500);
 
            //Rumble at 1.0f speed for 1000 milliseconds when the X or Y button is pushed
            controller.X.ValueChanged += (s, e) => controller.LeftRumble.Rumble(1.0f, 1000);
            controller.Y.ValueChanged += (s, e) => controller.RightRumble.Rumble(1.0f, 1000);
 
            //Rumble at the speed of the trigger position
            controller.LeftTrigger.ValueChanged += (s, e) => controller.LeftRumble.Rumble(e.Value);
            controller.RightTrigger.ValueChanged += (s, e) => controller.RightRumble.Rumble(e.Value);
 
            //Wait on ENTER to exit...
            Console.ReadLine();
        }
    }
}

Allseas – Innovation opens beers

Toying with an industrial robot at the office 😉

R&D Eindhoven (a.k.a. Inspection & Robotics) opens the Friday “borrel” beers with their new Fanuc M-710iC/45M Robot in combination with a Cognex In-Sight 2000 Vision Sensor.

R&D Eindhoven is part of the Innovation Department of Allseas Engineering B.V.

Duck Hunt VR (for the HTC Vive)

My first little Unity 3D Virtual Reality project, inspired by my old friend the Nintendo Entertainment System. Please keep in mind the I have never used Unity 3D before, so this is my first sandbox application…

Download link to DuckHuntVR Alpha 04: http://tinyurl.com/hb3u42x

This Alpha 04 release incorporated a lot of used feedback from the Vive subreddit: https://www.reddit.com/r/Vive/

In particular the feedback gathered during this live coding session: https://www.reddit.com/r/Vive/comments/4pbx4x/duck_hunt_vr_for_the_htc_vive_alpha_03_this_is_a/

DuckHuntVR game scene
DuckHuntVR Alpha 04 game scene.
Duck Red
Duck Red shot (with visible “blocks”).
Duck Green
Duck Green flying (with head-shot collider).
Duck Blue
Duck Blue flying.
Triple duck dog
Triple duck dog (only with default green ducks for now).
Zapper EU version.
Zapper EU version.
Zapper US version.
Zapper US version.

C# – MutableWhen Extension for the Task Parallel Library (TPL)

This is a little playful MutableWhenAny and MutableWhenAll extension for the Task Parallel Library (TPL), using a ObservableCollection.

The extension makes it possible to add or removed tasks to/from an ObservableCollection<Task> while the MutableWhenAny or MutableWhenAll is used to wait on the tasks in this (mutable) collection.

 https://github.com/okmer/MutableWhen

It’s not super useful in practice, but a nice little exercise that combines to cool C# features into a fun asynchronous “magic” trick.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Threading;
using System.Threading.Tasks;
 
namespace Com.Okmer.Extensions.ObservableCollectionOfTask
{
    public static class ObservableCollectionOfTaskExtention
    {
        private const int INFINITE = -1;
 
        public static async Task MutableWhenAll(this ObservableCollection<Task> collection)
        {
            await MutableWhenSomething(collection, Task.WhenAll);
        }
 
        public static async Task MutableWhenAny(this ObservableCollection<Task> collection)
        {
            await MutableWhenSomething(collection, Task.WhenAny);
        }
 
        private static async Task MutableWhenSomething(this ObservableCollection<Task> collection, Func<IEnumerable<Task>, Task> whenSomething)
        {
            Task waitAllTask = null;
            Task helperTask = null;
 
            bool isCollectionChanged = false;
 
            do
            {
                //Cancellation on collection changed event
                var cts = new CancellationTokenSource();
                var cancelActionHandler = (sender, arg) => cts.Cancel(false);
                collection.CollectionChanged += cancelActionHandler;
 
                //Current collection
                waitAllTask = whenSomething(collection);
 
                //Wait on current collection or collection changed event
                try
                {
                    helperTask = Task.Delay(INFINITE, cts.Token);
                    await Task.WhenAny(waitAllTask, helperTask);
                }
                finally
                {
                    isCollectionChanged = cts.IsCancellationRequested;
                    cts.Cancel(false);
                    cts.Dispose();
                    collection.CollectionChanged -= cancelActionHandler;
                }
            }
            while (isCollectionChanged);
 
            //Return the WaitAll on collection results
            await waitAllTask;
        }
    }
}

A simple example application that demonstrates the MutableWhenAll extension on an observable collection of tasks. The longest running task is added to the observable collection after MutableWhenAll is called, but the MutableWhenAll will complete only when all tasks (included this longest running task) are completed.

using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
 
using Com.Okmer.Extensions.ObservableCollectionOfTask;
 
namespace MutableWhenAllTest
{
    class Program
    {
        static void Main(string[] args)
        {
            ObservableCollection<Task> tasks = new ObservableCollection<Task>();
 
            Task t1 = Task.Run(async () => { await Task.Delay(1000); Console.WriteLine("t1"); });
            Task t2 = Task.Run(async () => { await Task.Delay(2000); Console.WriteLine("t2"); });
            Task t3 = Task.Run(async () => { await Task.Delay(3000); Console.WriteLine("t3"); });
 
            tasks.Add(t1);
            tasks.Add(t2);
 
            Task a1 = tasks.MutableWhenAll();
 
            tasks.Add(t3);
 
            a1.ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    Console.WriteLine("Canceled");
                }
 
                if (t.IsFaulted)
                {
                    Console.WriteLine("Faulted");
                }
 
                if (t.IsCompleted)
                {
                    Console.WriteLine("Completed");
                }
            });
 
            a1.Wait();
 
            Console.ReadLine();
        }
 
    }
}

InnoFaith – 3D.js front-end for embedded devices

SVG vector bases, touchscreen enabled, animated, and 3D.js driven front-end, running on an “embedded” Raspberry-Pi that is sampling 21 USB connected skin moisture sensors (each containing an array of 256×300 sample points).

3D.js SVG front-end data visualisation

The system is running battery power in a bag pack, carried by the human test subject. De system is hosting a live measurement data as a web service using a Wifi AP hosted by WiFi USB dongle connected to the Raspberry Pi, in connection with the 21 USB connected skin moisture sensors.

3D.js SVG front-end status visualisation

System status (including the external battery) can also be monitored through the same web interface (running fullscreen on a iPad).

EvilDir, create an EVIL named directory in Windows

A little “fun” Qt5 console application to create a directory (a.k.a. folder) ending with a space character (” “). This directory can not be removed with standard Windows tools, including most console applications.

#include <QCoreApplication>
#include <QDir>

int main(int argc, char *argv[])
{
  QCoreApplication a(argc, argv);

  QString evil_dir_name("Remko is a little Evil !!! ");

  for(int i=1; i<a.arguments().count(); i++)
  {
    if(a.arguments().at(i).compare("-d", Qt::CaseInsensitive) != 0)
    {
      evil_dir_name = a.arguments().at(i);
      evil_dir_name.append(" ");
      break;
    }
  }

  if(a.arguments().contains("-d"))
  {
    if(QDir(evil_dir_name).exists())
    {
      QDir().rmdir(evil_dir_name);
    }
  }
  else
  {
    QDir().mkdir(evil_dir_name);
  }
 
  return 0;
}

InnoFaith – OBSERV 520 iOS App

The skin diagnostics suite bundled with the OBSERV 520. This iPad based skin diagnostics suite uses the Bluetooth 4.0 Low Energy (BLE) to communicate with the OBSERV 520 by Sylton, and uses the iPad camera in combination with GPU accelerated image filters to visualise a broad range of skin concerns.

Overview of the OBSERV 520 iOS App

App Store link: https://itunes.apple.com/us/app/observ-520/id781554722

Sylton (InnoFaith) product information: https://www.sylton.com/observ

InnoFaith – AVEAL 210/220 iOS App

Skin care consultation suite for Point-of-Sale applications using the AVEAL 210/220. An iPad based skin care consultation suite, that combines questioners and measurements (using a bluetooth connected MFi+iAP measurement device), to provide an end-user with a skin type description. The goal is to provide a smooth and fast interface, with intuitive data visualisations.

App Store link: https://itunes.apple.com/us/app/aveal/id674486824

Sylton (InnoFaith) product information: https://www.sylton.com/aveal

Color Picker 1.1

I build a simple Color Picker 1.1 application that samples the pixel color under the mouse cursor point (because I needed it). The application is a stand alone (static build) Qt5 application with some minor Win32 API stuff, to sample the color at the cursor position.

ColorPicker 1.1

The application supports a number of RGB based color formats and formating formats. The application can run in the background, and used the CTRL+1, CTRL+2, and CTRL+3 hotkey combinations to sample a color in one of its three sample slots. The CTRL+SHIFT+1, CTRL+SHIFT+2, and CTRL+SHIFT+3 hotkey combinations can be used to copy the sample slot content to the clibboard. This enables easy copy and paste access to the sampled color values.

Coffee Tray 1.0 App for the iPad

Your relationships with your colleagues is important! Provide some work delight by getting a round of coffee once in a while (or get some colleague to do it for you).

Coffee Tray 1.0 main screen

This application will help you to remember and transport the hot beverage of choice for up-to five colleagues (plus one additional beverage for your self). Make great use of the perfectly flat surface of your own (or the companies) iPad.

Coffee Tray 1.0 icon

The current version provides a width range of hot beverages to choose from:
– Coffee black
– Coffee sugar
– Coffee creamer
– Coffee sugar & cream
– Bean coffee black
– Bean coffee sugar
– Cappuccino
– Cappuccino sugar
– Espresso
– Espresso sugar
– Chocolate
– Chocolate sugar
– Tea
– Tea sugar
– (Hot) Water

Start using the full office environment potential of your iPad today, and download this application!

Coffee Tray 1.0 selection screen

Apples reason to not approve the application for the App Store:
“We found your app encourages behavior that could result in damage to the user’s device, which is not in compliance with the App Store Review Guidelines.

Specifically, your App encourages the user to transport hot liquids on the device.”