Lee's Feature Complete PDE

Share you PDE file with our community
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 29, 2013 1:18 pm
Ok, the code compiles. Only a few syntax errors :) Anyway, it's posted in the 2nd post. Enjoy

Posts: 267
Joined: Fri Jul 20, 2012 7:13 am
Location: Oakley, CA
PostPosted: Fri Mar 29, 2013 3:27 pm
Nice work, Lee! I need to dial in my wave patterns and wave maker code this weekend. I'll be digging through your code for ideas while I'm at it :)
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 29, 2013 5:11 pm
rimai wrote:Hey Lee,
This actually triggered a very nice idea :)
I'm going to create a handful of function calls that can be triggered using the wifi commands.
Just like /mf that starts feeding mode.
This way, you can call custom functions through the web browser and we harass Curt to implement in the app too :)
By having those function calls, you can start CalibrateDosingPumps() or runSwabbie() for example without having to trigger it through memory bit set.


Instead of creating stub functions or hard coded function names that need to be defined and then needing to be added by curt and whoever on the iPhone app...why not have it take the name of a function and we can have it call a pointer to the function by name?

Posts: 12306
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Fri Mar 29, 2013 7:04 pm
Can you elaborate more?
Roberto.
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 29, 2013 7:13 pm
I'll see if I can write up some demo code...
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 29, 2013 7:51 pm
Maybe not exactly call by name...you'd need either a struct or object to hold properties of the function, like a name / index...

Code: Select all
Store your callback functions in an array like this.
// 2 can be from a #define num_functions 2
typedef void (*FunctionPointer) ();
FunctionPointer functions[2];

// user defines their functions, whatever name they want
void DoFunction1(void) {
   // do whatever here
};

void DoFunction2(void) {
   // do whatever here
};

// user assigns their functions to global variable, ie. ReefAngel.CustomFunctions[]
functions[0]=DoFunction1;
functions[1]=DoFunction2;

// add to web code (pseudo)
If http command == run_function {
    functions[x]();
}


If you made "functions" a linked list or even just an array of object that you could push and pop new functions. It old have a variable property name. A case would go through the list of objects until name="passed" name and then you would execute object.function();

Code: Select all
struct _Object {
    void (* functionPointer)();
    int value;
    char [] name;
};

    /* create struct */
    struct _Object Object;
    Object.value = 1;
    Object.name = "DoFunction1";
    Object.function = DoFunction1;


Anyway this could be used for a lot of things...adding screens, menus, callbacks for timers..(assign a function to a TimerClass to run when timer is triggered...
User avatar
Posts: 5362
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Fri Mar 29, 2013 8:12 pm
Here's a good demo for a timer made for Arduino that calls a function when complete.

http://playground.arduino.cc/Code/SimpleTimer
User avatar
Posts: 378
Joined: Mon Oct 24, 2011 7:52 pm
Location: Saint Louis
PostPosted: Fri Mar 29, 2013 8:17 pm
Calling functions through the wifi would be nice for things like triggering the remote feeding. It would be easier than changing a memory location like I am doing now. On your feeder, I eventually changed mine to feed small amounts every hour through the day. I don't know if it really helps the fish, but it sure did train them quickly to swim to a certain spot whenever the wavemakers stop. :)

-Jon

Posts: 12306
Joined: Fri Mar 18, 2011 6:47 pm
PostPosted: Fri Mar 29, 2013 8:28 pm
I'm still not convinced that keeping all the pointer and function arrays and names will be much benefit.
It seems to me that it uses a lot of RAM for little benefit.
I can see how power users may get some benefit, but I don't see anybody else even understanding it, let alone using it.
It's much simpler to just add fixed function calls. just like Curt did with the menu entries.
Like define DoFunction1() on h file and code it inside the INO code, so when the wifi command comes in, it goes and process what's inside DoFunction1() in your INO code.
Roberto.
PreviousNext

Return to My PDE/INO file

Who is online

Users browsing this forum: No registered users and 2 guests

cron