Motor.H
Go to the documentation of this file.
1 
7 // The contents of this file are subject to the Mozilla Public License
8 // Version 1.0 (the "License"); you may not use this file except in
9 // compliance with the License. You may obtain a copy of the License
10 // at http://www.mozilla.org/MPL/
11 //
12 // Software distributed under the License is distributed on an "AS IS"
13 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14 // the License for the specific language governing rights and
15 // limitations under the License.
16 
17 #ifndef _Motor_H_
18 #define _Motor_H_
19 
20 #include <config.h>
21 
22 #if defined(CONF_DMOTOR)
23 
24 #include <conio.h> // for the delay() function
25 #include <dmotor.h>
26 
38 class Motor {
39 public:
43  enum Port {
44  A,
45  B,
46  C
47  };
48 
52  enum Limits {
53  min = 0,
54  max = 255
55  };
56 
61  Motor(const Port port)
62  : ms(port == A ? motor_a_speed :
63  (port == B) ? motor_b_speed :
64  motor_c_speed),
65  md(port == A ? motor_a_dir :
66  (port == B) ? motor_b_dir :
68  { }
73  ~Motor() {off();}
80  const void speed(const unsigned char speed) const { (*ms)(speed); }
86  const void direction(const MotorDirection dir) const { (*md)(dir); }
91  const void forward() const { direction(fwd); }
98  const void forward(const unsigned char s) const { forward(); speed(s); }
103  const void reverse() const { direction(rev); }
110  const void reverse(const unsigned char s) const { reverse(); speed(s); }
116  const void brake() const { direction(::brake); }
123  const void brake(int duration) const { brake(); delay(duration); }
129  const void off() const { direction(::off); }
130 
131 private:
132  void (*ms)(unsigned char speed);
133  void (*md)(const MotorDirection dir);
134 };
135 
136 #else // CONF_DMOTOR
137 #warning Enable CONF_DMOTOR to use Motor.H
138 #endif // CONF_DMOTOR
139 #endif // _Motor_H_

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated on Sat Mar 15 2014 11:28:21 for brickOS Kernel Developer by doxygen 1.8.1.2