test2017-1-13

Dependencies:   AT24C1024 DMX-STM32 mbed

Revision:
4:c3f3fdde7eee
Parent:
0:d94213e24c2e
--- a/AccelStepper.h	Thu Mar 02 09:03:40 2017 +0000
+++ b/AccelStepper.h	Fri Mar 24 13:00:34 2017 +0000
@@ -22,49 +22,49 @@
 /// \li Extensive API
 /// \li Subclass support
 ///
-/// The latest version of this documentation can be downloaded from 
+/// The latest version of this documentation can be downloaded from
 /// http://www.airspayce.com/mikem/arduino/AccelStepper
-/// The version of the package that this documentation refers to can be downloaded 
+/// The version of the package that this documentation refers to can be downloaded
 /// from http://www.airspayce.com/mikem/arduino/AccelStepper/AccelStepper-1.47.zip
 ///
 /// Example Arduino programs are included to show the main modes of use.
 ///
 /// You can also find online help and discussion at http://groups.google.com/group/accelstepper
-/// Please use that group for all questions and discussions on this topic. 
+/// Please use that group for all questions and discussions on this topic.
 /// Do not contact the author directly, unless it is to discuss commercial licensing.
 /// Before asking a question or reporting a bug, please read http://www.catb.org/esr/faqs/smart-questions.html
 ///
-/// Tested on Arduino Diecimila and Mega with arduino-0018 & arduino-0021 
+/// Tested on Arduino Diecimila and Mega with arduino-0018 & arduino-0021
 /// on OpenSuSE 11.1 and avr-libc-1.6.1-1.15,
 /// cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5.
-/// Tested on Teensy http://www.pjrc.com/teensy including Teensy 3.1 built using Arduino IDE 1.0.5 with 
+/// Tested on Teensy http://www.pjrc.com/teensy including Teensy 3.1 built using Arduino IDE 1.0.5 with
 /// teensyduino addon 1.18 and later.
 ///
 /// \par Installation
 ///
 /// Install in the usual way: unzip the distribution zip file to the libraries
-/// sub-folder of your sketchbook. 
+/// sub-folder of your sketchbook.
 ///
 /// \par Theory
 ///
-/// This code uses speed calculations as described in 
-/// "Generate stepper-motor speed profiles in real time" by David Austin 
+/// This code uses speed calculations as described in
+/// "Generate stepper-motor speed profiles in real time" by David Austin
 /// http://fab.cba.mit.edu/classes/MIT/961.09/projects/i0/Stepper_Motor_Speed_Profile.pdf
 /// with the exception that AccelStepper uses steps per second rather than radians per second
 /// (because we dont know the step angle of the motor)
 /// An initial step interval is calculated for the first step, based on the desired acceleration
-/// On subsequent steps, shorter step intervals are calculated based 
+/// On subsequent steps, shorter step intervals are calculated based
 /// on the previous step until max speed is achieved.
-/// 
+///
 /// \par Donations
 ///
-/// This library is offered under a free GPL license for those who want to use it that way. 
+/// This library is offered under a free GPL license for those who want to use it that way.
 /// We try hard to keep it up to date, fix bugs
 /// and to provide free support. If this library has helped you save time or money, please consider donating at
 /// http://www.airspayce.com or here:
 ///
 /// \htmlonly <form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_donations" /> <input type="hidden" name="business" value="mikem@airspayce.com" /> <input type="hidden" name="lc" value="AU" /> <input type="hidden" name="item_name" value="Airspayce" /> <input type="hidden" name="item_number" value="AccelStepper" /> <input type="hidden" name="currency_code" value="USD" /> <input type="hidden" name="bn" value="PP-DonationsBF:btn_donateCC_LG.gif:NonHosted" /> <input type="image" alt="PayPal — The safer, easier way to pay online." name="submit" src="https://www.paypalobjects.com/en_AU/i/btn/btn_donateCC_LG.gif" /> <img alt="" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1" border="0" /></form> \endhtmlonly
-/// 
+///
 /// \par Trademarks
 ///
 /// AccelStepper is a trademark of AirSpayce Pty Ltd. The AccelStepper mark was first used on April 26 2010 for
