upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
uln200xa.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <stdint.h>
27 #include <sys/time.h>
28 
29 #include <mraa/gpio.h>
30 #include <mraa/pwm.h>
31 
32 namespace upm {
33 
62  class ULN200XA {
63  public:
64 
68  typedef enum {
69  DIR_CW = 0x01,
70  DIR_CCW = 0x02
72 
82  ULN200XA(int stepsPerRev, int i1, int i2, int i3, int i4);
83 
87  ~ULN200XA();
88 
95  uint32_t getMillis();
96 
101  void initClock();
102 
108  void setSpeed(int speed);
109 
116 
122  void stepperSteps(unsigned int steps);
123 
128  void release();
129 
130  private:
131  struct timeval m_startTime;
132 
133  // stepper (4-wire)
134  mraa_gpio_context m_stepI1;
135  mraa_gpio_context m_stepI2;
136  mraa_gpio_context m_stepI3;
137  mraa_gpio_context m_stepI4;
138 
139  // steps per revolution
140  int m_stepsPerRev;
141  int m_currentStep;
142  uint32_t m_stepDelay;
143 
148  void stepperStep();
149 
154  int m_stepDirection;
155  };
156 }
157 
158 
void setDirection(ULN200XA_DIRECTION_T dir)
Definition: uln200xa.cxx:131
void initClock()
Definition: uln200xa.cxx:84
uint32_t getMillis()
Definition: uln200xa.cxx:89
void release()
Definition: uln200xa.cxx:242
void stepperSteps(unsigned int steps)
Definition: uln200xa.cxx:214
~ULN200XA()
Definition: uln200xa.cxx:118
UPM module for the ULN200XA Darlington Stepper Driver.
Definition: uln200xa.h:62
ULN200XA_DIRECTION_T
Definition: uln200xa.h:68
ULN200XA(int stepsPerRev, int i1, int i2, int i3, int i4)
Definition: uln200xa.cxx:34
void setSpeed(int speed)
Definition: uln200xa.cxx:126