LightSensor.H
Go to the documentation of this file.
1 
7 //
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: Pat Welch (legOS@mousebrains.com)
21 
22 #ifndef _LightSensor_H_
23 #define _LightSensor_H_
24 
25 #include <config.h>
26 #include <c++/Sensor.H>
27 
28 #if defined(CONF_DSENSOR)
29 
46 class LightSensor : public Sensor {
47 public:
53  LightSensor(const Sensor::Port port) : Sensor(port, true) {}
61  unsigned int get() const {return LIGHT(sensor);}
69  unsigned int sample(unsigned int size = 10, int wait = 2) const {
70  if (size == 0) size = 1;
71  unsigned int sum(get());
72  for (unsigned int i = 1; i < size; ++i) {
73  sum += get();
74  delay(wait);
75  }
76  return sum / size;
77  }
78 };
79 
80 #else // CONF_DSENSOR
81 #warning Enable CONF_DSENSOR to use LightSensor.H
82 #endif // CONF_DSENSOR
83 #endif // _LightSensor_H_
kernel configuration file
LightSensor(const Sensor::Port port)
Instance an active light sensor at {port}.
Definition: LightSensor.H:53
C++ Sensor Class Interface.
Basic sensor interface.
Definition: Sensor.H:54
#define LIGHT(a)
map light sensor to 0..LIGHT_MAX
Definition: dsensor.h:77
void delay(unsigned ms)
uncalibrated delay loop
Definition: conio.c:204
unsigned int sample(unsigned int size=10, int wait=2) const
Get the average of {size} samples, waiting {wait} mSec between each sample.
Definition: LightSensor.H:69
Port
List of sensor identifiers (IDs).
Definition: Sensor.H:67
Light-sensor interface (active/passive mode).
Definition: LightSensor.H:46
volatile unsigned int & sensor
The address of our sensor value.
Definition: Sensor.H:181

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

Generated for brickOS Kernel Developer by doxygen 1.8.11