Instance of DHT class within specialised class

I have a programming question that I can’t seem to figure out; I’m using the dht.h library for temperature/humidity sensors, and I want to wrap a SHT22 within a class to make it accessible in a common way and similar to other sensors in the system (they all have a method to read the value, format it for the serial port and format it for the LCD).

To do so I include the DHT.h and this defines a class call “dht”
To wrap this inside my class I create it as a private instance buy defining “dht SensorDHT22;” but I always get an error “‘dht’ does not name a type”. If I do the same definition in my main loop it is happy with that definition - so i’ve done something wrong in my class definition… Can anybody tell me what?

MB

/*
  DHT22TempHumidity - basic template for LMS 10000 sensor
  Copyright (c) 2012 Mark Batchelour.  All right reserved.
  LMS 10000 reCreation project.     www.LMS10000.org
*/

// ensure this library description is only included once
#ifndef DHT22TempHumidity_h
#define DHT22TempHumidity_h

// include types & constants of Wiring core API
#include "Arduino.h"
#include <dht.h>

// library interface description
class DHT22TempHumidity
{
  // user-accessible "public" interface
  public:
    DHT22TempHumidity(int);
    float GetValue(void);
    float ReadSensor(void);
    void  DisplaySerial(void);
    void  DisplayLcd(void);


  // library-accessible "private" interface
  private:
    float value;
    dht  SensorDHT22;   // <-----  Here I'm trying to crate an instance of a dht from dht.h but I get an error "'dht' does not name a type"

};

#endif

What does your sketch look like? I'm guessing that you think you can hide the use of the dht library from the sketch. Forget it. You can't.

Paul,

Thanks for your comment; The sketch doesn’t do anything with this class yet as it fails to compile so far. The intention is to instantiate an instance of DHT22TempHumidity which contains all the access to the dht class. I’m not really worried about hiding it, so if the dht was public that would be fine, but it doesn’t seem to work like that either.

in the dht example program the dht class is instantiated by;

#include <dht.h>

dht DHT;

#define DHT11_PIN 4
#define DHT22_PIN 5

and that works fine. but when i try to instatiate a dht I get the error message

DHT22TempHumidity.h:30: error: ‘dht’ does not name a type

MB

but when i try to instatiate a dht I get the error message

I still can't see your sketch that instantiates your class.

Paul,

As I say the main sketch does nothing with my class yet as it doesn’t compile, but here it is;

/*
  LMS10000 EECS -  LMS 10000 Engine Electronic Contol System
  Copyright (c) 2012 Mark Batchelour.  All right reserved.
*/


// Includes ------------------------------------------------------------------------------------------------------
#include "LMS10000Constants.h"
#include <SerialCommand.h>
#include <LCD5110.h>
#include "DHT22TempHumidity.h"

// Locals ------------------------------------------------------------------------------------------------------
SerialCommand SCmd;   // The demo SerialCommand object

boolean SerialOutputEnabled = true;
boolean UseAuthorised = false;
String  StatusMessage = "";
String  ParamMessage = "";





// Setup ------------------------------------------------------------------------------------------------------
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); 

  LcdInitialise();
  LcdClear();
 
  gotoXY(LCDLeft,LCDBannerLine);
  LcdString(LCDbannerString);
  
  // Setup callbacks for SerialCommand commands 
  SCmd.addCommand(ControlPassword,PasswordGiven);       // Turn on serial output
  SCmd.addCommand(EngineStopCmdshort,StopEngine);           // Turns engine off
  SCmd.addCommand(EngineStopCmd,StopEngine);        // Turns engine off
  SCmd.addCommand(MonitorOffCmd,MonitoringOff);        // Turns monitoring off
  SCmd.addCommand(MonitorOnCmd,MonitoringOn);        // Turns monitoring off
  SCmd.addDefaultHandler(unrecognized);  // Handler for command that isn't matched  (says "What?") 
  Serial.println(RemoteReadyPrompt); 
}


// Security Functions ------------------------------------------------------------------------------------------
void PasswordGiven()
{
   UseAuthorised = true;
   Serial.println(RemoteAuthorisedMsg); 
   Serial.println(RemoteReadyPrompt); 
   StatusMessage += RemoteMonEnableMsg;
}




void unrecognized()
{
   Serial.println(RemoteBadCmdMsg); 
   Serial.println(RemoteReadyPrompt); 
}


