Two dimensional ScrollView for MonoDroid

There is no two dimensional scroll view for Android out of the box – the one that lets user scroll in both horizonal and vertical direction. There are either horizontal (HorizontalScrollView) or vertical (ScrollView) but not both. After some Googling around I’ve found that devs were mosty experimenting with combining HorizontalScrollView within ScrollView. This approach didn’t work for me and even if it did it has some drawbacks (such as scrolling is rectriected by one of the two directions at the same time).

At this point I was considering creating my own proper ScrollView from scratch but luckily I’ve stumbled across an implementation of the same idea by Matt Clark. The only problem was that I am on Mono For Android and Matt’s implementation is in pure java. Plus I didn’t have a clue whether his solution actually worked. Nevertheless I did convert his java code to C#/Mono For Android and voila, it worked almost immediately (after an hour or so of manual conversion – damn those java’s getters and setters instead of properties).

Attached are the C# sources in case anybody else needs it.

TwoDScrollView.cs (50.08 kb)

NT Konferenca 2012 lectures schedule for mobile devices

I’ve created a simple ASP MVC 4/jQuery Mobile UI web site that helps you with NT Konferenca 2012 lectures schedule if you have a mobile device (now, who doesn’t?). Note that it isn’t a well thought, thoroughly and carefully crafted site. Instead it is a quick and simple one, actually it took me an hour (thanks to wonderful tools – VS2010, NuGet and technologies - .net 4.0, OData, WCF Data Service, jQuery Mobile UI, ASP MVC 4 and so forth).

Feel free to browse the lectures schedule through ntk.rthand.com. I might add additional features in next days – feedback me if you’d like to see a feature.

Updated Righthand's utilities for managing Intel Rapid Storage Technology

I’ve updated my tools for managing IRST and dedicated page as well. Command line utility now displays arrays, volumes, disks, RAID support and ports.

It is also in line with the latest IRST 10.8.0.1003 drivers .

Noteworthy change is that the utilities require .net 4.0 – see the dedicated page for installation instructions and other info.

Expect much more in the future.

Here is a dedicated page to the tools.

SignalR client on Mono for Android

While SignalR is a great library for push notifications it has one “flaw”. There is no included Android client implementation currently, and by Android I mean Mono For Android. Luckily SignalR is an open source project and I decided to see how hard is to make it Mono For Android compatible. It turns out that it is pretty simple.

Here is the recipe (tested on Mono For Android 4.0.x):

  • SignalR depends on Newtonsoft.Json library (free, open source) developed by James Newton-King. Again, there is no Android port included with the original library but there is a port that works fine on Mono For Android. Get it here.
  • Get SignalR client sources. Create new Mono For Android class library and import all (WindowsPhone version of the project) files. Add WINDOWS_PHONE conditional compilation symbol to Project Properties/Build. Then reference the Newtonsoft.Json libary.
  • Mono For Android is currently missing TaskExtensions class required for unwrapping tasks. Get the sources for this class here. I assume it will appear in Mono For Android sooner or later. Add this class to the library and add proper using statements if/where necessary.

That’s it. You are now ready to receive SignalR push notifications.

Here is how you create a PersistentConnection (server part), and here is client code (that runs fine on Mono For Android).

Download the libraries and sources below

 MonoForAndroid.SignalR.Client.zip (1.40 mb)

Righthand Dataset Debugger Visualizer updated to 1.0.6

Here is the list of what’s have been added/changed in 1.0.6.:

  • better handling of a single DataTable - now, when table is part of a dataset, it loads entire dataset and jumps to the selected table. Note that when committing changes in this scenario, only changes in selected DataTable will be committed.
  • minor bug fixes

Go, grab v1.0.6 from dedicated page and visit forums as well.

Realtime graph for WPF

You know the Task Manager’s CPU Usage History graph that shows CPU utilization over time? Try that type of the graph in WPF and you’ll realize that it isn’t as easy as it should be due to the WPF’s performance for real time graphs. Which sucks due to the way WPF works. Even with 3rd party you’ll have hard time to find a graph fast enough to cope with even more than few hundred samples.

