-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/Tale152/brittany into de…
…velop
- Loading branch information
Showing
167 changed files
with
3,807 additions
and
706 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
edge/lib/brittany-concrete/src/mock/MockSerialArgsOperationHandler.h
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/hw/DHT22SensorHw.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "DHT22SensorHw.h" | ||
|
||
DHT22SensorHw::DHT22SensorHw(std::string id, uint8_t pin) : TempHumHwInterface(id, pin), dht(pin, DHT22) { | ||
dht.begin(); | ||
} | ||
|
||
std::optional<float> DHT22SensorHw::temperatureCelsius() { | ||
float temp = dht.readTemperature(); | ||
return isnan(temp) ? std::nullopt : std::optional(temp); | ||
} | ||
|
||
std::optional<float> DHT22SensorHw::temperatureKelvin() { | ||
std::optional<float> tempC = temperatureCelsius(); | ||
if(tempC.has_value()){ | ||
return std::optional(Temperature::fromCToK(tempC.value())); | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
std::optional<float> DHT22SensorHw::temperatureFahrenheit() { | ||
float temp = dht.readTemperature(true); | ||
return isnan(temp) ? std::nullopt : std::optional(temp); | ||
} | ||
|
||
std::optional<float> DHT22SensorHw::humidity() { | ||
float humidity = dht.readHumidity(); | ||
return isnan(humidity) ? std::nullopt : std::optional(humidity); | ||
} |
40 changes: 40 additions & 0 deletions
40
edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/hw/DHT22SensorHw.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#ifndef BRITTANY_DHT22_SENSOR_HW_H | ||
#define BRITTANY_DHT22_SENSOR_HW_H | ||
|
||
#include "hw/interfaces/TempHumHwInterface.h" | ||
#include <string> | ||
#include <DHT.h> | ||
#include <DHT_U.h> | ||
#include <optional> | ||
#include <Adafruit_Sensor.h> | ||
|
||
/** | ||
* @brief Concrete implementation of a DHT22 component. | ||
* | ||
*/ | ||
class DHT22SensorHw : public TempHumHwInterface { | ||
|
||
public: | ||
|
||
/** | ||
* @brief Construct a new DHT22SensorHw object. | ||
* | ||
* @param id the hw id. | ||
* @param pin the data pin of the DHT22. | ||
*/ | ||
DHT22SensorHw(std::string id, uint8_t pin); | ||
|
||
std::optional<float> temperatureCelsius(); | ||
|
||
std::optional<float> temperatureKelvin(); | ||
|
||
std::optional<float> temperatureFahrenheit(); | ||
|
||
std::optional<float> humidity(); | ||
|
||
private: | ||
|
||
DHT dht; | ||
|
||
}; | ||
#endif //BRITTANY_DHT22_SENSOR_HW_H |
36 changes: 36 additions & 0 deletions
36
edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/modules/DHT22Module.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef BRITTANY_DHT22_MODULE | ||
#define BRITTANY_DHT22_MODULE | ||
|
||
#include "modules/ComponentModule.h" | ||
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h" | ||
#include "temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.h" | ||
#include "temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.h" | ||
#include "util.h" | ||
|
||
#define DHT22_GET_TEMPERATURE_HANDLER_NAME "temperature" | ||
#define DHT22_GET_HUMIDITY_HANDLER_NAME "humidity" | ||
|
||
class DHT22Module : public ComponentModule<DHT22SensorHw> { | ||
|
||
public: | ||
|
||
DHT22Module(std::string name, std::list<DHT22SensorHw*> components): ComponentModule<DHT22SensorHw>(name, components) { | ||
_handlers.push_back( | ||
new DHT22GetTemperatureHandler( | ||
DHT22_GET_TEMPERATURE_HANDLER_NAME, | ||
as_route(DHT22_GET_TEMPERATURE_HANDLER_NAME), | ||
components | ||
) | ||
); | ||
_handlers.push_back( | ||
new DHT22GetHumidityHandler( | ||
DHT22_GET_HUMIDITY_HANDLER_NAME, | ||
as_route(DHT22_GET_HUMIDITY_HANDLER_NAME), | ||
components | ||
) | ||
); | ||
}; | ||
|
||
}; | ||
|
||
#endif //BRITTANY_DHT22_MODULE |
14 changes: 14 additions & 0 deletions
14
...brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "DHT22GetHumidityHandler.h" | ||
#include "util.h" | ||
|
||
DHT22GetHumidityHandler::DHT22GetHumidityHandler( | ||
std::string name, | ||
std::string path, | ||
std::list<DHT22SensorHw*> components | ||
): DHT22Handler(name, path, components) { | ||
|
||
} | ||
|
||
std::optional<float> DHT22GetHumidityHandler::sub_operation(DHT22SensorHw* hw, Json::Value args) { | ||
return hw -> humidity(); | ||
} |
26 changes: 26 additions & 0 deletions
26
...b/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetHumidityHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef BRITTANY_DHT22_GET_HUMIDITY_HANDLER_H | ||
#define BRITTANY_DHT22_GET_HUMIDITY_HANDLER_H | ||
|
||
#include <string> | ||
#include <list> | ||
#include "DHT22Handler.h" | ||
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h" | ||
|
||
class DHT22GetHumidityHandler : public DHT22Handler { | ||
|
||
public: | ||
|
||
DHT22GetHumidityHandler( | ||
std::string name, | ||
std::string path, | ||
std::list<DHT22SensorHw*> components | ||
); | ||
|
||
private: | ||
|
||
std::optional<float> sub_operation(DHT22SensorHw* hw, Json::Value args); | ||
|
||
std::list<DHT22SensorHw*> _components; | ||
}; | ||
|
||
#endif //BRITTANY_DHT22_GET_HUMIDITY_HANDLER_H |
24 changes: 24 additions & 0 deletions
24
...ttany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "DHT22GetTemperatureHandler.h" | ||
#include "util.h" | ||
|
||
DHT22GetTemperatureHandler::DHT22GetTemperatureHandler( | ||
std::string name, | ||
std::string path, | ||
std::list<DHT22SensorHw*> components | ||
): DHT22Handler(name, path, components) { | ||
|
||
} | ||
|
||
std::optional<float> DHT22GetTemperatureHandler::sub_operation(DHT22SensorHw* hw, Json::Value args) { | ||
if(args.isMember("unit")) { | ||
if(args["unit"] == "C" || args["unit"] == "c") { | ||
return hw -> temperatureCelsius(); | ||
} else if(args["unit"] == "K" || args["unit"] == "k") { | ||
return hw -> temperatureKelvin(); | ||
} else if(args["unit"] == "F" || args["unit"] == "f") { | ||
return hw -> temperatureFahrenheit(); | ||
} | ||
return std::nullopt; | ||
} | ||
return hw -> temperatureCelsius(); | ||
} |
26 changes: 26 additions & 0 deletions
26
...rittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22GetTemperatureHandler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H | ||
#define BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H | ||
|
||
#include <string> | ||
#include <list> | ||
#include "DHT22Handler.h" | ||
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h" | ||
|
||
class DHT22GetTemperatureHandler : public DHT22Handler { | ||
|
||
public: | ||
|
||
DHT22GetTemperatureHandler( | ||
std::string name, | ||
std::string path, | ||
std::list<DHT22SensorHw*> components | ||
); | ||
|
||
private: | ||
|
||
std::optional<float> sub_operation(DHT22SensorHw* hw, Json::Value args); | ||
|
||
std::list<DHT22SensorHw*> _components; | ||
}; | ||
|
||
#endif //BRITTANY_DHT22_GET_TEMPERATURE_HANDLER_H |
36 changes: 36 additions & 0 deletions
36
edge/lib/brittany-concrete/src/temp-hum-sensor/dht22/operation-handler/DHT22Handler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef BRITTANY_DHT22_HANDLER_H | ||
#define BRITTANY_DHT22_HANDLER_H | ||
|
||
#include <string> | ||
#include <list> | ||
#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h" | ||
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h" | ||
|
||
class DHT22Handler : public ValueReturnedAfterActionHandlerInterface<float> { | ||
|
||
public: | ||
|
||
DHT22Handler(std::string name, std::string path, std::list<DHT22SensorHw*> components) | ||
: ValueReturnedAfterActionHandlerInterface<float> (name, path, OperationType::PROPERTY, Type::NUMBER) { | ||
_components = components; | ||
}; | ||
|
||
private: | ||
|
||
std::optional<float> retrieveValue(Json::Value args) { | ||
std::optional<DHT22SensorHw*> oc = find_by_id(_components, args["id"].asCString()); | ||
if(oc.has_value()) { | ||
std::optional<float> opt_value = sub_operation(oc.value(), args); | ||
if(opt_value.has_value()) { | ||
return opt_value.value(); | ||
} | ||
} | ||
return std::nullopt; | ||
} | ||
|
||
virtual std::optional<float> sub_operation(DHT22SensorHw* hw, Json::Value args) = 0; | ||
|
||
std::list<DHT22SensorHw*> _components; | ||
}; | ||
|
||
#endif //BRITTANY_DHT22_HANDLER_H |
Oops, something went wrong.