Skip to content

Commit

Permalink
Released version v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Masino committed Feb 18, 2018
1 parent 1d4697a commit 15a1d8c
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 98 deletions.
9 changes: 8 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a xmlns:cc="http://creativecommons.org/ns#" href="https://www.facebook.com/dev.hackerinside/" rel="cc:morePermissions">https://www.facebook.com/dev.hackerinside/</a>
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>

The text of this license can also be found in the LICENSE.md file
13 changes: 13 additions & 0 deletions library.json
Original file line number Diff line number Diff line change
@@ -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" : "*"
}
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name=L293
version=3.1.0
author=Giuseppe Masino (qub1750ul) <http://www.facebook.com/dev.giuseppemasino>
maintainer=Giuseppe Masino (qub1750ul) <http://www.facebook.com/dev.giuseppemasino>
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
Expand Down
12 changes: 6 additions & 6 deletions src/L293_base.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 14 additions & 12 deletions src/L293_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

};
41 changes: 13 additions & 28 deletions src/L293_std.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,64 +15,49 @@ 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() );
}

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 );
}
19 changes: 8 additions & 11 deletions src/L293_std.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
38 changes: 12 additions & 26 deletions src/L293_twoWire.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() ;
}
17 changes: 7 additions & 10 deletions src/L293_twoWire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 15a1d8c

Please sign in to comment.