@@ -83,7 +83,7 @@
 /// Source Licensing, you must contribute all your source code to the open source
 /// community in accordance with the GPL Version 2 when your application is
 /// distributed. See http://www.gnu.org/copyleft/gpl.html
-/// 
+///
 /// \par Commercial Licensing
 /// This is the appropriate option if you are creating proprietary applications
 /// and you are not prepared to distribute and share the source code of your
@@ -98,11 +98,11 @@
 /// \version 1.4 Added functional contructor to support AFMotor, contributed by Limor, with example sketches.
 /// \version 1.5 Improvements contributed by Peter Mousley: Use of microsecond steps and other speed improvements
 ///              to increase max stepping speed to about 4kHz. New option for user to set the min allowed pulse width.
-///              Added checks for already running at max speed and skip further calcs if so. 
-/// \version 1.6 Fixed a problem with wrapping of microsecond stepping that could cause stepping to hang. 
+///              Added checks for already running at max speed and skip further calcs if so.
+/// \version 1.6 Fixed a problem with wrapping of microsecond stepping that could cause stepping to hang.
 ///              Reported by Sandy Noble.
 ///              Removed redundant _lastRunTime member.
-/// \version 1.7 Fixed a bug where setCurrentPosition() did not always work as expected. 
+/// \version 1.7 Fixed a bug where setCurrentPosition() did not always work as expected.
 ///              Reported by Peter Linhart.
 /// \version 1.8 Added support for 4 pin half-steppers, requested by Harvey Moon
 /// \version 1.9 setCurrentPosition() now also sets motor speed to 0.
@@ -111,16 +111,16 @@
 ///   Added optional enable line support for stepper drivers
 ///   Added inversion for step/direction/enable lines for stepper drivers
 /// \version 1.12 Announce Google Group
-/// \version 1.13 Improvements to speed calculation. Cost of calculation is now less in the worst case, 
+/// \version 1.13 Improvements to speed calculation. Cost of calculation is now less in the worst case,
 ///    and more or less constant in all cases. This should result in slightly beter high speed performance, and
-///    reduce anomalous speed glitches when other steppers are accelerating. 
+///    reduce anomalous speed glitches when other steppers are accelerating.
 ///    However, its hard to see how to replace the sqrt() required at the very first step from 0 speed.
 /// \version 1.14 Fixed a problem with compiling under arduino 0021 reported by EmbeddedMan
 /// \version 1.15 Fixed a problem with runSpeedToPosition which did not correctly handle
 ///    running backwards to a smaller target position. Added examples
 /// \version 1.16 Fixed some cases in the code where abs() was used instead of fabs().
 /// \version 1.17 Added example ProportionalControl
-/// \version 1.18 Fixed a problem: If one calls the funcion runSpeed() when Speed is zero, it makes steps 
+/// \version 1.18 Fixed a problem: If one calls the funcion runSpeed() when Speed is zero, it makes steps
 ///    without counting. reported by  Friedrich, Klappenbach.
 /// \version 1.19 Added MotorInterfaceType and symbolic names for the number of pins to use
 ///               for the motor interface. Updated examples to suit.
@@ -136,11 +136,11 @@
 ///               when _speed was small but non-zero. Reported by Brian Schmalz.
 ///               Precompute sqrt_twoa to improve performance and max possible stepping speed
 /// \version 1.22 Added Bounce.pde example
-///               Fixed a problem where calling moveTo(), setMaxSpeed(), setAcceleration() more 
+///               Fixed a problem where calling moveTo(), setMaxSpeed(), setAcceleration() more
 ///               frequently than the step time, even
-///               with the same values, would interfere with speed calcs. Now a new speed is computed 
+///               with the same values, would interfere with speed calcs. Now a new speed is computed
 ///               only if there was a change in the set value. Reported by Brian Schmalz.
-/// \version 1.23 Rewrite of the speed algorithms in line with 
+/// \version 1.23 Rewrite of the speed algorithms in line with
 ///               http://fab.cba.mit.edu/classes/MIT/961.09/projects/i0/Stepper_Motor_Speed_Profile.pdf
 ///               Now expect smoother and more linear accelerations and decelerations. The desiredSpeed()
 ///               function was removed.
