mirror of
https://github.com/Lemonochrme/clover.git
synced 2025-06-08 16:50:50 +02:00
Deleted Exception in platformio config. Added ServerException (dead code). Created MainComponent singleton.
This commit is contained in:
parent
ab0c2ca48c
commit
d4de1f6efb
5 changed files with 83 additions and 15 deletions
19
embedded/lib/Component/MainComponent.cpp
Normal file
19
embedded/lib/Component/MainComponent.cpp
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include "MainComponent.hpp"
|
||||||
|
|
||||||
|
MainComponent::MainComponent()
|
||||||
|
: _humidity(ComponentType::Analog, PIN_A0), _led(D8, D7, 2), _dht(DHT11, D3)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MainComponent::~MainComponent()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void MainComponent::setup()
|
||||||
|
{
|
||||||
|
_led.setup();
|
||||||
|
_dht.setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
Component& MainComponent::getHumidity() { return _humidity; }
|
||||||
|
LedComponent& MainComponent::getLed() { return _led; }
|
||||||
|
DHTComponent& MainComponent::getDHT() { return _dht; }
|
34
embedded/lib/Component/MainComponent.hpp
Normal file
34
embedded/lib/Component/MainComponent.hpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef _HEADER_COMPONENT_MAIN
|
||||||
|
#define _HEADER_COMPONENT_MAIN
|
||||||
|
|
||||||
|
#include "Component.hpp"
|
||||||
|
#include "LedComponent.hpp"
|
||||||
|
#include "DHTComponent.hpp"
|
||||||
|
|
||||||
|
class MainComponent {
|
||||||
|
public:
|
||||||
|
// Singleton
|
||||||
|
static MainComponent& GetInstance()
|
||||||
|
{
|
||||||
|
static MainComponent instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
// Public functions
|
||||||
|
void setup();
|
||||||
|
Component& getHumidity();
|
||||||
|
LedComponent& getLed();
|
||||||
|
DHTComponent& getDHT();
|
||||||
|
private:
|
||||||
|
// Singleton
|
||||||
|
MainComponent();
|
||||||
|
~MainComponent();
|
||||||
|
MainComponent(const MainComponent&) = delete;
|
||||||
|
MainComponent& operator=(const MainComponent&) = delete;
|
||||||
|
|
||||||
|
// Components
|
||||||
|
Component _humidity;
|
||||||
|
LedComponent _led;
|
||||||
|
DHTComponent _dht;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //
|
22
embedded/lib/ServerHandler/ServerException.hpp
Normal file
22
embedded/lib/ServerHandler/ServerException.hpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef _HEADER_SERVER_EXCEPTION
|
||||||
|
#define _HEADER_SERVER_EXCEPTION
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <exception>
|
||||||
|
#include "ServerException.hpp"
|
||||||
|
|
||||||
|
class ServerException : public std::exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ServerException(const char* msg, uint8_t code)
|
||||||
|
: _msg(msg), _code(code)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t code() { return _code; }
|
||||||
|
const char* what() { return _msg; }
|
||||||
|
private:
|
||||||
|
const char* _msg;
|
||||||
|
uint8_t _code;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _HEADER_SERVER_EXCEPTION
|
|
@ -11,7 +11,8 @@
|
||||||
[env:nodemcuv2]
|
[env:nodemcuv2]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = nodemcuv2
|
board = nodemcuv2
|
||||||
build_flags = -fexceptions
|
build_flags =
|
||||||
|
-std=c++11
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
tzapu/WiFiManager@^0.16.0
|
tzapu/WiFiManager@^0.16.0
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
#include <ESP8266WebServer.h>
|
#include <ESP8266WebServer.h>
|
||||||
|
|
||||||
#include "ServerHandler.hpp"
|
#include "ServerHandler.hpp"
|
||||||
#include "Component.hpp"
|
#include "MainComponent.hpp"
|
||||||
#include "LedComponent.hpp"
|
|
||||||
#include "DHTComponent.hpp"
|
|
||||||
#include "Screen.hpp"
|
#include "Screen.hpp"
|
||||||
|
|
||||||
#ifdef SSID_CLOVER
|
#ifdef SSID_CLOVER
|
||||||
|
@ -15,16 +13,12 @@
|
||||||
const char* pswd = PSWD_CLOVER;
|
const char* pswd = PSWD_CLOVER;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Component humidity(ComponentType::Analog, PIN_A0);
|
|
||||||
LedComponent led(D8,D7,2);
|
|
||||||
DHTComponent airSensor(DHT11,D3);
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// Sensors/Acuators setup
|
// Sensors/Acuators setup
|
||||||
led.setup();
|
MainComponent::GetInstance().setup();
|
||||||
airSensor.setup();
|
|
||||||
// Lights are off when powered
|
// Lights are off when powered
|
||||||
|
auto& led = MainComponent::GetInstance().getLed();
|
||||||
led.setColor(0,{0,0,0});
|
led.setColor(0,{0,0,0});
|
||||||
led.setColor(1,{0,0,0});
|
led.setColor(1,{0,0,0});
|
||||||
|
|
||||||
|
@ -43,8 +37,6 @@ void loop()
|
||||||
auto& serverHandler = ServerHandler::GetInstance();
|
auto& serverHandler = ServerHandler::GetInstance();
|
||||||
auto& dataHandler = DataHandler::GetInstance();
|
auto& dataHandler = DataHandler::GetInstance();
|
||||||
auto& screen = Display::Screen::GetInstance();
|
auto& screen = Display::Screen::GetInstance();
|
||||||
led.setColor(0,{32,0,0});
|
|
||||||
led.setColor(1,{0,32,0});
|
|
||||||
|
|
||||||
// Could not connect after setup: Showing screen failure
|
// Could not connect after setup: Showing screen failure
|
||||||
if(!serverHandler.isConnected())
|
if(!serverHandler.isConnected())
|
||||||
|
@ -71,9 +63,9 @@ void loop()
|
||||||
|
|
||||||
// Data gathered from various sensors
|
// Data gathered from various sensors
|
||||||
// 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940)
|
// 0 -> air(0), 0-300 -> dry(20), 300-700 -> humid (580), 700-950 -> water(940)
|
||||||
auto soilHumidityData = static_cast<float>(std::any_cast<int>(humidity.getValue()));
|
auto soilHumidityData = static_cast<float>(std::any_cast<int>(MainComponent::GetInstance().getHumidity().getValue()));
|
||||||
auto airTemperatureData = airSensor.getTemperature();
|
auto airTemperatureData = MainComponent::GetInstance().getDHT().getTemperature();
|
||||||
auto airHumidityData = airSensor.getHumidity();
|
auto airHumidityData = MainComponent::GetInstance().getDHT().getHumidity();
|
||||||
|
|
||||||
// Updating the data handler
|
// Updating the data handler
|
||||||
dataHandler.updateSoilMoistureData(soilHumidityData);
|
dataHandler.updateSoilMoistureData(soilHumidityData);
|
||||||
|
|
Loading…
Add table
Reference in a new issue