00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _Motor_H_
00018 #define _Motor_H_
00019
00020 #include <config.h>
00021
00022 #if defined(CONF_DMOTOR)
00023
00024 #include <conio.h>
00025 #include <dmotor.h>
00026
00038 class Motor {
00039 public:
00043 enum Port {
00044 A,
00045 B,
00046 C
00047 };
00048
00052 enum Limits {
00053 min = 0,
00054 max = 255
00055 };
00056
00061 Motor(const Port port)
00062 : ms(port == A ? motor_a_speed :
00063 (port == B) ? motor_b_speed :
00064 motor_c_speed),
00065 md(port == A ? motor_a_dir :
00066 (port == B) ? motor_b_dir :
00067 motor_c_dir)
00068 { }
00073 ~Motor() {off();}
00080 const void speed(const unsigned char speed) const { (*ms)(speed); }
00086 const void direction(const MotorDirection dir) const { (*md)(dir); }
00091 const void forward() const { direction(fwd); }
00098 const void forward(const unsigned char s) const { forward(); speed(s); }
00103 const void reverse() const { direction(rev); }
00110 const void reverse(const unsigned char s) const { reverse(); speed(s); }
00116 const void brake() const { direction(::brake); }
00123 const void brake(int duration) const { brake(); delay(duration); }
00129 const void off() const { direction(::off); }
00130
00131 private:
00132 void (*ms)(unsigned char speed);
00133 void (*md)(const MotorDirection dir);
00134 };
00135
00136 #else // CONF_DMOTOR
00137 #warning Enable CONF_DMOTOR to use Motor.H
00138 #endif // CONF_DMOTOR
00139 #endif // _Motor_H_