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

lego-sound.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: lego-sound.h 133 2013-03-10 15:15:38Z xander $
00010  */
00011 
00012 /** \file lego-sound.h
00013  * \brief SMUX driver for the Lego Sound sensor.
00014  *
00015  * lego-sound.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 3.59 AND HIGHER. 
00024 
00025  * \author Xander Soldaat (xander_at_botbench.com)
00026  * \date 25 November 2009
00027  * \version 0.2
00028  * \example lego-sound-SMUX-test1.c
00029  */
00030 
00031 #pragma systemFile
00032 
00033 #ifndef __COMMON_H__
00034 #include "common.h"
00035 #endif
00036 
00037 #ifdef __HTSMUX_SUPPORT__
00038 int SNDreadRaw(tMUXSensor muxsensor);
00039 int SNDreadNorm(tMUXSensor muxsensor);
00040 void SNDsetDBA(tMUXSensor muxsensor);
00041 void SNDsetDB(tMUXSensor muxsensor);
00042 
00043 /**
00044  * Get the raw value from the sensor
00045  * @param muxsensor the SMUX sensor port number
00046  * @return the raw value of the Sound Sensor
00047  */
00048 int SNDreadRaw(tMUXSensor muxsensor) {
00049   return 1023 - HTSMUXreadAnalogue(muxsensor);
00050 }
00051 
00052 
00053 /**
00054  * Get the processed value from the sensor.
00055  * @param muxsensor the SMUX sensor port number
00056  * @return processed value of the sensor or -1 if no valid range has been specified.
00057  */
00058 int SNDreadNorm(tMUXSensor muxsensor) {
00059   int _val = ((long)SNDreadRaw(muxsensor) * (long)100) / (long)1024;
00060   return _val;
00061 }
00062 
00063 
00064 /**
00065  * Set the mode of the sensor to DBA, this is done
00066  * by switching off DIG0.
00067  * @param muxsensor the SMUX sensor port number
00068  */
00069 void SNDsetDBA(tMUXSensor muxsensor) {
00070   HTSMUXsetAnalogueInactive(muxsensor);
00071 }
00072 
00073 
00074 /**
00075  * Set the mode of the sensor to DB, this is done
00076  * by switching on DIG0.
00077  * @param muxsensor the SMUX sensor port number
00078  */
00079 void SNDsetDB(tMUXSensor muxsensor) {
00080   HTSMUXsetAnalogueActive(muxsensor);
00081 }
00082 #endif // __HTSMUX_SUPPORT__
00083 
00084 /*
00085  * $Id: lego-sound.h 133 2013-03-10 15:15:38Z xander $
00086  */
00087 /* @} */
00088 /* @} */