Now I know why I kept trying and couldn't get it to work!
My very first function in main is:
int hmi_with_update(int current, int lower, int upper, byte inc, void (*update_function)(int))
A little involved, isn't it?
I did the following test to prove that arduino ide doesn't know how to create a declaration for function pointers:
Test 1:
main:
void setup()
{
}
void loop()
{
go(del);
}
void del(int de)
{
delay(de);
}
function.pde
void go(void (*update_function)(int))
{
(*update_function)(100);
}
No go
test_files.cpp: In function 'void loop()':
test_files:8: error: 'go' was not declared in this scope
Test 2:
One file:
main:
void go(void (*update_function)(int))
{
(*update_function)(100);
}
void setup()
{
}
void loop()
{
go(del);
}
void del(int de)
{
delay(de);
}
Passed!
Generated main.cpp:
#include "WProgram.h"
void setup();
void loop();
void del(int de);
void go(void (*update_function)(int))
{
(*update_function)(100);
}
void setup()
{
}
void loop()
{
go(del);
}
void del(int de)
{
delay(de);
}
Notice there is no declaration of go() in sight.
Test 3:
Put go() at the end of the single file:
main:
void setup()
{
}
void loop()
{
go(del);
}
void del(int de)
{
delay(de);
}
void go(void (*update_function)(int))
{
(*update_function)(100);
}
Error:
test_files.cpp: In function 'void loop()':
test_files:6: error: 'go' was not declared in this scope
Test 4:
I write my own declaration and put the function definition in the end:
void go(void (*update_function)(int));
void setup()
{
}
void loop()
{
go(del);
}
void del(int de)
{
delay(de);
}
void go(void (*update_function)(int))
{
(*update_function)(100);
}
Passed!
main.cpp
#include "WProgram.h"
void setup();
void loop();
void del(int de);
void go(void (*update_function)(int));
void setup()
{
}
void loop()
{
go(del);
}
void del(int de)
{
delay(de);
}
void go(void (*update_function)(int))
{
(*update_function)(100);
}
Yeah!
Test 5:
Keep the go() in a separate file and insert the declaration in main file.
main:
void go(void (*update_function)(int));
void setup()
{
}
void loop()
{
go(del);
}
void del(int de)
{
delay(de);
}
function.pde
void go(void (*update_function)(int))
{
(*update_function)(100);
}
Passed!
main.cpp is the same as test 4!
Master programmers aren't that legendary? Maybe I spoke too soon?
Anyway I'm glad it's not me this time. ;D ;D ;D