@@ -166,25 +166,25 @@
 ///                Unfortunately this meant changing the signature for all step*() functions.
 ///                Added example MotorShield, showing how to use AdaFruit Motor Shield to control
 ///                a 3 phase motor such as a HDD spindle motor (and without using the AFMotor library.
-/// \version 1.34  Added setPinsInverted(bool pin1Invert, bool pin2Invert, bool pin3Invert, bool pin4Invert, bool enableInvert) 
+/// \version 1.34  Added setPinsInverted(bool pin1Invert, bool pin2Invert, bool pin3Invert, bool pin4Invert, bool enableInvert)
 ///                to allow inversion of 2, 3 and 4 wire stepper pins. Requested by Oleg.
-/// \version 1.35  Removed default args from setPinsInverted(bool, bool, bool, bool, bool) to prevent ambiguity with 
+/// \version 1.35  Removed default args from setPinsInverted(bool, bool, bool, bool, bool) to prevent ambiguity with
 ///                setPinsInverted(bool, bool, bool). Reported by Mac Mac.
 /// \version 1.36  Changed enableOutputs() and disableOutputs() to be virtual so can be overridden.
-///                Added new optional argument 'enable' to constructor, which allows you toi disable the 
+///                Added new optional argument 'enable' to constructor, which allows you toi disable the
 ///                automatic enabling of outputs at construction time. Suggested by Guido.
-/// \version 1.37  Fixed a problem with step1 that could cause a rogue step in the 
+/// \version 1.37  Fixed a problem with step1 that could cause a rogue step in the
 ///                wrong direction (or not,
-///                depending on the setup-time requirements of the connected hardware). 
+///                depending on the setup-time requirements of the connected hardware).
 ///                Reported by Mark Tillotson.
-/// \version 1.38  run() function incorrectly always returned true. Updated function and doc so it returns true 
+/// \version 1.38  run() function incorrectly always returned true. Updated function and doc so it returns true
 ///                if the motor is still running to the target position.
 /// \version 1.39  Updated typos in keywords.txt, courtesey Jon Magill.
 /// \version 1.40  Updated documentation, including testing on Teensy 3.1
 /// \version 1.41  Fixed an error in the acceleration calculations, resulting in acceleration of haldf the intended value
 /// \version 1.42  Improved support for FULL3WIRE and HALF3WIRE output pins. These changes were in Yuri's original
 ///                contribution but did not make it into production.<br>
-/// \version 1.43  Added DualMotorShield example. Shows how to use AccelStepper to control 2 x 2 phase steppers using the 
+/// \version 1.43  Added DualMotorShield example. Shows how to use AccelStepper to control 2 x 2 phase steppers using the
 ///                Itead Studio Arduino Dual Stepper Motor Driver Shield model IM120417015.<br>
 /// \version 1.44  examples/DualMotorShield/DualMotorShield.ino examples/DualMotorShield/DualMotorShield.pde
 ///                was missing from the distribution.<br>
@@ -193,7 +193,7 @@
 /// \version 1.45  Fixed inaccuracy in acceleration rate by using Equation 15, suggested by Sebastian Gracki.<br>
 ///                Performance improvements in runSpeed suggested by Jaakko Fagerlund.<br>
 /// \version 1.46  Fixed error in documentation for runToPosition().
-///                Reinstated time calculations in runSpeed() since new version is reported 
+///                Reinstated time calculations in runSpeed() since new version is reported
 ///                not to work correctly under some circumstances. Reported by Oleg V Gavva.<br>
 
 ///
@@ -226,8 +226,8 @@
 ///
 /// This defines a single 2 or 4 pin stepper motor, or stepper moter with fdriver chip, with optional
 /// acceleration, deceleration, absolute positioning commands etc. Multiple
-/// simultaneous steppers are supported, all moving 
-/// at different speeds and accelerations. 
+/// simultaneous steppers are supported, all moving
+/// at different speeds and accelerations.
 ///
 /// \par Operation
 /// This module operates by computing a step time in microseconds. The step
@@ -246,15 +246,15 @@
 ///
 /// \par Caveats
 /// This is an open loop controller: If the motor stalls or is oversped,
