Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting integration of LCDGFX display driver with ArduinoMenu #423

Open
schwos opened this issue Aug 19, 2023 · 1 comment
Open

Starting integration of LCDGFX display driver with ArduinoMenu #423

schwos opened this issue Aug 19, 2023 · 1 comment

Comments

@schwos
Copy link

schwos commented Aug 19, 2023

We are leveraging small Arduino for a project which have limited memory. We have been successful in using LCDGFX to fit everything within the available memory we have. At the moment we are running about 85% prior to full optimization. We would like to leverage ArduinoMenu vs the LCDGFX built in menu as it provides a bit more flexibility.

Challenge we are having is LCDGFX leverages two class objects together Display and Nanoengine. Which are initialized in the following manner:

DisplaySSD1306_128x64_I2C display(-1); NanoEngine1<DisplaySSD1306_128x64_I2C> engine(display);

Using the Macro MENU_OUTPUTS we can't figure out how to pass the two class objects.

I am attempting to figure out how I can pass the nanengine and display objects to ArduinoMenu without throwing a compiler error.

I have tried:

MENU_OUTPUTS(out, MAX_DEPTH, NanoEngine1Out(engine, colors, fontX, fontY, offsetX, offsetY, {0, 0, U8_Width / fontX, U8_Height / fontY})
,NONE);

MENU_OUTPUTS(out, MAX_DEPTH, NanoEngine1Out(engine(display), colors, fontX, fontY, offsetX, offsetY, {0, 0, U8_Width / fontX, U8_Height / fontY})
,NONE);

The above give me -> This declaration has no storage class or type specifier

I have attempted without the Macro:

const Menu::panel panels[] MEMMODE={{0,0,40,2}}; Menu::navNode* nodes[sizeof(panels)/sizeof(Menu::panel)];//navNodes to store navigation status Menu::panelsList pList(panels,nodes,1);//a list of panels and nodes Menu::idx_t lcdTops[MAX_DEPTH]; //Menu::liquidCrystalOut outLCD(lcd,lcdTops,pList); Menu::menuOut* const outputs[] MEMMODE={&engine}; //list of output devices Menu::outputsList out(outputs,1);

This states ->

cannot convert 'NanoEngine1<DisplaySSD1306_128x64_I2C>' {aka 'NanoEngine<NanoCanvas<16, 16, 1>, DisplaySSD1306_128x64_I2C>'} to 'Menu::menuOut* const' in initialization

if I try Menu::menuOut* const outputs[] MEMMODE={&engine(display)};

Compiler states:

call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type

Below is the draft lcdgfxOut.h library to be inserted into ArduinoMenu..

