Ok guys,
Now the code looks like this:
the cpp file
#include "LcdMenu.h" //include deklaraciu tejto triedy
//constructor
LcdMenu::LcdMenu(){
}
void LcdMenu::addTextLine(int _lineNr, char _line[]){
//strcpy(myMenu[_lineNr], _line);
memcpy(myMenu[_lineNr], &_line[0], 19);
}
void LcdMenu::setOnOff(bool _onOff, char _ifTrue[], char _ifFalse[]){
onOff = _onOff;
strcpy(myMenu[5], _ifTrue);
strcpy(myMenu[6], _ifFalse);
}
void LcdMenu::setOnOff(bool _onOff){
onOff = _onOff;
}
void LcdMenu::setValue(char _line3[], int _valueI){
strcpy(myMenu[3], _line3);
lastValueI = valueI;
valueI = _valueI;
valueIset = true;
valueFset = false;
}
void LcdMenu::setValue(char _line3[], float _valueF){
strcpy(myMenu[3], _line3);
lastValueF = valueF;
valueF = _valueF;
valueFset = true;
valueIset = false;
}
const char* LcdMenu::getLine(int _lineNr){
if (_lineNr == 4)
{
if(strlen(myMenu[5]) > 0 && strlen(myMenu[6]) > 0)
{
if(onOff)
{ strcpy(myMenu[4], myMenu[5]); }
else
{ strcpy(myMenu[4], myMenu[6]); }
}
else if(strlen(myMenu[4]) <= 0)
{ //4=min width, 3= precision
if (valueFset){return dtostrf(valueF,4,2, myMenu[0]);}
if (valueIset){return dtostrf(valueI,4,0, myMenu[0]);}
}
return myMenu[_lineNr];
}
else
return myMenu[_lineNr];
}
float LcdMenu::getValueF(){ return valueF;}
float LcdMenu::getLastValueF(){ return valueF;}
int LcdMenu::getValueI(){ return valueI;}
int LcdMenu::getLastValueI(){ return valueI;}
In .h file "define maxMenuCount 21" should I also consider a place for a null character? Or I only have to enter 20
the .h file
#ifndef Lcd_MenuLib
#define Lcd_MenuLib
#if (ARDUINO >=100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define maxMenuCount 21 //+nulcharakter?
class LcdMenu
{
public:
LcdMenu();
void addTextLine(int _lineNr, char _line[]);
void setOnOff(bool _onOff, char _ifTrue[], char _ifFalse[]);
void setOnOff(bool _onOff);
void setValue(char _line3[], int _hodnotaI);
void setValue(char _line3[], float _hodnotaF);
const char* getLine(int _lineNr);
float getValueF();
int getValueI();
float getLastValueF();
int getLastValueI();
private:
int scrNr, arrayLenght;
float valueI, valueF, lastValueI, lastValueF;
bool onOff, valueFset, valueIset;
char line1[20], line2[20], line3[20], line4[20], ifTrue[20], ifFalse[20];
char myMenu[9][maxMenuCount]; // 9 = values //screen count
/*
* 0 - temp
* 1 - line1
* 2 - line2
* 3 - line3
* 4 - line4
* 5 - ifTrue
* 6 - ifFalse
* 7 -
* 8 -
*/
};
#endif
the test sketch
#include <LcdMenu.h>
LcdMenu menu();
void setup() {
Serial.begin(9600);
}
void loop()
{
delay(200);
Serial.println("***");
menu.addTextLine(1, "test1 too large text line");
menu.addTextLine(2, "test2");
menu.addTextLine(3, "test3");
//menu.addTextLine(4, "test4");
//menu.setOnOff(false, "It is true", "It is false");
menu.setValue("Value :", 10.5f);
for(int i=1; i<=4;i++)
{
Serial.print(i);
Serial.print(": ");
Serial.println(menu.getLine(i));
}
delay(5000);
}
See if you can find any improvements. I have only one problem now.
I removed the argument from the constructor of LcdMenu(), the compiler throws out an error:
Arduino: 1.8.4 (Windows 7), Vývojová doska:"Arduino/Genuino Uno"
C:\Users\SKHC2629\Documents\Arduino\HomeAutomationTest\HomeAutomationTest.ino: In function 'void loop()':
HomeAutomationTest:14: error: request for member 'addTextLine' in 'menu', which is of non-class type 'LcdMenu()'
menu.addTextLine(1, "test1 too large text line");
^
HomeAutomationTest:15: error: request for member 'addTextLine' in 'menu', which is of non-class type 'LcdMenu()'
menu.addTextLine(2, "test2");
^
HomeAutomationTest:16: error: request for member 'addTextLine' in 'menu', which is of non-class type 'LcdMenu()'
menu.addTextLine(3, "test3");
^
HomeAutomationTest:19: error: request for member 'setValue' in 'menu', which is of non-class type 'LcdMenu()'
menu.setValue("Value :", 10.5f);
^
HomeAutomationTest:25: error: request for member 'getLine' in 'menu', which is of non-class type 'LcdMenu()'
Serial.println(menu.getLine(i));
^
exit status 1
request for member 'addTextLine' in 'menu', which is of non-class type 'LcdMenu()'
Táto správa by mala mať viac informácií v
"Zobrazenie podrobného výstupu pri kompilácii"
podľa zapnutá voľba v Súbor -> Nastavenia.
Why? And thanks to all of you for your help...