/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is legOS code, released October 17, 1999.
*
* The Initial Developer of the Original Code is Markus L. Noga.
* Portions created by Markus L. Noga are Copyright (C) 1999
* Markus L. Noga. All Rights Reserved.
*
* Contributor(s): Markus L. Noga <markus@noga.de>
*/
#ifndef __cxx_sensor__
#define __cxx_sensor__
extern "C" {
#include <dsensor.h>
}
class Sensor {
public:
Sensor(unsigned *addr = s1, int active = 0) {
ptr = addr;
if (active)
ds_active(ptr);
else
ds_passive(ptr);
}
~Sensor() {
ds_passive(ptr);
}
unsigned value() {
return *ptr;
} public:
static unsigned *const Sensor::s1;
static unsigned *const Sensor::s2;
static unsigned *const Sensor::s3;
static unsigned *const Sensor::battery;
protected:
unsigned *ptr;
};
class LightSensor:public Sensor {
public:
LightSensor(unsigned *addr = s1, int active = 1):Sensor(addr, active) {
}
unsigned value() {
return LIGHT(Sensor::value());
}
};
class RotationSensor:public Sensor {
public:
RotationSensor(unsigned *addr = s1, int initial = 0);
~RotationSensor() {
ds_rotation_off(ptr);
}
inline int position() {
return *posPtr;
} protected:
int *volatile posPtr;
};
#endif // __cxx_sensor__
legOS-0.2.4 is released under the