Hence I’ve decide to build my own real time graph. It is based on Direct2D because Direct2D is much faster when it comes to presenting the graphical result. However, merging Direct2D into WPF is, again, not an easy task as it should be (hint to MS – there should be native WPF support for hosting Direct2D output). Anyway, I found the article Using Direct2D with WPF on CodePlex. It comes with sources which I use. Those sources require Windows API CodePack(WACP), a bug ridden set of managed API’s to various, otherwise unsupported, features (MS went with this approach (if it works, it works, if it doesn’t fix it by yourself) instead of providing an official support). The WACP binaries I provide are compiled from 1.1. sources with some bug fixed regarding DirectCompute.

Here is a snapshot from a graph showing a sinusoide as a product of many samples (the attached example contains required code and binaries).

realtimechart

I utilize a combination of Direct2D and samples optimization which yields smooth result even with million and more samples.

 

Required code

Create a class that implements IGraphItem interface. This class will hold a single sample through Time and Value property. Time typically represents a time elapsed since the start and it is expressed in millisecond while Value is a double and holds whatever value.

public class RealtimeGraphItem : IGraphItem
{    
    public int Time { get; set; }
    public double Value { get; set; }
}

Configure RealtimeGraphControl like

xmlns:rg="clr-namespace:Righthand.RealtimeGraph;assembly=Righthand.RealtimeGraph"
...
<rg:RealtimeGraphControl x:Name="Graph" AxisColor="Blue" AxisWidth="1"      VerticalLinesInterval="5" VerticalLabelsStep="2"  SpanX="100"
      MaxY="250" MinY="50"  HorizontalLinesInterval="10"/>

where SpanX is time span expressed in seconds telling the graph how many seconds are shown.

Finally create a BindingList<RealtimeGraphItem> source and bind it to Graph.SeriesSource property (BindingList is required as it has the event ListChanged that is used to trigger rendering update of the graph). And that’s it. When you add new items to the source the graph will automatically reflects the new state.

 

Requirements

.net 4.0

Dowload

Attached are binaries and the sources for the Example project.

Let me know what you think.

RealtimeGraph_1_0.zip (1.31 mb)

Burning a bootloader to a (Arduino’s) Atmega CPU

One of the many uses of an Arduino board is using it as an ISP (In-System Programmer). Which means burning bootloaders or programs without use of a bootloader directly to the ATmega CPU.

Why would somebody need to do that? Here is a real example.

I bought a 9 Degrees of Freedom Razor IMU a while ago. It is an Arduino compatible microcontroller with sensors in reality. Anyway, a small batch of these came with the wrong bootloader and I was lucky to get one of these. So, instead of sending it back and getting a new one I’d chose a simpler way. Burn the proper bootloader. There are ISPs out there that do the job just fine but for me it was an one time gig, thus I decided to go with an Arduino Mega ADK (which I have and I’ll refer to it simply as MegaADK) as an ISP.

A word of caution. This procedure worked for me. You might have a different hardware and it might not work well for you.

