Scott Hanselman

Showing Video on an Optimus Mini Three

February 07, 2007 Comment on this post [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

Scott 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.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
February 07, 2007 5:11
I haven't convinced the wife I need one of these yet... I'm assuming there's a user-mode process that hosts the plugin code and bridges the stuff to a kmode USB driver (or via the virtual serial interface)? Can't imagine they're using UMDF yet. I've got a few minutes, I'll see what I can whip up.
February 07, 2007 6:20
You've got mail...
February 07, 2007 6:37
Have you got yours to work with Vista yet? Mine found a driver for it, but the apps don't seem to connect to it...
February 07, 2007 6:49
Bah.. it looks like I got beat.. But I sent you some code also.
February 07, 2007 14:12
About plug-ins... we want to add some to our .net app, but don't want to reinvent the wheel. Can anyone recommend a nice, light-weight example to follow?
February 07, 2007 23:28
I see you found another use for your lovely book. :-D

j/k

that's pretty cool!
sam
February 07, 2007 23:32
oh, btw, you made it on engadget

sam
February 08, 2007 0:00
Good god, man, how do you find the time to do this stuff? Especially with a child.

Pretty sweet, though.
February 08, 2007 0:01
Dude, it was 15 min at lunch...honest.
February 08, 2007 0:45
"About plug-ins... we want to add some to our .net app, but don't want to reinvent the wheel. Can anyone recommend a nice, light-weight example to follow?"

Great example at dnrTV: http://www.dnrtv.com/default.aspx?showID=34

Once you have that figured out, there's more information about Providers in .NET at: http://www.dnrtv.com/default.aspx?showID=52
February 08, 2007 1:32
You've been dugg...

http://digg.com/mods/Enterprising_hacker_gets_video_playing_on_Optimus_Mini_Three
February 09, 2007 12:44
In russian news site you are called "american hacker". This is funny :-).
Link for the history - http://lenta.ru/news/2007/02/08/optimus/
March 15, 2007 4:20
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

Comments are closed.

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