Code Monkey home page Code Monkey logo

agent.contrib's Introduction

Agent.Contrib

A set of useful class libraries which should help folks create amazing Faces and Apps for AGENT SmartWatch.

I'm taking pull requests, and ideas for contributions.

If you browse the source real quick I have added a few Samples as to how to start using some of the features:

  • SimpleWatchFace - just a super simple example as to how to print the time on the screen.
  • SimpleWatchFaceWithButtons - simple time on the screen, and responds to the MiddleRight button to toggle showing the date on the screen.

Other highlights:

Documentation:

Drawing class:

  • A bunch of useful methods for drawing watch hands (for analog watch faces)
  • A method to draw a batter, with correct filler depending on the % of battery life
  • Drawing text or images at the center of the screen
  • Measuring Text width, based on fonts

Parse class:

  • All sorts of string to number parsing methods, and converting byte[] to string

GeoLocation class

  • Initial set of interfaces for defining location and position data. If we all can agree on an interface, then it will just make it easier for the entire community to create apps and faces...

Hardware class

  • ButtonHelper class is a threadsafe way for dealing with buttons. Can just wire up an event for the buttons you care about. No need to deal with InterruptPorts, and the class will automatically tell you which button and direction was clicked.

Reflection utilities

  • More advanced class, used to load up other types dynamically, etc..

Sample Usage

  • Download and build the Agent.Contrib project.
  • Create a new "Micro .NET Framework" "Command line" application
  • Import your favourite font as a resource, here we will use NinaB
  • Add a reference to Microsoft.SPOT.Graphics
  • Add a reference to AGENT.Contrib project
  • Add a new file to the project, called "BasicFace.cs"
  • Update BasicFace.cs to the following code:
using System.Globalization;
using Agent.Contrib.Face;
using Agent.Contrib.Settings;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation.Media;

namespace SimpleWatchFace
{
    public class SimpleFace : IFace
    {
        public ISettings Settings { get; set; }
        private Font font = Resources.GetFont(Resources.FontResources.NinaB);
        public void Render(Bitmap screen)
        {
            screen.DrawText(
                Settings.Now.ToString(DateTimeFormatInfo.CurrentInfo.ShortTimePattern),
                font,
                Color.White, 
                0,
                0
                );
        }

        public int UpdateSpeed
        {
            get { return 60*1000; }
        }
    }
}

  • Update Program.cs to the following:
using Agent.Contrib.Face;

namespace SimpleWatchFace
{
    public class Program
    {
        public static void Main()
        {
            var watch = new WatchFace(new SimpleFace());
            watch.Start();
        }
    }
}

Build and run!

Using Multiple Buttons

By default, watch faces only support the middle button the default for the button helper is to only enable the single button. If you want to enable all of the buttons on the right side, just use this prior to any calls to the button helper:

For example, place it at the top of your Main() in Program.cs

        ButtonHelper.ButtonSetup = new Buttons[]
            {
                Buttons.BottomRight, Buttons.MiddleRight, Buttons.TopRight
            };

This will override the default behaviour and enable all three of those buttons.

agent.contrib's People

Contributors

frenchdata avatar nicksi avatar eriknorenrg avatar hector47 avatar

Stargazers

 avatar Angus H. avatar Pin Shih Wang avatar Cong Nguyen avatar  avatar Rahul Ravikumar avatar Scott Hanselman avatar John Ehringer avatar Chad Bentz avatar Jonatas Saraiva avatar Philip Proplesch avatar Matt King avatar Brett Morrison avatar Blair Leduc avatar  avatar Phil Chuang avatar Sami Rajala avatar Edwin Hagen avatar Ayulin avatar  avatar John avatar Harald Svendberg avatar Gaurav Jain avatar Alexandre Brisebois avatar Teemu Tapanila avatar Andreas Oldeskog avatar Rob Chartier avatar dotnetdude avatar  avatar

Watchers

Mike Linnen avatar  avatar Yusuf Soyipek avatar Dario Mratovich avatar Rob Chartier avatar 12Lab avatar Blair Leduc avatar James Cloos avatar Sami Rajala avatar Phil Chuang avatar Pin Shih Wang avatar Harley avatar Teemu Tapanila avatar Alexandre Brisebois avatar Chad Bentz avatar  avatar  avatar  avatar  avatar Alain Bouchard avatar

agent.contrib's Issues

OutOfMemoryException.

If you allow one of the sample apps to run for extended period you will eventually hit an outofmemory exception. This occurs in the RandomNotification method of SimpleNotifications. If anyone follows this example they will inherit the same issue.

BaseChannel/GetBytes, buffer overrun potential

This needs some improvement to not overrun, and would be more useful if the byte array size was configurable. Also, add BytesToRead to the SP implementation, and use here for performance; push the byte content parsing up. Something like:

public int BufferLen { get; set/* use a method to change buffer size, protected with a lock, or disallow setting when port is opened*/; }

// don't worry about byte values here, just buffer and return the input, parse in caller.
protected byte[] GetBytes(SerialPort port)
{
int position = 0;
int bytesWaiting = port.BytesToRead;
bytesWaiting = Min(bytesWaiting,BufferLen);
byte[] buffer = new byte[bytesWaiting];
var bytesWaiting = port.Read(buffer,0,bytesWaiting); // returns bytes read
return buffer;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.