Lamp.H
Go to the documentation of this file.
1 
8 // The contents of this file are subject to the Mozilla Public License
9 // Version 1.0 (the "License"); you may not use this file except in
10 // compliance with the License. You may obtain a copy of the License
11 // at http://www.mozilla.org/MPL/
12 //
13 // Software distributed under the License is distributed on an "AS IS"
14 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15 // the License for the specific language governing rights and
16 // limitations under the License.
17 //
18 // This software was developed as part of the legOS project.
19 //
20 // Contributor: Stephen M Moraco (stephmo@users.sourceforge.net)
21 
22 #ifndef _Lamp_H_
23 #define _Lamp_H_
24 
25 #include <config.h>
26 
27 #if defined(CONF_DMOTOR)
28 
29 #include <dmotor.h>
30 
39 class Lamp {
40 public:
44  enum Port {
45  A,
46  B,
47  C
48  };
49 
54  Lamp(enum Port port)
55  : ms(port == A ? motor_a_speed :
56  (port == B) ? motor_b_speed :
57  motor_c_speed),
58  md(port == A ? motor_a_dir :
59  (port == B) ? motor_b_dir :
61  { }
66  ~Lamp() { off(); }
71  const void on() const { direction(::fwd); }
76  const void off() const { direction(::off); }
83  const void brightness(const unsigned char level) const { speed(level); }
84 private:
85  const void speed(const unsigned char speed) const { (*ms)(speed); }
86  const void direction(const MotorDirection dir) const { (*md)(dir); }
87 
88  void (*ms)(unsigned char speed);
89  void (*md)(const MotorDirection dir);
90 };
91 
92 #else // CONF_DMOTOR
93 #warning Enable CONF_DMOTOR to use Lamp.H
94 #endif // CONF_DMOTOR
95 
96 #endif // _Lamp_H_
Lamp(enum Port port)
construct a lamp connected to {port}
Definition: Lamp.H:54
Port
The RCX output pad to which the Lamp is connected.
Definition: Lamp.H:44
void motor_a_speed(unsigned char speed)
set motor A speed
Definition: dmotor.h:143
void motor_b_dir(MotorDirection dir)
set motor B direction to dir
RCX output pad A.
Definition: Lamp.H:45
const void on() const
Turn the Lamp on.
Definition: Lamp.H:71
void motor_c_dir(MotorDirection dir)
set motor C direction to dir
~Lamp()
destroy our lamp instance
Definition: Lamp.H:66
RCX output pad C.
Definition: Lamp.H:47
Interface: direct motor control.
RCX output pad B.
Definition: Lamp.H:46
void motor_a_dir(MotorDirection dir)
set motor A direction to dir
const void brightness(const unsigned char level) const
Set the power to the lamp.
Definition: Lamp.H:83
const void off() const
Turn the Lamp off.
Definition: Lamp.H:76
Lamp control interface.
Definition: Lamp.H:39
MotorDirection
the motor directions
Definition: dmotor.h:44
void motor_b_speed(unsigned char speed)
set motor B speed
Definition: dmotor.h:151
forward
Definition: dmotor.h:46
void motor_c_speed(unsigned char speed)
set motor C speed
Definition: dmotor.h:159

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

Generated for brickOS C++ by doxygen 1.8.11