00001 00008 // The contents of this file are subject to the Mozilla Public License 00009 // Version 1.0 (the "License"); you may not use this file except in 00010 // compliance with the License. You may obtain a copy of the License 00011 // at http://www.mozilla.org/MPL/ 00012 // 00013 // Software distributed under the License is distributed on an "AS IS" 00014 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00015 // the License for the specific language governing rights and 00016 // limitations under the License. 00017 // 00018 // This software was developed as part of the legOS project. 00019 // 00020 // Contributor: Stephen M Moraco (stephmo@users.sourceforge.net) 00021 00022 #ifndef _Lamp_H_ 00023 #define _Lamp_H_ 00024 00025 #include <config.h> 00026 00027 #if defined(CONF_DMOTOR) 00028 00029 #include <dmotor.h> 00030 00039 class Lamp { 00040 public: 00044 enum Port { 00045 A, 00046 B, 00047 C 00048 }; 00049 00054 Lamp(enum Port port) 00055 : ms(port == A ? motor_a_speed : 00056 (port == B) ? motor_b_speed : 00057 motor_c_speed), 00058 md(port == A ? motor_a_dir : 00059 (port == B) ? motor_b_dir : 00060 motor_c_dir) 00061 { } 00066 ~Lamp() { off(); } 00071 const void on() const { direction(::fwd); } 00076 const void off() const { direction(::off); } 00083 const void brightness(const unsigned char level) const { speed(level); } 00084 private: 00085 const void speed(const unsigned char speed) const { (*ms)(speed); } 00086 const void direction(const MotorDirection dir) const { (*md)(dir); } 00087 00088 void (*ms)(unsigned char speed); 00089 void (*md)(const MotorDirection dir); 00090 }; 00091 00092 #else // CONF_DMOTOR 00093 #warning Enable CONF_DMOTOR to use Lamp.H 00094 #endif // CONF_DMOTOR 00095 00096 #endif // _Lamp_H_
brickOS is released under the
Mozilla Public License.
Original code copyright 1998-2002 by the authors. |