How to

  1. Download ArduinoISP sketch that lives in Examples folder of Arduino IDE (using latest version – 1.0) to MegaADK.
  2. Connect MegaADK and Razor through SPI. (note: You will need to solder some pins to enable SPI on Razor). Pin 1 on Razor is marked with a white line (here you can find a diagram for SPI header).
    Connect (from MegaADK to Razor) MISO->MISO, MOSI->MOSI, SCK->SCK and SS->RESET. Power for Razor is brought through USB (using 3.3V FTDI Basic Break board) but you can use other power sources.

    razor
    Razor with marked pin 1 (blue) and SPI header (yellow)
    (original photo taken from Sparkfun)
  3. Using Arduino IDE select Tools/Programmer/Arduino as ISP and a target Tools/Board, which is Arduino Pro or Pro Mini (3.3V, 8Mhz) w/ ATmega328 in my case since ATmega328p is used on Razor.
  4. If everything worked properly you’d hit Tools/Burn Bootloader. But there is a bug in Arduino libraries that come with version 1.0. For some reason you have to find HardwareSerial.cpp source file (located in [Arduino setup folder]\hardware\arduino\cores\arduino. Edit the 43th line which goes like "#define SERIAL_BUFFER_SIZE 64” to “#define SERIAL_BUFFER_SIZE 128”. If the buffer isn’t set to 64 the burn process will most probably stop when it tries to burn data pages with error like this:
    avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64
  5. Hit the Tools/Burn Bootloader and wait for half a minute and there you go, a fresh bootloader is burned to the Razor and it can be programmed using classic Arduino way again.

Photo of my setup:

IMG_0424

On the left is Razor, on the centre is Arduino Mega ADK and on the right is a bread board for three LEDs that signal the status of the ISP (green, red and yellow signalling the burning in progress).

Using Arduino BT

I think that it is quite possibly to use the Arduino BT (Bluetooth version). I am mentioning BT version because it has an interesting quirk and a feature.

Reset pin

A program mode LED mentioned above is attached by default to pin 7. The problem is that pin 7 on BT version is used to reset the bluetooth module and shouldn’t be used for anything else. Even if you don’t connect the LED it will reset the bluetooth module and thus drop the connection between Arduino IDE and ArduinoBT once the burn process begins.

The remedy is quite simple. Before downloading ArduinoISP sketch to the ArduinoBT (step 1) you should modify the sources by changing the pin used for signalling the program mode. There are two occurrences:

#define LED_PMODE 7 and the other in void setup() procedure (not sure why the later isn’t using the former). Change number 7 to any other suitable pin and the Bluetooth connection won’t drop anymore.

Serial port speed

Bluetooth communication in ArduinoBT is supposed to run at 119200 bauds, but the ArduinoISP sketch is using 19200 bauds. Simply change the value in void setup() procedure to Serial.begin(119200);

There you go, ArduinoBT is a functioning ISP now.

Hope this article will help somebody.

Mounting Samsung Galaxy S on the bicycle

The challenge of mounting your smartphone on the bicycle is much bigger than one would assume. There is one rule though – avoid cheap mounting solutions otherwise the Gorilla glass will have to show its strength. There are few solutions, one of those is using RAM Mount holders which are supposed to be of a great quality and strength. They have a zillion of various combinations of these.

The proper one for my phone and the bicycle is called RAM Mount Adjustable Rugged Universal Finger Grip Holder Cradle for Cell Phone and Smartphone Mobile Devices (product number RAM-HOL-UN4U). What a name, huh? Note that’s just the cradle and it is universal. To mount it on the bicycle you’ll need the proper bicycle mount which goes by name of RAM EZ-ON/OFF™ Bicycle Mount with Dual Strap Base and Swivel Diamond Base Adapter (product name RAP-274-1U). Or even better, buy those two together as RAM EZ-ON/OFF™ Handlebar Mount (product name RAP-274-1-UN4U) to save a few bucks. I bought it from Ram-mount Slovenia.

After assembling and mounting it on the bicycle I have these observations.

The good

  • both cradle and mount are strong, good quality
  • assembling and mounting is straightforward
  • it rotates 360 degrees (albeit nor freely, it has predefined positions)
  • it would fit a variety of smartphones and other devices
  • interchangeable pieces
  • grips doesn’t interfere with phone buttons (not tested yet on the move)

The bad

  • looks big and not too aesthetic
  • due to the mounting mechanism it might not align (alignment might be off by a bit, but that’s can be adjusted I think)
  • it is not water proof (no protection) – but it wasn’t meant to be
  • expensive
  • a bit too high for Galaxy S. However this shouldn’t be an issue as lateral “fingers” won’t let it move anyway.

That said I didn’t yet take a ride with it due to the bad weather conditions (rain, rain and rain) but it certainly looks to me a very solid solution. The phone won’t fall off the bike, that’s for sure.

Here are few photos of the mounted phone next to the excellent Exposure Strada Mk.3 front light on my Cannondale M700. Now just waiting for the rainy period to finish as I am looking forward to test it.

 

RAM Mount for smart phoneRAM Mount for smart phone

RAM Mount for smart phoneRAM Mount for smart phone

RAM Mount for smart phoneRAM Mount for smart phone

RAM Mount for smart phone