Skip to content

RomulusAugustulus/HandySharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HandySharp

A simple wrapper for using the handy API version 2 in .NET projects. The wrapper is build upon the definition provided here: https://handyfeeling.com/api/handy/v2/docs Parts of the API marked as "removed in the future" are not implemented.

Installation

Just import the nuget package in your project: https://www.nuget.org/packages/HandySharp/1.0.0

How to use it

Import the nuget package into your project. In your project, simply create a new instance of the Handy class.

The following is a simple test program. It will connect to the handy with the specified connectionKey and perform a simple movement in Handy Alternate Motion Protocol mode.

using HandySharp;
using HandySharp.HandyResult

class Program
{
    static async void Main(string[] args)
    {
        //Place connection key of your handy here.
        string connectionKey = "";

        //Initialize a new instance connecting to the default API endpoints.
        Handy handy = new Handy();

        //Try to connect the app with your handy. Handing over the connection key generated by your handy.
        Result<InfoResult> result = await handy.Connect(connectionKey);

        //Continue only if connection was established.
        if (result.Success)
        {
            Console.Out.WriteLine("Handy connected successfully.");

            //Check the firmware status of the handy.
            if (result.Message.FwStatus != 0)
            {
                Console.Out.WriteLine("Your handy needs a firmware update to use this API. Please update it before attempting to run this example.")
            }
            else
            {
                try
                {
                    //Set the sliding range to full.
                    await handy.SetSlide(0, 100);

                    //Set the handy in Handy Alternate Motion Protocol mode.
                    await handy.SetMode(Modes.HAMP);

                    //Let the slider move.
                    await handy.SetHAMPStart();

                    //Set the speed to 20% of the maximum speed.
                    await handy.SetHAMPVelocity(20);

                    //Let the handy do it's work for 10 seconds.
                    await Task.Delay(10000);

                    //Stop the movement.
                    await handy.SetHAMPStop();

                    //Restrict the sliding range between 30% and 60% of the maximum range.
                    await handy.SetSlide(30, 60);

                    //Let the slider move again.
                    await handy.SetHAMPStart();

                    //Set the speed to 60% of the maximum speed.
                    await handy.SetHAMPVeloctiy(60);

                    //Let the handy do it's work for 10 seconds.
                    await Task.Delay(10000);

                    //Set the speed to 5% of the maximum speed.
                    await handy.SetHAMPVeloctiy(5);

                    //Let the handy do it's work for 10 seconds.
                    await Task.Delay(10000);

                    //Stop the movement.
                    await handy.SetHAMPStop();
                }
                catch (HandyErrorException e)
                {
                    //If the handy can not comply with a command a HandyErrorException will be thrown.
                    Console.Out.WriteLine("An error occured: " + e.Error.Message);
                }
                catch (HandyHTTPException e)
                {
                    //If the http response does not return 200, then a HandyHTTPException will be thrown.
                    Console.Out.WriteLine("An error occured: " + e.StatusCode);
                }
                finally
                {
                    //In any case, once you are done using the handy, you should disconnect.
                    handy.Disconnect();
                }
            }
        }
        else
        {
            Console.Out.WriteLine("Could not connect to handy.");
        }
    }
}

About

HandySharp is a wrapper for the handy v2 API completely written in C#.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages