8BitDo controller input in MonoGame (and Steam)

And you thought this blog was dead? I’m back 🙂

To business: I recently bought two 8bitdo Nintendo Controllers (8Bitdo Crissaegrim NES30 PROnes30-pro to use with RetroPi (works like a charm by the way).

However, to get them to work on my computer was something else.

The controllers don’t talk very nicely with your PC, so Steam and Monogame basically say ‘$$$$ you’ when you try to use the controller. However, the solution came in the form of this nifty tool: x360ce.

Ok, now what? Play steam games?!

The thing to know with x360ce is that you need to place the executable in each folder of the game(s) you’d like to play with your computer.

Paste the exe there, launch it, let it create the necessary files, test the controller and presto: you can now launch the game (from within steam if you also want your steam controllers to work) and the games will now detect your controller as if it were an Xbox 360 controller. (protip: this also works if you’re using the controller wireless, even with two of them connected without wires)

Pressing lots of stuff on the controller and simultaneous trying to take a screenshot...not easy, try it yourself!

Pressing lots of stuff on the controller and simultaneous trying to take a screenshot…not easy, try it yourself!

Monogame as well?

Yup, the same trick here. Simply put the x360ce exe in your debug/bin folder, launch it, and suddenly you can type fancy code such as (source) :

 if (capabilities.IsConnected)
            {
                // Get the current state of Controller1
                GamePadState state = GamePad.GetState(PlayerIndex.One);

                // You can also check the controllers "type"
                if (capabilities.GamePadType == GamePadType.GamePad)
                {
                    if (state.IsButtonDown(Buttons.A))
                        Exit();

Hooray for this. On to toying around with this sweet nostalgic controller

A cheaper Freewrite: some linuxnoob tips

Not having the funds to buy myself a Freewrite (formerly known as HemingWrite) I blew the dust from an old, but still working netbook (Samsung N150) and followed this great tutorial “How to turn your laptop into a typewriter“.

Here’s some handy tips if you want to redo the tutorial yourself

After install black screen

Apparently the Ubuntu Server is very barebones and on my netbooks it simply boots to a blank screen with a blinking cursor. Nothing more. To get started, you need to openup a terminal using ctrl+alt+F1. Yeah, I’m a linux noob.

Only boots using usb stick 😦

I followed the tutorial as is and discovered that my fresh Ubuntu wouldn’t boot unless I inserted the original USB-stick from which I had installed Ubuntu in the first place. The problem? The Ubuntu installer installed Grub on the stick instead of on the master harddisk.
This can be remedied simply by using the command:

sudo grub-install /dev/sda

Autologin and boot to terminal

The part about configuring tty1 to automatic login doens’t work anymore in more recent Ubuntu Server version. What you will need to do is oveeride the getty.service, as explained here.

First:

sudo systemctl edit getty@tty1

Then add the following content:


[Service]

ExecStart=

ExecStart=-/sbin/agetty --autologin yourusername --noclear %I 38400 linux

Type=idle

Save and exit.

Next, you will want to change the bootloader, grub, settings:

sudo nano /etc/default/grub

and change the GRUB_CMDLINE_LINUX_DEFAULT value to text.

Next up, write the changes to grub:

sudo update-grub

Connecting to wifi is real hard

Most modern wifi networks have WPA or WPA2 security, which is a bit of a pain in the a$$ to get connected to using a terminal-only shell.
Luckily a nifty tool called “nmtui” exist which is basically a text-based UI network configurator.It can be installed using:

sudo apt-get install network-manager

and can then be started by typing:

nmtui

Getting battery status

Use upower as explained here.

Twoway databinding to a MongoDB collection in WPF

I’ll show how to have a two-way databinding between a templated listbox and a MongoDB collection.
I’m finally got around toying with MongoDb.What I’ll show next might not be the most correct way, but it works for me.

Setup

I have a Listview defined in XAML with a datatemplate:

        <ListBox Name="mylistbox">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Naam, Mode=TwoWay}"></TextBox>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

I created an Entity class (can be a composite if you wish) which is is simple POCO with INotifyPropertyChanged implented. This Entity class well be serialized to my MongoDB collection as-is. Explained here, for example:

        public class Entity
        {
            public string Naam { get; set; }
        }

Retrieve the data and databind

Next up, we need to retrieve the data using a query (coll being my collection a retrieved earlier on (not shown)):

var query = coll.AsQueryable<Entity>().ToList();

The ToList part is important.This will ensure that we get a simple list of Entity objects as our ItemSource and not an IQueryable, otherwise the next part won’t work.

Write changes to database

You can now edit your data in your listbox and once you are ready, you can update all the changes to your MongoDB collection:

            foreach (var item in mylistbox.ItemsSource)
            {
                coll.Save(item);
            }

What’s on my Windows Phone – my favourite apps

I’m often get asked what apps I have installed on my phone. After explaining I have a Windows Phone 8 (Lumia 720) the question usually results in an awkward “erm..okay, nevermind”. But sometimes a fellow Microsoft enthousiast can be found. It is for these people that I have compiled a list of the apps I have on my ‘start menu’ (e.g. use-a-lot-apps) and those installed (e.g. handy-apps) So without further ado: Read more of this post

Oldschool CMD: deleting all files of a type with exceptions

Just some oldschool trickery: using the command prompt in windows (even works in dos! 🙂 ) it’s very easy to delete all the files of a certain type except those having a specifc name I wan’t to keep. Imagine I need to recursively delete all the jpg files in a folder and subfolders, except those named “folder.jpg”. The following command does this:

del /s dir *.jpg  /s | find /i /v "folder.jpg"

Why I put this on my blog? Because I might need it for future reference 😀

A clickable Windows Phone slider

The default behavior of the Windows Phone Slides control doens’t allow a user to click on the slider where the value should be set to. Instead, tapping anywhere on the slider will simply result in the slider incrementing by it’s default or given incrementsetting.

Following small piece of code shows how to have the wanted behavior by responding to the Tap- event of the Slider (named mySlider in the following codepiece).

        private void UIElement_OnTap(object sender, GestureEventArgs e)
        {
           if (mySlider.Orientation == System.Windows.Controls.Orientation.Horizontal)
            {
                var pos = e.GetPosition(mySlider).X;
                var width = mySlider.ActualWidth;
                mySlider.Value = (pos/width)*mySlider.Maximum;
            }
            else
            {
                var pos = e.GetPosition(mySlider).Y;
                var height = mySlider.ActualHeight;
                mySlider.Value =(1- (pos / height) )* mySlider.Maximum;
            }
        }

Creating an Intellisense compatible enum-based Dependency Property

Actually, this post has a way too fancy title , because in fact I will merely show that enum-based dependency properties are IntelliSense compatible “out-of-the-box”. (by the way, if you know all about dependcy properties: simply read the line in bold and you’ll know all there is to know).

When creating a (WP7/SL/WPF) usercontrol, one often ends up creating one more dependency properties (DP). Most of the times you only want a discrete set of possible values that can be assigned to the DP. The logical choice then of course is to have an enum-based DP.

Now, for the Intellisense to work it is important that you define the enum type OUTSIDE the usercontrols class. For example, suppose we have define the following enum:

public enum GraphTypes {Default, Point, Line}

Now, all that remains is to add a DP that uses this enum (remember that you can use the ‘dependencyproperty’ snippet that comes with VS):

        public static readonly DependencyProperty GraphTypeProperty =
            DependencyProperty.Register("GraphType", typeof (GraphTypes), typeof (GraphControl), new PropertyMetadata(GraphTypes.Default));

        public GraphTypes GraphType
        {
            get { return (GraphTypes) GetValue(GraphTypeProperty); }
            set { SetValue(GraphTypeProperty, value); }
        }

Once you now add the usercontrol elsewhere in your xaml-code, IntelliSense will happily show what values can be assigned to the DP:

There we go. That’s all there was too it.

Next post I’ll show how to create a WP7 user control to plot graphs using data binding. Consider some of the code here a sneak preview.