void MonitoringOn()
{
  if (UseAuthorised)
  {
      SerialOutputEnabled = true;
      StatusMessage = RemoteMonEnableMsg;
      Serial.println(RemoteMonEnableMsg); 
      Serial.println(RemoteReadyPrompt); 
  }
  else
  {
      Serial.println(RemoteNotAuthMsg);
      Serial.println(RemoteReadyPrompt); 
  }
}



void MonitoringOff()
{
  if (UseAuthorised)
  {
      SerialOutputEnabled = false;
      StatusMessage += RemoteMonDisableMsg;
      Serial.println(RemoteMonDisableMsg); 
      Serial.println(RemoteReadyPrompt); 
  }
  else
  {
      Serial.println(RemoteNotAuthMsg); 
      Serial.println(RemoteReadyPrompt); 
  }
}

// Engine control ----------------------------------------------------------------------------------------------------------------
void StopEngine()
{
  if (UseAuthorised)
  {
      // stop the engine
        Serial.println(RemoteEngStopMsg); 
        StatusMessage += RemoteEngStopMsg;
        Serial.println(RemoteReadyPrompt); 
  }
  else
  {
      Serial.println(RemoteNotAuthMsg); 
      Serial.println(RemoteReadyPrompt); 
  }

}


// main ----------------------------------------------------------------------------------------------------
void loop() {
  //pause for a while
  delay(UpdateInterval);
  
  // read serial commands
  
  SCmd.readSerial(); 
  
  // read sensors
  
  // Dispay parameters
  
  // Evaluate warnings
  
  // Raise alarms
  if (SerialOutputEnabled == true)
  {
 
  }
   
  gotoXY(LCDLeft,LCDStatusLine);
  Scroll(StatusMessage);
  gotoXY(LCDLeft,LCDParamLine);
  Scroll(ParamMessage);
}

and here is the body of the DHT22TempHumidity class;

/*
  DHT22TempHumidity - basic template for LMS 10000 sensor
  Copyright (c) 2012 Mark Batchelour.  All right reserved.
  LMS 10000 reCreation project.     www.LMS10000.org
*/

// ensure this library description is only included once
#ifndef DHT22TempHumidity_h
#define DHT22TempHumidity_h

// include types & constants of Wiring core API
#include "Arduino.h"
#include <dht.h>

// library interface description
class DHT22TempHumidity
{
  // user-accessible "public" interface
  public:
    DHT22TempHumidity(int);
    float GetValue(void);
    float ReadSensor(void);
    void  DisplaySerial(void);
    void  DisplayLcd(void);
    dht   SensorDHT22;   

  // library-accessible "private" interface
  private:
    float value;
   

};

#endif

Sorry, cut and paste error; Here is the body of the DHT22TempHumidity class;

/*
  DHT22TempHumidity.cpp - basic template for LMS 10000 sensor
  Copyright (c) 2012 Mark Batchelour.  All right reserved.
  www.LMS10000.org
 
*/

// include core Wiring API
#include "arduino.h"

// include this library's description file
#include "DHT22TempHumidity.h"
#include <dht.h>


// Constructor /////////////////////////////////////////////////////////////////
// Function that handles the creation and setup of instances

DHT22TempHumidity:: DHT22TempHumidity(int sensorPin)
{
  
  // initialize this instance's variables
  value = sensorPin;
  

  // init
}

// Public Methods //////////////////////////////////////////////////////////////
// Functions available in Wiring sketches, this library, and other libraries

float DHT22TempHumidity::GetValue(void)
{
}

float DHT22TempHumidity::ReadSensor(void)
{
}

void DHT22TempHumidity::DisplaySerial(void)
{

}

void DHT22TempHumidity::DisplayLcd(void)
{
}

// Private Methods /////////////////////////////////////////////////////////////
// Functions only available to other functions in this library

As I say the main sketch does nothing with my class yet as it doesn't compile, but here it is;

So, what I said in reply #1 is true. You are trying to hide the fact that dht.h is required from the sketch.

As I said, you can't do that.

Why, you might ask. Well, that's relatively simple. You don't own, maintain, or distribute the dht library. You just want to use it. But, suppose other people want to use your library. It won't compile or link for anyone that doesn't have the dht library installed. And, from looking at the sketch that uses (or will) your library, it isn't obvious that the dht library is needed.

One would actually have to look at the source for your library to see what other library or libraries are needed.

And that is the thing that the Arduino team does not want users to have to do.