Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Error unknown typ name 'DS18B20'



  • @mrjj
    hahaha :D

    nobody knows anything yet :D

    Summery:
    First i got one Class called SetTemperature.
    In that class is a variable HystTemperature.
    In order to change the value of that variable you need to create a object of Set Temperature like:

    SetTemperature S;
    S.setHystTemperature(e.g. 5);
    

    to receive that variable you also use:

    float x;
    Set Temperature S;
    x = S.getHystTemperature();
    

    The second class called "ReadTemperature" got one methode to evaluate the temperature and save it in the class variable actualTemp1. First you have to create an object of the class like:

    ReadTemperature R;
    R.ReadTemp(1);
    //Then actualTemp1 will be changed e.g. incremented by 1
    

    Then the third class should compare that both variables. So i have to create 2 object of each class and call the variables like:

    float x;
    float y;
    
    SetTemperature S;
    ReadTemperature R;
    
    x = S.getHystTemperature();
    y = R.actualTemp1;
    

    thats the only thing i want.
    But what do you mean e.g. with C.S.getHystTemperature() and so on?
    Where do you take de C.S.getHystTemperature()? and what should it do?

    Also with

    auto value2 = R.actualTemp1;
    C.R.actualTemp1 = value2;
    

    Where comes and what is C.R.actualTemp1^^



  • @mrjj
    Now it works.
    i reached the slave-address each sensor, made a code like this

    char w1_address[16];
    const char* adr1  = "10-000803673bfb";
    DS18B20 w1Device1 (adr1);
    actualTemp1 = w1Device1.getTemp();
    

    And it's working.
    But unfortunately if i add a new sensor. i have to find out his address and add it to the code. its not only plug and play^^

    But now a basic c++ problem.
    I created a class:
    checktemperature.h

    #ifndef CHECKTEMPERATURE_H
    #define CHECKTEMPERATURE_H
    
    #include <settemperature.h>
    #include <readtemperature.h>
    #include <wiringPi.h>
    
    class CheckTemperature
    {
    private:
        SetTemperature S;
        ReadTemperature R;
    public:
        void CheckTemp();
        float TempEin;
        float TempAus;
    };
    
    #endif // CHECKTEMPERATURE_H
    
    

    checktemperature.cpp

    #include "checktemperature.h"
    
    void CheckTemperature::CheckTemp()
    {
        TempEin = S.getHystTemperature();
        TempAus = S.getHystTemperature();
    
        if (R.actualTemp1 <= TempEin) digitalWrite(31, LOW);
        else if (R.actualTemp1 >= TempAus) digitalWrite(31, HIGH);
    
        if (R.actualTemp2 <= TempEin) digitalWrite(26, LOW);
        else if (R.actualTemp2 >= TempAus) digitalWrite(26, HIGH);
    
        if (R.actualTemp3 <= TempEin) digitalWrite(27, LOW);
        else if (R.actualTemp3 >= TempAus) digitalWrite(27, HIGH);
    
        if (R.actualTemp4 <= TempEin) digitalWrite(28, LOW);
        else if (R.actualTemp4 >= TempAus) digitalWrite(28, HIGH);
    
        if (R.actualTemp5 <= TempEin) digitalWrite(29, LOW);
        else if (R.actualTemp5 >= TempAus) digitalWrite(29, HIGH);
    }
    
    

    i call that funktion every 500ms in loop.
    But the values of R.actualTemp and S.getHystTemperature the value does not adjust, so they still at the moment when i start the program.
    Do you know whats wrong, cause i call that funktion every 500ms and at the beginning "TempEin= ..." and S.getHystTemperature(); is already changing^


  • Lifetime Qt Champion

    @AlexKrammer
    hehe lots of talk for 2 floats :)
    Ok first part i fully understand. seems fine.
    but not sure what you need the C class for then ?

    I dont understand when you will update ITs C/S and such.
    Maybe just drop C completely and do what you want to do with C/S in mainWin ?



  • @mrjj
    yes it should be possible.
    But to keep the structur and let it look quiet professional i'd tried to put it into a class.
    But the one thing that i dont understand yet is. If i create a object each class in CheckTemp and try to call the variables out of them. why they dont include the values which i gave them e.g when the slider moved.


  • Lifetime Qt Champion

    @AlexKrammer said in Error unknown typ name 'DS18B20':

    But the one thing that i dont understand yet is. If i create a object each class in CheckTemp and try to call the variables out of them. why they dont include the values which i gave them e.g when the slider moved.

    Because they are NOT tied to the S/R in main. its own variables and unless you
    directly write to them via C.s then they stay at zero.

    So when you change C/S that lives in main, the ones in C does not change with them
    They are seperate variables and has own values and will only change if you directly do that.

    much like

    int NUM =4;

    class Test {
    int NUM=0;
    }

    TEST c;

    NUM = 100;

    will have not change c.NUM at all.



  • This post is deleted!


  • @mrjj
    yeah but i dont write NUM = 100.
    I write c.NUM = 100.

    i write:

    class TEST{
        int NUM = 0;
    }
    
    MainWindow{
    TEST c;
    c.NUM = 100;
    }
    
    CheckTemperature
    {
         float example;
         TEST c;
         example  = c.NUM;
         //example still 0
    }
    
    
    

  • Lifetime Qt Champion

    @AlexKrammer
    Yes and then its ok. then you update c.num but NOT
    the NUM outside.
    Its 100% the same with your SetTemperature/ReadTemperature
    in MainWin and those in C.



  • @mrjj
    i dont want to update NUM outside..
    look one post above. I edited it


  • Lifetime Qt Champion

    @AlexKrammer

    CheckTemperature
    {
         float example;
         TEST c;
         example  = c.NUM;
         //example still 0
    }
    

    Yes as you make a local TEST c variable
    so if you did if you did c.NUM=100
    somewhere else its not the same TEST instance.

    So TEST c; should be a member if you want to set its NUM outside of CheckTemperature

    then it works.



  • @mrjj
    yes i did it?
    i created a object of Test in MainWindow
    then i put c.NUM = 100;

    after that i created a object of Test in CheckTemperature too
    but c.NUM dont have 100. Its still have 0.


  • Lifetime Qt Champion

    @AlexKrammer So, you create two instances of Test, change one of them and expect the other one to have the same change? How? By magic? Maybe I don't get something as the thread is already quite long...

    Test a;
    Test b;
    a.NUM = 100;
    // Why should b.NUM be 100 now?!
    


  • @jsulm
    where do i create two instaces of Test? I only create a Object of TEST with c. change the Variable NUM and try to get c.NUM in a other Class

    class TEST{
    int NUM = 0;
    }

    MainWindow{
    TEST c;
    c.NUM = 100;
    }

    CheckTemperature
    {
    float example;
    TEST c;
    example = c.NUM;
    //example still 0
    }

    Or do i change the value of the variable in the object TEST c (c.NUM) i created? Not the Variable in the class TEST


  • Lifetime Qt Champion

    @AlexKrammer said in Error unknown typ name 'DS18B20':

    where do i create two instaces of Test?

    In the code you just posted (hint: instance is the same thing as object):

    MainWindow{
    TEST c; // First instance
    c.NUM = 100;
    }
    
    CheckTemperature
    {
    float example;
    TEST c; // Second instance, c here is NOT the same as in MainWindow!
    example = c.NUM;
    //example still 0
    }
    

  • Lifetime Qt Champion

    @jsulm said in Error unknown typ name 'DS18B20':

    TEST c; // First instance

    This has to go in .h , in the MainWindow class and then

    TEST c; // Second instance, has to be removed then
    its the same and it should work.



  • @mrjj
    If i create in MainWindow.h a instance called TEST c;

    That instance won't work in class CheckTemperature. Will it?


  • Lifetime Qt Champion

    @AlexKrammer
    No as its 2 different instances. one in MainWin and one in CheckTemperature.
    They are not the same.



  • @mrjj
    And is there a posibility to use a variable of a class in 2 other classes


  • Lifetime Qt Champion

    @AlexKrammer
    Yes if you use a pointer or reference then it will point back to the original variable.

    like

    int Num=0; the actual one

    class Test() {
    int &NumRef;
    void Test( int MyNum ) : NumRef(MyNum) {}
    }

    then when you create the instance

    Test MyTest(Num);

    Then it points to the actual one and will always have the same value.

    But often its not the best idea and can be solved other way like give it directly when you want to
    other classes to use the data.

    class Test() {
    int DoSomething(int NumTouse);
    }

    Test c;
    int result = c.DoSomething(Num);



  • @mrjj well thank you very much. My problem has been fixed and about this problem i'm going to read something on a c++ article.
    Thanks for your time.


  • Lifetime Qt Champion

    @AlexKrammer
    Good to hear and you are welcome.
    Its a good idea to read up on c++ as Qt uses it a lot and
    its best to have good understanding on some of the concepts as not to feel really uphill:)


Log in to reply