- 12V Akku mit 280 Ah bauen         
Ergebnis 11 bis 16 von 16

Thema: nochmal Arraypointerreferenztohuwabohu

Baum-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #15
    HaWe
    Gast
    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:

    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();
           }
        }   
        
        */
        
    }
    (Ausgabe über Serial + über OLED, aber OLED lässt sich auch auskommentieren)
    Geändert von HaWe (10.12.2018 um 09:12 Uhr)

Ähnliche Themen

  1. Nochmal zu den adc Ports
    Von Fenriz im Forum Robby RP6
    Antworten: 2
    Letzter Beitrag: 30.08.2008, 12:20
  2. Nochmal Uhrzeit
    Von martin66119 im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 2
    Letzter Beitrag: 05.11.2007, 12:42
  3. nochmal : Greifarm
    Von JonasK im Forum Mechanik
    Antworten: 4
    Letzter Beitrag: 30.06.2007, 15:25
  4. Nochmal Roboterbau
    Von N00b|Linux im Forum Allgemeines zum Thema Roboter / Modellbau
    Antworten: 5
    Letzter Beitrag: 28.01.2005, 09:06
  5. Motortreiber (nochmal)
    Von Gottfreak im Forum Controller- und Roboterboards von Conrad.de
    Antworten: 10
    Letzter Beitrag: 20.03.2004, 14:12

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •  

LiFePO4 Speicher Test