河北快3

Scott Hanselman

Showing Video on an Optimus Mini Three

February 6, '07 Comments [13] Posted in Coding4Fun | Programming | Reviews | Screencasts | Tools
Sponsored By

I got frustrated with MSBUILD today so I took a lunch break to clear my mind and decided to play with my Optimus Mini Three (user's manual). The hardware is really lovely. Sincerely. Each key is 96x96 24-bit color and very bright.

However, while their software configurator is pretty as heck, their Plugin Model is stuck in the world of VTables and is largely unusable for the general hacker out there. If you want to write a plugin, you do it in C++ and implement a Create() method and export it. There are three pure virtual methods that a plugin writer needs to implement, GetInfo, Paint, and OnKeyDown. My preferred software environment is managed. Full stop. I'm not going to apologize for preferring it. I was a bad-ass in C++ back in the day, but I fully recognize that those days are over, and I'm not going to write another lpcszcbFoo* again.

I'm pretty disappointed that I'd need to do all that unmanaged dancing. That said, if you, dear reader, would like to dance, I'd like an unmanaged shim in C++ that forwards these three calls to a parallel C# managed interface. Any takers? Give me a call. I'm sure we could work on it together and give it back to the company so their plugin model wouldn't suck so much. It'd really make the device take off, I think. I'd love to do a Continuous Integration widget.

Anyway, while they are a USB device, as with all good (read: usable/hackable) USB devices they are really a "Prolific USB-Serial" Device so they are addressable via a virtual COM port and they have a well defined spec. So instead of a plugin, this is currently a command line app. I suspect it'd be pretty easy to make it a Tray App and basically rewrite their config app in .NET.

They also include a C# sample that pushes bitmaps to the buttons as byte[] arrays. I used the existing IVideoSource libraries from the brilliant Andrew Kirillov (he worked on the motion detection baby article for Coding4Fun with me) and captured each frame from the AVI and resized it to 96x96 before pushing it to the Mini Three.

The SendToButton method takes a .NET Bitmap and a button number apart and sends it as an array that's 96x96x3 (3 for R,G,B). It calls the Optimus C-style library via PInvoke calls.

public unsafe static void SendToButton(int button, Bitmap i)
{
    byte[] bmpBytes = null;
    BitmapData bData = i.LockBits(new Rectangle(new Point(), i.Size), 
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
    try
    {
        // number of bytes in the bitmap
        int byteCount = bData.Stride * i.Height;
        bmpBytes = new byte[byteCount];
 
        // Copy the locked bytes from memory
        Marshal.Copy(bData.Scan0, bmpBytes, 0, byteCount);
    }
    // don't forget to unlock the bitmap!!
    finally
    {
        i.UnlockBits(bData);
    }
    IOptimusMini.ShowPictureBlocking(button, bmpBytes);
}

Here's a fantastically poor video taken with a cell phone camera that shows an AVI of a plane landing on the second mini-three button. The frame rate is crap, but it'll do. I've also got the Mini Three showing my infant son's internet "cradle cam" via a secure MJPEG stream as well. I think I'll do a Vista Side Show driver at some point as well.

Video: Video on an Optimus Mini Three. I'll do a more complete Coding4Fun Article soon.

About Scott

河北快3Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.


  Newsletter
Sponsored By
Hosting By
Wednesday, 07 February 2007 20:01:59 UTC
Dude, it was 15 min at lunch...honest.
Thursday, 15 March 2007 00:20:51 UTC
My boss just handed me one of these button pads and told me to make it do something cool. I'm inspired with the things you are making it do. I am big into home automation and I'm looking to develop my own plugins for this thing. I don't know any C programing... can I do any customization with python or perl?

One idea for a useful app for me would be to make the 2 buttons on the left and right scroll through a list of possible A/V sources, and when the middle button is pressed it sends a signal to my home automation controller to set that source on the tv.
I also use switchers and scalers in these home automation systems. If I could somehow take a downscaled composite feed from my switcher and send that image into one of the buttons, it would be extremely slick.

Any links to source code I can tinker around with would be greatly appreciated.

-Vince
Vince
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.