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

include/dsensor.h

Go to the documentation of this file.
00001 
00006 /*
00007  *  The contents of this file are subject to the Mozilla Public License
00008  *  Version 1.0 (the "License"); you may not use this file except in
00009  *  compliance with the License. You may obtain a copy of the License
00010  *  at http://www.mozilla.org/MPL/
00011  *
00012  *  Software distributed under the License is distributed on an "AS IS"
00013  *  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00014  *  the License for the specific language governing rights and
00015  *  limitations under the License.
00016  *
00017  *  The Original Code is legOS code, released October 17, 1999.
00018  *
00019  *  The Initial Developer of the Original Code is Markus L. Noga.
00020  *  Portions created by Markus L. Noga are Copyright (C) 1999
00021  *  Markus L. Noga. All Rights Reserved.
00022  *
00023  *  Contributor(s): Markus L. Noga <markus@noga.de>
00024  */
00025 
00026 /*
00027  *   2000.04.30 - Paolo Masetti <paolo.masetti@itlug.org>
00028  *
00029  *      - Some typecast & ()s in macros to avoid strange effects
00030  *        using them...
00031  *
00032  *  2000.09.06 - Jochen Hoenicke <jochen@gnu.org>
00033  *
00034  *      - Added velocity calculation for rotation sensor.
00035  */
00036 
00037 
00038 #ifndef __dsensor_h__
00039 #define __dsensor_h__
00040 
00041 #ifdef  __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 #include <config.h>
00046 
00047 #ifdef CONF_DSENSOR
00048 
00049 #include <sys/h8.h>
00050 #include <sys/bitops.h>
00051 
00053 //
00054 // Definitions
00055 //
00057 
00058 //
00060 //
00061 #define SENSOR_1        AD_C    
00062 #define SENSOR_2        AD_B    
00063 #define SENSOR_3        AD_A    
00064 #define BATTERY         AD_D    
00065 
00066 //
00068 //
00069 #define LIGHT_RAW_BLACK 0xffc0  
00070 #define LIGHT_RAW_WHITE 0x5080  
00071 
00072 
00073 //
00074 // convert raw values to 0 (dark) .. LIGHT_MAX (bright)
00075 // roughly 0-100.
00076 //
00077 #define LIGHT(a)    (147 - ds_scale(a)/7)       
00078 #define LIGHT_MAX   LIGHT(LIGHT_RAW_WHITE)      
00079 
00080 //
00081 // processed active light sensor
00082 //
00083 #define LIGHT_1     LIGHT(SENSOR_1)             
00084 #define LIGHT_2     LIGHT(SENSOR_2)             
00085 #define LIGHT_3     LIGHT(SENSOR_3)             
00086 
00087 #ifdef CONF_DSENSOR_ROTATION
00088 //
00089 // processed rotation sensor
00090 //
00091 #define ROTATION_1  (ds_rotations[2])   
00092 #define ROTATION_2  (ds_rotations[1])   
00093 #define ROTATION_3  (ds_rotations[0])   
00094 #endif
00095 
00096 #ifdef CONF_DSENSOR_VELOCITY
00097 //
00098 // processed velocity sensor
00099 //
00100 #define VELOCITY_1  (ds_velocities[2])
00101 #define VELOCITY_2  (ds_velocities[1])
00102 #define VELOCITY_3  (ds_velocities[0])
00103 #endif
00104 
00105 #ifdef CONF_DSENSOR_MUX
00106 #define SENSOR_1A (ds_muxs[2][0])
00107 #define SENSOR_1B (ds_muxs[2][1])
00108 #define SENSOR_1C (ds_muxs[2][2])
00109 #define SENSOR_2A (ds_muxs[1][0])
00110 #define SENSOR_2B (ds_muxs[1][1])
00111 #define SENSOR_2C (ds_muxs[1][2])
00112 #define SENSOR_3A (ds_muxs[0][0])
00113 #define SENSOR_3B (ds_muxs[0][1])
00114 #define SENSOR_3C (ds_muxs[0][2])
00115 #endif //CONF_DSENSOR_MUX
00116 
00118 #define TOUCH(a)    ((unsigned int)(a) < 0x8000)
00119 
00120 //  Processed touch sensors
00121 //
00122 #define TOUCH_1     TOUCH(SENSOR_1)             
00123 #define TOUCH_2     TOUCH(SENSOR_2)             
00124 #define TOUCH_3     TOUCH(SENSOR_3)             
00125 
00126 
00127 #define ds_scale(x)   ((unsigned int)(x)>>6)    
00128 #define ds_unscale(x) ((unsigned int)(x)<<6)    
00129 
00130 
00131 //
00132 // Variables
00133 //
00135 
00136 //
00137 // don't manipulate directly unless you know what you're doing!
00138 //
00139 
00140 extern unsigned char ds_activation;     
00141 
00142 #ifdef CONF_DSENSOR_ROTATION
00143 extern unsigned char ds_rotation;       
00144 
00145 extern volatile int ds_rotations[3];    
00146 
00147 #endif
00148 #ifdef CONF_DSENSOR_VELOCITY
00149 extern volatile int ds_velocities[3];   
00150 #endif
00151 
00152 #ifdef CONF_DSENSOR_MUX
00153 extern unsigned char ds_mux;    
00154 
00155 extern volatile int ds_muxs[3][3];      
00156 #endif //CONF_DSENSOR_MUX
00157 
00159 //
00160 // Functions
00161 //
00163 
00165 
00167 extern inline void ds_active(volatile unsigned *sensor)
00168 {
00169   if (sensor == &SENSOR_3)
00170     bit_set(&ds_activation, 0);
00171   else if (sensor == &SENSOR_2)
00172     bit_set(&ds_activation, 1);
00173   else if (sensor == &SENSOR_1)
00174     bit_set(&ds_activation, 2);
00175 }
00176 
00178 
00180 extern inline void ds_passive(volatile unsigned *sensor)
00181 {
00182   if (sensor == &SENSOR_3) {
00183     bit_clear(&ds_activation, 0);
00184     bit_clear(&PORT6, 0);
00185   } else if (sensor == &SENSOR_2) {
00186     bit_clear(&ds_activation, 1);
00187     bit_clear(&PORT6, 1);
00188   }  else if (sensor == &SENSOR_1) {
00189     bit_clear(&ds_activation, 2);
00190     bit_clear(&PORT6, 2);
00191   }
00192 }
00193 
00194 #ifdef CONF_DSENSOR_ROTATION
00195 
00196 
00202 extern void ds_rotation_set(volatile unsigned *sensor, int pos);
00203 
00205 
00207 extern inline void ds_rotation_on(volatile unsigned *sensor)
00208 {
00209   if (sensor == &SENSOR_3)
00210     bit_set(&ds_rotation, 0);
00211   else if (sensor == &SENSOR_2)
00212     bit_set(&ds_rotation, 1);
00213   else if (sensor == &SENSOR_1)
00214     bit_set(&ds_rotation, 2);
00215 }
00216 
00218 
00220 extern inline void ds_rotation_off(volatile unsigned *sensor)
00221 {
00222   if (sensor == &SENSOR_3)
00223     bit_clear(&ds_rotation, 0);
00224   else if (sensor == &SENSOR_2)
00225     bit_clear(&ds_rotation, 1);
00226   else if (sensor == &SENSOR_1)
00227     bit_clear(&ds_rotation, 2);
00228 }
00229 #endif // CONF_DSENSOR_ROTATION
00230 
00231 
00232 #ifdef CONF_DSENSOR_MUX
00233 
00234 #define DS_MUX_POST_SWITCH 150
00235 
00236 
00247 extern void ds_mux_on(volatile unsigned *sensor,
00248                       unsigned int ch1,
00249                       unsigned int ch2,
00250                       unsigned int ch3);
00251 
00252 
00254 
00256 extern inline void ds_mux_off(volatile unsigned *sensor)
00257 {
00258   if (sensor == &SENSOR_3)
00259     bit_clear(&ds_mux, 0);
00260   else if (sensor == &SENSOR_2)
00261     bit_clear(&ds_mux, 1);
00262   else if (sensor == &SENSOR_1)
00263     bit_clear(&ds_mux, 2);
00264 }//endof ds_mux_off
00265 #endif // CONF_DSENSOR_MUX
00266 
00267 
00268 
00269 
00270 
00271 #endif // CONF_DSENSOR
00272 
00273 #ifdef  __cplusplus
00274 }
00275 #endif
00276 
00277 #endif // __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:52 2004 for brickOS C by doxygen 1.3.5