mardi 5 mai 2015

The best overloaded method match has some invalid arguments C# WPF LEAP

Error 1 The best overloaded method match for 'LeapController1.LeapEventListener.LeapEventListener(LeapController1.ILeapEventDelegate)' has some invalid arguments

Error 2 Argument 1: cannot convert from 'LeapController1.MainWindow' to 'LeapController1.ILeapEventDelegate'

I am trying to update the data to the labels on the GUI and i don't know what went wrong.

This is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Leap; //using leap motion library

namespace LeapController1
{

public partial class MainWindow : Window
{

    private Controller controller = new Controller();


    private LeapEventListener listener;
    public MainWindow()
    {
        InitializeComponent();
        this.controller = new Controller();
        this.listener = new LeapEventListener(this);
        controller.AddListener(listener);

        Console.ReadKey(); //prevent console output from closing
        controller.RemoveListener(listener); //remove listener from controller
        controller.Dispose(); //dispose controller
    }

    delegate void LeapEventDelegate(string EventName);

    public void LeapEventNotification(string EventName)
    {
        if (this.CheckAccess())
        {
            switch (EventName)
            {
                case "onInit":
                    txtInit.Content = "Initialised";
                    break;

                case "onConnect":
                     txtConnect.Content = "Connected";
                     this.connectHandler();
                     break;

                case "onDisconnect":
                    txtConnect.Content = "Disconnected";
                    break;

                case "onFrame":
                    txtFrame.Content = " on Frame";
                    this.movement(this.controller.Frame());
                    break;
            }
        }
        else
        {
            Dispatcher.Invoke(new LeapEventDelegate(LeapEventNotification), new object[] { EventName });
        }
    }//end method LeapEventNotification

    public void connectHandler()
    {
        this.controller.SetPolicyFlags(Controller.PolicyFlag.POLICY_IMAGES);
        this.controller.SetPolicy(Controller.PolicyFlag.POLICY_BACKGROUND_FRAMES);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_KEY_TAP);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_SCREEN_TAP);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_SWIPE);
        this.controller.EnableGesture(Gesture.GestureType.TYPE_CIRCLE);
        this.controller.Config.SetFloat("Gesture.Swipe.MinLength", 100.0f);
    }

    public void movement(Leap.Frame frame)
    {
        HandList allHands = frame.Hands; //get hand data array
        foreach (Hand hand in allHands) //run for each element in array 
        {
            Leap.Vector normal = hand.PalmNormal; //get hand.PalmNormal data
            Leap.Vector direction = hand.Direction; //get hand.Direction data

            double pitch = direction.Pitch; //get pitch data
            double pitch1 = (pitch) * (180 / Math.PI); //convert rad to deg
            int finalpitch = (int)(pitch1); //nearest whole number

            double roll = normal.Roll; //get roll data
            double roll1 = (roll) * (180 / Math.PI); //convert rad to deg
            int finalroll = (int)(roll1); //nearest whole number

            txtPitch.Content = finalpitch; //assign data to label
            txtRoll.Content = finalroll; //assign data to label

        }

        GestureList gestures = frame.Gestures(); //returns a list of gestures

            for (int i = 0; i < gestures.Count(); i++) //run when gesture made
            {
                Gesture gesture = gestures[i]; //gesture at that instant

                switch (gesture.Type) //check gesture type
                {
                    //if gesture.Type == TYPE_SWIPE
                    case Gesture.GestureType.TYPE_SWIPE:
                        txtGesture.Content = "SWIPE";
                        break;

                    //if gesture.Type == TYPE_SCREEN_TAP
                    case Gesture.GestureType.TYPE_SCREEN_TAP:
                        txtGesture.Content = "SCREEN TAP";
                        break;

                    //if gesture.Type == TYPE_KEY_TAP
                    case Gesture.GestureType.TYPE_KEY_TAP:
                        txtGesture.Content = "KEY TAP";
                        break;

                    //if gesture.Type == neither of the above
                    default:
                        txtGesture.Content = "UNKNOWN";
                        break;
                }
            }
    }

}

public interface ILeapEventDelegate
{
    void LeapEventNotification(string EventName);
}

public class LeapEventListener : Listener
{
    ILeapEventDelegate eventDelegate;

    public LeapEventListener(ILeapEventDelegate delegateObject)
    {
        this.eventDelegate = delegateObject;
    }

    public override void OnInit(Controller controller)
    {
        this.eventDelegate.LeapEventNotification("onInit");
    }

    public override void OnConnect(Controller controller)
    {
        this.eventDelegate.LeapEventNotification("onConnect");
    }

    public override void OnDisconnect(Controller controller)
    {
        this.eventDelegate.LeapEventNotification("onDisconnect");      
    }

    public override void OnFrame(Controller controller)
    {
        this.eventDelegate.LeapEventNotification("onFrame");
    }       
} 

}

Aucun commentaire:

Enregistrer un commentaire