Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

include/dsensor.h File Reference

Interface: direct reading of sensors. More...

#include <config.h>
#include <sys/h8.h>
#include <sys/bitops.h>

Include dependency graph for dsensor.h:

Include dependency graph

Go to the source code of this file.

Defines

#define SENSOR_1   AD_C
 Sensor on input pad 1.

#define SENSOR_2   AD_B
 Sensor on input pad 2.

#define SENSOR_3   AD_A
 Sensor on input pad 3.

#define BATTERY   AD_D
 Battery sensor.

#define LIGHT_RAW_BLACK   0xffc0
 active light sensor raw black value

#define LIGHT_RAW_WHITE   0x5080
 active light sensor raw white value

#define LIGHT(a)   (147 - ds_scale(a)/7)
 map light sensor to 0..LIGHT_MAX

#define LIGHT_MAX   LIGHT(LIGHT_RAW_WHITE)
 maximum decoded value

#define LIGHT_1   LIGHT(SENSOR_1)
 light sensor on input 1

#define LIGHT_2   LIGHT(SENSOR_2)
 light sensor on input 2

#define LIGHT_3   LIGHT(SENSOR_3)
 light sensor on input 3

#define ROTATION_1   (ds_rotations[2])
 rotation sensor on input 1

#define ROTATION_2   (ds_rotations[1])
 rotation sensor on input 2

#define ROTATION_3   (ds_rotations[0])
 rotation sensor on input 3

#define TOUCH(a)   ((unsigned int)(a) < 0x8000)
 Convert raw data to touch sensor (0: off, else pressed).

#define TOUCH_1   TOUCH(SENSOR_1)
 touch sensor on input 1

#define TOUCH_2   TOUCH(SENSOR_2)
 touch sensor on input 2

#define TOUCH_3   TOUCH(SENSOR_3)
 touch sensor on input 3

#define ds_scale(x)   ((unsigned int)(x)>>6)
 mask off bottom 6 bits

#define ds_unscale(x)   ((unsigned int)(x)<<6)
 leave room for bottom 6 bits


Functions

void ds_active (volatile unsigned *sensor)
 set sensor mode to active (light sensor emits light, rotation works)

void ds_passive (volatile unsigned *sensor)
 set sensor mode to passive (light sensor detects ambient light)

void ds_rotation_set (volatile unsigned *sensor, int pos)
 set rotation to an absolute value

void ds_rotation_on (volatile unsigned *sensor)
 start tracking rotation sensor

void ds_rotation_off (volatile unsigned *sensor)
 stop tracking rotation sensor


Variables

unsigned char ds_activation
 activation bitmask

unsigned char ds_rotation
 rotation bitmask

volatile int ds_rotations [3]
 rotational position


Detailed Description

Interface: direct reading of sensors.

Author:
Markus L. Noga <markus@noga.de>

Definition in file dsensor.h.


Define Documentation

#define BATTERY   AD_D
 

Battery sensor.

Definition at line 64 of file dsensor.h.

#define ds_scale  )     ((unsigned int)(x)>>6)
 

mask off bottom 6 bits

Definition at line 127 of file dsensor.h.

#define ds_unscale  )     ((unsigned int)(x)<<6)
 

leave room for bottom 6 bits

Definition at line 128 of file dsensor.h.

#define LIGHT  )     (147 - ds_scale(a)/7)
 

map light sensor to 0..LIGHT_MAX

Definition at line 77 of file dsensor.h.

#define LIGHT_1   LIGHT(SENSOR_1)
 

light sensor on input 1

Definition at line 83 of file dsensor.h.

#define LIGHT_2   LIGHT(SENSOR_2)
 

light sensor on input 2

Definition at line 84 of file dsensor.h.

#define LIGHT_3   LIGHT(SENSOR_3)
 

light sensor on input 3

Definition at line 85 of file dsensor.h.

#define LIGHT_MAX   LIGHT(LIGHT_RAW_WHITE)
 

maximum decoded value

Definition at line 78 of file dsensor.h.

#define LIGHT_RAW_BLACK   0xffc0
 

