diff --git a/.travis.yml b/.travis.yml index 87bbf11..aacdf2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,22 @@ language: c before_install: + # Download and install Arduino IDE environment - wget http://downloads.arduino.cc/arduino-1.8.5-linux64.tar.xz - tar xf arduino-1.8.5-linux64.tar.xz - sudo mv arduino-1.8.5 /usr/local/share/arduino - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino install: + # Install the library in the arduino user libraries folder - ln -s $PWD /usr/local/share/arduino/libraries/Easyuino script: - - arduino --verify --board arduino:avr:uno $PWD/examples/Leds/RGBLedExample.ino - - arduino --verify --board arduino:avr:uno $PWD/examples/Leds/RelayExample.ino - - arduino --verify --board arduino:avr:uno $PWD/examples/Leds/RelayNamedExample.ino - - arduino --verify --board arduino:avr:uno $PWD/examples/Leds/DistanceMeterExample.ino - - arduino --verify --board arduino:avr:uno $PWD/examples/Leds/DistanceMeterNonBlockExample.ino - - arduino --verify --board arduino:avr:uno $PWD/examples/Leds/DistanceMeterAccurateExample.ino + - arduino --verify --board arduino:avr:uno $PWD/examples/Leds/RGBLed/RGBLedExample.ino + - arduino --verify --board arduino:avr:uno $PWD/examples/Relay/RelayExample.ino + - arduino --verify --board arduino:avr:uno $PWD/examples/Relay/RelayNamed/RelayNamedExample.ino + - arduino --verify --board arduino:avr:uno $PWD/examples/UltraSonicModule/DistanceMeter/DistanceMeterExample.ino + - arduino --verify --board arduino:avr:uno $PWD/examples/UltraSonicModule/DistanceMeterNonBlock/DistanceMeterNonBlockExample.ino + - arduino --verify --board arduino:avr:uno $PWD/examples/UltraSonicModule/DistanceMeterAccurate/DistanceMeterAccurateExample.ino + - arduino --verify --board arduino:avr:uno $PWD/examples/WaterDetector/WaterDetectorExample.ino notifications: email: on_success: change - on_failure: change + on_failure: change \ No newline at end of file diff --git a/Easyuino.vcxitems b/Easyuino.vcxitems index c42d0d0..f40204e 100644 --- a/Easyuino.vcxitems +++ b/Easyuino.vcxitems @@ -31,11 +31,12 @@ - - + + + @@ -48,8 +49,8 @@ - - + + @@ -63,6 +64,8 @@ + + @@ -70,11 +73,11 @@ - + - + \ No newline at end of file diff --git a/Keywords.txt b/Keywords.txt index da2ed91..c24a796 100644 --- a/Keywords.txt +++ b/Keywords.txt @@ -57,6 +57,25 @@ updateDistanceNonBlock KEYWORD2 ################################################## DistanceMeterAccurate KEYWORD1 ################################################## +# WaterDetector # +################################################## +WaterDetector KEYWORD1 +begin KEYWORD2 +end KEYWORD2 +getWaterStatus KEYWORD2 +getWaterStatusRange KEYWORD2 +isWaterDetected KEYWORD2 +################################################## +# WaterStatus # +################################################## +WaterStatus KEYWORD1 +DRY LITERAL1 +FEW_DROPS LITERAL1 +WET LITERAL1 +FLOOD LITERAL1 +INVALID LITERAL1 +NOT_INITIALIZED LITERAL1 +################################################## # GSMService # ################################################## GSMService KEYWORD1 diff --git a/README.md b/README.md index c43254d..9343334 100644 --- a/README.md +++ b/README.md @@ -12,34 +12,39 @@ The Easyuino library has 5 fundamental goals: ## Sensors and Devices Support The development of the library, including fixes and addition of new sensors/devices, will be done depending on: -- My time availability (Now I am doing my Masters Degree Thesis in Computer Science and Engineering that stoles a good slice of my time) +- My time availability (Now I am doing my Masters Degree Thesis in Computer Science and Engineering that stoles a huge slice of my time) - Interest of people in Easyuino Important: Nevertheless I will accept suggestions for interesting devices/sensors to develop and if there are a lot of interest I will start prioritize them. -More Important: If you have any question about the library or some doubts about the supported devices you can contact me too !!! +More Important: If you have any question about easyuino you can contact me !!! Contact Channels: - Email: easyuino@gmail.com -### Implemented, Documented and Tested = Ready to Use +### Already Implemented, Documented and Tested = Ready to Use -- RGB led, Ultrasonic Module (measure distances) , GSM Module (currently only SMS services), Relay Module +- RGB led +- Ultrasonic Module (measure distances) +- GSM Module (currently only SMS services) +- Relay Module +- Water Detector Sensor ### Currently Developing -- Water/Rain Detector -- Displays: OLED lcd and Seven Segments +- Water Flow Sensor (as a sensor exclusively and as a flow rate meter) +- Seven Segments Display ### Develop in a Near Future -- Infra Red Receiver +- Soil moisture/humidity Sensor +- Photoresistor/Light Sensor - Flame Sensor +- Infra Red Receiver ### Develop in a Long Term Future - Temperature/Humidity sensor -- Photoresistors/Light sensor - Knock sensor - Sound sensor - Optical Fingerprint sensor @@ -53,6 +58,14 @@ Contact Channels: 3. *[Optional]* Look at https://github.com/Strabox/Easyuino/wiki to usage examples and details about the API 4. **[Not Optional]** Have fun!!! +## Important: API Usage Examples and Additional Information + +**Project's wiki has a set of usage examples of the library API plus more detailed information about it: https://github.com/Strabox/Easyuino/wiki** + +## Related and Useful Libraries + +https://github.com/Strabox/GSMLibrary I have this Arduino library too that is used to interact with GSM/GPRS boards. It is separated from this one because addresses a much more complex device but follows identical rules of Easyuino. + ## Easyuino History I am Computer Scientist and Engineer (not an Electrotechnical one) that loves programming special in C/C++. diff --git a/examples/Leds/20171022_232756.jpg b/examples/Leds/RGBLed/RGBLedCircuit.jpg similarity index 100% rename from examples/Leds/20171022_232756.jpg rename to examples/Leds/RGBLed/RGBLedCircuit.jpg diff --git a/examples/Leds/RGBLedExample.ino b/examples/Leds/RGBLed/RGBLedExample.ino similarity index 60% rename from examples/Leds/RGBLedExample.ino rename to examples/Leds/RGBLed/RGBLedExample.ino index 8f9167b..b496ca2 100644 --- a/examples/Leds/RGBLedExample.ino +++ b/examples/Leds/RGBLed/RGBLedExample.ino @@ -5,26 +5,37 @@ RGBLedExample.ino #include // Include the library in order to the compiler know you want Easyuino library using Easyuino::RGBLed; // Necessary in order to use RGBLed +using Easyuino::Color; // Necessary for some method calls -int red_pin = 9; // Arduino pin connected to led red pin -int green_pin = 10; // Arduino pin connected to led green pin +int red_pin = 9; // Arduino pin connected to led red pin +int green_pin = 10; // Arduino pin connected to led green pin int blue_pin = 11; // Arduino pin connected to led blue pin RGBLed led(red_pin, green_pin, blue_pin); // Create the RGBLed object that exposes the API to use void setup() { - led.begin(); // Called in setup method to initialize the RGBLed in order to accept requests + led.begin(); // Called in setup method to initialize the RGBLed in order to accept requests } void loop() { + /* + - This method call sets the color to YELLOW. There are several ones + you can chose normally as seen in the list below. + - List of Colors Available: RED, GREEN, BLUE, YELLOW, WHITE, ORANGE, + PINK, SALMON, VIOLET, AQUA, BROWN, FIREBRICK, DARKGREY, OLIVE, SKYBLUE + */ + led.setColor(Color::YELLOW); + + delay(2000); + /* - This method call set the led color to RED. - First parameter controls the amount of red (0-255). - First parameter controls the amount of green (0-255). - First parameter controls the amount of blue (0-255). - The color of the led will be the overlap of the amount of 3 colors. See: - https://en.wikipedia.org/wiki/Additive_color - - You can use this link to pick up RGB colors: + https://en.wikipedia.org/wiki/Additive_color + - You can use this link to pick up RGB colors: https://www.w3schools.com/colors/colors_picker.asp */ led.setColor(255, 0, 0); @@ -41,23 +52,15 @@ void loop() { delay(2000); - /* - - This method sets the color to YELLOW. There are several ones - you can chose normally you can see the list in IDEs. - */ - led.setColor(RGBLed::COLOR::YELLOW); - - delay(2000); - - /* - - This method will set the color to BLUE. See Hexadecimal color code on how to use it. - - You can use this link to pick up Hexadecimal codes https://www.w3schools.com/colors/colors_picker.asp + /* + - This method will set the color to BLUE. See Hexadecimal color code on how to use it. + - You can use this link to pick up Heaxadecimal codes https://www.w3schools.com/colors/colors_picker.asp */ led.setColor("#0000ff"); delay(2000); - /* + /* - This method will turn off the led. After this call you can't set the color of the led anymore while led.begin(); is not called again. */ diff --git a/examples/Relay/RelayExample.ino b/examples/Relay/RelayExample.ino index 21ae462..231016c 100644 --- a/examples/Relay/RelayExample.ino +++ b/examples/Relay/RelayExample.ino @@ -6,7 +6,7 @@ RelayExample.ino using Easyuino::Relay; // Necessary in order to use Relay -int arduinoPin = 6; // Arduino pin that controls the relay +int arduinoPin = 6; // Arduino pin that controls the relay Relay relay(arduinoPin); // Create the Relay object that exposes the API to use @@ -15,11 +15,10 @@ void setup() { - Initialize the Relay API. - The first parameter is TRUE if we connect something to the Normally Closed (NC) of the relay, and FALSE if we connect to the Normally Open (NO). - - The second parameter is the level of the relay when it is in Normally Closed state. + - The second parameter is the digital level of the relay when it is in Normally Closed state. This is needed because some relays activate when we put HIGH on the pin and others on LOW. - - relay.begin(); is equal to relay.begin(false, HIGH); which is the common configuration. */ - relay.begin(false, HIGH); + relay.begin(false, HIGH); // Equivalent to: relay.begin(); which is the common configuration } void loop() { @@ -38,13 +37,13 @@ void loop() { delay(2000); /* - Return TRUE if the device is on and FALSE if it is off + Return true if the device is on and false if it is off */ bool result = relay.isOn(); /* - - This method will turn off the relay and after that no more calls to - the relay will work without call the relay.begin(); again. + - This method will turn off the device and after that no more calls to + the relay will be possible without call the relay.begin(); again. */ relay.end(); } \ No newline at end of file diff --git a/examples/Relay/RelayNamedExample.ino b/examples/Relay/RelayNamed/RelayNamedExample.ino similarity index 89% rename from examples/Relay/RelayNamedExample.ino rename to examples/Relay/RelayNamed/RelayNamedExample.ino index 2728ae9..d981c30 100644 --- a/examples/Relay/RelayNamedExample.ino +++ b/examples/Relay/RelayNamed/RelayNamedExample.ino @@ -7,13 +7,13 @@ RelayNamedExample.ino using Easyuino::RelayNamed; // Necessary in order to use RelayNamed int arduinoPin = 6; // Arduino pin that controls the relay -char* controlledDevice = "Lamp";// The difference for normal relay is that the relay stays with a name identifier name attached +const char* controlledDevice = "Lamp";// The difference for normal relay is that the relay stays with a name identifier name attached RelayNamed relayNamed(arduinoPin, controlledDevice); // Create the RelayNamed object that exposes the API to use void setup() { Serial.begin(9600); // Used to start the serial connection with the computer. Change the 9600 if needed. - relayNamed.begin(false, HIGH); // See RelayExample.ino for the explanation + relayNamed.begin(false, HIGH); // See RelayExample.ino for the explanation } void loop() { diff --git a/examples/UltraSonicModule/DistanceMeterExample.ino b/examples/UltraSonicModule/DistanceMeter/DistanceMeterExample.ino similarity index 100% rename from examples/UltraSonicModule/DistanceMeterExample.ino rename to examples/UltraSonicModule/DistanceMeter/DistanceMeterExample.ino diff --git a/examples/UltraSonicModule/DistanceMeterAccurateExample.ino b/examples/UltraSonicModule/DistanceMeterAccurate/DistanceMeterAccurateExample.ino similarity index 99% rename from examples/UltraSonicModule/DistanceMeterAccurateExample.ino rename to examples/UltraSonicModule/DistanceMeterAccurate/DistanceMeterAccurateExample.ino index 5acd000..ea6aed5 100644 --- a/examples/UltraSonicModule/DistanceMeterAccurateExample.ino +++ b/examples/UltraSonicModule/DistanceMeterAccurate/DistanceMeterAccurateExample.ino @@ -1,4 +1,4 @@ -/* +/* DistanceMeterAccurateExample.ino */ diff --git a/examples/UltraSonicModule/DistanceMeterNonBlockExample.ino b/examples/UltraSonicModule/DistanceMeterNonBlock/DistanceMeterNonBlockExample.ino similarity index 99% rename from examples/UltraSonicModule/DistanceMeterNonBlockExample.ino rename to examples/UltraSonicModule/DistanceMeterNonBlock/DistanceMeterNonBlockExample.ino index b8d42f1..9f964ac 100644 --- a/examples/UltraSonicModule/DistanceMeterNonBlockExample.ino +++ b/examples/UltraSonicModule/DistanceMeterNonBlock/DistanceMeterNonBlockExample.ino @@ -1,4 +1,4 @@ -/* +/* DistanceMeterNonBlockExample.ino */ diff --git a/examples/WaterDetector/WaterDetectorExample.ino b/examples/WaterDetector/WaterDetectorExample.ino new file mode 100644 index 0000000..ad66067 --- /dev/null +++ b/examples/WaterDetector/WaterDetectorExample.ino @@ -0,0 +1,84 @@ +/* +WaterDetectorExample.ino +*/ + +#include // Include the library in order to the compiler know you want Easyuino library + +using Easyuino::WaterDetector; // Necessary in order to use WaterDetector +using Easyuino::WaterStatus; // Necessary for some methods calls + +int digitalPin = 7; // Arduino pin that connects to the digital pin of the sensor (normally called D0) +int analogPin = 6; // Arduino pin that conencts to the analog pin of the sensor (normally called A0) + +WaterDetector waterDetector(digitalPin, analogPin); // Create the WaterDetector object that exposes the API to use + +void setup() { + /* + Initialize the serial monitor + */ + Serial.begin(9600); + /* + - Initialize the WaterDetector API + - The first parameter is the digital level (HIGH or LOW) that appear in the digital pin when + the water touches the sensor and the amount of it is above the pre-defined threshold set by the + potentiometer of the board. This is necessary because some sensor versions use HIGH others LOW. + */ + waterDetector.begin(LOW); // Equivalent to: waterDetector.begin(); which is the common configuration +} + +void loop() { + /* + This API call will return true when water is detected in the sensor and false otherwise. + */ + bool res = waterDetector.isWaterDetected(); + Serial.println(res); + + delay(2000); + + /* + This API call will return a set of results (see C++ enumerates) that you can compare to see + how much water is touching the sensor. + WARNING: This reading is independent from the above one because the above one is controlled by + the physical potentiometer and digital pin of the sensor. On the other hand the + getWaterStatus uses the analog pin to decide how "wet" :) the sensor is. + */ + WaterStatus status = waterDetector.getWaterStatus(); + + if (status == WaterStatus::DRY) { + Serial.println("Sensor is dry!"); + } + else if (status == WaterStatus::FEW_DROPS) { + Serial.println("Sensor has a few drops in it!"); + } + else if (status == WaterStatus::WET) { + Serial.println("Sensor is wet!"); + } + else if (status == WaterStatus::FLOOD) { + Serial.println("Sensor is flooded!"); + } + else if (status == WaterStatus::INVALID) { + Serial.println("Sensor had a strange invalid reading!"); + } + else { + Serial.println("Begin method was not called!"); + } + + delay(2000); + + /* + This API call is more advanced basically it gives you a number from [0,1023] to describe how "wet" + :) the sensor is. 1023 is when the sensor is completely dry and 0 when is completely flooded. + Note: The method getWaterStatus is based on this call. + */ + unsigned int howWet = waterDetector.getWaterStatusRange(); + Serial.println(howWet); + + delay(2000); + + /* + This API call will terminate the sensing ability of the water detector and all the requests + after this one will be invalid. If you want use the sensor again you must call the begin + method again. + */ + waterDetector.end(); +} \ No newline at end of file diff --git a/examples/WaterFlow/.gitkeep b/examples/WaterFlow/.gitkeep new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/examples/WaterFlow/.gitkeep @@ -0,0 +1 @@ +#pragma once diff --git a/library.properties b/library.properties index d67e680..7f6ce85 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Easyuino -version=1.0.0 +version=1.1.0 author=Andre Pires maintainer=Andre Pires sentence=Easyuino Library offer a set of APIs to interact with some sensors and devices connected with Arduino diff --git a/src/Device.h b/src/Device.h index e49e0ef..38c1bd1 100644 --- a/src/Device.h +++ b/src/Device.h @@ -34,15 +34,17 @@ Device.h #include "WProgram.h" #endif +#include "Utilities.h" + namespace Easyuino { /* - General class that provides the common API and behaviour for the majority of peripheric/sensors for Arduino + General class that provides the common API and behaviour for the majority of devices/sensors for Arduino */ class Device { protected: - /* Used to know if the peripherical is initialized and ready to receive requests */ + /* Used to know if the device is initialized and ready to receive requests */ bool _isInitialized; public: @@ -54,13 +56,13 @@ namespace Easyuino { #pragma region Public Pure Virtual Common API Methods - /* Used to put the peripherical ready to receive requests. Normally this have some default behaviour some + /* Used to put the device ready to receive requests. Normally this have some default behaviour some devices have other API method with same name that receives other arguments to a better customization. @return - True: If the device was initializer. False: Otherwise. */ virtual bool begin() = 0; - /* Used to stop the device. After this the peripherical will not process API requests. */ + /* Used to stop the device. After this the the device will not process API requests. */ virtual void end() = 0; #pragma endregion @@ -69,8 +71,8 @@ namespace Easyuino { #pragma region Public Common API Methods /* - Verify is the periphetical is initialized and ready to use. - @return - True: If peripherical is initialized. False: Otherwise. + Verify is the device is initialized and ready to use. + @return - True: If device is initialized. False: Otherwise. */ bool isInitialized() const; diff --git a/src/DistanceMeter.h b/src/DistanceMeter.h index 10dafc0..c051c3a 100644 --- a/src/DistanceMeter.h +++ b/src/DistanceMeter.h @@ -27,6 +27,7 @@ DistanceMeter.h #ifndef _EASYUINO_DISTANCE_METER_h #define _EASYUINO_DISTANCE_METER_h +#include "Utilities.h" #include "Device.h" #define ECHO_TIMEOUT_MICROS 30000UL // 0.03 Seconds (Time of sound to travel 8 meters plus a small bonus) @@ -58,10 +59,10 @@ namespace Easyuino { volatile float _distance; public: - DistanceMeter(uint8_t triggerPin, uint8_t echoPin); + DistanceMeter(IN uint8_t triggerPin, IN uint8_t echoPin); /* Contructor used when we have US with only one pin for trigger and echo */ - DistanceMeter(uint8_t triggerEchoPin); + DistanceMeter(IN uint8_t triggerEchoPin); ~DistanceMeter(); @@ -94,7 +95,7 @@ namespace Easyuino { Execute a block distance measure and calculate the distance based on the sound speed @return distance (Centimeters) - Distance measured */ - float executeUpdateDistanceBlock(float soundSpeedCmSec); + float executeUpdateDistanceBlock(IN float soundSpeedCmSec); }; diff --git a/src/DistanceMeterAccurate.h b/src/DistanceMeterAccurate.h index 6b1f293..2206039 100644 --- a/src/DistanceMeterAccurate.h +++ b/src/DistanceMeterAccurate.h @@ -27,11 +27,12 @@ DistanceMeterAccurate.h #ifndef _EASYUINO_DISTANCE_METER_ACCURATE_h #define _EASYUINO_DISTANCE_METER_ACCURATE_h +#include "Utilities.h" #include "DistanceMeterNonBlock.h" namespace Easyuino { - enum TemperatureScale { + enum TemperatureScale : uint8_t { CELSIUS, KELVIN, FAHRENHEIT }; @@ -55,9 +56,9 @@ namespace Easyuino { TemperatureScale _temperatureScale; public: - DistanceMeterAccurate(uint8_t triggerPin, uint8_t echoPin); + DistanceMeterAccurate(IN uint8_t triggerPin, IN uint8_t echoPin); - DistanceMeterAccurate(uint8_t triggerEchoPin); + DistanceMeterAccurate(IN uint8_t triggerEchoPin); ~DistanceMeterAccurate(); @@ -69,7 +70,7 @@ namespace Easyuino { @param airTemperature - Air temperatures to be used when calculating the distance (good if it is the current temperature) @param temperatureScale - The temperature scale that is being provided (CELSIUS, KELVIN or FAHRENHEIT) */ - void updateDistance(float airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS, TemperatureScale temperatureScale = CELSIUS); + void updateDistance(IN float airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS, IN TemperatureScale temperatureScale = CELSIUS); /* Updates the distance of the US to the objects in a non-blocking way. It means that the call to the method will return immediatly and in the "background" the distance measure will ocurr after a while depending on the distance @@ -77,7 +78,7 @@ namespace Easyuino { @param airTemperature - Air temperatures to be used when calculating the distance (good if it is the current temperature) @param temperatureScale - The temperature scale that is being provided (CELSIUS, KELVIN or FAHRENHEIT) */ - void updateDistanceNonBlock(float airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS, TemperatureScale temperatureScale = CELSIUS); + void updateDistanceNonBlock(IN float airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS, IN TemperatureScale temperatureScale = CELSIUS); private: /* @@ -86,7 +87,7 @@ namespace Easyuino { @param temperatureScale - The scale of the temperature given (CELSIUS, KELVIN or FAHRENHEIT) @return soundSpeed (cm/sec) - The sound of the speed */ - static float CalculateSoundSpeed(float airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS, TemperatureScale temperatureScale = CELSIUS); + static float CalculateSoundSpeed(IN float airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS, IN TemperatureScale temperatureScale = CELSIUS); }; diff --git a/src/DistanceMeterNonBlock.h b/src/DistanceMeterNonBlock.h index 881fa59..a0827bc 100644 --- a/src/DistanceMeterNonBlock.h +++ b/src/DistanceMeterNonBlock.h @@ -27,6 +27,7 @@ DistanceMeterNonBlock.h #ifndef _EASYUINO_DISTANCE_METER_NON_BLOCK_h #define _EASYUINO_DISTANCE_METER_NON_BLOCK_h +#include "Utilities.h" #include "DistanceMeter.h" #define MAXIMUM_NUMBER_OF_DM_NON_BLOCK 2 // WARNING: DON'T change it because it will broke the API @@ -69,9 +70,9 @@ namespace Easyuino { volatile bool _echoSent; public: - DistanceMeterNonBlock(uint8_t triggerPin, uint8_t echoPin); + DistanceMeterNonBlock(IN uint8_t triggerPin, IN uint8_t echoPin); - DistanceMeterNonBlock(uint8_t triggerEchoPin); + DistanceMeterNonBlock(IN uint8_t triggerEchoPin); ~DistanceMeterNonBlock(); @@ -109,18 +110,18 @@ namespace Easyuino { @param soundSpeedCmPerSec (cm/sec) - The sound speed to be taken in account. @return distance (Centimeters) - The distance to the object. */ - float calculateDistance(float soundSpeedCmPerSec); + float calculateDistance(IN float soundSpeedCmPerSec); private: #pragma region Interrupt Management/Handling Methods /* Interrupt handler of the DistanceMeterNonBlock instance that is in charge of the measurement */ - void interruptHandler(unsigned long interruptCallTimeMicros); + void interruptHandler(IN unsigned long interruptCallTimeMicros); /* Assign a new DistanceMeterNonBlock instance to an available spot */ - static void assignInstance(DistanceMeterNonBlock* dm); + static void assignInstance(IN DistanceMeterNonBlock* dm); /* Delete the DistanceMeterNonBlock instance from the available spot */ - static void deleteInstance(DistanceMeterNonBlock* dm); + static void deleteInstance(IN DistanceMeterNonBlock* dm); /* Attach the interrupt interruptCaller function to the right instance object */ static void attachInterruptToInstance(DistanceMeterNonBlock* dm); diff --git a/src/DistanceMeterPrintable.h b/src/DistanceMeterPrintable.h index ddfa516..cd8fdf8 100644 --- a/src/DistanceMeterPrintable.h +++ b/src/DistanceMeterPrintable.h @@ -27,9 +27,9 @@ DistanceMeterPrintable.h #ifndef _EASYUINO_DISTANCE_METER_PRINTABLE_h #define _EASYUINO_DISTANCE_METER_PRINTABLE_h +#include "Utilities.h" #include "Printable.h" #include "DistanceMeter.h" -#include "Utilities.h" namespace Easyuino { @@ -40,7 +40,7 @@ namespace Easyuino { class DistanceMeterPrintable : public DistanceMeter, public Printable { public: - DistanceMeterPrintable(uint8_t triggerPin, uint8_t echoPin); + DistanceMeterPrintable(IN uint8_t triggerPin, IN uint8_t echoPin); ~DistanceMeterPrintable(); diff --git a/src/Easyuino.h b/src/Easyuino.h index 129d370..5629283 100644 --- a/src/Easyuino.h +++ b/src/Easyuino.h @@ -39,9 +39,6 @@ SOFTWARE. #include "GSMService.h" #include "SMS.h" - #include "OLEDlcd.h" - #include "SevenSegments.h" - #include "Relay.h" #include "RelayNamed.h" @@ -51,8 +48,8 @@ SOFTWARE. #include "DistanceMeterPrintable.h" #include "RGBLed.h" - #include "InfraRedReceiver.h" - #include "RainDetector.h" + #include "WaterDetector.h" + #include "Utilities.h" #endif diff --git a/src/EasyuinoTests.h b/src/EasyuinoTests.h index 36af3cd..8b14e54 100644 --- a/src/EasyuinoTests.h +++ b/src/EasyuinoTests.h @@ -33,5 +33,6 @@ EasyuinoTests.h #include "tests\DistanceMeterTest.h" #include "tests\DistanceMeterNonBlockTest.h" #include "tests\DistanceMeterAccurateTest.h" +#include "tests\WaterDetectorTest.h" #endif diff --git a/src/GSMService.h b/src/GSMService.h index 9462ebd..e5e91f6 100644 --- a/src/GSMService.h +++ b/src/GSMService.h @@ -28,27 +28,20 @@ GSMService.h #define _EASYUINO_GSM_SERVICE_h #include - +#include "Utilities.h" #include "Device.h" #include "SMS.h" -#include "Utilities.h" - -/* Define API method parameter to be exclusively an input */ -#define IN -/* Define API method parameter to be exclusively an output */ -#define OUT -/* Define API method parameter that is used as input and output */ -#define INOUT -/* It can change from board to board (Use the compatible with your board) */ -#define GSM_SIM900_BAUD_RATE 9600 +/* It can change depending on the board (DEFAULT VALUE) */ +#define GSM_DEFAULT_BAUD_RATE 9600 -/* IMPORTANT: Size (bytes) of the buffer used internally to receive/send data from/to the GSM board -if you have more memory you can change this (Advisable to change if you will receive Calls or huge SMSs) +/* +IMPORTANT: Size (bytes) of the buffer used internally to receive/send data from/to the GSM board +if you have more memory you can change this (Advisable to change if you will receive huge SMSs) */ #define INTERNAL_BUFFER_SIZE_BYTES 128 -/* IMPORTANT: Maximum number of allowed numbers to call and send sms to the board */ +/* IMPORTANT: Maximum number of allowed numbers to do CALLS and send SMS to the board */ #define MAX_NUMBER_OF_ALLOWED_NUMBERS 4 namespace Easyuino { @@ -56,7 +49,7 @@ namespace Easyuino { /* Used to indicate the status of the request to the GSMService API */ - enum GSMRequestStatus { + enum class GSMRequestStatus : uint8_t { /* The request was successful executed */ GSM_OK = 0, /* Happens in many cases where the board answer with things we were not expected due to: @@ -64,70 +57,42 @@ namespace Easyuino { - Defect in the board (not likely) or a general hardware error. IMPORTANT: In this case we consider the request failed and we try put all the things in a consistent and previous state. */ - GSM_UNEXPECTED_REPLY = -1, + GSM_UNEXPECTED_REPLY = 1, /* GSMService API Tried communicate (e.g: send commands) to the board and it didn't answer in reasonable time */ - GSM_BOARD_DIDNT_REPLY = -2, - /* The GSMService API was not correctly initialized and can't process requests */ - GSM_SERVICE_NOT_INITIALIZED = -3, + GSM_BOARD_DIDNT_REPLY = 2, /* When provided an invalid argument to the GSMService API (e.g: negative pin number, negative baud rate, ...) */ - GSM_REQUEST_INVALID_ARGUMENT = -5, + GSM_REQUEST_INVALID_ARGUMENT = 4, /* Not possible add more allowed numbers to the GSMService API */ - GSM_MAXIMUM_ALLOWED_NUMBERS_REACHED = -6 - }; - - /* - Interface fot the GSMService API - */ - class IGSMService { - - public: - - virtual bool begin(IN unsigned long gsmBoardBaudRate) = 0; - - virtual GSMRequestStatus addAllowedNumber(IN unsigned long phoneNumberToAdd) = 0; - - virtual GSMRequestStatus isAllowed(IN unsigned long phoneNumber, INOUT bool& allowed) = 0; - - virtual GSMRequestStatus removeAllowedNumber(IN unsigned long phoneNumberToRemove) = 0; - - virtual GSMRequestStatus clearAllowedNumbers() = 0; - - virtual GSMRequestStatus beginListenForSMS() = 0; - - virtual GSMRequestStatus availableSMS(INOUT SMS &message, OUT bool &smsRead) = 0; - - virtual GSMRequestStatus sendSMS(IN SMS &sms) = 0; - - virtual GSMRequestStatus deleteAllReadSMS() = 0; - - virtual GSMRequestStatus deleteAllSentAndReadSMS() = 0; - - virtual GSMRequestStatus deleteAllSMS() = 0; - + GSM_MAXIMUM_ALLOWED_NUMBERS_REACHED = 5, + /* The GSMService API was not correctly initialized and can't process requests */ + NOT_INITIALIZED = 255 }; /* - Implementation of an GSMService API to interact with the GSM board through a set of well defined methods + Implementation of an GSMService API to interact with the GSM board through a set of well defined methods. + @Physical Devices Supported: + - SIM900 Chipset + @Physical Devices Tested: + - SIM900 Chipset */ - class GSMService : public IGSMService, public Device { + class GSMService : public Device { private: - /* Status of calls to private API of the GSMService */ - enum GSMInternalRequestStatus { + enum GSMInternalRequestStatus : uint8_t { GSM_INTERNAL_OK = 0, - GSM_INTERNAL_COMMUNICATION_FAILED = -1 + GSM_INTERNAL_COMMUNICATION_FAILED = 1 }; /* Indicate what type and amount of stored SMSs we want to delete (See AT Commands Reference) */ - enum GSMSmsDeleteFlag { + enum GSMSmsDeleteFlag : uint8_t { INDEX_PARAMTER_CHOSEN_ONLY = 0, ALL_READ_SMS = 1, ALL_SENT_AND_READ_SMS = 2, - ALL_SMS = 4 + ALL_SMS = 3 }; - const unsigned long WAIT_FOR_DATA_TIMEOUT = 5000; // 5 seconds + const unsigned long WAIT_FOR_DATA_TIMEOUT = 5000; // 5 Seconds Timeout const char *AT_OK = "\r\nOK\r\n"; const char *AT_ERROR = "\r\nERROR\r\n"; @@ -141,11 +106,9 @@ namespace Easyuino { bool _isInitialized; bool _readyToReceiveSMS; - public: - /* - Creates a GSMService + Creates a GSMService API object. @param txPin - Pin used to send the serial information to GSM module @param rxPin - Pin used to receive the serial information from GSM module @param outputStream - Stream to output the GSM Module outputs in case of necessary debug @@ -153,7 +116,7 @@ namespace Easyuino { GSMService(IN uint8_t txPin, IN uint8_t rxPin, IN Stream &outputStream); /* - Creates a GSMService + Creates a GSMService API object. @param txPin - Pin used to send the serial information to GSM module @param rxPin - Pin used to receive the serial information from GSM module */ @@ -172,9 +135,6 @@ namespace Easyuino { bool begin(); - /* - Closes all the communications with the GSM module - */ void end(); /* @@ -187,7 +147,7 @@ namespace Easyuino { /* Verify if the phone number is in the list of allowed numbers @param phoneNumber - Number to verify - @param allowed - After the method executes: True - If the number is in allowed list or if the list is empty. False - Otherwise. + @param allowed - After the method executes. True: If the number is in allowed list or if the list is empty. False: Otherwise. @return - GSMService API request status */ GSMRequestStatus isAllowed(IN unsigned long phoneNumber, INOUT bool& allowed); @@ -246,9 +206,8 @@ namespace Easyuino { private: - /* - + Delete SMS dependind on the flags passed to the method. */ GSMRequestStatus deleteSMS(IN GSMSmsDeleteFlag parameter, IN unsigned int messageIndex = 0); diff --git a/src/InfraRedReceiver.h b/src/InfraRedReceiver.h index 06b7134..f17b4a1 100644 --- a/src/InfraRedReceiver.h +++ b/src/InfraRedReceiver.h @@ -27,6 +27,7 @@ InfraRedReceiver.h #ifndef _EASYUINO_INFRA_RED_RECEIVER_h #define _EASYUINO_INFRA_RED_RECEIVER_h +#include "Utilities.h" #include "Device.h" namespace Easyuino { diff --git a/src/Printable.h b/src/Printable.h index f4a5ab3..951887a 100644 --- a/src/Printable.h +++ b/src/Printable.h @@ -34,6 +34,8 @@ Printable.h #include "WProgram.h" #endif +#include "Utilities.h" + namespace Easyuino { /* @@ -52,7 +54,7 @@ namespace Easyuino { #pragma endregion /* Write the Device state string representation to a given stream (e.g: Used to Debug) */ - friend Stream& operator<<(Stream & stream, const Printable& printable); + friend Stream& operator<<(IN Stream & stream, IN const Printable& printable); }; diff --git a/src/RGBLed.h b/src/RGBLed.h index 1669b27..fa43fd4 100644 --- a/src/RGBLed.h +++ b/src/RGBLed.h @@ -27,30 +27,29 @@ RGBLed.h #ifndef _EASYUINO_RGB_LED_h #define _EASYUINO_RGB_LED_h +#include "Utilities.h" #include "Device.h" namespace Easyuino { - /* RGBLed API allows to easily interact with a RGB led to set its color for example */ - class RGBLed : public Device { - - public: - /* Enum with the types of RGB physical leds */ - enum LED_TYPE { + enum LedType : uint8_t { COMMON_ANODE, COMMON_CATODE }; /* Enum with a set of pre defined colors that the RGBLed API knows how to write */ - enum COLOR { - RED, GREEN, BLUE, YELLOW, WHITE, ORANGE, PINK, SALMON, VIOLET, AQUA, BROWN, FIREBRICK, DARKGREY, OLIVE, - SKYBLUE + enum Color : uint8_t { + RED, GREEN, BLUE, YELLOW, WHITE, ORANGE, PINK, SALMON, VIOLET, AQUA, BROWN, + FIREBRICK, DARKGREY, OLIVE, SKYBLUE }; + /* RGBLed API allows to easily interact with a RGB led to set its color for example */ + class RGBLed : public Device { + private: /* The type of the led defined by the enumerate LED_TYPE */ - LED_TYPE _ledType; + LedType _ledType; /* The Arduino pin connected do led's red pin */ uint8_t _redPin; @@ -65,7 +64,7 @@ namespace Easyuino { @param greenPin - The Arduino pin connected to led's green pin @param bluePin - The Arduino pin connected to led's blue pin */ - RGBLed(uint8_t redPin, uint8_t greenPin, uint8_t bluePin); + RGBLed(IN uint8_t redPin, IN uint8_t greenPin, IN uint8_t bluePin); /* Makes a RGBLed object that exposes the API @param redPin - The Arduino pin connected do led's red pin @@ -73,7 +72,7 @@ namespace Easyuino { @param bluePin - The Arduino pin connected to led's blue pin @param ledType - The type of the LED's inners */ - RGBLed(uint8_t redPin, uint8_t greenPin, uint8_t bluePin, LED_TYPE ledType); + RGBLed(IN uint8_t redPin, IN uint8_t greenPin, IN uint8_t bluePin, IN LedType ledType); /* Destroys a RGBLed object that exposes the API and frees the resources*/ ~RGBLed(); @@ -96,17 +95,17 @@ namespace Easyuino { @param green - Green value (0-255) @param blue - Blue value (0-255) */ - void setColor(uint8_t red, uint8_t green, uint8_t blue); + void setColor(IN uint8_t red, IN uint8_t green, IN uint8_t blue); /* Set the led's color based on the hexadecimal color code used in web context @param hexadecimalCode - String that represents a valid hexadecimal color code (e.g: "#ffffff" to red color) */ - void setColor(char hexadecimalColoCode[8]); + void setColor(IN char hexadecimalColoCode[8]); /* Set the led's color based in a set o pre defined colors @param color - Enum value that represents the wanted color */ - void setColor(COLOR color); + void setColor(IN Color color); #pragma endregion diff --git a/src/RainDetector.h b/src/RainDetector.h deleted file mode 100644 index ab5a5b1..0000000 --- a/src/RainDetector.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -MIT License - -Copyright (c) 2017 André Pires - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ -/* -RainDetector.h -*/ -#ifndef _EASYUINO_RAIN_DETECTOR_h -#define _EASYUINO_RAIN_DETECTOR_h - -#include "Device.h" - -namespace Easyuino { - - class RainDetector : public Device { - - // TODO: Implementation soon - - }; - -}; - -#endif diff --git a/src/Relay.h b/src/Relay.h index 2395a11..c02ec78 100644 --- a/src/Relay.h +++ b/src/Relay.h @@ -27,6 +27,7 @@ Relay.h #ifndef _EASYUINO_RELAY_h #define _EASYUINO_RELAY_h +#include "Utilities.h" #include "Device.h" namespace Easyuino { @@ -51,7 +52,7 @@ namespace Easyuino { Creates a Relay object to interact with the physical one @param arduionPin - Arduino pin that is connected with the relay (normaly called IN pins) */ - Relay(uint8_t arduinoPin); + Relay(IN uint8_t arduinoPin); /* Used to free all the resources associated with the Relay object @@ -65,7 +66,7 @@ namespace Easyuino { @param isNormallyClosed - Define what are the state that relay is powering the device (lamp, engine, etc) @param normallyClosedPinLevel - Digital level of the normally closed relay state (some relays activate on HIGH other on LOW) */ - bool begin(bool isNormallyClosed, uint8_t normallyClosedPinLevel); + bool begin(IN bool isNormallyClosed, IN uint8_t normallyClosedPinLevel); void end(); diff --git a/src/RelayNamed.h b/src/RelayNamed.h index e49936e..d3b42e6 100644 --- a/src/RelayNamed.h +++ b/src/RelayNamed.h @@ -27,9 +27,9 @@ RelayNamed.h #ifndef _EASYUINO_RELAY_NAMED_h #define _EASYUINO_RELAY_NAMED_h +#include "Utilities.h" #include "Device.h" #include "Printable.h" -#include "Utilities.h" #include "Relay.h" #define MAX_NAME_SIZE 15 // Maximum size for a identifier @@ -57,7 +57,7 @@ namespace Easyuino { @param arduionPin - Arduino pin that is connected with the relay (normal in relay is IN pins) @param name - Name (identifier) to the device that the relay activates */ - RelayNamed(uint8_t arduinoPin, const char* deviceName); + RelayNamed(IN uint8_t arduinoPin, IN const char* deviceName); ~RelayNamed(); diff --git a/src/SMS.h b/src/SMS.h index 9dd8be0..2d94e96 100644 --- a/src/SMS.h +++ b/src/SMS.h @@ -30,17 +30,16 @@ SMS.h #include "Utilities.h" /* Maximum SMS size to allow static allocation of resources */ -#define MAX_SMS_SIZE 64 +#define MAX_SMS_SIZE 50 namespace Easyuino { /* - Represents a SMS object used to send and receive it from the GSMService + Represents a SMS object used to send and receive it from the GSMService API. */ class SMS { private: - /* Country code used to put in the prefix */ unsigned int _countryPrefixCode; /* Phone number without the country prefix code */ @@ -49,18 +48,17 @@ namespace Easyuino { char _message[MAX_SMS_SIZE + 1]; public: - /* Create a SMS object used to send/receive SMS from GSMLibrary @param number - Number of sender or receiver @param message - Message content @param countryPrefixCode - Country prefix code of the message. Default value is 351 (Portugal Code) */ - SMS(unsigned long number, const char* message, unsigned int countryPrefixCode = 351); + SMS(IN unsigned long number, IN const char* message, IN unsigned int countryPrefixCode = 351); /* Create an empty SMS @param number - Country prefix code of the message.Default value is 351 (Portugal Code) */ - SMS(unsigned int countryPrefixCode = 351); + SMS(IN unsigned int countryPrefixCode = 351); /* Get the country prefix code associated with the SMS @return - Number associated with the SMS OR 0 if it was impossible to obtain the prefix code. @@ -70,7 +68,7 @@ namespace Easyuino { /* Set the country prefix code associated with the SMS. Valid numbers are in range [0,999]. @param newCountryPrefixCode - New country prefix code to the SMS */ - void setCountryPrefixCode(unsigned int newCountryPrefixCode); + void setCountryPrefixCode(IN unsigned int newCountryPrefixCode); /* Get the number associated with the SMS @return - Number associated with the SMS @@ -80,7 +78,7 @@ namespace Easyuino { /* Set the number of the SMS @param number - The new number to be set on the SMS */ - void setNumber(unsigned long newNumber); + void setNumber(IN unsigned long newNumber); /* Get the message associated with the SMS @return - Message associated with the SMS @@ -90,7 +88,7 @@ namespace Easyuino { /* Set the message of the SMS @param message - The new message to be set on the SMS */ - void setMessage(const char* newMessage); + void setMessage(IN const char* newMessage); /* Resets the message to zeros, number to zero and the country prefix code to 0 (Undefined)*/ void reset(); diff --git a/src/SevenSegments.h b/src/SevenSegments.h index 5666579..6c8779b 100644 --- a/src/SevenSegments.h +++ b/src/SevenSegments.h @@ -27,13 +27,30 @@ SevenSegments.h #ifndef _EASYUINO_SEVEN_SEGMENTS_h #define _EASYUINO_SEVEN_SEGMENTS_h +#include "Utilities.h" #include "Device.h" namespace Easyuino { class SevenSegments : public Device { - // TODO: Implementation soon + private: + uint8_t _clkPin; + uint8_t _dataPin; + + public: + SevenSegments(uint8_t clkPin, uint8_t dataPin); + + bool begin(); + + void end(); + + void print(uint8_t byte); + + private: + void start(); + + void stop(); }; diff --git a/src/Utilities.h b/src/Utilities.h index 563232e..a629124 100644 --- a/src/Utilities.h +++ b/src/Utilities.h @@ -30,35 +30,47 @@ Utilities.h #include #include +/* Define Easyuino API method parameter to be exclusively an input */ +#define IN +/* Define Easyuino API method parameter to be exclusively an output */ +#define OUT +/* Define Easyuino API method parameter that is used as input and output */ +#define INOUT + namespace Easyuino { /* - Provides some auxiliary functions for internal use in library but at same time expose it to public - for the library users. + Provides some auxiliary functions for internal use in library but at same + time expose it to public for the library users. */ class Utilities { - public: - /* - Wrapper around the stdlib.h malloc to make it safe of overflows in the the majority of common - string manipulation cases and at same time zero's all the allocated memory too. - */ - static void* EasyMalloc(unsigned int sizeInBytes); + public: + /* + Wrapper around the stdlib.h malloc to make it safe of overflows in the the majority + of common string manipulation cases and at same time zero's all the allocated memory too. + @param + */ + static void* EasyMalloc(IN unsigned int sizeInBytes); - /* - Fills a given buffer with zeros - */ - static void ZeroBuffer(void *buffer, size_t bufferSize); + /* + Fills a given buffer with zeros. + @param buffer - Pointer to the buffer + @param bufferSize - Buffer's size + */ + static void ZeroBuffer(IN void *buffer, IN size_t bufferSize); - /* - Put a \0 in the last character - */ - static void OverrideLastStringChar(char* string); + /* + Put a \0 in the last character of the string. + @param string - Pointer to the string + */ + static void OverrideLastStringChar(IN char* string); - /* - Put a \0 in the last two characters - */ - static void OverrideLastTwoChar(char* string); + /* + Put a \0 in the last two characters of the string. + @param string - Pointer to the string + */ + static void OverrideLastTwoChar(IN char* string); }; diff --git a/src/WaterDetector.h b/src/WaterDetector.h new file mode 100644 index 0000000..1956b92 --- /dev/null +++ b/src/WaterDetector.h @@ -0,0 +1,95 @@ +/* +MIT License + +Copyright (c) 2017 André Pires + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +/* +WaterDetector.h +*/ +#ifndef _EASYUINO_WATER_DETECTOR_h +#define _EASYUINO_WATER_DETECTOR_h + +#include "Utilities.h" +#include "Device.h" + +#define DRY_MAX_LEVEL 975 +#define FEW_WATER_DROPS_MAX_LEVEL 750 +#define WET_MAX_LEVEL 400 +#define FLOOD_MAX_LEVEL 0 + +namespace Easyuino { + + /* Used to easily indicate how wet is the water sensor */ + enum class WaterStatus : uint8_t { + DRY = 0, FEW_DROPS = 1, WET = 2, FLOOD = 3, INVALID = 4, NOT_INITIALIZED = 255 + }; + + /* + RainDetector API is used to detect the amount of water that is touching the sensor. + */ + class WaterDetector : public Device { + + private: + /* Arduino pin connected to digital pin (Normally D0 in sensor PCB) */ + uint8_t _digitalPin; + /* Arduino pin connected to analog pin (Normally A0 in sensor PCB) */ + uint8_t _analogPin; + /* Digital level that triggers the water sensor */ + uint8_t _digitalPinTriggerLevel; + + public: + WaterDetector(IN uint8_t digitalPin, IN uint8_t analogPin); + + ~WaterDetector(); + + bool begin(); + + /* + @param digitalPinTriggerLevel - The digital level that is triggered in digital + pin when water is sensed. + */ + bool begin(IN uint8_t digitalPinTriggerLevel); + + void end(); + + /* + Returns an enumerate value depending on how wet is the sensor. + @return WaterStatus - Available options in WaterStatus enumerate. + */ + WaterStatus getWaterStatus(); + + /* + Return a number in [0,1023] depending on dry is the sensor. Used in getWaterStatus method. + @return - A number in range [0,1023], 1023 = dry and 0 = flood or -1 if API is not initialized + */ + unsigned int getWaterStatusRange(); + + /* + Used to get the value from the digital pin that is activated when a wet threshold is passed. + @return - True: If water threshold detection passed. False: Otherwise. + */ + bool isWaterDetected(); + + }; + +}; + +#endif diff --git a/src/OLEDlcd.h b/src/WaterFlowMeter.h similarity index 62% rename from src/OLEDlcd.h rename to src/WaterFlowMeter.h index 511ed5a..958fffd 100644 --- a/src/OLEDlcd.h +++ b/src/WaterFlowMeter.h @@ -22,21 +22,59 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* -OLEDlcd.h +WaterFlowMeter.h */ -#ifndef _EASYUINO_OLED_LCD_h -#define _EASYUINO_OLED_LCD_h +#ifndef _EASYUINO_WATER_FLOW_METER_h +#define _EASYUINO_WATER_FLOW_METER_h +#include "Utilities.h" #include "Device.h" namespace Easyuino { - class OLEDlcd : public Device { + /* + Water flow meter used to + */ + class WaterFlowMeter : public Device { - // TODO: Implementation soon + private: + /* */ + static WaterFlowMeter* Singleton; + + /* */ + uint8_t _sensorPin; + + /* */ + float _sensorCalibration; + + unsigned long _lastCheckTimestamp; + /* */ + volatile uint16_t _pulseCounter; + /* */ + float _flowRate; + + public: + WaterFlowMeter(IN uint8_t sensorPin); + + ~WaterFlowMeter(); + + bool begin(); + + void end(); + + void updateFlowRate(); + + bool isFlowing(); + + float getFlowRate(); + + private: + void countPulses(); + + static void InterruptCaller(); }; }; -#endif +#endif \ No newline at end of file diff --git a/examples/RainDetector/.gitkeep b/src/WaterFlowSensor.h similarity index 100% rename from examples/RainDetector/.gitkeep rename to src/WaterFlowSensor.h diff --git a/src/main/Displays/OLEDlcd.cpp b/src/main/Displays/OLEDlcd.cpp deleted file mode 100644 index 2011c2b..0000000 --- a/src/main/Displays/OLEDlcd.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* -MIT License - -Copyright (c) 2017 André Pires - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ -#include "../../OLEDlcd.h" - -namespace Easyuino { - - //TODO: Implementation soon - -} \ No newline at end of file diff --git a/src/main/Displays/SevenSegments.cpp b/src/main/Displays/SevenSegments.cpp index f3b09f6..36f2cdd 100644 --- a/src/main/Displays/SevenSegments.cpp +++ b/src/main/Displays/SevenSegments.cpp @@ -23,8 +23,77 @@ SOFTWARE. */ #include "../../SevenSegments.h" +#define INITIALIZE 7 + namespace Easyuino { //TODO: Implementation soon + SevenSegments::SevenSegments(uint8_t clkPin, uint8_t dataPin) : Device() { + _clkPin = clkPin; + _dataPin = dataPin; + } + + bool SevenSegments::begin() { + if (!_isInitialized) { + print(INITIALIZE); + _isInitialized = true; + } + return _isInitialized; + } + + void SevenSegments::end() { + if (_isInitialized) { + _isInitialized = false; + } + } + + void SevenSegments::print(uint8_t byte) { + start(); + for (uint8_t i = 0; i < 8; i++) + { + digitalWrite(_clkPin, LOW); + delayMicroseconds(5); + digitalWrite(_dataPin, (byte & (1 << i)) >> i); + delayMicroseconds(5); + digitalWrite(_clkPin, HIGH); + delayMicroseconds(5); + } + + // wait for ACK + digitalWrite(_clkPin, LOW); + delayMicroseconds(5); + + pinMode(_dataPin, INPUT); + + digitalWrite(_clkPin, HIGH); + delayMicroseconds(5); + + bool ack = digitalRead(_dataPin) == 0; + + pinMode(_dataPin, OUTPUT); + stop(); + } + + void SevenSegments::start() { + digitalWrite(_clkPin, HIGH); //send start signal to TM1637 + digitalWrite(_dataPin, HIGH); + delayMicroseconds(5); + + digitalWrite(_dataPin, LOW); + digitalWrite(_clkPin, LOW); + delayMicroseconds(5); + } + + void SevenSegments::stop() { + digitalWrite(_clkPin, LOW); + digitalWrite(_dataPin, LOW); + delayMicroseconds(5); + + digitalWrite(_clkPin, HIGH); + digitalWrite(_dataPin, HIGH); + delayMicroseconds(5); + } + + } diff --git a/src/main/GSM/GSMService.cpp b/src/main/GSM/GSMService.cpp index 23a4b4a..eb660ae 100644 --- a/src/main/GSM/GSMService.cpp +++ b/src/main/GSM/GSMService.cpp @@ -23,18 +23,15 @@ SOFTWARE. */ #include "../../GSMService.h" -#define DELAY_WAIT_FOR_DATA 250 // 200 milliseconds - Used to wait for all the data from the GSM board +#define DELAY_WAIT_FOR_DATA 200 // 200 milliseconds: Used to wait for all the data from the GSM board -/* List of used and deprecated by API AT commands */ - -#define AT_ATE0 "ATE0\r" // Disables the command echoing -#define AT_CNMI "AT+CNMI=2,2,0,0,0\r" // Make GSM board send the SMS to the serial ports when received -#define AT_CMGD "AT+CMGD=" // Deletes SMS (SMS Index, [optional] flag) +#define AT_ATE0 "ATE0\r" // Disables the command echoing +#define AT_CNMI "AT+CNMI=2,2,0,0,0\r" // Make GSM board send the SMS to the serial ports when received +#define AT_CMGD "AT+CMGD=" // Deletes SMS (SMS Index, [optional] flag) #define CHAR_CTRL_Z (char)26 #define CHAR_ESC (char)27 - namespace Easyuino { GSMService::GSMService(IN uint8_t txPin, IN uint8_t rxPin, IN Stream &outputStream) @@ -82,7 +79,7 @@ namespace Easyuino { } bool GSMService::begin() { - return begin(GSM_SIM900_BAUD_RATE); + return begin(GSM_DEFAULT_BAUD_RATE); } void GSMService::end() { @@ -93,7 +90,7 @@ namespace Easyuino { } GSMRequestStatus GSMService::addAllowedNumber(IN unsigned long numberToAdd) { - if (numberToAdd == 0) { // Necessary because we consider 0 not valid number + if (numberToAdd == 0) { // Necessary because we consider 0 not valid number GSMRequestStatus::GSM_REQUEST_INVALID_ARGUMENT; } @@ -107,7 +104,7 @@ namespace Easyuino { } GSMRequestStatus GSMService::isAllowed(IN unsigned long phoneNumber, INOUT bool &allowed) { - if (phoneNumber == 0) { // Necessary because we consider 0 not valid number + if (phoneNumber == 0) { // Necessary because we consider 0 not valid number allowed = false; return GSMRequestStatus::GSM_REQUEST_INVALID_ARGUMENT; } @@ -127,7 +124,7 @@ namespace Easyuino { } GSMRequestStatus GSMService::removeAllowedNumber(IN unsigned long phoneNumberToRemove) { - if (phoneNumberToRemove == 0) { // Necessary because we consider 0 not valid number + if (phoneNumberToRemove == 0) { // Necessary because we consider 0 not valid number return GSMRequestStatus::GSM_REQUEST_INVALID_ARGUMENT; } @@ -148,7 +145,7 @@ namespace Easyuino { GSMRequestStatus GSMService::beginListenForSMS() { if (!_isInitialized) { - return GSMRequestStatus::GSM_SERVICE_NOT_INITIALIZED; + return GSMRequestStatus::NOT_INITIALIZED; } GSMInternalRequestStatus internalTemp; @@ -179,7 +176,7 @@ namespace Easyuino { smsRead = false; if (!_isInitialized) { - return GSMRequestStatus::GSM_SERVICE_NOT_INITIALIZED; + return GSMRequestStatus::NOT_INITIALIZED; } if (!_readyToReceiveSMS || !lookForGSMBoardData()) { return GSMRequestStatus::GSM_OK; @@ -235,7 +232,7 @@ namespace Easyuino { GSMRequestStatus GSMService::sendSMS(IN SMS &sms) { if (!_isInitialized) { - return GSMRequestStatus::GSM_SERVICE_NOT_INITIALIZED; + return GSMRequestStatus::NOT_INITIALIZED; } GSMInternalRequestStatus internalTemp; @@ -283,12 +280,11 @@ namespace Easyuino { #pragma endregion - #pragma region Private Methods GSMRequestStatus GSMService::deleteSMS(IN GSMSmsDeleteFlag flag, IN unsigned int messageIndex) { if (!_isInitialized) { - return GSMRequestStatus::GSM_SERVICE_NOT_INITIALIZED; + return GSMRequestStatus::NOT_INITIALIZED; } GSMInternalRequestStatus internalTemp; @@ -312,15 +308,10 @@ namespace Easyuino { GSMService::GSMInternalRequestStatus GSMService::waitForGSMBoardData() { unsigned long waitInitTime = millis(); - unsigned long currentTime = millis(); while (_GSMSerial->available() == 0) { /* ACTIVELY wait for data */ - currentTime = millis(); - if (currentTime <= waitInitTime) { // Prevent the cases where millis() register overflow - waitInitTime = millis(); // TODO: Solution may cause a bigger timeout - } - else if ((currentTime - waitInitTime) > WAIT_FOR_DATA_TIMEOUT) { - return GSM_INTERNAL_COMMUNICATION_FAILED; // TIMEOUT - Waiting for board reply + if ((millis() - waitInitTime) > WAIT_FOR_DATA_TIMEOUT) { // TIMEOUT - Waiting for board reply + return GSM_INTERNAL_COMMUNICATION_FAILED; } } lookForGSMBoardData(); diff --git a/src/main/GSM/SMS.cpp b/src/main/GSM/SMS.cpp index d15267d..7bfb83f 100644 --- a/src/main/GSM/SMS.cpp +++ b/src/main/GSM/SMS.cpp @@ -25,14 +25,14 @@ SOFTWARE. namespace Easyuino { - SMS::SMS(unsigned long number, const char* message, unsigned int countryPrefixCode) + SMS::SMS(IN unsigned long number, IN const char* message, IN unsigned int countryPrefixCode) : SMS::SMS() { setNumber(number); setMessage(message); setCountryPrefixCode(countryPrefixCode); } - SMS::SMS(unsigned int countryPrefixCode) { + SMS::SMS(IN unsigned int countryPrefixCode) { Utilities::ZeroBuffer(_message, MAX_SMS_SIZE + 1); setNumber(0); setCountryPrefixCode(countryPrefixCode); @@ -42,7 +42,7 @@ namespace Easyuino { return _countryPrefixCode; } - void SMS::setCountryPrefixCode(unsigned int newCountryPrefixCode) { + void SMS::setCountryPrefixCode(IN unsigned int newCountryPrefixCode) { _countryPrefixCode = newCountryPrefixCode; } @@ -50,7 +50,7 @@ namespace Easyuino { return _number; } - void SMS::setNumber(unsigned long newNumber) { + void SMS::setNumber(IN unsigned long newNumber) { _number = newNumber; } @@ -58,7 +58,7 @@ namespace Easyuino { return _message; } - void SMS::setMessage(const char* newMessage) { + void SMS::setMessage(IN const char* newMessage) { Utilities::ZeroBuffer(_message, MAX_SMS_SIZE + 1); strncpy(_message, newMessage, MAX_SMS_SIZE); } diff --git a/src/main/Leds/RGBLed.cpp b/src/main/Leds/RGBLed.cpp index 5255df7..6f00db1 100644 --- a/src/main/Leds/RGBLed.cpp +++ b/src/main/Leds/RGBLed.cpp @@ -25,12 +25,12 @@ SOFTWARE. namespace Easyuino { - RGBLed::RGBLed(uint8_t redPin, uint8_t greenPin, uint8_t bluePin) - : RGBLed(redPin, greenPin, bluePin, LED_TYPE::COMMON_CATODE ) { // Default: Common Catode + RGBLed::RGBLed(IN uint8_t redPin, IN uint8_t greenPin, IN uint8_t bluePin) + : RGBLed(redPin, greenPin, bluePin, LedType::COMMON_CATODE ) { // Default: Common Catode /* Do Nothing */ } - RGBLed::RGBLed(uint8_t redPin, uint8_t greenPin, uint8_t bluePin, LED_TYPE ledType) { + RGBLed::RGBLed(IN uint8_t redPin, IN uint8_t greenPin, IN uint8_t bluePin, IN LedType ledType) { _redPin = redPin; _greenPin = greenPin; _bluePin = bluePin; @@ -63,12 +63,12 @@ namespace Easyuino { } } - void RGBLed::setColor(uint8_t red, uint8_t green, uint8_t blue) { + void RGBLed::setColor(IN uint8_t red, IN uint8_t green, IN uint8_t blue) { if (_isInitialized) { if (red >= 0 && red <= 255 && green >= 0 && green <= 255 && blue >= 0 && blue <= 255) { - if (_ledType == LED_TYPE::COMMON_ANODE) { + if (_ledType == LedType::COMMON_ANODE) { red = 255 - red; green = 255 - green; blue = 255 - blue; @@ -81,7 +81,7 @@ namespace Easyuino { } - void RGBLed::setColor(char hexadecimalColorCode[8]) { + void RGBLed::setColor(IN char hexadecimalColorCode[8]) { uint8_t red, green, blue; char temp[5] = "0X\0\0"; for (uint8_t i = 0; i < 8; i++) { @@ -101,53 +101,53 @@ namespace Easyuino { setColor(red, green, blue); } - void RGBLed::setColor(COLOR color) { + void RGBLed::setColor(IN Color color) { if (_isInitialized) { switch (color) { - case COLOR::RED: + case Color::RED: setColor(255, 0, 0); break; - case COLOR::GREEN: + case Color::GREEN: setColor(0, 255, 0); break; - case COLOR::BLUE: + case Color::BLUE: setColor(0, 0, 255); break; - case COLOR::YELLOW: + case Color::YELLOW: setColor(255, 255, 0); break; - case COLOR::WHITE: + case Color::WHITE: setColor(255, 255, 255); break; - case COLOR::ORANGE: + case Color::ORANGE: setColor(255, 165, 0); break; - case COLOR::PINK: + case Color::PINK: setColor(255, 192, 203); break; - case COLOR::SALMON: + case Color::SALMON: setColor(250, 128, 114); break; - case COLOR::VIOLET: + case Color::VIOLET: setColor(238, 130, 238); break; - case COLOR::AQUA: + case Color::AQUA: setColor(0, 255, 255); break; - case COLOR::BROWN: + case Color::BROWN: setColor(165, 42, 42); break; - case COLOR::DARKGREY: + case Color::DARKGREY: setColor(165, 169, 169); break; - case COLOR::OLIVE: + case Color::OLIVE: setColor(128, 128, 0); break; - case COLOR::SKYBLUE: + case Color::SKYBLUE: setColor(135, 206, 235); break; - case COLOR::FIREBRICK: + case Color::FIREBRICK: setColor(178, 34, 34); break; default: diff --git a/src/main/Relay/Relay.cpp b/src/main/Relay/Relay.cpp index e46caef..3167304 100644 --- a/src/main/Relay/Relay.cpp +++ b/src/main/Relay/Relay.cpp @@ -25,7 +25,7 @@ SOFTWARE. namespace Easyuino { - Relay::Relay(uint8_t arduinoPin) : Device() { + Relay::Relay(IN uint8_t arduinoPin) : Device() { _arduinoPin = arduinoPin; } @@ -35,7 +35,7 @@ namespace Easyuino { return begin(false, HIGH); // Default is a device connected to a Normally Open terminal } - bool Relay::begin(bool isNormallyClosed, uint8_t normallyClosedPinLevel) { + bool Relay::begin(IN bool isNormallyClosed, IN uint8_t normallyClosedPinLevel) { if (!_isInitialized && (normallyClosedPinLevel == HIGH || normallyClosedPinLevel == LOW)) { pinMode(_arduinoPin, OUTPUT); digitalWrite(_arduinoPin, normallyClosedPinLevel); diff --git a/src/main/Relay/RelayNamed.cpp b/src/main/Relay/RelayNamed.cpp index 7d01749..5dacf87 100644 --- a/src/main/Relay/RelayNamed.cpp +++ b/src/main/Relay/RelayNamed.cpp @@ -25,7 +25,7 @@ SOFTWARE. namespace Easyuino { - RelayNamed::RelayNamed(uint8_t arduinoPin, const char * deviceName) : Relay(arduinoPin) { + RelayNamed::RelayNamed(IN uint8_t arduinoPin, IN const char * deviceName) : Relay(arduinoPin) { memset(_name, 0, MAX_NAME_SIZE); strncpy(_name, deviceName, MAX_NAME_SIZE); } diff --git a/src/main/UltraSonicModule/DistanceMeter.cpp b/src/main/UltraSonicModule/DistanceMeter.cpp index 375a232..9abf692 100644 --- a/src/main/UltraSonicModule/DistanceMeter.cpp +++ b/src/main/UltraSonicModule/DistanceMeter.cpp @@ -25,14 +25,14 @@ SOFTWARE. namespace Easyuino { - DistanceMeter::DistanceMeter(uint8_t triggerPin, uint8_t echoPin) : Device() { + DistanceMeter::DistanceMeter(IN uint8_t triggerPin,IN uint8_t echoPin) : Device() { _triggerPin = triggerPin; _echoPin = echoPin; _distance = -1.0f; _isEchoing = false; } - DistanceMeter::DistanceMeter(uint8_t triggerEchoPin) + DistanceMeter::DistanceMeter(IN uint8_t triggerEchoPin) : DistanceMeter(triggerEchoPin, triggerEchoPin) { /* Do Nothing */ } @@ -69,7 +69,7 @@ namespace Easyuino { } float DistanceMeter::getDistanceInches() { - return getDistanceCentimeters() * 0.3937007874f; // Conversion centimeters to inches + return getDistanceCentimeters() * 0.3937007874f; // Conversion centimeters to inches } void DistanceMeter::updateDistance() { @@ -80,7 +80,7 @@ namespace Easyuino { } } - float DistanceMeter::executeUpdateDistanceBlock(float soundSpeedCmSec) { + float DistanceMeter::executeUpdateDistanceBlock(IN float soundSpeedCmSec) { unsigned long echoTravelTime = 0; _isEchoing = true; if (_echoPin == _triggerPin) { // Change the pin to output if it is 3 pin module to send echo diff --git a/src/main/UltraSonicModule/DistanceMeterAccurate.cpp b/src/main/UltraSonicModule/DistanceMeterAccurate.cpp index 66731d0..c3e125f 100644 --- a/src/main/UltraSonicModule/DistanceMeterAccurate.cpp +++ b/src/main/UltraSonicModule/DistanceMeterAccurate.cpp @@ -25,13 +25,13 @@ SOFTWARE. namespace Easyuino { - DistanceMeterAccurate::DistanceMeterAccurate(uint8_t triggerPin, uint8_t echoPin) + DistanceMeterAccurate::DistanceMeterAccurate(IN uint8_t triggerPin, IN uint8_t echoPin) : DistanceMeterNonBlock(triggerPin, echoPin) { _airTemperature = DEFAULT_AIR_TEMPERATURE_CELSIUS; _temperatureScale = CELSIUS; } - DistanceMeterAccurate::DistanceMeterAccurate(uint8_t triggerEchoPin) + DistanceMeterAccurate::DistanceMeterAccurate(IN uint8_t triggerEchoPin) : DistanceMeterAccurate(triggerEchoPin, triggerEchoPin) { /* Do Nothing */ } @@ -43,7 +43,7 @@ namespace Easyuino { return calculateDistance(CalculateSoundSpeed(_airTemperature, _temperatureScale)); } - void DistanceMeterAccurate::updateDistance(float airTemperature, TemperatureScale temperatureScale) { + void DistanceMeterAccurate::updateDistance(IN float airTemperature, IN TemperatureScale temperatureScale) { if (_isInitialized) { if (!_isEchoing || (_isEchoing && isUpdateDistanceNonBlockTimeout())) { _airTemperature = airTemperature; @@ -53,7 +53,7 @@ namespace Easyuino { } } - void DistanceMeterAccurate::updateDistanceNonBlock(float airTemperature, TemperatureScale temperatureScale) { + void DistanceMeterAccurate::updateDistanceNonBlock(IN float airTemperature, IN TemperatureScale temperatureScale) { if (_isInitialized) { if (!_isEchoing || (_isEchoing && isUpdateDistanceNonBlockTimeout())) { _airTemperature = airTemperature; @@ -63,7 +63,7 @@ namespace Easyuino { } } - float DistanceMeterAccurate::CalculateSoundSpeed(float airTemperature, TemperatureScale temperatureScale) { + float DistanceMeterAccurate::CalculateSoundSpeed(IN float airTemperature, IN TemperatureScale temperatureScale) { float celsiusAirTemperature; switch (temperatureScale) { case TemperatureScale::FAHRENHEIT: diff --git a/src/main/UltraSonicModule/DistanceMeterNonBlock.cpp b/src/main/UltraSonicModule/DistanceMeterNonBlock.cpp index 5ab1a79..b84ecb2 100644 --- a/src/main/UltraSonicModule/DistanceMeterNonBlock.cpp +++ b/src/main/UltraSonicModule/DistanceMeterNonBlock.cpp @@ -27,7 +27,7 @@ namespace Easyuino { DistanceMeterNonBlock* DistanceMeterNonBlock::INSTANCES[MAXIMUM_NUMBER_OF_DM_NON_BLOCK]; - DistanceMeterNonBlock::DistanceMeterNonBlock(uint8_t triggerPin, uint8_t echoPin) + DistanceMeterNonBlock::DistanceMeterNonBlock(IN uint8_t triggerPin, IN uint8_t echoPin) : DistanceMeter(triggerPin, echoPin) { _lastTimeTrigger = _lastTimeEcho = 0; _echoSent = false; @@ -36,7 +36,7 @@ namespace Easyuino { DistanceMeterNonBlock::assignInstance(this); } - DistanceMeterNonBlock::DistanceMeterNonBlock(uint8_t triggerEchoPin) + DistanceMeterNonBlock::DistanceMeterNonBlock(IN uint8_t triggerEchoPin) : DistanceMeterNonBlock(triggerEchoPin, triggerEchoPin) { /* Do Nothing */ } @@ -117,9 +117,8 @@ namespace Easyuino { return false; } - float DistanceMeterNonBlock::calculateDistance(float soundSpeedCmPerSec) { - // Micro timer overflow detected returning last one we had OR the value stored is the most recent we have - if (!_isDirtyDistance || (_lastTimeEcho <= _lastTimeTrigger)) { + float DistanceMeterNonBlock::calculateDistance(IN float soundSpeedCmPerSec) { + if (!_isDirtyDistance) { return _distance; } else { @@ -131,7 +130,7 @@ namespace Easyuino { #pragma region Interrupt Management/Handling Methods - void DistanceMeterNonBlock::interruptHandler(unsigned long interruptCallTimeMicros) { + void DistanceMeterNonBlock::interruptHandler(IN unsigned long interruptCallTimeMicros) { if (!_blockingMeasure) { if (digitalRead(_echoPin) == HIGH && _isEchoing && !_echoSent) { _lastTimeTrigger = interruptCallTimeMicros; @@ -146,7 +145,7 @@ namespace Easyuino { } /* Static */ - void DistanceMeterNonBlock::assignInstance(DistanceMeterNonBlock* dm) { + void DistanceMeterNonBlock::assignInstance(IN DistanceMeterNonBlock* dm) { if (DistanceMeterNonBlock::INSTANCES[0] == NULL) { DistanceMeterNonBlock::INSTANCES[0] = dm; } @@ -160,7 +159,7 @@ namespace Easyuino { } /* Static */ - void DistanceMeterNonBlock::deleteInstance(DistanceMeterNonBlock* dm) { + void DistanceMeterNonBlock::deleteInstance(IN DistanceMeterNonBlock* dm) { if (DistanceMeterNonBlock::INSTANCES[0] == dm) { DistanceMeterNonBlock::INSTANCES[0] = NULL; } @@ -170,7 +169,7 @@ namespace Easyuino { } /* Static */ - void DistanceMeterNonBlock::attachInterruptToInstance(DistanceMeterNonBlock* dm) { + void DistanceMeterNonBlock::attachInterruptToInstance(IN DistanceMeterNonBlock* dm) { if (DistanceMeterNonBlock::INSTANCES[0] == dm) { attachInterrupt(digitalPinToInterrupt(dm->_echoPin), DistanceMeterNonBlock::interruptCaller0, CHANGE); } diff --git a/src/main/UltraSonicModule/DistanceMeterPrintable.cpp b/src/main/UltraSonicModule/DistanceMeterPrintable.cpp index b5e2d37..444332b 100644 --- a/src/main/UltraSonicModule/DistanceMeterPrintable.cpp +++ b/src/main/UltraSonicModule/DistanceMeterPrintable.cpp @@ -25,7 +25,7 @@ SOFTWARE. namespace Easyuino { - DistanceMeterPrintable::DistanceMeterPrintable(uint8_t triggerPin, uint8_t echoPin) + DistanceMeterPrintable::DistanceMeterPrintable(IN uint8_t triggerPin, IN uint8_t echoPin) : DistanceMeter(triggerPin, echoPin) { /* Do Nothing */ } diff --git a/src/main/Utilities/Printable.cpp b/src/main/Utilities/Printable.cpp index 5836857..0ff3b7d 100644 --- a/src/main/Utilities/Printable.cpp +++ b/src/main/Utilities/Printable.cpp @@ -25,7 +25,7 @@ SOFTWARE. namespace Easyuino { - Stream & operator<<(Stream & stream, const Printable & printable) { + Stream & operator<<(IN Stream & stream, IN const Printable & printable) { char *tempRes = printable.toString(); stream.print(tempRes); free(tempRes); diff --git a/src/main/Utilities/Utilities.cpp b/src/main/Utilities/Utilities.cpp index 1b5cdac..a065d00 100644 --- a/src/main/Utilities/Utilities.cpp +++ b/src/main/Utilities/Utilities.cpp @@ -27,7 +27,7 @@ SOFTWARE. namespace Easyuino { - void* Utilities::EasyMalloc(unsigned int sizeInBytes) { + void* Utilities::EasyMalloc(IN unsigned int sizeInBytes) { void* resPtr = NULL; resPtr = (void*)malloc(sizeInBytes + EXTRA_SAFE_BYTES_MALLOC); if (resPtr == NULL) { @@ -39,18 +39,18 @@ namespace Easyuino { } } - void Utilities::ZeroBuffer(void *buffer, size_t bufferSize) { + void Utilities::ZeroBuffer(IN void *buffer,IN size_t bufferSize) { memset(buffer, 0, bufferSize); } - void Utilities::OverrideLastStringChar(char* string) { + void Utilities::OverrideLastStringChar(IN char* string) { int stringLength = strlen(string); if (stringLength >= 1) { *(string + (sizeof(char) * (stringLength - 1))) = '\0'; } } - void Utilities::OverrideLastTwoChar(char* string) { + void Utilities::OverrideLastTwoChar(IN char* string) { int stringLength = strlen(string); if (stringLength >= 1) { *(string + (sizeof(char) * (stringLength - 1))) = '\0'; diff --git a/src/main/WaterDetector/RainDetector.cpp b/src/main/WaterDetector/RainDetector.cpp deleted file mode 100644 index 98e9044..0000000 --- a/src/main/WaterDetector/RainDetector.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* -MIT License - -Copyright (c) 2017 André Pires - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ -#include "../../RainDetector.h" - -namespace Easyuino { - - //TODO: Implementation soon - -} \ No newline at end of file diff --git a/src/main/WaterDetector/WaterDetector.cpp b/src/main/WaterDetector/WaterDetector.cpp new file mode 100644 index 0000000..a422ac0 --- /dev/null +++ b/src/main/WaterDetector/WaterDetector.cpp @@ -0,0 +1,94 @@ +/* +MIT License + +Copyright (c) 2017 André Pires + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +#include "../../WaterDetector.h" + +namespace Easyuino { + + WaterDetector::WaterDetector(IN uint8_t digitalPin, IN uint8_t analogPin) + : Device() { + _digitalPin = digitalPin; + _analogPin = analogPin; + } + + WaterDetector::~WaterDetector() { /* Do Nothing */ } + + bool WaterDetector::begin() { + return begin(LOW); + } + + bool WaterDetector::begin(IN uint8_t digitalPinTriggerLevel) { + if (!_isInitialized && (digitalPinTriggerLevel == HIGH || digitalPinTriggerLevel == LOW)) { + pinMode(_digitalPin, INPUT); + _digitalPinTriggerLevel = digitalPinTriggerLevel; + _isInitialized = true; + } + return _isInitialized; + } + + void WaterDetector::end() { + if (_isInitialized) { + _isInitialized = false; + } + } + + WaterStatus WaterDetector::getWaterStatus() { + if (_isInitialized) { + unsigned int read = analogRead(_analogPin); + if (read >= DRY_MAX_LEVEL) { + return WaterStatus::DRY; + } + else if (read >= FEW_WATER_DROPS_MAX_LEVEL) { + return WaterStatus::FEW_DROPS; + } + else if(read >= WET_MAX_LEVEL) { + return WaterStatus::WET; + } + else if (read >= FLOOD_MAX_LEVEL) { + return WaterStatus::FLOOD; + } + return WaterStatus::INVALID; + } + return WaterStatus::NOT_INITIALIZED; + } + + unsigned int WaterDetector::getWaterStatusRange() { + if (_isInitialized) { + return analogRead(_analogPin); + } + return -1; + } + + bool WaterDetector::isWaterDetected() { + if (_isInitialized) { + if (digitalRead(_digitalPin) == _digitalPinTriggerLevel) { + return true; + } + else { + return false; + } + } + return false; + } + +} \ No newline at end of file diff --git a/src/main/WaterFlow/WaterFlowMeter.cpp b/src/main/WaterFlow/WaterFlowMeter.cpp new file mode 100644 index 0000000..e75c356 --- /dev/null +++ b/src/main/WaterFlow/WaterFlowMeter.cpp @@ -0,0 +1,94 @@ +/* +MIT License + +Copyright (c) 2017 André Pires + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +#include "../../WaterFlowMeter.h" + +namespace Easyuino { + + WaterFlowMeter* WaterFlowMeter::Singleton; + + WaterFlowMeter::WaterFlowMeter(IN uint8_t sensorPin) { + _sensorPin = sensorPin; + if (Singleton != NULL) { + delete Singleton; + } + Singleton = this; + } + + WaterFlowMeter::~WaterFlowMeter() { + Singleton = NULL; + } + + bool WaterFlowMeter::begin() { + if (!_isInitialized) { + pinMode(_sensorPin, INPUT); + digitalWrite(_sensorPin, HIGH); + attachInterrupt(digitalPinToInterrupt(_sensorPin), InterruptCaller, FALLING); + _pulseCounter = 0; + _lastCheckTimestamp = 0; + _flowRate = 0.0f; + _isInitialized = true; + } + return _isInitialized; + } + + void WaterFlowMeter::end() { + if (_isInitialized) { + detachInterrupt(digitalPinToInterrupt(_sensorPin)); + _isInitialized = false; + } + } + + void WaterFlowMeter::updateFlowRate() { + detachInterrupt(digitalPinToInterrupt(_sensorPin)); + _flowRate = (1000.0 / (millis() - _lastCheckTimestamp)) * _pulseCounter / _sensorCalibration; + _lastCheckTimestamp = millis(); + _pulseCounter = 0; + attachInterrupt(digitalPinToInterrupt(_sensorPin), InterruptCaller, FALLING); + } + + bool WaterFlowMeter::isFlowing() { + if (_flowRate < 0.001f) { + return false; + } + else { + return true; + } + } + + float WaterFlowMeter::getFlowRate() { + return 0.0f; + } + + void WaterFlowMeter::countPulses() { + _pulseCounter++; + } + + /* Static */ + void WaterFlowMeter::InterruptCaller() { + if (Singleton != NULL) { + Singleton->countPulses(); + } + } + +}; \ No newline at end of file diff --git a/src/main/WaterFlow/WaterFlowSensor.cpp b/src/main/WaterFlow/WaterFlowSensor.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/RGBLedTest.h b/src/tests/RGBLedTest.h index fb71f06..9d234fc 100644 --- a/src/tests/RGBLedTest.h +++ b/src/tests/RGBLedTest.h @@ -70,19 +70,19 @@ class RGBLedTest : public ManualTest { testEnd(); testStart("GREEN LED"); - rgbLedCatode->setColor(RGBLed::COLOR::GREEN); + rgbLedCatode->setColor(RGBLed::Color::GREEN); testEnd(); testStart("PINK LED"); - rgbLedCatode->setColor(RGBLed::COLOR::PINK); + rgbLedCatode->setColor(RGBLed::Color::PINK); testEnd(); testStart("WHITE LED"); - rgbLedCatode->setColor(RGBLed::COLOR::WHITE); + rgbLedCatode->setColor(RGBLed::Color::WHITE); testEnd(); testStart("FIREBRICK LED"); - rgbLedCatode->setColor(RGBLed::COLOR::FIREBRICK); + rgbLedCatode->setColor(RGBLed::Color::FIREBRICK); testEnd(); testStart("END RGB LED => LED OFF"); diff --git a/src/tests/WaterDetectorTest.h b/src/tests/WaterDetectorTest.h new file mode 100644 index 0000000..bfe3c76 --- /dev/null +++ b/src/tests/WaterDetectorTest.h @@ -0,0 +1,94 @@ +/* +MIT License + +Copyright (c) 2017 André Pires + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +/* +WaterDetectorTest.h +*/ +#ifndef _EASYUINO_WATER_DETECTOR_TEST_h +#define _EASYUINO_WATER_DETECTOR_TEST_h + +#include "Easyuino.h" +#include "ManualTest.h" + +using Easyuino::WaterDetector; + +class WaterDetectorTest : public ManualTest { + + private: + WaterDetector* waterDetector; + + public: + WaterDetectorTest(Stream &debugStream, uint8_t digitalPin, uint8_t analogPin) : ManualTest(debugStream) { + waterDetector = new WaterDetector(digitalPin, analogPin); + } + + protected: + void testsSetup() { + waterDetector->begin(); + } + + void tests() { + unsigned long time = 0; + + testStart("SEE PRINTS"); + time = millis(); + while ((millis() - time) < 20000) { + _debugStream->println(waterDetector->getWaterStatusRange()); + _debugStream->println(waterDetector->isWaterDetected()); + switch (waterDetector->getWaterStatus()) + { + case WaterDetector::DRY: + _debugStream->println("DRY"); + break; + case WaterDetector::FEW_DROPS: + _debugStream->println("FEW_DROPS"); + break; + case WaterDetector::WET: + _debugStream->println("WET"); + break; + case WaterDetector::FLOOD: + _debugStream->println("FLOOD"); + break; + } + delay(750); + } + testEnd(); + + testStart("END => ASSERTS TRUE"); + waterDetector->end(); + _debugStream->println(waterDetector->getWaterStatus() == WaterDetector::WaterStatus::NOT_INITIALIZED); + _debugStream->println(waterDetector->getWaterStatusRange() == -1); + _debugStream->println(!waterDetector->isWaterDetected()); + testEnd(); + + } + + void afterTestSuite() { + waterDetector->end(); + delete waterDetector; + waterDetector = NULL; + } + +}; + +#endif \ No newline at end of file