upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
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 
61  class ULN200XA {
62  public:
63 
67  typedef enum {
68  DIR_CW = 0x01,
69  DIR_CCW = 0x02
71 
81  ULN200XA(int stepsPerRev, int i1, int i2, int i3, int i4);
82 
86  ~ULN200XA();
87 
94  uint32_t getMillis();
95 
100  void initClock();
101 
107  void setSpeed(int speed);
108 
115 
121  void stepperSteps(unsigned int steps);
122 
127  void release();
128 
129  private:
130  struct timeval m_startTime;
131 
132  // stepper (4-wire)
133  mraa_gpio_context m_stepI1;
134  mraa_gpio_context m_stepI2;
135  mraa_gpio_context m_stepI3;
136  mraa_gpio_context m_stepI4;
137 
138  // steps per revolution
139  int m_stepsPerRev;
140  int m_currentStep;
141  uint32_t m_stepDelay;
142 
147  void stepperStep();
148 
153  int m_stepDirection;
154  };
155 }
156 
157 
void setDirection(ULN200XA_DIRECTION_T dir)
Definition: uln200xa.cxx:125
void initClock()
Definition: uln200xa.cxx:78
Definition: a110x.h:29
uint32_t getMillis()
Definition: uln200xa.cxx:83
void release()
Definition: uln200xa.cxx:236
void stepperSteps(unsigned int steps)
Definition: uln200xa.cxx:208
~ULN200XA()
Definition: uln200xa.cxx:112
UPM module for the ULN200XA Darlington Stepper driver.
Definition: uln200xa.h:61
ULN200XA(int stepsPerRev, int i1, int i2, int i3, int i4)
Definition: uln200xa.cxx:32
ULN200XA_DIRECTION_T
Definition: uln200xa.h:67
void setSpeed(int speed)
Definition: uln200xa.cxx:120