diff --git a/.vscode/settings.json b/.vscode/settings.json index d8cb326..4707309 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "files.associations": { "string": "cpp" - } + }, + "cmake.configureOnOpen": false } \ No newline at end of file diff --git a/lib/Component/Component.cpp b/lib/Component/Component.cpp new file mode 100644 index 0000000..98b84c9 --- /dev/null +++ b/lib/Component/Component.cpp @@ -0,0 +1,27 @@ +#include "Component.hpp" + +Component::Component(ComponentType ct, uint8_t p) +: _type(ct), _pin(p) +{} + +std::any Component::getValue(void){ + switch(_type) + { + case ComponentType::Digital: + return digitalRead(_pin); + case ComponentType::Analog: + return analogRead(_pin); + default: + return 0; + } +} + +void Component::sendValue(std::any data) +{ + switch(_type) { + case ComponentType::Digital: + digitalWrite(_pin, std::any_cast(data)); + case ComponentType::Analog: + analogWrite(_pin, std::any_cast(data)); + } +} \ No newline at end of file diff --git a/lib/Component/Component.hpp b/lib/Component/Component.hpp new file mode 100644 index 0000000..344d781 --- /dev/null +++ b/lib/Component/Component.hpp @@ -0,0 +1,23 @@ +#ifndef _HEADER_COMPONENT +#define _HEADER_COMPONENT +#include +#include + +enum class ComponentType { + Digital, + Analog, + I2C, + Serial +}; + +class Component{ + public: + Component(ComponentType ct, uint8_t p); + std::any getValue(); + void sendValue(std::any data); + private: + ComponentType _type; + const uint8_t _pin; +}; + +#endif //_HEADER_COMPONENT \ No newline at end of file diff --git a/lib/Component/Display.cpp b/lib/Component/Display.cpp new file mode 100644 index 0000000..e2c8d00 --- /dev/null +++ b/lib/Component/Display.cpp @@ -0,0 +1,16 @@ +#include "Display.hpp" + +Display::Display() +{ + _display = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0,U8X8_PIN_NONE,SCL,SDA); + _display->begin(); +} + +void Display::loop() +{ + _display->clearBuffer(); // clear the internal memory + _display->setFont(u8g2_font_ncenB08_tr); // choose a suitable font + _display->drawStr(0,10,"Hello World!"); // write something to the internal memory + _display->sendBuffer(); // transfer internal memory to the display + delay(1000); +} \ No newline at end of file diff --git a/lib/Component/Display.hpp b/lib/Component/Display.hpp new file mode 100644 index 0000000..79b6c25 --- /dev/null +++ b/lib/Component/Display.hpp @@ -0,0 +1,10 @@ +#include +#include + +class Display { + public: + Display(); + void loop(); + private: + U8G2_SSD1306_128X64_NONAME_F_HW_I2C* _display; +}; \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 239547c..32bd1eb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,6 +12,8 @@ platform = espressif8266 board = nodemcuv2 framework = arduino -lib_deps = tzapu/WiFiManager@^0.16.0 - bbx10/DNSServer@^1.1.0 - ArduinoJson +lib_deps = + tzapu/WiFiManager@^0.16.0 + bbx10/DNSServer@^1.1.0 + ArduinoJson + olikraus/U8g2@^2.35.7 diff --git a/src/main.cpp b/src/main.cpp index dc97a3c..ab540cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,27 +4,27 @@ #include "ServerHandler.hpp" #include "DataHandler.hpp" +#include "Component.hpp" +#include "Display.hpp" DataHandler dataHandler; ServerHandler serverHandler(&dataHandler); // Référence à dataHandler +Component humidity(ComponentType::Analog, PIN_A0); +Display screen; - -void setup() { +void setup() +{ Serial.begin(9600); - - dataHandler.updateTemperatureData(20.0); - dataHandler.updateHumidityData(3.141592); - - serverHandler.setup("Redmi Note 10", "bbooksdd"); + serverHandler.setup("Iphone de Nicole", "cesthonteux"); } -void loop() { +void loop() +{ + screen.loop(); + dataHandler.updateTemperatureData(random(1800, 2200) / 100.0); + dataHandler.updateHumidityData(static_cast(std::any_cast(humidity.getValue()))); Serial.println(dataHandler.getJsonData()); - - dataHandler.updateTemperatureData(random(1800, 2200)/100.0); - dataHandler.updateHumidityData(random(4400, 5000)/100.0); delay(1000); - serverHandler.loop(); }