Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]

LEGOSND-driver.h

Go to the documentation of this file.
00001 /*!@addtogroup Lego
00002  * @{
00003  * @defgroup legosnd Sound Sensor
00004  * Sound Sensor
00005  * @{
00006  */
00007 
00008 /*
00009  * $Id: LEGOSND-driver.h 47 2011-01-17 19:47:22Z xander $
00010  */
00011 
00012 /** \file LEGOSND-driver.h
00013  * \brief SMUX driver for the Lego Sound sensor.
00014  *
00015  * LEGOSND-driver.h provides an API for the Lego Sound driver.
00016  *
00017  * Changelog:
00018  * - 0.1: Initial release
00019  * - 0.2: Make use of new calls for analogue SMUX sensors in common.h
00020  *
00021  * License: You may use this code as you wish, provided you give credit where its due.
00022  *
00023  * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 2.00 AND HIGHER.
00024  * \author Xander Soldaat (mightor_at_gmail.com)
00025  * \date 25 November 2009
00026  * \version 0.2
00027  * \example LEGOSND-SMUX-test1.c
00028  */
00029 
00030 #pragma systemFile
00031 
00032 #ifndef __COMMON_H__
00033 #include "common.h"
00034 #endif
00035 
00036 #ifdef __HTSMUX_SUPPORT__
00037 int SNDreadRaw(tMUXSensor muxsensor);
00038 int SNDreadNorm(tMUXSensor muxsensor);
00039 void SNDsetDBA(tMUXSensor muxsensor);
00040 void SNDsetDB(tMUXSensor muxsensor);
00041 
00042 /**
00043  * Get the raw value from the sensor
00044  * @param muxsensor the SMUX sensor port number
00045  * @return the raw value of the Sound Sensor
00046  */
00047 int SNDreadRaw(tMUXSensor muxsensor) {
00048   return 1023 - HTSMUXreadAnalogue(muxsensor);
00049 }
00050 
00051 
00052 /**
00053  * Get the processed value from the sensor.
00054  * @param muxsensor the SMUX sensor port number
00055  * @return processed value of the sensor or -1 if no valid range has been specified.
00056  */
00057 int SNDreadNorm(tMUXSensor muxsensor) {
00058   int _val = ((long)SNDreadRaw(muxsensor) * (long)100) / (long)1024;
00059   return _val;
00060 }
00061 
00062 
00063 /**
00064  * Set the mode of the sensor to DBA, this is done
00065  * by switching off DIG0.
00066  * @param muxsensor the SMUX sensor port number
00067  */
00068 void SNDsetDBA(tMUXSensor muxsensor) {
00069   HTSMUXsetAnalogueInactive(muxsensor);
00070 }
00071 
00072 
00073 /**
00074  * Set the mode of the sensor to DB, this is done
00075  * by switching on DIG0.
00076  * @param muxsensor the SMUX sensor port number
00077  */
00078 void SNDsetDB(tMUXSensor muxsensor) {
00079   HTSMUXsetAnalogueActive(muxsensor);
00080 }
00081 #endif // __HTSMUX_SUPPORT__
00082 
00083 /*
00084  * $Id: LEGOSND-driver.h 47 2011-01-17 19:47:22Z xander $
00085  */
00086 /* @} */
00087 /* @} */