USB menu remake
Posted by kll on June 19 2015 15:53:14
in my last play with RTC libraries here, special daily alarm tool... i see some nice things, and now
i want erase my own RTC code and use that libs. also in my USB MENU tool.

i also see there, and in a other external serial menu lib ( what is nice but i not want to use )
a good feature, a function call where you can give a function you want to execute as a parameter.
that is something i want to learn first. for this i try to read the PJRC libs.
until now my menu code is a big list of "switch case", with that function call i might make it more modular,
but not sure if its then more readable??
but the challenge seems to be to understand the class definition they use for this ( AlarmClass) .
well, even with the 2 examples i was not able to get a class definition of that kind running in only a main.ino. ( error: no member in function..), what is a compiler error when main.ino, lib.h, lib.cpp is compiled in wrong sequence.
but for what i need the class thing anyway?
test_call.ino// KLL test function call function from parameter
typedef void (*OnTick_t)(); // callback function typedef
void myfunction(String outtext="", OnTick_t onTickHandler = NULL) {
Serial.println(outtext); // print info
if( onTickHandler != NULL) { (*onTickHandler)(); } // call the handler
void mycall() {
Serial.println("mycall run"); // called job
void setup() { // put your setup code here, to run once:
while (!Serial) ; // wait until Arduino Serial Monitor opens / Leonardo family
myfunction("show text",mycall);
void loop() { ; } // put your main code here, to run repeatedly

upload, monitor:
show text
mycall run

working on menu_kll_v29 i move some code ( functions that had a own TAB )
to common / there where just too many TAB's.
as with modern IDEs the memcheck tool is outdated / deleted.
and using the IDE 1.6.5 ( first nightly) i see warnings that are not visible with older IDE versions, esp. about using char[] or Strings, and number formats.

now, even above function call function looks nice, i decided not to use it here now.
i clean up serial menu input "switch ... " by a simple if
use for '1' .. '9' a function call menu_1()..
and same in contijobs ( 1 ..9 ). if the JOB is enabled the basic loop_counter counts up to a limit ( like 1001 .. 1009 loops )
and only then call the JOBx(). In there, if it is a timed JOB, the delta millis are checked, on that limit the real user function is executed.
why that complicated nested structure? the serial check and the millis call and check are the slowest functions in arduino
to try to execute them in every loop would slow down the whole multi job idea.
by using a count limit ( slightly different for each conti job ) ensures 1.000.000 loops in under 20sec. and a rotating execution of the JOBs / checks. ( see loop reporting what shows the time each 1.000.000 loops, if diagnostic is ON)
in that prepared 1 .. 9 conti JOB structure i do not use the ( here new ) PJRC alarmtimer,
that is only used for
- a daily alarm DAYJOB1() and its "end" DAYJOB1_end() x minutes later
- and a hourly job to check if RTC and arduino time is drifting
but there again, the alarm_update has a loop counter, so not perform alarm tool ( checks ) in every loop!
the 9 prepared CONTI JOBs are inactive and empty, but can be enabled / disabled by menu 2 ..9 ( even no menu help text defined )
only JOB 1 is active by default with a 2 sec timer and switch LED 13 as a EXAMPLE for you.
their features:
- enable / disable for startup
- toggle enable by menu
- ask for setting of counter ( for very fast conti jobs ) or ask for timer setting
for delta millis controlled jobs.

for menu called ONE TIME JOBS pls use any not used single character.

for more daily jobs pls use up to 5 more alarm timer in TAB rtc.

if no RTC now the compile time is used to set the arduino time / very wrong after reset /