Skip to content

Commit

Permalink
Merge branch 'edge' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tale152 committed May 5, 2022
2 parents 541ef2b + ff494b9 commit 8f89683
Show file tree
Hide file tree
Showing 75 changed files with 1,354 additions and 552 deletions.
18 changes: 17 additions & 1 deletion edge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,21 @@ tasks.register<Exec>("testRealHw") {
}

tasks.register<Exec>("upload") {
commandLine("pio", "run", "-e", "nodemcuv2", "-t", "upload")

val envs: List<String> = File("platformio.ini").readLines().filter{
it.matches(Regex("\\[env:.*\\]"))
}.map{
it.substringAfter("[env:").substringBefore("]")
}.filter {
it != "native" && it != "nodemcuv2"
}
println("Please select the environment to upload: [0-" + (envs.size - 1).toString() + "]\n")
for ((i, item) in envs.withIndex()) {
println(i.toString() + ". " + item)
}

val userInput = readLine()?.toIntOrNull()
if(userInput != null && userInput >= 0 && userInput < envs.size) {
commandLine("pio", "run", "-e", envs[userInput], "-t", "upload")
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "DigitalLightHw.h"
#include <Arduino.h>

DigitalLightHw::DigitalLightHw(std::string id, uint8_t pin) : DigitalLightHwInterface(id, pin) {
DigitalLightHw::DigitalLightHw(std::string id, uint8_t pin) : DigitalLightHwInterface(id), OnePin(pin) {
pinMode(pin, OUTPUT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define BRITTANY_DIGITAL_LIGHT_HW_H

#include "hw/interfaces/DigitalLightHwInterface.h"
#include "hw/feature/OnePin.h"

/**
* @brief Concrete implementation of a Digital Light component.
*
*/
class DigitalLightHw : public DigitalLightHwInterface {
class DigitalLightHw : public DigitalLightHwInterface, public OnePin {

public:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@ class DHT22Module : public ComponentModule<DHT22SensorHw> {

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
)
new DHT22GetTemperatureHandler(DHT22_GET_TEMPERATURE_HANDLER_NAME, components)
);
_handlers.push_back(
new DHT22GetHumidityHandler(
DHT22_GET_HUMIDITY_HANDLER_NAME,
as_route(DHT22_GET_HUMIDITY_HANDLER_NAME),
components
)
new DHT22GetHumidityHandler(DHT22_GET_HUMIDITY_HANDLER_NAME, components)
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

DHT22GetHumidityHandler::DHT22GetHumidityHandler(
std::string name,
std::string path,
std::list<DHT22SensorHw*> components
): DHT22Handler(name, path, components) {
): DHT22Handler(name, components) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DHT22GetHumidityHandler : public DHT22Handler {

DHT22GetHumidityHandler(
std::string name,
std::string path,
std::list<DHT22SensorHw*> components
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

DHT22GetTemperatureHandler::DHT22GetTemperatureHandler(
std::string name,
std::string path,
std::list<DHT22SensorHw*> components
): DHT22Handler(name, path, components) {
): DHT22Handler(name, components) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ class DHT22GetTemperatureHandler : public DHT22Handler {

public:

DHT22GetTemperatureHandler(
std::string name,
std::string path,
std::list<DHT22SensorHw*> components
);
DHT22GetTemperatureHandler(std::string name, std::list<DHT22SensorHw*> components);

private:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,22 @@

#include <string>
#include <list>
#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h"
#include "operation-handler/interfaces/RetrieveValueFromComponentInterface.h"
#include "temp-hum-sensor/dht22/hw/DHT22SensorHw.h"

class DHT22Handler : public ValueReturnedAfterActionHandlerInterface<float> {
class DHT22Handler : public RetrieveValueFromComponentInterface<DHT22SensorHw, float> {

public:

DHT22Handler(std::string name, std::string path, std::list<DHT22SensorHw*> components)
: ValueReturnedAfterActionHandlerInterface<float> (name, path, OperationType::PROPERTY, Type::NUMBER) {
_components = components;
DHT22Handler(std::string name, std::list<DHT22SensorHw*> components)
: RetrieveValueFromComponentInterface<DHT22SensorHw, float> (name, 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
3 changes: 2 additions & 1 deletion edge/lib/brittany-concrete/src/web-server/Esp8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

#include "web-server/WebServer.h"
#include "edge/Edge.h"
#include "ESP8266WebServer.h"
#include <ESP8266WebServer.h>
#include "HttpStatusCodes_C++.h"
#include "json_util.h"
#include "util/DebugPrint.h"
#include <ESP8266WiFi.h>

/**
* @brief ESP8266WebServer implementation of web server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class MockDigitalLightHw : public DigitalLightHwInterface {

public:

MockDigitalLightHw(std::string id, uint8_t pin) : DigitalLightHwInterface(id, pin){ }
MockDigitalLightHw(std::string id) : DigitalLightHwInterface(id) {
_isOn = false;
}

void on() {
_isOn = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,17 @@
#include "mock-digital-light/operation-handler/MockIsOnDigitalLightHandler.h"
#include "mock-digital-light/operation-handler/MockTurnOffDigitalLightHandler.h"
#include "mock-digital-light/operation-handler/MockTurnOnDigitalLightHandler.h"

#define MOCK_IS_ON_HANDLER_MODULE_NAME "isOn"
#define MOCK_TURN_ON_HANDLER_MODULE_NAME "turnOn"
#define MOCK_TURN_OFF_HANDLER_MODULE_NAME "turnOff"
#include "modules/ModuleNames.h"

class MockDigitalLightModule : public ComponentModule<MockDigitalLightHw> {

public:

MockDigitalLightModule(std::string name, std::list<MockDigitalLightHw*> components): ComponentModule<MockDigitalLightHw>(name, components) {
_handlers.push_back(
new MockIsOnDigitalLightHandler(
MOCK_IS_ON_HANDLER_MODULE_NAME,
as_route(MOCK_IS_ON_HANDLER_MODULE_NAME),
components
)
);
_handlers.push_back(
new MockTurnOnDigitalLightHandler(
MOCK_TURN_ON_HANDLER_MODULE_NAME,
as_route(MOCK_TURN_ON_HANDLER_MODULE_NAME),
components
)
);
_handlers.push_back(
new MockTurnOffDigitalLightHandler(
MOCK_TURN_OFF_HANDLER_MODULE_NAME,
as_route(MOCK_TURN_OFF_HANDLER_MODULE_NAME),
components
)
);
MockDigitalLightModule(std::list<MockDigitalLightHw*> components)
: ComponentModule<MockDigitalLightHw>(module_as_string(ModuleNames::Light), components) {
_handlers.push_back(new MockIsOnDigitalLightHandler(components));
_handlers.push_back(new MockTurnOnDigitalLightHandler(components));
_handlers.push_back(new MockTurnOffDigitalLightHandler(components));
};

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,20 @@
#include <list>
#include <string>
#include <json/json.h>
#include "operation-handler/interfaces/ValueReturnedAfterActionHandlerInterface.h"
#include "operation-handler/interfaces/components/IsOnSwitchableHandler.h"
#include "mock-digital-light/hw/MockDigitalLightHw.h"
#include "operation-handler/OperationHandlerResult.h"
#include "HttpStatusCodes_C++.h"
#include "util.h"
#include <optional>

class MockIsOnDigitalLightHandler : public ValueReturnedAfterActionHandlerInterface<bool> {
class MockIsOnDigitalLightHandler: public IsOnSwitchableHandler<MockDigitalLightHw> {

public:

MockIsOnDigitalLightHandler(
std::string name,
std::string path,
std::list<MockDigitalLightHw*> components
): ValueReturnedAfterActionHandlerInterface<bool>(
name,
path,
OperationType::PROPERTY,
Type::BOOLEAN
) {
_components = components;
MockIsOnDigitalLightHandler(std::list<MockDigitalLightHw*> components)
: IsOnSwitchableHandler<MockDigitalLightHw>("isOn", components) {
};

private:

std::optional<bool> retrieveValue(Json::Value args) {
std::optional<MockDigitalLightHw*> oc = find_by_id(_components, args["id"].asCString());
if(oc.has_value()){
return std::optional(oc.value() -> isOn());
}
return std::nullopt;
}

std::list<MockDigitalLightHw*> _components;

};

#endif //BRITTANY_MOCK_IS_ON_DIGITAL_LIGHT_HANDLER_INTERFACE_H
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,19 @@

#include <list>
#include <string>
#include <json/json.h>
#include "operation-handler/interfaces/TurnOffHandlerInterface.h"
#include "operation-handler/interfaces/TurnOffHandlerInterface.cpp"
#include "operation-handler/interfaces/components/TurnOffSwitchableHandler.h"
#include "mock-digital-light/hw/MockDigitalLightHw.h"
#include "operation-handler/OperationHandlerResult.h"
#include "util.h"

class MockTurnOffDigitalLightHandler : public TurnOffHandlerInterface {
class MockTurnOffDigitalLightHandler: public TurnOffSwitchableHandler<MockDigitalLightHw> {

public:

MockTurnOffDigitalLightHandler(
std::string name,
std::string path,
std::list<MockDigitalLightHw*> components
): TurnOffHandlerInterface(name, path) {
_components = components;
};

private:
MockTurnOffDigitalLightHandler(std::list<MockDigitalLightHw*> components)
: TurnOffSwitchableHandler<MockDigitalLightHw>("turnOff", components) {

bool turnOff(std::string id) {
std::optional<MockDigitalLightHw*> oc = find_by_id(_components, id);
if(oc.has_value()) {
oc.value() -> off();
return true;
} else {
return false;
}
};

std::list<MockDigitalLightHw*> _components;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,19 @@

#include <list>
#include <string>
#include <json/json.h>
#include "operation-handler/interfaces/TurnOnHandlerInterface.h"
#include "operation-handler/interfaces/TurnOnHandlerInterface.cpp"
#include "operation-handler/interfaces/components/TurnOnSwitchableHandler.h"
#include "mock-digital-light/hw/MockDigitalLightHw.h"
#include "operation-handler/OperationHandlerResult.h"
#include "util.h"

class MockTurnOnDigitalLightHandler : public TurnOnHandlerInterface {
class MockTurnOnDigitalLightHandler: public TurnOnSwitchableHandler<MockDigitalLightHw> {

public:

MockTurnOnDigitalLightHandler(
std::string name,
std::string path,
std::list<MockDigitalLightHw*> components
): TurnOnHandlerInterface(name, path) {
_components = components;
};

private:

bool turnOn(std::string id) {
std::optional<MockDigitalLightHw*> oc = find_by_id(_components, id);
if(oc.has_value()) {
oc.value() -> on();
return true;
} else {
return false;
}
};

std::list<MockDigitalLightHw*> _components;
MockTurnOnDigitalLightHandler(std::list<MockDigitalLightHw*> components)
: TurnOnSwitchableHandler<MockDigitalLightHw>("turnOn", components) {

}
};

#endif //BRITTANY_MOCK_TURN_ON_DIGITAL_LIGHT_HANDLER_INTERFACE_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef BRITTANY_MOCK_DEHUMIDIFIER_MODULE_H
#define BRITTANY_MOCK_DEHUMIDIFIER_MODULE_H

#include <list>
#include "operation-handler/interfaces/components/TurnOffSwitchableHandler.h"
#include "operation-handler/interfaces/components/TurnOnSwitchableHandler.h"
#include "operation-handler/interfaces/components/IsOnSwitchableHandler.h"
#include "mock-switchable/hw/MockSwitchableHw.h"
#include "modules/ComponentModule.h"
#include "modules/ModuleNames.h"

class MockDehumidifierModule : public ComponentModule<MockSwitchableHw> {

public:

MockDehumidifierModule(std::list<MockSwitchableHw*> components)
: ComponentModule<MockSwitchableHw>(module_as_string(ModuleNames::Humidity), components) {
_handlers.push_back(
new TurnOnSwitchableHandler<MockSwitchableHw>(
"dehumidifyOn",
components
)
);
_handlers.push_back(
new TurnOffSwitchableHandler<MockSwitchableHw>(
"dehumidifyOff",
components
)
);
_handlers.push_back(
new IsOnSwitchableHandler<MockSwitchableHw>(
"isDehumidifyOn",
components
)
);
};

};

#endif //BRITTANY_MOCK_DEHUMIDIFIER_MODULE_H
Loading

0 comments on commit 8f89683

Please sign in to comment.