-/// AccelStepper will not have a correct 
+/// AccelStepper will not have a correct
 /// idea of where the motor really is (since there is no feedback of the motor's
 /// real position. We only know where we _think_ it is, relative to the
 /// initial starting point).
 ///
 /// \par Performance
 /// The fastest motor speed that can be reliably supported is about 4000 steps per
-/// second at a clock frequency of 16 MHz on Arduino such as Uno etc. 
-/// Faster processors can support faster stepping speeds. 
+/// second at a clock frequency of 16 MHz on Arduino such as Uno etc.
+/// Faster processors can support faster stepping speeds.
 /// However, any speed less than that
 /// down to very slow speeds (much less than one per second) are also supported,
 /// provided the run() function is called frequently enough to step the motor
@@ -265,18 +265,17 @@
 {
 public:
     /// \brief Symbolic names for number of pins.
-    /// Use this in the pins argument the AccelStepper constructor to 
+    /// Use this in the pins argument the AccelStepper constructor to
     /// provide a symbolic name for the number of pins
     /// to use.
-    typedef enum
-    {
-	FUNCTION  = 0, ///< Use the functional interface, implementing your own driver functions (internal use only)
-	DRIVER    = 1, ///< Stepper Driver, 2 driver pins required
-	FULL2WIRE = 2, ///< 2 wire stepper, 2 motor pins required
-	FULL3WIRE = 3, ///< 3 wire stepper, such as HDD spindle, 3 motor pins required
+    typedef enum {
+        FUNCTION  = 0, ///< Use the functional interface, implementing your own driver functions (internal use only)
+        DRIVER    = 1, ///< Stepper Driver, 2 driver pins required
+        FULL2WIRE = 2, ///< 2 wire stepper, 2 motor pins required
+        FULL3WIRE = 3, ///< 3 wire stepper, such as HDD spindle, 3 motor pins required
         FULL4WIRE = 4, ///< 4 wire full stepper, 4 motor pins required
-	HALF3WIRE = 6, ///< 3 wire half stepper, such as HDD spindle, 3 motor pins required
-	HALF4WIRE = 8  ///< 4 wire half stepper, 4 motor pins required
+        HALF3WIRE = 6, ///< 3 wire half stepper, such as HDD spindle, 3 motor pins required
+        HALF4WIRE = 8  ///< 4 wire half stepper, 4 motor pins required
     } MotorInterfaceType;
 
     /// Constructor. You can have multiple simultaneous steppers, all moving
@@ -286,21 +285,21 @@
     /// The motor pins will be initialised to OUTPUT mode during the
     /// constructor by a call to enableOutputs().
     /// \param[in] interface Number of pins to interface to. 1, 2, 4 or 8 are
-    /// supported, but it is preferred to use the \ref MotorInterfaceType symbolic names. 
+    /// supported, but it is preferred to use the \ref MotorInterfaceType symbolic names.
     /// AccelStepper::DRIVER (1) means a stepper driver (with Step and Direction pins).
     /// If an enable line is also needed, call setEnablePin() after construction.
     /// You may also invert the pins using setPinsInverted().
-    /// AccelStepper::FULL2WIRE (2) means a 2 wire stepper (2 pins required). 
-    /// AccelStepper::FULL3WIRE (3) means a 3 wire stepper, such as HDD spindle (3 pins required). 
-    /// AccelStepper::FULL4WIRE (4) means a 4 wire stepper (4 pins required). 
+    /// AccelStepper::FULL2WIRE (2) means a 2 wire stepper (2 pins required).
+    /// AccelStepper::FULL3WIRE (3) means a 3 wire stepper, such as HDD spindle (3 pins required).
+    /// AccelStepper::FULL4WIRE (4) means a 4 wire stepper (4 pins required).
     /// AccelStepper::HALF3WIRE (6) means a 3 wire half stepper, such as HDD spindle (3 pins required)
     /// AccelStepper::HALF4WIRE (8) means a 4 wire half stepper (4 pins required)
     /// Defaults to AccelStepper::FULL4WIRE (4) pins.
     /// \param[in] pin1 Arduino digital pin number for motor pin 1. Defaults
-    /// to pin 2. For a AccelStepper::DRIVER (interface==1), 
+    /// to pin 2. For a AccelStepper::DRIVER (interface==1),
     /// this is the Step input to the driver. Low to high transition means to step)
     /// \param[in] pin2 Arduino digital pin number for motor pin 2. Defaults
-    /// to pin 3. For a AccelStepper::DRIVER (interface==1), 
+    /// to pin 3. For a AccelStepper::DRIVER (interface==1),
     /// this is the Direction input the driver. High means forward.
     /// \param[in] pin3 Arduino digital pin number for motor pin 3. Defaults
     /// to pin 4.
@@ -309,9 +308,9 @@
     /// \param[in] enable If this is true (the default), enableOutputs() will be called to enable
     /// the output pins at construction time.
     // AccelStepper(uint8_t interface = AccelStepper::FULL4WIRE, uint8_t pin1 = 2, uint8_t pin2 = 3, uint8_t pin3 = 4, uint8_t pin4 = 5, bool enable = true);
-	AccelStepper(uint8_t interface, PinName pin1 = LED1, PinName pin2 = LED2, PinName pin3 = LED3, PinName pin4 = LED4, bool enable = true);
+    AccelStepper(uint8_t interface, PinName pin1 = LED1, PinName pin2 = LED2, PinName pin3 = LED3, PinName pin4 = LED4, bool enable = true);
 
-    /// Alternate Constructor which will call your own functions for forward and backward steps. 
+    /// Alternate Constructor which will call your own functions for forward and backward steps.
     /// You can have multiple simultaneous steppers, all moving
     /// at different speeds and accelerations, provided you call their run()
     /// functions at frequent enough intervals. Current Position is set to 0, target
@@ -320,14 +319,16 @@
     /// \param[in] forward void-returning procedure that will make a forward step
     /// \param[in] backward void-returning procedure that will make a backward step
     AccelStepper(void (*forward)(), void (*backward)());
-    
+
     /// Set the target position. The run() function will try to move the motor (at most one step per call)
     /// from the current position to the target position set by the most
-    /// recent call to this function. Caution: moveTo() also recalculates the speed for the next step. 
+    /// recent call to this function. Caution: moveTo() also recalculates the speed for the next step.
     /// If you are trying to use constant speed movements, you should call setSpeed() after calling moveTo().
     /// \param[in] absolute The desired absolute position. Negative is
     /// anticlockwise from the 0 position.
-    void    moveTo(long absolute); 
+    void    moveTo(long absolute);
+
+    void newSpeed();
 
     /// Set the target position relative to the current position
     /// \param[in] relative The desired position relative to the current position. Negative is
@@ -358,7 +359,7 @@
 
     /// Sets the acceleration/deceleration rate.
     /// \param[in] acceleration The desired acceleration in steps per second
-    /// per second. Must be > 0.0. This is an expensive call since it requires a square 
+    /// per second. Must be > 0.0. This is an expensive call since it requires a square
     /// root to be calculated. Dont call more ofthen than needed
     void    setAcceleration(float acceleration);
 
@@ -387,7 +388,7 @@
     /// The currently motor position.
     /// \return the current motor position
     /// in steps. Positive is clockwise from the 0 position.
-    long    currentPosition();  
+    long    currentPosition();
 
     /// Resets the current position of the motor, so that wherever the motor
     /// happens to be right now is considered to be the new 0 position. Useful
@@ -396,9 +397,9 @@
     /// Has the side effect of setting the current motor speed to 0.
     /// \param[in] position The position in steps of wherever the motor
     /// happens to be right now.
-    void    setCurrentPosition(long position);  
-    
-    /// Moves the motor (with acceleration/deceleration) 
+    void    setCurrentPosition(long position);
+
+    /// Moves the motor (with acceleration/deceleration)
     /// to the target position and blocks until it is at
     /// position. Dont use this in event loops, since it blocks.
     void    runToPosition();
@@ -430,16 +431,16 @@
     /// mode. Called automatically by the constructor.
     virtual void    enableOutputs();
 
-    /// Sets the minimum pulse width allowed by the stepper driver. The minimum practical pulse width is 
+    /// Sets the minimum pulse width allowed by the stepper driver. The minimum practical pulse width is
     /// approximately 20 microseconds. Times less than 20 microseconds
     /// will usually result in 20 microseconds or so.
-    /// \param[in] minWidth The minimum pulse width in microseconds. 
+    /// \param[in] minWidth The minimum pulse width in microseconds.
     void    setMinPulseWidth(unsigned int minWidth);
 
     /// Sets the enable pin number for stepper drivers.
     /// 0xFF indicates unused (default).
-    /// Otherwise, if a pin is set, the pin will be turned on when 
-    /// enableOutputs() is called and switched off when disableOutputs() 
+    /// Otherwise, if a pin is set, the pin will be turned on when
+    /// enableOutputs() is called and switched off when disableOutputs()
     /// is called.
     /// \param[in] enablePin Arduino digital pin number for motor enable
     /// \sa setPinsInverted
@@ -460,16 +461,15 @@
     void    setPinsInverted(bool pin1Invert, bool pin2Invert, bool pin3Invert, bool pin4Invert, bool enableInvert);
 
 protected:
-	DigitalOut *_pin0;
-	DigitalOut *_pin1;
-	DigitalOut *_pin2;
-	DigitalOut *_pin3;
+    DigitalOut *_pin0;
+    DigitalOut *_pin1;
+    DigitalOut *_pin2;
+    DigitalOut *_pin3;
 
     /// \brief Direction indicator
     /// Symbolic names for the direction the motor is turning
-    typedef enum
-    {
-	DIRECTION_CCW = 0,  ///< Clockwise
+    typedef enum {
+        DIRECTION_CCW = 0,  ///< Clockwise
         DIRECTION_CW  = 1   ///< Counter-Clockwise
     } Direction;
 
@@ -504,7 +504,7 @@
 
     /// Called to execute a step on a stepper driver (ie where pins == 1). Only called when a new step is
     /// required. Subclasses may override to implement new stepping
-    /// interfaces. The default sets or clears the outputs of Step pin1 to step, 
+    /// interfaces. The default sets or clears the outputs of Step pin1 to step,
     /// and sets the output of _pin2 to the desired direction. The Step pin (_pin1) is pulsed for 1 microsecond
     /// which is the minimum STEP pulse width for the 3967 driver.
     /// \param[in] step The current step phase number (0 to 7)
@@ -597,7 +597,7 @@
 
     /// Enable pin for stepper driver, or 0xFF if unused.
     //uint8_t        _enablePin;
-	DigitalOut *_enablePin;
+    DigitalOut *_enablePin;
 
     /// The pointer to a forward-step procedure
     void (*_forward)();
@@ -627,7 +627,7 @@
 
 /// @example Overshoot.pde
 ///  Check overshoot handling
-/// which sets a new target position and then waits until the stepper has 
+/// which sets a new target position and then waits until the stepper has
 /// achieved it. This is used for testing the handling of overshoots
 
 /// @example MultiStepper.pde
@@ -639,14 +639,14 @@
 /// Shows how to run AccelStepper in the simplest,
 /// fixed speed mode with no accelerations
 
-/// @example Blocking.pde 
+/// @example Blocking.pde
 /// Shows how to use the blocking call runToNewPosition
-/// Which sets a new target position and then waits until the stepper has 
+/// Which sets a new target position and then waits until the stepper has
 /// achieved it.
 
 /// @example AFMotor_MultiStepper.pde
 /// Control both Stepper motors at the same time with different speeds
-/// and accelerations. 
+/// and accelerations.
 
 /// @example AFMotor_ConstantSpeed.pde
 /// Shows how to run AccelStepper in the simplest,
@@ -654,7 +654,7 @@
 
 /// @example ProportionalControl.pde
 /// Make a single stepper follow the analog value read from a pot or whatever
-/// The stepper will move at a constant speed to each newly set posiiton, 
+/// The stepper will move at a constant speed to each newly set posiiton,
 /// depending on the value of the pot.
 
 /// @example Bounce.pde
@@ -672,8 +672,8 @@
 /// using the Adafruit Motor Shield http://www.ladyada.net/make/mshield/index.html.
 
 /// @example DualMotorShield.pde
-/// Shows how to use AccelStepper to control 2 x 2 phase steppers using the 
+/// Shows how to use AccelStepper to control 2 x 2 phase steppers using the
 /// Itead Studio Arduino Dual Stepper Motor Driver Shield
 /// model IM120417015
 
-#endif 
\ No newline at end of file
+#endif
\ No newline at end of file