Arduino Menu 3.0

Working libraries, libraries being ported and related hardware
User avatar
BennehBoy
Posts: 383
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Arduino Menu 3.0

Postby BennehBoy » Thu Mar 02, 2017 9:43 am

HI,

I was hoping to use an off the shelf menu system for one of my projects, this one seemed to offer some of the best features:

https://github.com/neu-rah/ArduinoMenu

It claimed to work on Teensy so I was hopeful that it would work with STM32

Anyway whilst compiling I get this error:

Code: Select all

menuBase.cpp:50:76: error: in C++98 'defaultOptions' must be initialized by constructor, not by '{...}'

 config defaultOptions={'>','-',false,false,Menu::defaultNavCodes,false,true};


I guess this is due stm32 using C++98 & not C++11, do I simply need to create 'defaultOptions' first then populate it?
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 383
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Arduino Menu 3.0

Postby BennehBoy » Thu Mar 02, 2017 10:38 am

I changed the build flags in boards.txt to this:

Code: Select all

mapleMini.build.cpu_flags=-DMCU_STM32F103CB -DSERIAL_USB -std=gnu++11


This works but cc1.exe throws some warnings.

Not sure if c++11 standards will breake anything else?
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 383
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Arduino Menu 3.0

Postby BennehBoy » Thu Mar 02, 2017 10:41 am

Works == Compiles.

The Mini Crashes as soon as any of the input buttons are pressed.

Suspect this is because the menu code overloads a lot of functions.

Other code works fine with the uplifted c++ standard so it's just this menu system, ah well. The joys of being on the fringe.
-------------------------------------
https://github.com/BennehBoy

User avatar
BennehBoy
Posts: 383
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Arduino Menu 3.0

Postby BennehBoy » Thu Mar 02, 2017 12:53 pm

OK so I found the cause of the crash, but I'm stumped regarding why.

Perhaps those with more experience may be able to assist?

When a button is pressed the menu fires this event

Code: Select all

result action1(eventMask e,navNode& nav, prompt &item) {
  Serial<<e<<" event on "<<item<<", proceed menu"<<endl;
  Serial.flush();
  return proceed;
}


I noticed that all text was output OK up to 'item'

If I remove 'item' from the Streaming output then the code got further (didn't crash at all).

The class definiton for prompt is pretty hardcode, and although the above code works fine on AVR, something caused the same code to crash on STM32

Code: Select all

    class prompt {
      friend class navNode;
      friend class menuOut;
      protected:
        const promptShadow* shadow;//constant read-only data (PROGMEM)
      public:
        status enabled=enabledStatus;//ignore enter if false
        bool dirty=true;//needs to be  redrawn
        inline uint16_t hash() const {
          int tmp=(int)this;
          return ((uint16_t*)&tmp)[sizeof(this)/sizeof(uint16_t)-1];
        }
        virtual classes type() const {return promptClass;}
        inline prompt(const promptShadow& shadow):shadow(&shadow) {}
        inline void enable() {enabled=enabledStatus;}
        inline void disable() {enabled=disabledStatus;}
        inline const char* getText() const {return shadow->getText();}
        inline const systemStyles sysStyles() const {return shadow->_sysStyles();}
        inline const eventMask events() const {return shadow->_events();}
        inline styles style() const {return shadow->_style();}
        inline bool canNav() const {return sysStyles()&_canNav;}//can receive navigation focus and process keys
        inline bool isMenu() const {return sysStyles()&_menuData;}//has menu data list and can be a navNode target
        inline bool isVariant() const {return sysStyles()&_isVariant;}//a menu as an enumerated field, connected to a variable value
        inline bool parentDraw() const {return sysStyles()&_parentDraw;}//a menu as an enumerated field, connected to a variable value
        virtual idx_t printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len);//raw print to output device
        virtual bool changed(const navNode &nav,const menuOut& out,bool sub=true) {return dirty;}
        //this is the system version of enter handler, its used by elements like toggle
        virtual result sysHandler(SYS_FUNC_PARAMS) {return proceed;}
        inline result operator()(FUNC_PARAMS) const {return (*shadow)(FUNC_VALUES);}
        idx_t printRaw(menuOut& out,idx_t len) const;
        virtual prompt* seek(idx_t* uri,idx_t len) {return len?NULL:this;}
        virtual bool async(const char *uri,navRoot& root,idx_t lvl) {
          return ((!*uri)||(uri[0]=='/'&&!uri[1]));
        }

        //some functions to use on htmlFmt
        // for enumerations:
        virtual idx_t selected() const {return 0;}
        virtual void printValue(menuOut&) const {}
        virtual void printHigh(menuOut&) const {}
        virtual void printLow(menuOut&) const {}

    };


