独家偷窥:手腕上的AGENT智能手表模拟器和托管.NET代码!

博客介绍了AGENT智能手表,它基于.NET MicroFramework,允许开发者使用C#编写应用程序。作者强调了模拟器的重要性,使得在没有实际设备的情况下也能进行开发和调试。文章还展示了如何使用Visual Studio 2012和.NET MicroFramework SDK编写手表应用,并探讨了电池管理和低功耗设计。此外,提到了未来的可能性,如创建各种实用程序和应用程序。
摘要由CSDN通过智能技术生成

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.

我对智能手表一无所知。 从最初的Microsoft SPOT手表(从10年前开始!)到Pebble ,现在一直是我一直都在使用,现在从Secret Labs转到AGENT智能手表。 Secret Labs是为我们带来了使用.NET Micro Framework的Netduino开源电子平台的人们。 您可以编写C#并以64k或64gig(从手腕到云)运行它,这真是太棒了。

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.

即将召开的会议:如果您是2013年7月在芝加哥或附近的城市,请考虑从SecretLabs和我加入Chris Walker参加MonkeySpace会议! 我们将谈论有关使用C#开发嵌入式系统和AGENT Watch的信息。 功率因素有哪些? 这种编码的级别有多低? 一种应用程序会导致电池电量消耗,而另一种会使手表运行一周吗? 通知和蓝牙呢? 我们将介绍所有这些内容,并加入我们。

The AGENT Smart Watch will talk to your phone

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

AGENT智能手表正试图筹集10万美元来制造一款手表,截至撰写本文时,它们的身价已近百万美元! 距离这个酷炫的Kickstarter仅几小时的路程。 (请记住,Kickstarter是一项投资,而不是商店。)

Not only is this a .NET Microframework Device, but we can start writing apps now using the AGENT Watch Emulator. From their Kickstarter site:

这不仅是.NET Microframework设备,我们现在也可以使用AGENT Watch Emulator开始编写应用程序。 在他们的Kickstarter网站上:

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.

传统的智能手表在不受限制的环境中运行应用程序。 AGENT的操作系统包括托管运行时,该运行时针对我们的低功耗架构进行了优化。 它称为.NET Micro Framework,它使监视应用程序可信赖。

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.

这种功能丰富的托管运行时还为开发人员提供了他们渴望的现代功能:基于事件的编程;基于事件的编程;基于事件的编程。 多线程垃圾收集; lambda表达式; 异常处理; 自动电源管理; 以及更多。

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.

您可以安装VS2012和.NET Micro Framework 4.3并为手腕编写一个应用程序! 我在Xamarin的演讲“ C#如何保存我的婚姻”中提到了这一点。 您可以为嵌入式系统,手表,平板电脑,台式机,网站,大型云系统等编写.NET应用程序。

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.

全面披露:我与SecretLabs没有任何财务利益或业务关系,但我们是朋友,而且我是粉丝。 我帮助Chris在Kickstarter页面上撰写了一些副本,并撰写了文字并审核了视频,这是我的一个好帮手。 我没有从SecretLabs收到任何钱,我用自己的钱支持了Kickstarter。

image
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."

我获得了AGENT Smart Watch模拟器的预览,以及来自Kickstarter支持者Esben Bast的一些代码,后者创建了一个二进制钟面。 我加载了VS2012和二进制时钟仿真器。 此初始代码仅约100行。 您可以在此处在解决方案资源管理器中查看参考。 SPOT的意思是“智能个人对象技术”。

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:

有一个模拟器的事实是巨大的。 不用担心打破手表,甚至没有手表! Agent Watch SDK在我的注册表中放置了对AGENT Emulator的引用,因此它直接显示在Visual Studio中:

image

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

然后,我可以在没有手表的情况下调试我的手表应用程序,就像编写电话应用程序或网站一样。 这是VS内部的一流经验。 这使我作为.NET开发人员感到特别有能力,因为这意味着我已经知道如何为这款手表编写应用程序,而我之前从未见过。

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.

.NET Micro Framework默认没有加载字体,但是我可以将它们作为资源包含在内。 C:\ Program Files(x86)\ Microsoft .NET Micro Framework \ v4.3 \ Fonts中有一些“ tinyfnt ”文件,或者我可以下载或自己做一个。 更好的是,我可以使用Miloush的TinyFontTool

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.

然后在我的UpdateTime()方法中,在我的二进制时钟屏幕上绘制时间。

_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!

再次运行我的模拟器,我也可以打印时间!

Now my AGENT Smart Watch has the time printed above the Binary Clock

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

代码中唯一真正的“微框架主义”是表盘不想使用很多功率,因此您应该“入睡”。 就像编写控制台应用程序一样。 如果您的main()函数结束,那么您的应用程序将结束! 但是,由于这是一个表盘,所以我们希望它一直运行,因此,我们启动了一个1秒钟的计时器,然后永远Hibernatemain()。 所有有趣的事情都作为事件在后台线程上发生。 (如果您正在做其他事情,手表可以控制寿命和墓碑,或者杀死表盘。)

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.

最后一部分很有趣。 您在这里有两个事件处理程序,一个事件处理程序每​​秒更新一次,然后一个事件处理程序监视Button被按下。 您希望手表应用程序是事件驱动的...它需要做的事尽可能 少, 直到有时间做些事情为止。 该InterruptPort正在监视中间按钮(VK_SELECT按钮)。 ResisterMode.PullDown表示按钮按下时将显示“ 1”或true 。 InterruptEdgeBoth表示当按下按钮以及按钮按下时我会收到事件。

去做手表应用程序! (Go make Watch Apps!)

Here's another cool watch face from Dylan Mazurek next to the Big Digits example:

以下是Big Digits示例旁边的Dylan Mazurek的另一个很酷的表盘:

PixelFace example Watch for AGENT Smart Watch
BigDigits example Watch for AGENT Smart Watch

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:

最后,这是史蒂夫·布金(Steve Bulgin )为皮特·布朗(Pete Brown)创作的一张世界时面Kong的动画概念,以及下面的另一个史蒂夫(Steve)概念:

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?

下一步将不仅仅是表盘,还将是手表实用程序和应用程序。 也许是适用于我的FitBit的应用程序,还是管理血糖的应用程序? 也许是Nest应用程序来控制我的恒温器

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.

AGENT Watch Emulator模拟器将于本周四www.agentwatches.com上提供下载。 您可以通过今天安装.NET Micro Framework做好准备。

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.

可以使用Microsoft Visual Studio 2012(包括免费的Express版)以C#编写Watch应用。 通过蓝牙部署应用程序并进行交互式调试。

Download Visual Studio Express 2012 Download .NET Micro Framework SDK v4.3

下载Visual Studio Express 2012下载.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.

开发人员还可以将AGENT用作辅助显示,从其Objective-C,C#或Java智能手机应用程序通过蓝牙与之交互。

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)!

即使手表已于12月出货,我仍将立即开始编写应用程序,因此我已经准备好进入Watch App Store(即将推出)!

翻译自: https://www.hanselman.com/blog/exclusive-sneak-peek-the-agent-smart-watch-emulator-and-managed-net-code-on-my-wrist

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值