edge icon indicating copy to clipboard operation
edge copied to clipboard

How to create and reuse an instance variable with using Edge?

Open jamiedejong opened this issue 9 years ago • 2 comments

Hello,

What is my issue? When I say "Blink green" the drone will do exactly what I want. That works great.

When I say "Blink green" again, it will execute the code, but the drone doesn't give a response. The drone gives only a response in the first time. So every time I have to restart the program to make it work. Annoying...

What happens the second time? It will do exactly the same, it's executing the code as well, but the drone doesn't give a response.

Here's the code:

    private static void _speechRecognitionEngine_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
        switch (e.Result.Text)
        {
            case "Blink green":
                Task.Run((Action)blinkGreen);
                break;
        }
    }

    // ONLY WORKS THE FIRST TIME
    // WHEN I SAY "BLINK GREEN" AGAIN, IT'S WILL EXECUTE THE 
    // CODE BUT THE DRONE DOESN'T GIVE A RESPONSE. ONLY THE 
    // FIRST TIME (SO I HAVE TO RESTART THE PROGRAM)
    public static async void blinkGreen()
    {
        var func = Edge.Func(@"
            var arDrone = require('ar-drone');
            var client = arDrone.createClient(); 

            return function(data, callback){
                client.animateLeds('blinkGreen',5,2);
                callback(null, data);
            }
        ");
        Console.WriteLine(await func("BLINK EXECUTED!"));
    }

I think there is something going on with:

var arDrone = require('ar-drone');
var client = arDrone.createClient(); 

I am allowed to create one client I guess. I have to create and reuse the client instance, so I can use the same client which would solve the problem. But I have no idea how to do that with the Edge.js module...

I hope someone could help me out with this problem.

Thanks,

Jamie

jamiedejong avatar Feb 13 '16 11:02 jamiedejong