The obvious alarm bell is the comment about PROGMEM

So I went and had a look at the definition for promptshadow:

Code: Select all

    struct promptShadowRaw {
      actionRaw a;//the hooked callback function
      systemStyles sysStyles;
      const char*text;
      const eventMask events;//registered events
      styles style;
    };
    class promptShadow:public action {
      protected:
        systemStyles sysStyles;
        const char*text;
        const eventMask events;//registered events (mask)
        styles style;
      public:
        promptShadow(const char* t,action a=doNothing,eventMask e=noEvent,styles s=noStyle)
          :action(a),sysStyles(_noStyle),text(t),events(e),style(s) {}
        inline const char* getText() const {return (const char*)memPtr(text);}
        inline const systemStyles _sysStyles() const {return (systemStyles)memEnum(&sysStyles);}
        inline const eventMask _events() const {return (eventMask)memEnum(&events);}
        inline const styles _style() const {return (styles)memEnum(&style);}
    };


And am none the wiser :D

The code is riddled with macros so it's pretty hard to follow.
-------------------------------------
https://github.com/BennehBoy

stevestrong
Posts: 722
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Arduino Menu 3.0

Postby stevestrong » Thu Mar 02, 2017 1:12 pm

Try to comment out the line with Serial.flush() as it will not work as expected.

User avatar
BennehBoy
Posts: 383
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Arduino Menu 3.0

Postby BennehBoy » Thu Mar 02, 2017 1:22 pm

stevestrong wrote:Try to comment out the line with Serial.flush() as it will not work as expected.


Have done, but the crash is still occurring prior to that when it's attempting to output that prompt object.

I've just compiled the same code against an UNO and it looks like the library is broken there too, it throws out a stream of garbage at that point then gets caught by an internal error catch - looks like STM32 is less forgiving.

I'll issue a bug report to the library maintainer.
-------------------------------------
https://github.com/BennehBoy

victor_pv
Posts: 945
Joined: Mon Apr 27, 2015 12:12 pm

Re: Arduino Menu 3.0

Postby victor_pv » Thu Mar 02, 2017 2:33 pm

BennehBoy wrote:
stevestrong wrote:Try to comment out the line with Serial.flush() as it will not work as expected.


Have done, but the crash is still occurring prior to that when it's attempting to output that prompt object.

I've just compiled the same code against an UNO and it looks like the library is broken there too, it throws out a stream of garbage at that point then gets caught by an internal error catch - looks like STM32 is less forgiving.

I'll issue a bug report to the library maintainer.


Perhaps item is not initialized properly where it should and contains a null pointer?

User avatar
BennehBoy
Posts: 383
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Arduino Menu 3.0

Postby BennehBoy » Thu Mar 02, 2017 3:15 pm

Quite possibly.

I've reported it to the library maintainer, it's a bit beyond me to debug.
-------------------------------------
https://github.com/BennehBoy

zmemw16
Posts: 974
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Arduino Menu 3.0

Postby zmemw16 » Thu Mar 02, 2017 4:39 pm

what happens when just printing item? 'Serial << item<<endl;'
and add a simple 'Serial<<'***************'<<endl;' line to see if it dies there
srp

User avatar
BennehBoy
Posts: 383
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Arduino Menu 3.0

Postby BennehBoy » Thu Mar 02, 2017 5:12 pm

zmemw16 wrote:what happens when just printing item? 'Serial << item<<endl;'


Crashes

zmemw16 wrote:and add a simple 'Serial<<'***************'<<endl;' line to see if it dies there
srp


Prints out the asterisks, no crash.
-------------------------------------
https://github.com/BennehBoy


Return to “Libraries & Hardware”

Who is online

Users browsing this forum: No registered users and 2 guests