active light sensor raw black value

Definition at line 69 of file dsensor.h.

#define LIGHT_RAW_WHITE   0x5080
 

active light sensor raw white value

Definition at line 70 of file dsensor.h.

#define ROTATION_1   (ds_rotations[2])
 

rotation sensor on input 1

Definition at line 91 of file dsensor.h.

#define ROTATION_2   (ds_rotations[1])
 

rotation sensor on input 2

Definition at line 92 of file dsensor.h.

#define ROTATION_3   (ds_rotations[0])
 

rotation sensor on input 3

Definition at line 93 of file dsensor.h.

#define SENSOR_1   AD_C
 

Sensor on input pad 1.

Definition at line 61 of file dsensor.h.

Referenced by ds_active(), ds_passive(), ds_rotation_off(), and ds_rotation_on().

#define SENSOR_2   AD_B
 

Sensor on input pad 2.

Definition at line 62 of file dsensor.h.

Referenced by ds_active(), ds_passive(), ds_rotation_off(), and ds_rotation_on().

#define SENSOR_3   AD_A
 

Sensor on input pad 3.

Definition at line 63 of file dsensor.h.

Referenced by ds_active(), ds_passive(), ds_rotation_off(), and ds_rotation_on().

#define TOUCH  )     ((unsigned int)(a) < 0x8000)
 

Convert raw data to touch sensor (0: off, else pressed).

Definition at line 118 of file dsensor.h.

#define TOUCH_1   TOUCH(SENSOR_1)
 

touch sensor on input 1

Definition at line 122 of file dsensor.h.

#define TOUCH_2   TOUCH(SENSOR_2)
 

touch sensor on input 2

Definition at line 123 of file dsensor.h.

#define TOUCH_3   TOUCH(SENSOR_3)
 

touch sensor on input 3

Definition at line 124 of file dsensor.h.


Function Documentation

void ds_active volatile unsigned *  sensor  )  [inline]
 

set sensor mode to active (light sensor emits light, rotation works)

Parameters:
sensor: &SENSOR_1,&SENSOR_2,&SENSOR_3

Definition at line 167 of file dsensor.h.

References ds_activation, SENSOR_1, SENSOR_2, and SENSOR_3.

void ds_passive volatile unsigned *  sensor  )  [inline]
 

set sensor mode to passive (light sensor detects ambient light)

Parameters:
sensor: &SENSOR_1,&SENSOR_2,&SENSOR_3

Definition at line 180 of file dsensor.h.

References ds_activation, SENSOR_1, SENSOR_2, and SENSOR_3.

void ds_rotation_off volatile unsigned *  sensor  )  [inline]
 

stop tracking rotation sensor

Parameters:
sensor: &SENSOR_1,&SENSOR_2,&SENSOR_3

Definition at line 220 of file dsensor.h.

References ds_rotation, SENSOR_1, SENSOR_2, and SENSOR_3.

void ds_rotation_on volatile unsigned *  sensor  )  [inline]
 

start tracking rotation sensor

Parameters:
sensor: &SENSOR_1,&SENSOR_2,&SENSOR_3

Definition at line 207 of file dsensor.h.

References ds_rotation, SENSOR_1, SENSOR_2, and SENSOR_3.

void ds_rotation_set volatile unsigned *  sensor,
int  pos
 

set rotation to an absolute value

Parameters:
sensor one of &SENSOR_1, &SENSOR_2, or &SENSOR_3
pos the current rotational postion (typically use 0 here)
Returns:
Nothing
The axis should be inert during the function call.


Variable Documentation

unsigned char ds_activation
 

activation bitmask

Definition at line 140 of file dsensor.h.

Referenced by ds_active(), and ds_passive().

unsigned char ds_rotation
 

rotation bitmask

Definition at line 143 of file dsensor.h.

Referenced by ds_rotation_off(), and ds_rotation_on().

volatile int ds_rotations[3]
 

rotational position

Definition at line 145 of file dsensor.h.


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

Generated on Mon Feb 16 21:01:54 2004 for brickOS C by doxygen 1.3.5