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
UpdateTime(null);
// 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),
false,
Port.ResistorMode.PullDown,
Port.InterruptMode.InterruptEdgeBoth);
_button.OnInterrupt += _button_OnInterrupt;
// go to sleep; time updates will happen automatically every minute
Thread.Sleep(Timeout.Infinite);
}
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.3Developers 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)!
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.
About Newsletter
December can't come soon enough.
It triggered the geek bug on me!
I spread it to my friends, although not even a handful will be able to read the binary format (which I loved by the way).
I will do an experience with my kid when she will learn the decimal code: give her a watch like this and see if she gets the binary way smoothly ;)
Jokes a side: those are the kind of things that really teach people how to code or appreciate the others effort on creating tools/frameworks.
Like in the old 70's song: "Oh baby it a lego-world".
Live longer and prosper!
I'm envisioning some cool Windows Phone 8 apps paired with apps for the AGENT.
A quick screenshot:
https://www.facebook.com/photo.php?fbid=277448055733627
I tested that app on both an AGENT prototype watch and the emulator. No code changes required, other than swapping the name of the target Bluetooth device on the phone.
Chris
Then again, the FDA will probably always stand in the way of that.
thanks, Scott
@Tom -- an early SDK and emulator will be available for download tomorrow evening. :) We're pretty excited to see what you build!
Chris
Secret Labs
This is so accessible!
http://www.agentwatches.com/#tools
If you're adventurous--you can even create a Windows Phone app and use its Proximity and Networking features to connect to the AGENT Emulator via Bluetooth Serial Port Profile :)
BTW, Rob Chartier posted a blog post about installing the tools here:
http://weblogs.asp.net/rchartier/archive/2013/06/20/getting-started-with-developing-for-the-agent-smartwatch.aspx
We'll be updating the SDK with new features, creating tutorials, etc. over the next few months as we move towards autumn production.
Chris
Secret Labs
Can't wait to get my hands on it and the actual hardware in December.
Awesome that they support Windows Phone. That's what ruled out the Pebble for me.
Comments are closed.