Project

General

Profile

Revision 1496

Reverted "libdragonfly" folder back to version before Init Checking was implemented and did "make dist" to recompile the library. BOM LEDs now shine
correctly.

View differences:

motor.c
34 34
 * Much of this is taken from FWR's library, author: Tom Lauwers
35 35
 **/
36 36

  
37
#include "dragonfly_defs.h"
38 37
#include "motor.h"
39 38

  
40 39
/**
......
44 43
 * @{
45 44
 **/
46 45

  
47
unsigned char motors_initd=0;
48

  
49 46
/**
50 47
 * Initializes both motors so that they can be used with future
51 48
 * calls to motor1_set and motor2_set.
52 49
 *
53
 * @return 0 if init succesfull, an error code otherwise
54
 *
55 50
 * @see motors_off, motor1_set, motor2_set
56 51
 **/
57
int motors_init( void ) {
58

  
59
  if(motors_initd)
60
    return ERROR_INIT_ALREADY_INITD;
61

  
62

  
52
void motors_init( void ) {
63 53
  // Configure counter such that we use phase correct
64 54
  // PWM with 8-bit resolution
65 55
  PORTA &= 0x0F;
......
75 65
  OCR1AL=0;
76 66
  OCR1BH=0;
77 67
  OCR1BL=0;
78

  
79
  motors_initd=1;
80
  return 0;
81 68
}
82 69

  
83 70
/**
......
87 74
 * @param direction Either FORWARD or BACKWARD to set the direction of rotation.
88 75
 * @param speed The speed the motor will run at, in the range 0-255.
89 76
 * 
90
 * @return 0 if init succesfull, an error code otherwise
91
 *
92 77
 * @see motor_r_set, motors_init
93 78
 **/
94
int motor_l_set(int direction, int speed) {
95
  if(!motors_initd)
96
    return ERROR_LIBRARY_NOT_INITD;
79
void motor_l_set(int direction, int speed) {
97 80

  
98 81
  if(direction == 0) {
99 82
    // turn off PWM first if switching directions
......
115 98
	
116 99
  // Set the timer to count up to speed, an 8-bit value
117 100
  OCR1AL = speed;
118

  
119
  return 0;
120 101
}
121 102

  
122 103
/**
......
126 107
 * @param direction Either FORWARD or BACKWARD to set the direction of rotation.
127 108
 * @param speed The speed the motor will run at, in the range 0-255.
128 109
 *
129
 * @return 0 if init succesfull, an error code otherwise
130
 *
131 110
 * @see motor_l_set, motors_init
132 111
 **/
133
int motor_r_set(int direction, int speed) {
134
  if(!motors_initd)
135
    return ERROR_LIBRARY_NOT_INITD;
136

  
112
void motor_r_set(int direction, int speed) {
137 113
  if(direction == 0) {
138 114
    //		PORTD |= 0x20;
139 115
    //		PORTD &= 0x7F;
......
155 131
    PORTA = (PORTA & 0x3F) | 0x40;
156 132
  }
157 133
  OCR1BL = speed;
158

  
159
  return 0;
160 134
}
161 135

  
162 136
/**
......
166 140
 * @param direction Either FORWARD or BACKWARD to set the direction of rotation.
167 141
 * @param speed The speed the motor will run at, in the range 0-255.
168 142
 *
169
 * @return 0 if init succesfull, an error code otherwise
170
 *
171 143
 * @see motor2_set, motors_init
172 144
 **/
173
int motor1_set(int direction, int speed) {
174
  return motor_l_set(direction, speed);
145
void motor1_set(int direction, int speed) {
146
	motor_l_set(direction, speed);
175 147
}
176 148

  
177 149
/**
......
181 153
 * @param direction Either FORWARD or BACKWARD to set the direction of rotation.
182 154
 * @param speed The speed the motor will run at, in the range 0-255.
183 155
 *
184
 * @return 0 if init succesfull, an error code otherwise
185
 *
186 156
 * @see motor2_set, motors_init
187 157
 **/
188
int motor2_set(int direction, int speed) {
189
  return motor_r_set(direction, speed);
158
void motor2_set(int direction, int speed) {
159
	motor_r_set(direction, speed);
190 160
}
191 161

  
192 162

  
193 163
/**
194 164
 * Turns off both motors.
195 165
 *
196
 * @return 0 if init succesfull, an error code otherwise
197
 *
198 166
 * @see motors_init
199 167
 **/
200
int motors_off( void ) {
201
  if(!motors_initd)
202
    return ERROR_LIBRARY_NOT_INITD;
203

  
168
void motors_off( void ) {
204 169
  OCR1AL = 0x0;
205 170
  OCR1BL = 0x0;
206

  
207
  return 0;
208 171
}
209 172

  
210 173
/**@}**///end defgroup

Also available in: Unified diff