Showing posts with label api example. Show all posts
Showing posts with label api example. Show all posts

Monday, May 30, 2016

New Nuget Package for Custom UWP Siren Apps

We just release a new SirenOfShame.Device nuget package for controlling sirens from Universal Windows Platform (UWP) projects.  Between that and the new cross platform soscmd.jar capability we released last week, and the original device api, there's no reason not to build that siren-based bathroom timer you've always wanted for your office.

What's cool about our new UWP support is that you can now build apps for a wide range of devices including Windows PC's, tablets, (phones?), Raspberry Pi's running Windows IoT, and even XBox (!).  In fact, the first person that successfully runs a siren from an XBox gets a free mug (tweet us).

The documentation is in the GitHub project, but at the moment it looks something like the following.

Getting Started


To create your own custom siren of shame device software:
  1. In Visual Studio Create new Universal Windows Platform project
  2. In Nuget Package Manager:
    Install-Package SirenOfShame.Device
  3. Add the following to the Package.appxmanifest:
    <Capabilities>
      <DeviceCapability Name="humaninterfacedevice">
        <Device Id="vidpid:16D0 0646">
          <Function Type="usage:FF9C 0001"/>
        </Device>
      </DeviceCapability>
    </Capabilities>
  4. Instantiate a SirenOfShameDevice, subscribe to Connected, try turning on the led's like this:
    public MainPage() {
      _sirenOfShameDevice = new SirenOfShameDevice();
      _sirenOfShameDevice.Connected += SirenOfShameDeviceOnConnected;
    }
    private async void SirenOfShameDeviceOnConnected(
      object sender, EventArgs eventArgs) {
    
      var manualControlData = new ManualControlData
      {
        Led0 = (byte)255,
        Led1 = (byte)255,
        Led2 = (byte)255,
        Led3 = (byte)255,
        Led4 = (byte)255,
        Siren = false
      };
      await _sirenOfShameDevice.ManualControl(manualControlData);
    }
  5. For more details on how to use the API check out the SirenOfShame.HardwareTestGui project

Summary


We hope you enjoy. Please consider sharing anything fun that you create. If you have any questions please don't hesitate to ask on twitter, facebook, or here in the comments.

Wednesday, May 11, 2016

New API: Snapshot Stats

If you're a Team CI Pro user enjoying the weekly e-mails and stats, and thinking what fun you could have with that raw data (we won't judge), then we've got some fantastic news: we've opened up a new API just for you!

Weekly recap e-mail

This API is basically a list of weekly snapshots of your teams stats.  We originally took these snapshots to get the delta's that are in the e-mails.  But now they're available for you to use and abuse.

API Key


To get started you'll need an API key.  To get it click the new "Get Your API Key" button in the Team CI section of the site.



Then type your password, click the button and copy the resulting API Key.



Hit That API


To get the data POST to http://sirenofshame.com/ApiV1/Snapshots.  To pass your credentials you can use: Content-Type: application/json with

{'UserName': '[YourUsername]','Password': '[YourApiKey]'}

or if you prefer you can use Content-Type: application/x-www-form-urlencoded with

Username=[YourUsername]&Password=[YourApiKey]

In other words:

curl --url http://sirenofshame.com/ApiV1/Snapshots -H "Content-Type:application/x-www-form-urlencoded" -d "UserName=[Username]&Password=[ApiKey]"

The result is hopefully something like:

{
    "Success": true,
    "ErrorMessage": null,
    "Result": [
        {
            "StatSnapshotId": 174,
            "SnapshotDate": "/Date(1428091201543)/",
            "Users": [
                {
                    "DisplayName": "Lee Richardson",
                    "RawName": "leerichardson",
                    "Fseb": 4,
                    "TotalBuilds": 399,
                    "Csb": 0,
                    "FailPercent": 105,
                    "Achievements": 12,
                    "Reputation": 189,
                    "UserId": 782,
                    "UserStatSnapshotId": 2958
                },
                { /* all of your other users should be listed here */ }        
           ]
        },
        /* up to 2 years worth of snapshots should be here */
    ]
}

Summary


Hope you enjoy.  If you do something fun with the data please consider sharing by posting here or shooting us a note on twitter or Facebook.

Monday, September 12, 2011

Introduction to the Siren of Shame Device API

So you don't want to monitor a build but still want to use that cool device you picked up from SirenofShame.com. This post will get you started.

First step is downloading the DLLs from github. If you want examples and the latest code I would recommend grabbing the code via Git from here. Don't have Git and want to look at a simple example go here (this example is pretty much what is covered in this blog post).

OK, lets write some code. Start by creating a new WinForm project (it must be .NET 4 non-client profile) and open up the code behind.

We're going to need access to the device. This is where the class SirenOfShameDevice comes it. SirenOfShameDevice wraps all the functionality of the device in one nice clean wrapper. ISirenOfShameDevice is just an interface allowing you to mock out the device for unit testing which I know all of you are doing, Right? So lets create one. Add the following to your form.
private readonly ISirenOfShameDevice _sirenOfShameDevice
   = new SirenOfShameDevice();

Next we're going to need to know when the device gets plugged in so we can do something cool with it. Windows will send messages to all the open windows on the system when a USB device is plugged in. Well we are going to take advantage of that and listen for those events. Good thing for you SirenOfShameDevice takes care of most of that for you but it does need a little help and that's where this code comes in. Add this to your form.
protected override void WndProc(ref Message m) {
   if (_sirenOfShameDevice != null) {
      _sirenOfShameDevice.WndProc(ref m);
   }
   base.WndProc(ref m);
}

Great, but how do we know when it connects. Well we need to hook up some events to, you guessed it, the SirenOfShameDevice class. Add the following lines to your form.
_sirenOfShameDevice.Connected += SirenOfShameDeviceConnected;
_sirenOfShameDevice.Disconnected += SirenOfShameDeviceDisconnected;

void SirenOfShameDeviceConnected(object sender, EventArgs e) {
   // do something fun, enable some buttons.
}

void SirenOfShameDeviceDisconnected(object sender, EventArgs e) {
   // do something fun, disable some buttons.
}

This tutorial sucks, I'm running the program and I still don't hear the siren going off.

Hold on you're almost done I promise. You need to add a button to make it go. Add the following code to the button's click event.
_sirenOfShameDevice.PlayAudioPattern(
   _sirenOfShameDevice.AudioPatterns.First(),
   new TimeSpan(0, 0, 0, 10));
_sirenOfShameDevice.PlayLightPattern(
   _sirenOfShameDevice.LedPatterns.First(),
   new TimeSpan(0, 0, 0, 10));

This will play the first audio pattern and the first LED pattern on the device for 10 seconds.

Want to know what other audio patterns are on the device or what cool light patterns you can annoy your friends with, check out the SimpleSirenOfShameDeviceExample on how to do it. Or, wait for the next tutorial blog post which may come out never (I'm lazy what can I say).

Now go forth and create the next cool Siren of Shame application. If it's cool we'll put it on our site and promote it for you.