`#ifndef RSITE_ARDUINOP_MENU_LCDGFX
#define RSITE_ARDUINOP_MENU_LCDGFX
//#include <U8g2lib.h>
#include "lcdgfx.h"
#include "lcdgfx_gui.h"
//DisplaySSD1306_128x64_I2C display(-1); // or (-1,{busId, addr, scl, sda, frequency}). This line is suitable for most platforms by default
//NanoEngine1<DisplaySSD1306_128x64_I2C> engine(display);

#include "menuDefs.h"

namespace Menu {

class NanoEngine1Out:public gfxOut {
	public:
  int8_t offsetX=0;
  int8_t offsetY=0;
		NanoEngine1<DisplaySSD1306_128x64_I2C>& gfx;
		//NanoEngine1& gfx;
		const colorDef<uint8_t> (&colors)[nColors];
		NanoEngine1Out(
			NanoEngine1<DisplaySSD1306_128x64_I2C>& gfx,
			//NanoEngine1& gfx,
			const colorDef<uint8_t> (&c)[nColors],
			idx_t* t,
			panelsList &p,
			idx_t resX=6,
			idx_t resY=9,
			idx_t offsetX=0,
			idx_t offsetY=0,
    int fontMarginY=1
		) :gfxOut(resX,resY,t,p,(styles)(menuOut::redraw|menuOut::rasterDraw)),gfx(gfx),colors(c) {
				//gfx.getCanvas().setOffset();
				//gfx.setFontPosBottom(); // U8Glib font positioning
				this->offsetX=offsetX;
				this->offsetY=offsetY;
      this->fontMarginY=fontMarginY;
		}

		NanoEngine1Out(
			NanoEngine1<DisplaySSD1306_128x64_I2C>& gfx,
			const colorDef<uint8_t> (&c)[nColors],
			idx_t* t,
			panelsList &p,
			idx_t resX,
			idx_t resY,
			idx_t offsetX,
			idx_t offsetY,
			int fontMarginX,
			int fontMarginY
		) :gfxOut(resX,resY,t,p,(styles)(menuOut::redraw|menuOut::rasterDraw)),gfx(gfx),colors(c) {
				//gfx.setFontPosBottom(); // U8Glib font positioning
				this->offsetX=offsetX;
				this->offsetY=offsetY;
				this->fontMarginX=fontMarginX;
				this->fontMarginY=fontMarginY;
		}

		size_t write(uint8_t ch) override {return gfx.getCanvas().printChar(ch);}

		inline uint8_t getColor(colorDefs color=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) const {
			return memByte(&(stat==enabledStatus?colors[color].enabled[selected+edit]:colors[color].disabled[selected]));
		}

		void setColor(colorDefs c,bool selected=false,status s=enabledStatus,bool edit=false) override {
			gfx.getCanvas().setColor(getColor(c,selected,s,edit));
		}

		void clearLine(idx_t ln,idx_t panelNr=0,colorDefs color=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) override {
			const panel p=panels[panelNr];
			setColor(color,selected,stat,edit);
			gfx.getCanvas().fillRect(p.x*resX + offsetX /*- 1*/,(p.y+ln)*resY + offsetY /*- fontMarginY*/,maxX()*resX /*+ fontMarginY*/ /*+ fontMarginY*/,resY /*+ fontMarginY*/ /*+ fontMarginY*/);
			//setCursor(0,ln);
		}
		void clear() override {
			setCursor(0,0);
			setColor(fgColor);
			panels.reset();
		}
		void clear(idx_t panelNr) override {
			const panel p=panels[panelNr];
			setColor(bgColor,false,enabledStatus,false);
			gfx.getCanvas().fillRect(p.x*resX + offsetX,p.y*resY + offsetY,p.w*resX,p.h*resY);
			//clear();
			panels.nodes[panelNr]=NULL;
		}
		void box(idx_t panelNr,idx_t x,idx_t y,idx_t w=1,idx_t h=1,colorDefs c=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) override {
			const panel p=panels[panelNr];
			gfx.getCanvas().drawRect((p.x+x)*resX,(p.y+y)*resY,w*resX,h*resY/*+(fontMarginY<<1)*/);
		}

		void rect(idx_t panelNr,idx_t x,idx_t y,idx_t w=1,idx_t h=1,colorDefs c=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) override {
			const panel p=panels[panelNr];
			gfx.getCanvas().fillRect((p.x+x)*resX,(p.y+y)*resY,w*resX,h*resY/*+(fontMarginY<<1)*/);
		}

		void setCursor(idx_t x,idx_t y,idx_t panelNr=0) override {
			// _trace(Serial<<"setCursor"<<endl);
			const panel p=panels[panelNr];
			gfx.getDisplay().setTextCursor((p.x+x)*resX+fontMarginX + offsetX,(p.y+y+1)*resY-fontMarginY + offsetY);
			//gfx.getCanvas().printFixedPgm((p.x+x)*resX+fontMarginX + offsetX,(p.y+y+1)*resY-fontMarginY + offsetY,"");
			//gfx. = (p.x+x)*resX+fontMarginX + offsetX;
			//gfx.ty = (p.y+y+1)*resY-fontMarginY + offsetY;
		}

		idx_t startCursor(navRoot& root,idx_t x,idx_t y,bool charEdit,idx_t panelNr) override {
		  if (charEdit) {
		    // rect(panelNr,  x-1,  y, 1, 1, bgColor, false, enabledStatus, false);
				const panel p=panels[panelNr];
				gfx.getCanvas().drawRect((p.x+x)*resX + offsetX +fontMarginX,(p.y+y)*resY+ offsetY /*-fontMarginY*/,resX,resY);
		    setColor(fgColor,false,enabledStatus,false);
		  }/* else
		    box(panelNr,  x,  y, 1, 1, bgColor, false, enabledStatus, false);*/
		  return 0;
		}

		// idx_t endCursor(navRoot& root,idx_t x,idx_t y,bool charEdit,idx_t panelNr) override {
		//   setColor(fgColor,true,enabledStatus,true);return 0;
		// }

  idx_t editCursor(navRoot& root,idx_t x,idx_t y,bool editing,bool charEdit,idx_t panelNr=0) override {
		  if (editing) {
				_trace(Serial<<"editCursor"<<endl);
				// box(panelNr,x-1,y);
				const panel p=panels[panelNr];
				gfx.getCanvas().drawRect((x+p.x-1)*resX + offsetX + fontMarginX-1,(p.y+y)*resY + offsetY /*- fontMarginY+2*/,resX+1 ,resY);
			}
		  return 0;
		}

		void drawCursor(idx_t ln,bool selected,status stat,bool edit=false,idx_t panelNr=0) override {
			// _trace(Serial<<"drawCursor"<<endl);
			const panel p=panels[panelNr];
			// gfxOut::drawCursor(ln,selected,stat);
			setColor(cursorColor,selected,stat);
			gfx.getCanvas().drawRect(p.x*resX + offsetX /*+ fontMarginX*/,(p.y+ln)*resY + offsetY /*+ fontMarginY*/,maxX()*resX ,resY);
		}
		idx_t printRaw(const char* at,idx_t len) override {
			trace(Serial<<"NanoEngine1Out::printRaw"<<endl);
			trace(Serial<<"["<<at<<"]");
			return print((__FlashStringHelper*)at);
		  // const char* p=at;
		  // uint8_t ch;
		  // for(int n=0;(ch=memByte(at++))&&(len==0||n<len);n++) {
			// 	trace(Serial<<"["<<ch<<"]");
		  //   write(ch);
		  // }
		  // return at-p-1;
		}

};

}
#endif //RSITE_ARDUINOP_MENU_U8G2
`

@schwos
Copy link
Author

schwos commented Aug 19, 2023

I was successful in getting the MENU_OUTPUTS to generate the initialize:

Menu::idx_t outTops73[2]; panel _panels_outPanels73[] ={{0, 0, 128 / 6, 64 / 10}}; Menu::navNode* _nodes_outPanels73[sizeof(_panels_outPanels73)/sizeof(panel)]; Menu::panelsList outPanels73(_panels_outPanels73,_nodes_outPanels73,sizeof(_panels_outPanels73)/sizeof(panel));; Menu::NanoEngine1Out out73(engine,colors,outTops73,outPanels73,6,10,0,3); Menu::menuOut* out_outPtrs[] ={ &out73, }; Menu::outputsList out(out_outPtrs,sizeof(out_outPtrs)/sizeof(Menu::menuOut*));

Though at moment I have LCDGFX complaining..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant