From 90898aa8e5765aa05e9ad2e9e66543015f288b4f Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Fri, 22 Dec 2023 14:28:34 +0100 Subject: [PATCH] Added many comments --- embedded/lib/Component/Component.hpp | 18 ++++ embedded/lib/Component/DHTComponent.hpp | 22 +++++ embedded/lib/Component/LedComponent.hpp | 35 ++++++++ embedded/lib/Component/MainComponent.hpp | 22 +++++ embedded/lib/DataHandler/DataHandler.hpp | 30 +++++++ embedded/lib/Display/Screen.cpp | 3 + embedded/lib/Display/Screen.hpp | 89 ++++++++++++++++++++ embedded/lib/ServerHandler/ServerHandler.hpp | 25 ++++++ embedded/src/warning.hpp | 16 ++++ 9 files changed, 260 insertions(+) diff --git a/embedded/lib/Component/Component.hpp b/embedded/lib/Component/Component.hpp index b730b9f..c473ea0 100644 --- a/embedded/lib/Component/Component.hpp +++ b/embedded/lib/Component/Component.hpp @@ -10,8 +10,26 @@ enum class ComponentType { class Component{ public: + /** + * @brief Construct a new Component object + * + * @param ct see ComponentType enum + * @param p pin conncted to the Component + */ Component(ComponentType ct, uint8_t p); + + /** + * @brief Get the Value as an std::any + * + * @return std::any recast into the type depending on the component + */ std::any getValue(); + + /** + * @brief Send the value as an std::any, + * + * @param data be careful of the component type of the object + */ void sendValue(std::any data); private: ComponentType _type; diff --git a/embedded/lib/Component/DHTComponent.hpp b/embedded/lib/Component/DHTComponent.hpp index 0421ecf..ff7b06e 100644 --- a/embedded/lib/Component/DHTComponent.hpp +++ b/embedded/lib/Component/DHTComponent.hpp @@ -7,10 +7,32 @@ class DHTComponent { public: + /** + * @brief Construct a new DHTComponent object + * + * @param type type of DHT given by the DHT_U.h + * @param pin the pin where the DHT is connected + */ DHTComponent(uint8_t type, byte pin); ~DHTComponent(); + + /** + * @brief called once the setup() is done in Arduino + */ void setup(); + + /** + * @brief Get the Humidity value + * + * @return float from 0.0 to 100.0% + */ float getHumidity(); + + /** + * @brief Get the Temperature value + * + * @return float in Celcius + */ float getTemperature(); private: diff --git a/embedded/lib/Component/LedComponent.hpp b/embedded/lib/Component/LedComponent.hpp index 6b5380c..ead61be 100644 --- a/embedded/lib/Component/LedComponent.hpp +++ b/embedded/lib/Component/LedComponent.hpp @@ -3,6 +3,9 @@ #include "Component.hpp" #include +/** + * @brief Color composed of multiple bytes, rgb + */ struct Color { byte red; @@ -12,6 +15,9 @@ struct Color Color operator-(byte value); }; +/** + * @brief a set of colors to use when powering the led + */ namespace LedColors { constexpr Color LED_OFF = {0,0,0}; @@ -21,6 +27,9 @@ namespace LedColors constexpr Color TOO_WET = {0x1B,0x09,0x3F}; } +/** + * @brief ENUM for the two used LED + */ enum class LedNumber { LED_HARDWARE = 0, LED_PLANT = 1 @@ -29,10 +38,36 @@ enum class LedNumber { class LedComponent { public: + /** + * @brief Construct a new Led Component object + * + * @param pin the pin used to communicate with the LED + * @param pin_clock the pin clock with the chainable LED + * @param led_number number of LED in the chain + */ LedComponent(byte pin, byte pin_clock, uint8_t led_number); ~LedComponent(); + + /** + * @brief called once the setup() is done in Arduino + */ void setup(); + + /** + * @brief Set the Color of the LED. + * + * @param led_number Selecting the LED to light up + * @param color Color of the LED + */ void setColor(LedNumber led_number, Color color); + + /** + * @brief Set the Color of the LED. + * + * @param led_number Selecting the LED to light up + * @param color Color of the LED + * @param fading_time From 0,0,0 to the Color + */ void setColor(LedNumber led_number, Color color, uint16_t fading_time); private: diff --git a/embedded/lib/Component/MainComponent.hpp b/embedded/lib/Component/MainComponent.hpp index e7dfe87..d4d5088 100644 --- a/embedded/lib/Component/MainComponent.hpp +++ b/embedded/lib/Component/MainComponent.hpp @@ -14,9 +14,31 @@ public: return instance; } // Public functions + + /** + * @brief create all the instanciations of the component + */ void setup(); + + /** + * @brief Get the Humidity object reference + * + * @return Component& + */ Component& getHumidity(); + + /** + * @brief Get the Led object reference + * + * @return LedComponent& + */ LedComponent& getLed(); + + /** + * @brief Get the DHT object reference + * + * @return DHTComponent& + */ DHTComponent& getDHT(); private: // Singleton diff --git a/embedded/lib/DataHandler/DataHandler.hpp b/embedded/lib/DataHandler/DataHandler.hpp index 8b3c46d..ba05cef 100644 --- a/embedded/lib/DataHandler/DataHandler.hpp +++ b/embedded/lib/DataHandler/DataHandler.hpp @@ -13,10 +13,40 @@ public: } // Public functions + + /** + * @brief Get the Json Data object + * + * @return String + */ String getJsonData(); + + /** + * @brief Update the moisture of the internal Data Handler + * + * @param humidity + */ void updateSoilMoistureData(float humidity); + + /** + * @brief Update the moisture of the internal Data Handler + * + * @param temperature + */ void updateAirTemperatureData(float temperature); + + /** + * @brief Update the moisture of the internal Data Handler + * + * @param humidity + */ void updateAirHumidityData(float humidity); + + /** + * @brief Update the moisture of the internal Data Handler + * + * @param light + */ void updateLightData(float light); private: // Singleton diff --git a/embedded/lib/Display/Screen.cpp b/embedded/lib/Display/Screen.cpp index 7c00467..c000e85 100644 --- a/embedded/lib/Display/Screen.cpp +++ b/embedded/lib/Display/Screen.cpp @@ -45,6 +45,7 @@ void Screen::Setup(uint8_t *font) airHumidityPicture.SetOffset(OFFSET_ICONS); // Static Components + // Using shared object for inheritance connectingWindow.Add({std::make_shared(headerSetup), std::make_shared(TextBox("connect", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0))}); connectionfailedWindow.Add({std::make_shared(headerSetup), @@ -110,7 +111,9 @@ void Screen::connected(const char *ipaddress, uint8_t timing) if (timing != 0) { _screen->setFont(u8g2_font_3x3basic_tr); + // While timing is not finished, incrementing the loading String _loading.concat(" "); + // Draw the button in inverted mode _screen->drawButtonUTF8(0, _screen->getDisplayHeight() - 5, U8G2_BTN_INV, _screen->getStrWidth(_loading.c_str()), 0, 0, _loading.c_str()); _screen->setFont(_font); } diff --git a/embedded/lib/Display/Screen.hpp b/embedded/lib/Display/Screen.hpp index d4ded26..2937a6c 100644 --- a/embedded/lib/Display/Screen.hpp +++ b/embedded/lib/Display/Screen.hpp @@ -30,6 +30,9 @@ namespace Display { + /** + * @brief Each frame of the clover boot animation + */ constexpr Picture CLOVER_FRAMES[] = { {clover1_bits, clover1_width, clover1_height}, {clover2_bits, clover2_width, clover2_height}, @@ -43,20 +46,33 @@ namespace Display {clover10_bits, clover10_width, clover10_height}, {clover11_bits, clover11_width, clover11_height}, }; + + /** + * @brief Icons per component + */ constexpr Picture ICONS[] = { {humidity_bits,humidity_width,humidity_height}, {thermometer_bits,thermometer_width,thermometer_height}, {air_humidity_bits,air_humidity_width,air_humidity_height}, }; + + /** + * @brief Icons per component (warning variant) + */ constexpr Picture ICONS_WARNING[] = { {humidity_warning_bits,humidity_warning_width,humidity_warning_height}, {thermometer_warning_bits,thermometer_warning_width,thermometer_warning_height}, {air_humidity_warning_bits,air_humidity_warning_width,air_humidity_warning_height}, }; + + // Const from the Screen constexpr uint8_t MAX_BOOT_FRAMES = 25; constexpr uint8_t OFFSET_ICONS = 55; constexpr uint8_t OFFSET_TEXT = 75; + /** + * @brief Used for the pictures icons. Each icon has an index linked to a sensor + */ enum class Sensors { SOIL_MOISTURE = 0, THERMOMETER, @@ -73,18 +89,91 @@ namespace Display return instance; } // Public functions + + /** + * @brief To be called when the setup() of the Arduino library finished + * + * @param font font from the U8G2 library. + */ void Setup(uint8_t *font); + + /** + * @brief Screen to display when connecting + * + * @param state from 0 to 3, shows little dots at the end of the text + */ void connecting(uint8_t state=0); + + /** + * @brief Screen to display when not connected + */ void notConnected(); + + /** + * @brief Screen to display when connected, a little loading bar is showed. + * ! Should use the latest Component Library + * + * @param ipaddress text to display, an IpAdress is recommended, but it can be a complete URL + * @param timing if equals 0, stop the loading. + */ void connected(const char *ipaddress, uint8_t timing); + + /** + * @brief Screen bootscreen + */ void boot(); + + /** + * @brief Screen for the main loop with the sensors information + * + * @param plantHumidity must be a percentage + * @param airTemperature must not exceed 99°C + * @param airHumidity must be a percentage + */ void loop(const float plantHumidity, const float airTemperature, const float airHumidity); + + /** + * @brief Set the Warning Icon for a given sensor + * + * @param sensorId the sensor to change icon + * @param warning if precised as false, will reset the normal icon + */ void setWarningIcon(Sensors sensorId, bool warning=true); + // Getters + /** + * @brief Get the Height of the Screen + * + * @return uint16_t + */ uint16_t getHeight(); + + /** + * @brief Get the Width of the Screen + * + * @return uint16_t + */ uint16_t getWidth(); + + /** + * @brief Get the Screen object + * + * @return U8G2_SSD1306_128X64_NONAME_F_HW_I2C& + */ U8G2_SSD1306_128X64_NONAME_F_HW_I2C& getScreen(); + + /** + * @brief Get the Text Width from a given string + * + * @param str + * @return uint16_t depending on the font size, get the text width + */ uint16_t getTextWidth(const char * str); + + /** + * @return true if the bootscreen havent finished + * @return false if the bootscreen finished + */ bool isBooting(); private: // Singleton diff --git a/embedded/lib/ServerHandler/ServerHandler.hpp b/embedded/lib/ServerHandler/ServerHandler.hpp index a6852d6..b0a23a9 100644 --- a/embedded/lib/ServerHandler/ServerHandler.hpp +++ b/embedded/lib/ServerHandler/ServerHandler.hpp @@ -18,10 +18,35 @@ public: return instance; } // Public functions + + /** + * @brief setup the wifi when the Arduino is starting its connections + * + * @param ssid the name of the wifi + * @param password the password of the wifi + */ void setup(const char* ssid, const char* password); + + /** + * @brief Calls the Screen Singleton and shows the IP during a certain time. + */ void showIp(); + + /** + * @brief The basic loop of the Server, sending JSON data over the port 80. + */ void loop(); + + /** + * @return true if connected to the wifi + * @return false if failed to connect + */ bool isConnected(); + + /** + * @return true When finished showing IP and connecting + * @return false still in state of connecting + */ bool showBoot(); diff --git a/embedded/src/warning.hpp b/embedded/src/warning.hpp index 8cb43c8..fada3da 100644 --- a/embedded/src/warning.hpp +++ b/embedded/src/warning.hpp @@ -20,13 +20,29 @@ namespace Warning { constexpr float AIR_TEMPERATURE_TOO_HOT = 29.0f; constexpr float AIR_TEMPERATURE_TOO_COLD = 14.0f; + /** + * @brief Different type of status for the LED (memory optimisation) + */ enum class LedMoistureStatus { IDLE, DRY, WET }; + /** + * @brief Change the LED Color depending on the humidity + * + * @param soilHumidity + */ void warningLedLoop(const float soilHumidity); + + /** + * @brief Changing icons of the Screen when some parameters are superior to a certain threashold. + * + * @param plantMoisture + * @param airTemperature + * @param airHumidity + */ void warningScreenLoop(const float plantMoisture, const float airTemperature, const float airHumidity); }