ist das nicht mein eigener Code?
Der war zwar zu kompilieren, aber ergab ja einen Runtime Error.
Oder hast du daran etwas verändert?
Druckbare Version
ist das nicht mein eigener Code?
Der war zwar zu kompilieren, aber ergab ja einen Runtime Error.
Oder hast du daran etwas verändert?
Der ist geändert. Produziert bei mir keinen Error.
ach so, du übergibst auch schon die Liste an den Constructor...
mal sehen...
- - - Aktualisiert - - -
gehört aber global instanziiert, nicht jedes Mal neu in der loop,Code:tMenu menu0(char ** mlist0);
und warum übergibst du die Liste mlist0 als Doppelpointer mitsamt Variablentyp char** ?
Parameter führen doch keine Typen beim Aufruf...?
Das gibt bei mir zumindest auch einen compile error.
Instanziiere ich indes global per
lässt es sich kompilieren, erzeugt aber ebenfalls wieder einen Laufzeitfehler, wie schon zuvorCode:tMenu menu0(6,11, (char**)mlist0 );
Zitat:
rst cause:4, boot mode: (1,7)
wdt reset
Code:class tMenu {
protected:
int16_t MENULEN, LINELEN, VISLNUM, FONTHI;
public:
char ** list;
tMenu * preMenu;
int16_t act;
tMenu (int16_t menulen, int16_t linelen, char ** extlist) // constructor
{
MENULEN = menulen; // number of available menu options
LINELEN = linelen; // line length of menu options
list = new char*[MENULEN];
for(int i = 0; i < MENULEN; i++)
{
list[i] = new char[LINELEN+1];
strncpy( list[i], extlist[i], LINELEN);
}
}
};
//
Ja, weiß ich, war nur zum Test.Zitat:
gehört aber global instanziiert, nicht jedes Mal neu in der loop
Weil alles andere zu Fehlermeldungen führte. Ich habe mir die Meldungen durchgelesen und das gegeben, was der Compiler haben wollte. Meine Arduino-IDE ist so damit zufrieden.Zitat:
warum übergibst du die Liste mlist0 als Doppelpointer mitsamt Variablentyp char** ?
Und wie gesagt, bin ich eher hier an der Stelle eine schlechte Hilfe. Weiß noch nicht mal, ob Dich das so in irgendeiner Weise weiter bringt. Weil ich zu wenig damit programmiert habe, gerade in C/C++. Ich muss mich unbedingt mehr damit beschäftigen, allerdings ist die Sprache teils sehr eigenartig, das gefällt mir nicht so gut. Da gibt es andere mit denen es sich einfacher umgehen lässt und man wegen so einem Mini-Problem nicht tagelang suchen muss. Aber so ist es nun mal mit C.
Ich hole die Tage mal mein dickes C-Buch aus dem Schrank, mal schauen, was dort zur Parameterübergabe drin steht, ob man das hier in der Arduino-IDE überhaupt brauchen kann. Dann übe ich mal ein wenig.
MfG
ja, vielen Dank für dein Interesse!
Falls mal jemand den gesamten (komplizierteren) Code richtig komplett testen möchte (Button-Steuerung auskommentiert), hier ist er:
(Ausgabe über Serial + über OLED, aber OLED lässt sich auch auskommentieren)Code:
// i2c
#include <Wire.h> // Incl I2C comm, but needed for not getting compile error
//----------------------------------------------------------------------------
// display driver
//----------------------------------------------------------------------------
#include <Adafruit_GFX.h> //
// Adafruit Arduino or ESP OLED driver
//#include <Adafruit_SSD1306.h>
#include <ESP_SSD1306.h> // Modification of Adafruit_SSD1306 for ESP8266 compatibility
#include <Fonts/FreeSans12pt7b.h> //
#include <Fonts/FreeSansBold12pt7b.h> //
#include <Fonts/FreeSans9pt7b.h> //
#include <Fonts/FreeMono12pt7b.h> //
#include <Fonts/FreeMono9pt7b.h>
// Pin definitions
#define OLED_RESET 10 // GPIO10=D12 Pin RESET signal (virtual)
//Adafruit_SSD1306 display(OLED_RESET);
//Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
ESP_SSD1306 display(OLED_RESET);
//----------------------------------------------------------------------------
// ButtonClass buttons
//----------------------------------------------------------------------------
/*
#include <ButtonClass.h>
// 3 buttons for menu control
tButton btn0;
tButton btn1;
tButton btnEnter;
*/
//----------------------------------------------------------------------------
// OLED menu
//----------------------------------------------------------------------------
class tMenu {
private:
void parselist() {
bool issub;
issub=false;
int16_t N = MENULEN;
for(int line=0; line<N; line++) {
for(int k=strlen(list[line]-1); k<LINELEN-1; k++) {
if(list[line][k]=='\0') list[line][k]=' ';
if(list[line][k]=='>') issub=true;
}
if(issub) list[line][LINELEN-2] = '>';
else list[line][LINELEN-2] = '.';
list[line][LINELEN-1] = '\0';
issub=false;
}
}
protected:
int16_t MENULEN, LINELEN, VISLNUM, FONTHI;
int16_t firstvln, lastvln, displn;
char buf[20];
public:
char ** list;
tMenu * preMenu;
int16_t act;
tMenu (int16_t menulen, int16_t linelen, char ** extlist, tMenu* pMenu) : // constructor
MENULEN(5), LINELEN(11), VISLNUM(5), FONTHI(13), act(0)
{
firstvln=0; lastvln=0; displn=0;
act=0;
MENULEN = menulen; // number of available menu options
LINELEN = linelen; // line length of menu options
preMenu = pMenu; // predesessor menu
list = new char*[MENULEN];
for(int i = 0; i < MENULEN; i++)
{
list[i] = new char[LINELEN+1];
strncpy( list[i], extlist[i], LINELEN); // <<<< Hier funktioniert es nicht !!
}
}
void initscr(int16_t vislnum, uint8_t fonthi ) { // ()=defaults=(5,13)
VISLNUM = vislnum; // number of visible menu options
FONTHI = fonthi;
}
void mdisplay() {
if(act>VISLNUM-1) firstvln=_min(act-1, MENULEN-VISLNUM);
else firstvln=0;
lastvln=firstvln+VISLNUM-1;
display.clearDisplay();
for(int i=firstvln; i<=lastvln; i++) {
displn=(FONTHI-3) + (i-firstvln)*FONTHI;
if(i==act) {
display.setCursor(0, displn); display.print('>');
Serial.print('>');
}
else Serial.print(' ');
Serial.println(list[i]);
display.setCursor(11, displn); display.print(list[i]);
}
display.display();
Serial.println();
}
int32_t checkbtn(int8_t btop, int8_t bbtm, int8_t bfunc) {
if(btop==1){ // dec
if(act>0) act--;
//Serial.print ("^"); Serial.println(act);
mdisplay();
return 11 ;
}
if(btop==3){ // min
act=0;
//Serial.print ("^"); Serial.println(act);
mdisplay();
return 13 ;
}
if(bbtm==1){ // inc
if(act<MENULEN-1) act++;
//Serial.print ("v"); Serial.println(act);
mdisplay();
return 21;
}
if(bbtm==3){ // max
act=MENULEN-1;
//Serial.print ("v"); Serial.println(act);
mdisplay();
return 23;
}
if(bfunc==1){
sprintf(buf,"MenuLn %d ToDo=%d", act,bfunc);
Serial.println(buf);
return 1;
}
if(bfunc==2){
sprintf(buf,"MenuLn %d ToDo=%d", act,bfunc);
Serial.println(buf);
}
if(bfunc==3){
sprintf(buf,"MenuLn %d ToDo=%d", act,bfunc);
Serial.println(buf);
return 3;
}
return 0;
}
~tMenu() { // destructor
// Dynamically delete the array
delete[] list ;
}
};
char mlist0[6][11] = {"Titel 0","Zeile1","zu menu02>","Zeile3","Zeile4","Zeile5"};
tMenu menu0(6,11, (char**)mlist0, &menu0); // numEntries, lineLength, preMenu (N/A);
char mlist02[5][11] = {"Titel 02","ESC>","Zeile2","Zeile3","zu menu024"};
tMenu menu02(5,11, (char**)mlist02, &menu0); // numEntries, lineLength, preMenu=menu0;
char mlist024[6][11] = {"Titel 024","ESC >","Ja","Nein","foo","bas"};
tMenu menu024(6,11, (char**)mlist024, &menu02); // numEntries, lineLength, preMenu=menu02;
tMenu * actMenu = &menu0;
//----------------------------------------------------------------------------
// OLED dashboard
//----------------------------------------------------------------------------
void dashboard(int8_t mode) {
display.clearDisplay();
display.setFont();
if (mode == 0) {
display.setFont(); // h=8.0 pt
display.setCursor( 0, 0); display.print(" 0 Hello World 1");
}
display.display();
display.setFont();
}
void setup(void)
{
// Start Serial
Serial.begin(115200);
delay(3000); // wait for Serial()
Serial.println("Serial started");
/*
btn0.init(D6, INPUT_PULLUP, 50);
btn1.init(D3, INPUT_PULLUP, 50);
btnEnter.init(D4, INPUT_PULLUP, 50);
*/
// Start Wire (SDA, SCL)
//Wire.begin(ESPSDA,ESPSCL); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Wire.begin();
// SSD1306 Init
display.begin(SSD1306_SWITCHCAPVCC); // Switch OLED
//display.begin(SSD1306_SWITCHCAPVCC, 0x3D, true, false);
display.setRotation(2);
display.clearDisplay(); // Clear the buffer.
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Hello, world!");
display.display();
//--------------------------------------
// test + debug
display.setFont(&FreeMono9pt7b); // h=13.10pt
display.clearDisplay();
display.display();
Serial.println("menu init:");
strcpy(menu0.list[0], " menu0"); // debug: menu name at top line
strcpy(menu02.list[0], " menu02"); // debug: menu name at top line
strcpy(menu024.list[0], " menu024"); // debug: menu name at top line
Serial.println("actMenu=menu0");
actMenu = &menu0; //
actMenu->mdisplay();
actMenu = &menu02; //
actMenu->mdisplay();
actMenu = &menu024; //
actMenu->mdisplay();
delay(1);
}
void loop() {
int32_t result;
/*
result = actMenu->checkbtn(btn0.click(), btn1.click(), btnEnter.click() );
if(result==3) { // long press btnEnter
if( (actMenu==&menu0) && actMenu->act==2) {
actMenu = &menu02;
actMenu->mdisplay();
}
else
if( (actMenu==&menu02) && actMenu->act==4) {
actMenu = &menu024;
actMenu->mdisplay();
}
else
if( (actMenu==&menu02) && actMenu->act==1) {
actMenu = actMenu->preMenu;
actMenu->mdisplay();
}
else
if( (actMenu==&menu024) && actMenu->act==1) {
actMenu = actMenu->preMenu;
actMenu->mdisplay();
}
}
*/
}
habe es hingekriegt, bin selber überrascht:
Code:tMenu (int16_t menulen, int16_t linelen, char ** extlist, tMenu* pMenu) : // constructor
MENULEN(5), LINELEN(11), VISLNUM(5), FONTHI(13), act(0)
{
firstvln=0; lastvln=0; displn=0;
act=0;
MENULEN = menulen; // number of available menu options
LINELEN = linelen; // line length of menu options
preMenu = pMenu; // predesessor menu
list = new char*[MENULEN];
for(int i = 0; i < MENULEN; i++)
{
list[i] = new char[LINELEN+1];
strncpy( list[i], extlist[i], strlen(extlist[i]));
}
}
Ausgabe der Menüs, völlig korrekt (Ausgabe hier testweise nur immer max. 5 Einträge):Code:char * mlist0[11] = {"Titel 0","Zeile1","zu menu02>","Zeile3","Zeile4","Zeile5"};
tMenu menu0(6,11, (char**)mlist0, &menu0); // numEntries, lineLength, preMenu (N/A);
char * mlist02[11] = {"Titel 02","ESC>","Zeile2","Zeile3","zu menu024"};
tMenu menu02(5,11, (char**)mlist02, &menu0); // numEntries, lineLength, preMenu=menu0;
char * mlist024[11] = {"Titel 024","ESC >","Ja","Nein","foo","bas"};
tMenu menu024(6,11, (char**)mlist024, &menu02); // numEntries, lineLength, preMenu=menu02;
Code:>Titel 0
Zeile1
zu menu02>
Zeile3
Zeile4
>Titel 02
ESC>
Zeile2
Zeile3
zu menu024
>Titel 024
ESC >
Ja
Nein
foo