Closed tpak closed 7 years ago
Hey, just giving this a bump to see if anyone (especially Jon) can lend a hand. It's summer and maybe it got lost in the silence of vacations. Thanks.
Sorry for the late reply. There are two things I noticed (just looking at the code without running it):
mu_mi5
passes save_int
instead of its address &save_int
;save_int
has the parameter NumericMenuItem* p_menu_item
instead of MenuItem* p_menu_item
. When save_int
takes a MenuItem*
you can cast it to a NumericMenuItem*
in that function.The cast on line 62 looks fine to me.
Let me know if this helps.
Thanks for getting back to me.
Hmm. Changing line 42 to this: NumericMenuItem mm_mi5("Level 1 - Int Item 5 (Item)", &save_int, 5, 0, 5, 1, format_int); and I still get the exact same thing.
If I change save_int to be declared like this: void save_int(MenuItem* p_menu_item) it complains b/c mm_mi5 is declared as NumericMenuItem which is what I need it to be - its the same error/warning but slightly different working
Also, If I passed save_int a MenuItem, I guess I could cast it but I don't understand why do that rather than have save_int accept a NumericMenuItem in the first place, its whole reason is to accept a numeric ...
Feel like I am missing something obvious here. Like I said, very rusty C++ skills.
I'll run the code on an Arduino this week and take a look for you.
I got this working using my second point above:
save_int
should take a MenuItem*
MenuItem*
to a NumericMenuItem*
So the function will be:
void save_int(MenuItem* p_menu_item)
{
NumericMenuItem* p_nmi = (NumericMenuItem*) p_menu_item;
Serial.println("inside save_int ");
altitude = (int) p_nmi->get_value();
Serial.println(altitude);
}
Don't forget to change the forward declaration.
I'll close this issue. Re-open if it doesn't solve your problem.
Thanks! Happened to be in my office when this came through, that worked. Like I said, pretty rusty C skills these days. I appreciate your effort especially since this isn't a bug and is just my current proficiency level ...
First, thanks for this library, it is hopefully going to save me a pile of headaches. Now, if I can ever get my (very, very, very) rusty C/C++ skills back this would probably be obvious to me.
I started with the serial nav example and have hacked it to work with my 4 line LCD and 3 buttons up, down, select. So far so good; however, I have run into a compile warning that I'd like you to look at. I backported my changes to the original serial nav example for discussion sake. It is pasted at the end of this. My changes are all preceded by a line with //**
What I am trying to accomplish is, without writing a custom class, save the numeric value from a NumericMenuItem into a global variable upon exit/select from a menu item. It works but I am not sure I am doing it correctly. (nag about documentation and examples goes here) I think this is a perfect use for the SelectFnPtr is it not?
I declare and provide a function "sav_int" to be called when the NumericMenuItem mm_mi5 is exited and add it to the mm_mi5 declaration. I get the compiler warning:
Can you tell if I am doing this correctly and if not what should I change? Like I said, I am fairly rusty with my C/C++.
Also, at line 62 of my code where I cast the value from the menu item, is that the correct way to do that here?
altitude = (int)(*p_menu_item).get_value();
Thanks. Chris(I also attached my version of serial_nav.ino as zip - you should be able to just drop it in place and give it a try)
serial_nav.ino.zip