Exclusive Sneak Peek: The AGENT Smart Watch Emulator and managed .NET code on my wrist!
I'm totally geeked out about Smart Watches. I always have been, from the original Microsoft SPOT watch (from 10 years ago!) to the Pebble, and now the AGENT Smart Watch from Secret Labs. Secret Labs are the folks that brought us the Netduino open source electronics platform that uses the .NET Micro Framework. It's pretty awesome that you can write C# and run it in 64k or in 64gigs, from the wrist to the cloud.
Upcoming Conference: If you're in or around Chicago in July 2013, consider joining Chris Walker from SecretLabs and I at the MonkeySpace conference! We'll be speaking about developing for embedded systems and the AGENT Watch with C#. What are the power considerations? How low-level is this kind of coding? Can one kind of app cause battery drain while another keeps the watch going for a week? What about notifications and bluetooth? We'll cover all this and lots more, join us.
The AGENT Smart Watch was trying to raise $100k to build a watch and as of the time of this writing they are within spitting distance of a MILLION dollars! There's just hours to go to get in on this cool Kickstarter. (Remember, Kickstarter is an investment, not a store.)
Not only is this a .NET Microframework Device, but we can start writing apps now using the AGENT Watch Emulator. From their Kickstarter site:
Traditional smartwatches run apps in an unrestricted environment. AGENT's OS includes a managed runtime, optimized for our low-power architecture. It is called the .NET Micro Framework and it makes watch apps trustable.
This feature-rich managed runtime also offers developers modern features they crave: event-based programming; multi-threading; garbage collection; lambda expressions; exception handling; automatic power management; and much more.
You can install VS2012 and the .NET Micro Framework 4.3 and write an app for your wrist! I alluded to this a little in my Xamarin talk "How C# Saved My Marriage." You can write .NET apps for embedded systems, a watch, tablets, desktops, web sites, large cloud systems and more.
Full disclosure: I have no financial stake or business relationship with SecretLabs, but we are friends and I'm a fan. I helped Chris with some copy writing on the Kickstarter page, its text and reviewing the video as a favor. I have received no money from SecretLabs and I backed the Kickstarter with my own money.
I got a preview of the AGENT Smart Watch emulator, and some code from Kickstarter backer Esben Bast who created a binary clock face. I loaded up VS2012 and the binary clock emulator. This initial code is just about 100 lines. You can see the references in Solution Explorer here. SPOT means "Smart Personal Object Technlogy."
The fact that there is an emulator is huge. No worries about breaking a watch or even having a watch! The Agent Watch SDK puts a reference to the AGENT Emulator in my registry, so it shows up directly in Visual Studio:
Then I can debug my watch app without a watch, just as if I were writing a Phone App or Web Site. It's a first class experience inside of VS. This makes me feel particularly empowered as a .NET developer because it means I already know how to write apps for this watch and I've never even seen it before..
The code is pretty straightforward, if appropriately low-level. This IS a small device we're talking about!
You've got total control over the screen and what can be displayed. You could create any watch face that you could imagine (that would fit on the screen) because you have a Bitmap to draw to.
The .NET Micro Framework has no fonts loaded by default, but I can include them as resources. There's some "tinyfnt" files in C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.3\Fonts or I could download or make some myself. Even better I can use the TinyFontTool from Miloush.
I can load a font from a resource like this:
font = Resources.GetFont(Resources.FontResources.small);
and then later in my UpdateTime() method, Draw the time on my binary clock screen.
_bitmap.DrawText(DateTime.Now.ToString("HH:mm:ss"), font, Color.White, 45, 15);
Run my emulator again and I have the time printed as well!
The only real "microframework-ism" in the code is that the watch face doesn't want to use a lot of power, so you should "go to sleep." It's the same as if you were writing a console app. If your main() function ends, then your app will end! But, since this is a watch face, we want it to run all the time, so, we start a 1 second timer, then sleep the main() forever. Everything interesting happens as an event on a background thread. (The watch can control the lifetime and tombstone or kill the watch face if you're doing other things.)
public static void Main()
_bitmap = new Bitmap(Bitmap.MaxWidth, Bitmap.MaxHeight);
_font = Resources.GetFont(Resources.FontResources.small);
// display the time immediately
// set up timer to refresh time every minute
DateTime currentTime = DateTime.Now;
TimeSpan dueTime = new TimeSpan(0); // beginning of next minute
TimeSpan period = new TimeSpan(0, 0, 0, 1, 0); // update time every minute
_updateClockTimer = new Timer(UpdateTime, null, dueTime, period); // start our minute timer
_button = new InterruptPort(HardwareProvider.HwProvider.GetButtonPins(Button.VK_SELECT),
_button.OnInterrupt += _button_OnInterrupt;
// go to sleep; time updates will happen automatically every minute
That last part is interesting. You've got two event handlers here, the one to UpdateTime every second and then one to watch for the Button getting pressed. You want the watch app to be event-driven...it needs to do as
little as possible NOTHING until it's time to do something. This InterruptPort is watching for the the middle button (the VK_SELECT button). ResisterMode.PullDown means the button will show "1" or true when it's pressed. InterruptEdgeBoth means I get events when the button is pressed AND when it goes up.
Go make Watch Apps!
Here's another cool watch face from Dylan Mazurek next to the Big Digits example:
And finally, here's an animated concept for a World Time face that Steve Bulgin made for Pete Brown as well as another Steve concept below:
The next step will be more than watch faces, it will be watch utilities and apps. Maybe an app for my FitBit, or an app to manage Blood Sugar? Perhaps a Nest app to control my thermostat?
The AGENT Watch Emulator emulator will be available to download this Thursday at www.agentwatches.com. You can get ready by installing the .NET Micro Framework today.
Watch apps can be written in C# using Microsoft Visual Studio 2012 (including the free Express edition). Deploy your apps over Bluetooth and debug them interactively.
Download Visual Studio Express 2012
Download .NET Micro Framework SDK v4.3
Developers can also use AGENT as a secondary display, interacting with it remotely via Bluetooth from their Objective-C, C#, or Java smartphone app.
Even though the watch ships in December, I'm going to start writing apps now so I'm ready for the Watch App Store (coming soon)!