diff --git a/Changelog.md b/Changelog.md
index cd95dfc..03f338e 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -7,8 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[![Keep a Changelog specification badge](https://img.shields.io/badge/Keep%20a%20Changelog%20Specification-1.0.0-orange.svg)](http://keepachangelog.com)
[![Semantic Versioning specification badge](https://img.shields.io/badge/Semantic%20Versioning%20Specification-2.0.0-orange.svg)](http://semver.org)
+## [4.0.0] - 2018-02-18 ##
-## [Unreleased] ##
+### Added ###
+
+- Platformio library manager support
+
+## Changed ##
+
+- Improved code safety and cleaning
### Removed ###
diff --git a/README.md b/README.md
index 1aa8018..fc8ed9d 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,6 @@ In no event shall me and/or other peopole that holds the rights and/or are impli
The above copyright notice and this permission notice shall accompany and/or be included ( depending on the type of work ) in all the derived works from mine, as addendum to compliance with the provisions above.
-If you need permissions that are beyond the scope of this license, you can ask to me through this facebook page https://www.facebook.com/dev.hackerinside/
+If you need permissions that are beyond the scope of this license, you can ask to me through this facebook page https://www.facebook.com/dev.giuseppemasino/
The text of this license can also be found in the LICENSE.md file
diff --git a/library.json b/library.json
new file mode 100644
index 0000000..f8407db
--- /dev/null
+++ b/library.json
@@ -0,0 +1,13 @@
+{
+ "name" : "L293" ,
+ "description" : "A library to control motors with the L293x motor driver and L298x compatible modules" ,
+ "keywords" : "motor" ,
+ "repository" :
+ {
+ "type" : "git" ,
+ "url" : "https://github.com/qub1750ul/Arduino_L293.git"
+ } ,
+ "license" : "CC-BY-SA-4.0" ,
+ "frameworks" : "Arduino" ,
+ "platforms" : "*"
+}
diff --git a/library.properties b/library.properties
index 78c8eae..ff2064f 100644
--- a/library.properties
+++ b/library.properties
@@ -1,7 +1,7 @@
name=L293
-version=3.1.0
-author=Giuseppe Masino (qub1750ul)
-maintainer=Giuseppe Masino (qub1750ul)
+version=4.0.0
+author=Giuseppe Masino (qub1750ul)
+maintainer=Giuseppe Masino (qub1750ul)
sentence=A library to control motors with the L293x motor driver and L298x compatible modules
paragraph=
category=Device Control
diff --git a/src/L293_base.cpp b/src/L293_base.cpp
index 9b6f1c8..bfee2ee 100644
--- a/src/L293_base.cpp
+++ b/src/L293_base.cpp
@@ -1,21 +1,21 @@
#include "L293_base.hpp"
-void L293_base :: stop()
+void L293_base :: setPWMOffset( int16_t _PWMOffset )
{
- analogWrite( enablePin, 0 );
+ PWMOffset = _PWMOffset;
}
-void L293_base :: setPWMOffset(int16_t _PWMOffset)
+void L293_base :: stop() const
{
- PWMOffset = _PWMOffset;
+ analogWrite( enablePin, 0 );
}
-uint8_t L293_base :: getRawPWMDC()
+uint8_t L293_base :: getRawPWMDC() const
{
return RawPWMDC;
}
-uint8_t L293_base :: getPWMDC()
+uint8_t L293_base :: getPWMDC() const
{
// Take the user-specified PWM value and, if it's set, apply the offset value to it
// make sure that the returned value is within the limits of an unsigned 8-bit integer
diff --git a/src/L293_base.hpp b/src/L293_base.hpp
index c77bba3..4b88f8f 100644
--- a/src/L293_base.hpp
+++ b/src/L293_base.hpp
@@ -13,21 +13,23 @@ class L293_base
{
public:
- void stop(); ///< Stops the motor by power reduction
- void setPWMOffset( int16_t _PWMOffset ); ///< Applys an offset over the speed value of the motor
- uint8_t getRawPWMDC(); ///< Returns the last set speed value without applying the offset
- uint8_t getPWMDC(); ///< Return the effective last set speed value
+ virtual ~L293_base() = 0;
- virtual void forward() = 0; ///< Makes the motor to go forward
- virtual void back() = 0; ///< Makes the motor to go reverse
- virtual bool isForward() = 0; ///< Tells the information about the motor that the name says
- virtual bool isReverse() = 0; ///< Tells the information about the motor that the name says
- virtual bool isStopped() = 0; ///< Tells the information about the motor that the name says
+ inline void setPWMOffset( int16_t _PWMOffset ) ; ///< Applys an offset over the speed value of the motor
+ inline void stop() const ; ///< Stops the motor by power reduction
+ inline uint8_t getRawPWMDC() const ; ///< Returns the last set speed value without applying the offset
+ inline uint8_t getPWMDC() const ; ///< Return the effective last set speed value
+
+ virtual void forward( uint8_t PWMDC = 0 ) = 0 ;
+ virtual void back( uint8_t PWMDC = 0 ) = 0 ;
+ virtual bool isForward() const = 0 ;
+ virtual bool isReverse() const = 0 ;
+ virtual bool isStopped() const = 0 ;
protected:
- int16_t PWMOffset; ///< An offset value for the RawPWMDC
- uint8_t enablePin; ///< The MCU pin connected to the H-bridge's ENABLE pin
- uint8_t RawPWMDC; ///< The duty-cycle of the PWM signal applied to the enablePin
+ int16_t PWMOffset; ///< An offset value for the RawPWMDC
+ uint8_t enablePin; ///< The MCU pin connected to the H-bridge's ENABLE pin
+ uint8_t RawPWMDC; ///< The duty-cycle of the PWM signal applied to the enablePin
};
diff --git a/src/L293_std.cpp b/src/L293_std.cpp
index 716e23d..1aad9e0 100644
--- a/src/L293_std.cpp
+++ b/src/L293_std.cpp
@@ -1,6 +1,6 @@
#include "L293_std.hpp"
-L293 :: L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int16_t _PWMOffset = 0 )
+L293 :: L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int16_t _PWMOffset )
{
enablePin = _enablePin;
forwardPin = _forwardPin;
@@ -15,22 +15,18 @@ L293 :: L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int1
void L293 :: forceStop( uint16_t handlingTime )
{
- if ( (*this).isForward() ) digitalWrite( reversePin, HIGH );
- else if ( (*this).isReverse() ) digitalWrite( forwardPin, HIGH );
+ if ( this->isForward() ) digitalWrite( reversePin, HIGH );
+ else if ( this->isReverse() ) digitalWrite( forwardPin, HIGH );
delay( handlingTime );
- (*this).stop();
+ this->stop();
}
void L293 :: forward( uint8_t _PWMDC )
{
- RawPWMDC = _PWMDC;
- (*this).forward();
- }
+ if( _PWMDC > 0 ) RawPWMDC = _PWMDC;
-void L293 :: forward()
- {
- (*this).stop();
+ this->stop();
digitalWrite( reversePin, LOW );
digitalWrite( forwardPin, HIGH );
analogWrite( enablePin, this->getPWMDC() );
@@ -38,41 +34,30 @@ void L293 :: forward()
void L293 :: back( uint8_t _PWMDC )
{
- RawPWMDC = _PWMDC;
- (*this).back();
- }
+ if( _PWMDC > 0 ) RawPWMDC = _PWMDC;
-void L293 :: back()
- {
- (*this).stop();
+ this->stop();
digitalWrite( forwardPin, LOW );
digitalWrite( reversePin, HIGH );
- analogWrite( enablePin, (*this).getPWMDC() );
- }
-
-uint8_t L293 :: getDirection()
- {
- return (*this).isForward() ? 0 :
- (*this).isReverse() ? 1 :
- (*this).isForceStopped() ? 2 : 3 ;
+ analogWrite( enablePin, this->getPWMDC() );
}
-bool L293 :: isForward()
+bool L293 :: isForward() const
{
return digitalRead( forwardPin ) && !digitalRead( reversePin );
}
-bool L293 :: isReverse()
+bool L293 :: isReverse() const
{
return !digitalRead( forwardPin ) && digitalRead( reversePin );
}
-bool L293 :: isForceStopped()
+bool L293 :: isForceStopped() const
{
return digitalRead( forwardPin ) && digitalRead( reversePin );
}
-bool L293 :: isStopped()
+bool L293 :: isStopped() const
{
return !digitalRead( forwardPin ) && !digitalRead( reversePin );
}
diff --git a/src/L293_std.hpp b/src/L293_std.hpp
index c18bbc1..4deee72 100644
--- a/src/L293_std.hpp
+++ b/src/L293_std.hpp
@@ -14,17 +14,14 @@ class L293 : public L293_base
L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int16_t _speedOffset = 0 );
- void forceStop( uint16_t handlingTime ); ///< Stops the motor by electrically braking it
- bool isForceStopped(); ///< Tells the information about the motor that the name says
-
- virtual void forward( uint8_t _PWMDC ); ///< Makes the motor to go forward and sets a new speed value
- virtual void forward(); ///< Makes the motor to go forward
- virtual void back( uint8_t _PWMDC ); ///< Makes the motor to go reverse and sets a new speed value
- virtual void back(); ///< Makes the motor to go reverse
- virtual bool isForward(); ///< Tells the information about the motor that the name says
- virtual bool isReverse(); ///< Tells the information about the motor that the name says
- virtual bool isStopped(); ///< Tells the information about the motor that the name says
- virtual uint8_t getDirection(); ///< deprecated
+ inline void forceStop( uint16_t handlingTime ); ///< Stops the motor by electrically braking it
+ inline bool isForceStopped() const ; ///< Tells the information about the motor that the name says
+
+ inline void forward( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go forward and sets a new speed value
+ inline void back( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go reverse and sets a new speed value
+ inline bool isForward() const override ; ///< Tells the information about the motor that the name says
+ inline bool isReverse() const override ; ///< Tells the information about the motor that the name says
+ inline bool isStopped() const override ; ///< Tells the information about the motor that the name says
protected:
diff --git a/src/L293_twoWire.cpp b/src/L293_twoWire.cpp
index 7673c4b..fc4d569 100644
--- a/src/L293_twoWire.cpp
+++ b/src/L293_twoWire.cpp
@@ -1,6 +1,6 @@
#include "L293_twoWire.hpp"
-L293_twoWire :: L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset = 0 )
+L293_twoWire :: L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset )
{
enablePin = _enablePin;
directionPin = _directionPin;
@@ -13,47 +13,33 @@ L293_twoWire :: L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t
void L293_twoWire :: forward( uint8_t _PWMDC )
{
- RawPWMDC = _PWMDC;
- (*this).forward();
- }
+ if( _PWMDC ) RawPWMDC = _PWMDC ;
-void L293_twoWire :: forward()
- {
- (*this).stop();
+ this->stop();
digitalWrite( directionPin, HIGH );
- analogWrite( enablePin, (*this).getPWMDC() );
+ analogWrite( enablePin, this->getPWMDC() );
}
void L293_twoWire :: back( uint8_t _PWMDC )
{
- RawPWMDC = _PWMDC;
- (*this).back();
- }
+ if( _PWMDC ) RawPWMDC = _PWMDC ;
-void L293_twoWire :: back()
- {
- (*this).stop();
+ this->stop();
digitalWrite( directionPin, LOW );
- analogWrite(enablePin, (*this).getPWMDC() );
- }
-
-
-bool L293_twoWire :: getDirection()
- {
- return digitalRead( directionPin );
+ analogWrite(enablePin, this->getPWMDC() );
}
-bool L293_twoWire :: isForward()
+bool L293_twoWire :: isForward() const
{
return digitalRead( directionPin );
}
-bool L293_twoWire :: isReverse()
+bool L293_twoWire :: isReverse() const
{
- return !( (*this).isForward() );
+ return !( this->isForward() ) ;
}
-bool L293_twoWire :: isStopped()
+bool L293_twoWire :: isStopped() const
{
- return (*this).getPWMDC() ? 1 : 0 ;
+ return this->getPWMDC() ;
}
diff --git a/src/L293_twoWire.hpp b/src/L293_twoWire.hpp
index c4d0609..ac0a286 100644
--- a/src/L293_twoWire.hpp
+++ b/src/L293_twoWire.hpp
@@ -14,16 +14,13 @@ class L293_twoWire : public L293_base
{
public:
- L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset = 0 );
-
- virtual void forward( uint8_t _PWMDC ); ///< Makes the motor to go forward and sets a new speed value
- virtual void forward(); ///< Makes the motor to go forward
- virtual void back( uint8_t _PWMDC ); ///< Makes the motor to go reverse and sets a new speed value
- virtual void back(); ///< Makes the motor to go reverse
- virtual bool getDirection(); ///< Tells the current direction of the motor
- virtual bool isForward(); ///< Tells the information about the motor that the name says
- virtual bool isReverse(); ///< Tells the information about the motor that the name says
- virtual bool isStopped(); ///< Tells the information about the motor that the name says
+ L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset = 0 ) ;
+
+ void forward( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go forward and optionally sets a new speed value
+ void back( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go reverse and optionally sets a new speed value
+ bool isForward() const override ;
+ bool isReverse() const override ;
+ bool isStopped() const override ;
private: