- MultiPlus Wechselrichter Insel und Nulleinspeisung Conrad         
Ergebnis 1 bis 10 von 11

Thema: "alias" einer Klassen-Instanz als Verweis auf "echte" Instanz

Baum-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #5
    HaWe
    Gast
    ich hatte es nur nachträglich geändert, zur Verdeutlichung, aber das menu02 ist auch da.

    Der vollständige Code ist ein wenig erweitert gegenüber dem gekürzten Beispiel - hoffe, es ist nicht zuviel

    Code:
    
    // I2C
    #include <Wire.h>         // Incl I2C comm, but needed for not getting compile error
    #define ESPSDA D2         // defaults
    #define ESPSCL D1         // 
    
    // TFT
    //#include <Adafruit_SSD1306.h>
    #include <ESP_SSD1306.h>    // Modification of Adafruit_SSD1306 for ESP8266 compatibility
    #include <Adafruit_GFX.h>   // Needs a little change in original Adafruit library (See README.txt file)
    #include <Fonts/FreeSans12pt7b.h>            // 
    #include <Fonts/FreeSansBold12pt7b.h>        // 
    #include <Fonts/FreeSans9pt7b.h>             //
    #include <Fonts/FreeMono12pt7b.h>            //   
    #include <Fonts/FreeMono9pt7b.h>    
    // Pin definitions
    
    //----------------------------------------------------------------------------
    // display driver
    //----------------------------------------------------------------------------
    #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 btnfx;
    
    
     
    //----------------------------------------------------------------------------
    // OLED menu
    //----------------------------------------------------------------------------
     
    class tMenu {  
      protected:    
         int16_t    MENULEN, LINELEN, VISLNUM, FONTHI; 
         char       buf[20];     
         int8_t     firstvln, lastvln, displn;   
      
      public:      
         int16_t ID, pre_ID;
         int8_t  act, pre_act;
         char    **list; 
         int     test;    
         
         tMenu (int16_t menulen, int16_t linelen, int16_t id) // constructor
         {
            firstvln=0; lastvln=0; displn=0;     
            pre_ID=0;
            act=0;
            pre_act=0;
            MENULEN = menulen;  // number of available menu options        
            LINELEN = linelen;  // line length of menu options 
            ID = id;       
                   
            list = new char*[MENULEN];
            for(int i = 0; i < MENULEN; i++)
            {
              list[i] = new char[LINELEN+1];
            }        
         }      
         
         void init(int16_t vislnum=5, byte fonthi=13 ) {  // ()=defaults=(5,13)
            for(int i=0; i<MENULEN; i++) {
               sprintf(buf,"%d .......|", i);
               strncpy(list[i], buf, LINELEN);
               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(byte 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,"Menu %d-%d ToDo=%d", ID,act,bfunc);
               Serial.println(buf);
               return 1;
            }
            if(bfunc==2){           
               sprintf(buf,"Menu %d-%d ToDo=%d", ID,act,bfunc);
               Serial.println(buf);
            }
            if(bfunc==3){           
               sprintf(buf,"Menu %d-%d ToDo=%d", ID,act,bfunc);
               Serial.println(buf);
               return 3;
            }
            return 0;         
         }
      
         ~tMenu()  { // destructor    
            // Dynamically delete the array  
            delete[] list ;
         }
    };
     
    
    tMenu menu0(10,20, 0); // numEntries, lineLength, menuID;
    tMenu menu02(10,20, 2); 
    
    
    tMenu & actMenu = menu0;
    tMenu & preMenu = menu0;
    
    
    
    
    
    //----------------------------------------------------------------------------
    // OLED dashboard
    //----------------------------------------------------------------------------
    
    void dashboard(byte 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
      //pinMode(D3, OUTPUT);       // + LED_BUILTIN
    
    
      btn0.init(D6, INPUT_PULLUP, 50);
      btn1.init(D3, INPUT_PULLUP, 50);
      btnfx.init(D4, INPUT_PULLUP, 50);
      
     
      //pinMode(D7, OUTPUT);
      //pinMode(D8, OUTPUT);
      
    	Serial.begin(115200);
      delay(2000); // wait for Serial()
      Serial.println("Serial started");
    
      
      // 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
    
      Serial.println();
      for(byte i=0; i<10; i++) {
         Serial.print("-");
         Serial.println(menu0.list[i]);
      }
      menu0.init(); // optional numVisibleLines, fontHeight; defaults = (5,13)
      display.clearDisplay(); 
      display.display();
    
      display.setFont(&FreeMono9pt7b); // h=13.10pt
      menu0.mdisplay();
    }
    
    
    void loop() {
        int32_t result;
        
        result = menu0.checkbtn(btn0.click(), btn1.click(), btnfx.click() ); 
    
        &actMenu = menu02; // test
        
        
    }
    Geändert von HaWe (07.12.2018 um 16:23 Uhr)

Ähnliche Themen

  1. Antworten: 10
    Letzter Beitrag: 01.11.2017, 12:53
  2. RN-LCD-Adapter und lcd_i2c.lib "Lcdpower Alias="
    Von Kugel5 im Forum Basic-Programmierung (Bascom-Compiler)
    Antworten: 7
    Letzter Beitrag: 26.09.2009, 00:00
  3. Antworten: 7
    Letzter Beitrag: 30.12.2007, 17:52
  4. Antworten: 16
    Letzter Beitrag: 07.10.2006, 15:01
  5. Raupenfahrzeug alias "Minehunter"
    Von Defragger im Forum Vorstellung+Bilder+Ideen zu geplanten eigenen Projekten/Bots
    Antworten: 79
    Letzter Beitrag: 24.09.2005, 11:59

Berechtigungen

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

LiFePO4 Speicher Test