Skip to content

Commit 15a1d8c

Browse files
author
Giuseppe Masino
committed
Released version v4.0.0
1 parent 1d4697a commit 15a1d8c

File tree

10 files changed

+85
-98
lines changed

10 files changed

+85
-98
lines changed

Changelog.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
[![Keep a Changelog specification badge](https://img.shields.io/badge/Keep%20a%20Changelog%20Specification-1.0.0-orange.svg)](http://keepachangelog.com)
88
[![Semantic Versioning specification badge](https://img.shields.io/badge/Semantic%20Versioning%20Specification-2.0.0-orange.svg)](http://semver.org)
99

10+
## [4.0.0] - 2018-02-18 ##
1011

11-
## [Unreleased] ##
12+
### Added ###
13+
14+
- Platformio library manager support
15+
16+
## Changed ##
17+
18+
- Improved code safety and cleaning
1219

1320
### Removed ###
1421

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ In no event shall me and/or other peopole that holds the rights and/or are impli
3333

3434
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.
3535

36-
If you need permissions that are beyond the scope of this license, you can ask to me through this facebook page <a xmlns:cc="http://creativecommons.org/ns#" href="https://www.facebook.com/dev.hackerinside/" rel="cc:morePermissions">https://www.facebook.com/dev.hackerinside/</a>
36+
If you need permissions that are beyond the scope of this license, you can ask to me through this facebook page <a xmlns:cc="http://creativecommons.org/ns#" href="https://www.facebook.com/dev.giuseppemasino/" rel="cc:morePermissions">https://www.facebook.com/dev.giuseppemasino/</a>
3737

3838
The text of this license can also be found in the LICENSE.md file

library.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name" : "L293" ,
3+
"description" : "A library to control motors with the L293x motor driver and L298x compatible modules" ,
4+
"keywords" : "motor" ,
5+
"repository" :
6+
{
7+
"type" : "git" ,
8+
"url" : "https://github.com/qub1750ul/Arduino_L293.git"
9+
} ,
10+
"license" : "CC-BY-SA-4.0" ,
11+
"frameworks" : "Arduino" ,
12+
"platforms" : "*"
13+
}

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name=L293
2-
version=3.1.0
3-
author=Giuseppe Masino (qub1750ul) <http://www.facebook.com/dev.giuseppemasino>
4-
maintainer=Giuseppe Masino (qub1750ul) <http://www.facebook.com/dev.giuseppemasino>
2+
version=4.0.0
3+
author=Giuseppe Masino (qub1750ul)
4+
maintainer=Giuseppe Masino (qub1750ul)
55
sentence=A library to control motors with the L293x motor driver and L298x compatible modules
66
paragraph=
77
category=Device Control

src/L293_base.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#include "L293_base.hpp"
22

3-
void L293_base :: stop()
3+
void L293_base :: setPWMOffset( int16_t _PWMOffset )
44
{
5-
analogWrite( enablePin, 0 );
5+
PWMOffset = _PWMOffset;
66
}
77

8-
void L293_base :: setPWMOffset(int16_t _PWMOffset)
8+
void L293_base :: stop() const
99
{
10-
PWMOffset = _PWMOffset;
10+
analogWrite( enablePin, 0 );
1111
}
1212

13-
uint8_t L293_base :: getRawPWMDC()
13+
uint8_t L293_base :: getRawPWMDC() const
1414
{
1515
return RawPWMDC;
1616
}
1717

18-
uint8_t L293_base :: getPWMDC()
18+
uint8_t L293_base :: getPWMDC() const
1919
{
2020
// Take the user-specified PWM value and, if it's set, apply the offset value to it
2121
// make sure that the returned value is within the limits of an unsigned 8-bit integer

src/L293_base.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@ class L293_base
1313
{
1414
public:
1515

16-
void stop(); ///< Stops the motor by power reduction
17-
void setPWMOffset( int16_t _PWMOffset ); ///< Applys an offset over the speed value of the motor
18-
uint8_t getRawPWMDC(); ///< Returns the last set speed value without applying the offset
19-
uint8_t getPWMDC(); ///< Return the effective last set speed value
16+
virtual ~L293_base() = 0;
2017

21-
virtual void forward() = 0; ///< Makes the motor to go forward
22-
virtual void back() = 0; ///< Makes the motor to go reverse
23-
virtual bool isForward() = 0; ///< Tells the information about the motor that the name says
24-
virtual bool isReverse() = 0; ///< Tells the information about the motor that the name says
25-
virtual bool isStopped() = 0; ///< Tells the information about the motor that the name says
18+
inline void setPWMOffset( int16_t _PWMOffset ) ; ///< Applys an offset over the speed value of the motor
19+
inline void stop() const ; ///< Stops the motor by power reduction
20+
inline uint8_t getRawPWMDC() const ; ///< Returns the last set speed value without applying the offset
21+
inline uint8_t getPWMDC() const ; ///< Return the effective last set speed value
22+
23+
virtual void forward( uint8_t PWMDC = 0 ) = 0 ;
24+
virtual void back( uint8_t PWMDC = 0 ) = 0 ;
25+
virtual bool isForward() const = 0 ;
26+
virtual bool isReverse() const = 0 ;
27+
virtual bool isStopped() const = 0 ;
2628

2729
protected:
2830

29-
int16_t PWMOffset; ///< An offset value for the RawPWMDC
30-
uint8_t enablePin; ///< The MCU pin connected to the H-bridge's ENABLE pin
31-
uint8_t RawPWMDC; ///< The duty-cycle of the PWM signal applied to the enablePin
31+
int16_t PWMOffset; ///< An offset value for the RawPWMDC
32+
uint8_t enablePin; ///< The MCU pin connected to the H-bridge's ENABLE pin
33+
uint8_t RawPWMDC; ///< The duty-cycle of the PWM signal applied to the enablePin
3234

3335
};

src/L293_std.cpp

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "L293_std.hpp"
22

3-
L293 :: L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int16_t _PWMOffset = 0 )
3+
L293 :: L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int16_t _PWMOffset )
44
{
55
enablePin = _enablePin;
66
forwardPin = _forwardPin;
@@ -15,64 +15,49 @@ L293 :: L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int1
1515

1616
void L293 :: forceStop( uint16_t handlingTime )
1717
{
18-
if ( (*this).isForward() ) digitalWrite( reversePin, HIGH );
19-
else if ( (*this).isReverse() ) digitalWrite( forwardPin, HIGH );
18+
if ( this->isForward() ) digitalWrite( reversePin, HIGH );
19+
else if ( this->isReverse() ) digitalWrite( forwardPin, HIGH );
2020

2121
delay( handlingTime );
22-
(*this).stop();
22+
this->stop();
2323
}
2424

2525
void L293 :: forward( uint8_t _PWMDC )
2626
{
27-
RawPWMDC = _PWMDC;
28-
(*this).forward();
29-
}
27+
if( _PWMDC > 0 ) RawPWMDC = _PWMDC;
3028

31-
void L293 :: forward()
32-
{
33-
(*this).stop();
29+
this->stop();
3430
digitalWrite( reversePin, LOW );
3531
digitalWrite( forwardPin, HIGH );
3632
analogWrite( enablePin, this->getPWMDC() );
3733
}
3834

3935
void L293 :: back( uint8_t _PWMDC )
4036
{
41-
RawPWMDC = _PWMDC;
42-
(*this).back();
43-
}
37+
if( _PWMDC > 0 ) RawPWMDC = _PWMDC;
4438

45-
void L293 :: back()
46-
{
47-
(*this).stop();
39+
this->stop();
4840
digitalWrite( forwardPin, LOW );
4941
digitalWrite( reversePin, HIGH );
50-
analogWrite( enablePin, (*this).getPWMDC() );
51-
}
52-
53-
uint8_t L293 :: getDirection()
54-
{
55-
return (*this).isForward() ? 0 :
56-
(*this).isReverse() ? 1 :
57-
(*this).isForceStopped() ? 2 : 3 ;
42+
analogWrite( enablePin, this->getPWMDC() );
5843
}
5944

60-
bool L293 :: isForward()
45+
bool L293 :: isForward() const
6146
{
6247
return digitalRead( forwardPin ) && !digitalRead( reversePin );
6348
}
6449

65-
bool L293 :: isReverse()
50+
bool L293 :: isReverse() const
6651
{
6752
return !digitalRead( forwardPin ) && digitalRead( reversePin );
6853
}
6954

70-
bool L293 :: isForceStopped()
55+
bool L293 :: isForceStopped() const
7156
{
7257
return digitalRead( forwardPin ) && digitalRead( reversePin );
7358
}
7459

75-
bool L293 :: isStopped()
60+
bool L293 :: isStopped() const
7661
{
7762
return !digitalRead( forwardPin ) && !digitalRead( reversePin );
7863
}

src/L293_std.hpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ class L293 : public L293_base
1414

1515
L293( uint8_t _enablePin, uint8_t _forwardPin, uint8_t _reversePin, int16_t _speedOffset = 0 );
1616

17-
void forceStop( uint16_t handlingTime ); ///< Stops the motor by electrically braking it
18-
bool isForceStopped(); ///< Tells the information about the motor that the name says
19-
20-
virtual void forward( uint8_t _PWMDC ); ///< Makes the motor to go forward and sets a new speed value
21-
virtual void forward(); ///< Makes the motor to go forward
22-
virtual void back( uint8_t _PWMDC ); ///< Makes the motor to go reverse and sets a new speed value
23-
virtual void back(); ///< Makes the motor to go reverse
24-
virtual bool isForward(); ///< Tells the information about the motor that the name says
25-
virtual bool isReverse(); ///< Tells the information about the motor that the name says
26-
virtual bool isStopped(); ///< Tells the information about the motor that the name says
27-
virtual uint8_t getDirection(); ///< deprecated
17+
inline void forceStop( uint16_t handlingTime ); ///< Stops the motor by electrically braking it
18+
inline bool isForceStopped() const ; ///< Tells the information about the motor that the name says
19+
20+
inline void forward( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go forward and sets a new speed value
21+
inline void back( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go reverse and sets a new speed value
22+
inline bool isForward() const override ; ///< Tells the information about the motor that the name says
23+
inline bool isReverse() const override ; ///< Tells the information about the motor that the name says
24+
inline bool isStopped() const override ; ///< Tells the information about the motor that the name says
2825

2926
protected:
3027

src/L293_twoWire.cpp

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "L293_twoWire.hpp"
22

3-
L293_twoWire :: L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset = 0 )
3+
L293_twoWire :: L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset )
44
{
55
enablePin = _enablePin;
66
directionPin = _directionPin;
@@ -13,47 +13,33 @@ L293_twoWire :: L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t
1313

1414
void L293_twoWire :: forward( uint8_t _PWMDC )
1515
{
16-
RawPWMDC = _PWMDC;
17-
(*this).forward();
18-
}
16+
if( _PWMDC ) RawPWMDC = _PWMDC ;
1917

20-
void L293_twoWire :: forward()
21-
{
22-
(*this).stop();
18+
this->stop();
2319
digitalWrite( directionPin, HIGH );
24-
analogWrite( enablePin, (*this).getPWMDC() );
20+
analogWrite( enablePin, this->getPWMDC() );
2521
}
2622

2723
void L293_twoWire :: back( uint8_t _PWMDC )
2824
{
29-
RawPWMDC = _PWMDC;
30-
(*this).back();
31-
}
25+
if( _PWMDC ) RawPWMDC = _PWMDC ;
3226

33-
void L293_twoWire :: back()
34-
{
35-
(*this).stop();
27+
this->stop();
3628
digitalWrite( directionPin, LOW );
37-
analogWrite(enablePin, (*this).getPWMDC() );
38-
}
39-
40-
41-
bool L293_twoWire :: getDirection()
42-
{
43-
return digitalRead( directionPin );
29+
analogWrite(enablePin, this->getPWMDC() );
4430
}
4531

46-
bool L293_twoWire :: isForward()
32+
bool L293_twoWire :: isForward() const
4733
{
4834
return digitalRead( directionPin );
4935
}
5036

51-
bool L293_twoWire :: isReverse()
37+
bool L293_twoWire :: isReverse() const
5238
{
53-
return !( (*this).isForward() );
39+
return !( this->isForward() ) ;
5440
}
5541

56-
bool L293_twoWire :: isStopped()
42+
bool L293_twoWire :: isStopped() const
5743
{
58-
return (*this).getPWMDC() ? 1 : 0 ;
44+
return this->getPWMDC() ;
5945
}

src/L293_twoWire.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ class L293_twoWire : public L293_base
1414
{
1515
public:
1616

17-
L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset = 0 );
18-
19-
virtual void forward( uint8_t _PWMDC ); ///< Makes the motor to go forward and sets a new speed value
20-
virtual void forward(); ///< Makes the motor to go forward
21-
virtual void back( uint8_t _PWMDC ); ///< Makes the motor to go reverse and sets a new speed value
22-
virtual void back(); ///< Makes the motor to go reverse
23-
virtual bool getDirection(); ///< Tells the current direction of the motor
24-
virtual bool isForward(); ///< Tells the information about the motor that the name says
25-
virtual bool isReverse(); ///< Tells the information about the motor that the name says
26-
virtual bool isStopped(); ///< Tells the information about the motor that the name says
17+
L293_twoWire( uint8_t _enablePin, uint8_t _directionPin, int16_t _PWMOffset = 0 ) ;
18+
19+
void forward( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go forward and optionally sets a new speed value
20+
void back( uint8_t _PWMDC = 0 ) override ; ///< Makes the motor to go reverse and optionally sets a new speed value
21+
bool isForward() const override ;
22+
bool isReverse() const override ;
23+
bool isStopped() const override ;
2724

2825
private:
2926

0 commit comments

Comments
 (0)