mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-21 12:42:10 +02:00
Fix capitalize folder and file name ignored
This commit is contained in:
149
src/Sht/Sht.cpp
Normal file
149
src/Sht/Sht.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
#include "Sht.h"
|
||||
|
||||
#include "../Libraries/arduino-sht/SHTSensor.h"
|
||||
|
||||
/** Cast _sensor to SHTSensor */
|
||||
#define shtSensor() ((SHTSensor *)(this->_sensor))
|
||||
|
||||
/**
|
||||
* @brief Check that is sensor initialized
|
||||
*
|
||||
* @return true Initialized
|
||||
* @return false Not-initialized
|
||||
*/
|
||||
bool Sht::isBegin(void) {
|
||||
if (this->_isBegin) {
|
||||
return true;
|
||||
}
|
||||
AgLog("Sensor not-initialized");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check board is support I2C to work with this sensor
|
||||
*
|
||||
* @return true Supported
|
||||
* @return false Not supported
|
||||
*/
|
||||
bool Sht::boardSupported(void) {
|
||||
if (this->_bsp == NULL) {
|
||||
this->_bsp = getBoardDef(this->_boardType);
|
||||
}
|
||||
|
||||
if ((this->_bsp == NULL) || (this->_bsp->I2C.supported == false)) {
|
||||
AgLog("Board not supported");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Construct a new Sht:: Sht object
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
Sht::Sht(BoardType type) : _boardType(type) {}
|
||||
|
||||
/**
|
||||
* @brief Destroy the Sht:: Sht object
|
||||
*
|
||||
*/
|
||||
Sht::~Sht() {}
|
||||
|
||||
#if defined(ESP8266)
|
||||
/**
|
||||
* @brief Init sensor, Ifthis funciton not call the other funtion call will
|
||||
* always return false or value invalid
|
||||
*
|
||||
* @param wire wire TwoWire instance, Must be initialized
|
||||
* @param debugStream Point to debug Serial to print debug log
|
||||
* @return true Sucecss
|
||||
* @return false Failure
|
||||
*/
|
||||
bool Sht::begin(TwoWire &wire, Stream &debugStream) {
|
||||
_debugStream = &debugStream;
|
||||
return begin(wire);
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
/**
|
||||
* @brief Initialize sensor, should be init sensor before use other API, if not
|
||||
* return result always failed
|
||||
*
|
||||
* @param wire TwoWire instance, Must be initialized
|
||||
* @return true Success
|
||||
* @return false Failure
|
||||
*/
|
||||
bool Sht::begin(TwoWire &wire) {
|
||||
if (_isBegin) {
|
||||
AgLog("Initialized, call end() then try again");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (boardSupported() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Create new sensor */
|
||||
_sensor = new SHTSensor();
|
||||
if (_sensor == nullptr) {
|
||||
AgLog("Create SHTSensor failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Initialize sensor */
|
||||
if (shtSensor()->init(wire) == false) {
|
||||
AgLog("Initialize SHTSensor failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only supported by SHT3x
|
||||
if (shtSensor()->setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM) == false) {
|
||||
AgLog("Configure sensor failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
AgLog("Initialize");
|
||||
_isBegin = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-initialize sht sensor
|
||||
*
|
||||
*/
|
||||
void Sht::end(void) {
|
||||
if (_isBegin == false) {
|
||||
return;
|
||||
}
|
||||
delete shtSensor();
|
||||
_isBegin = false;
|
||||
#if defined(ESP8266)
|
||||
_debugStream = nullptr;
|
||||
#else
|
||||
#endif
|
||||
_isBegin = false;
|
||||
AgLog("De-Initialize");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get temprature degree celcius
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
float Sht::getTemperature(void) { return shtSensor()->getTemperature(); }
|
||||
|
||||
/**
|
||||
* @brief Get humidity
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
float Sht::getRelativeHumidity(void) { return shtSensor()->getHumidity(); }
|
||||
|
||||
/**
|
||||
* @brief Measure temperature and humidity
|
||||
*
|
||||
* @return true Success
|
||||
* @return false Failure
|
||||
*/
|
||||
bool Sht::measure(void) { return shtSensor()->readSample(); }
|
42
src/Sht/Sht.h
Normal file
42
src/Sht/Sht.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef _SHT_H_
|
||||
#define _SHT_H_
|
||||
|
||||
#include "../main/BoardDef.h"
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
/**
|
||||
* @brief This class with define how to handlet sensirion sensor sht4x and
|
||||
* sht3x(Temperature and humidity sensor)
|
||||
*
|
||||
*/
|
||||
class Sht {
|
||||
private:
|
||||
BoardType _boardType;
|
||||
bool _isBegin = false;
|
||||
void *_sensor;
|
||||
const BoardDef *_bsp = NULL;
|
||||
#if defined(ESP8266)
|
||||
Stream *_debugStream = nullptr;
|
||||
const char *TAG = "SHT";
|
||||
#else
|
||||
#endif
|
||||
bool isBegin(void);
|
||||
bool boardSupported(void);
|
||||
|
||||
public:
|
||||
Sht(BoardType type);
|
||||
~Sht();
|
||||
|
||||
#if defined(ESP8266)
|
||||
bool begin(TwoWire &wire, Stream &debugStream);
|
||||
#else
|
||||
#endif
|
||||
bool begin(TwoWire &wire);
|
||||
void end(void);
|
||||
bool measure(void);
|
||||
float getTemperature(void);
|
||||
float getRelativeHumidity(void);
|
||||
};
|
||||
|
||||
#endif /** _SHT_H_ */
|
Reference in New Issue
Block a user