00001 00007 // The contents of this file are subject to the Mozilla Public License 00008 // Version 1.0 (the "License"); you may not use this file except in 00009 // compliance with the License. You may obtain a copy of the License 00010 // at http://www.mozilla.org/MPL/ 00011 // 00012 // Software distributed under the License is distributed on an "AS IS" 00013 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00014 // the License for the specific language governing rights and 00015 // limitations under the License. 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> // for the delay() function 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_
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2002 by the authors. |