Source Code Description (Helper Functions)

serial_mac.h / serial_mac.cp

Functions necessary for initializing/de-initializing the serial port as well as to allow communications between the serial port and the Laser Range Finder.  This code was obtained from Greg L.  Reid and modified slightly for our purpose.  As a result, the functions contained in these files will not be described.

NOTE
The serial port must be properly closed prior to program execution by calling the appropriate function (serial_close()).  Failure to do so may result in a "freezing" of the port and prevent other applications from accessing it.  In the event the port does "freeze", the computer must be re-started.

To test whether the port is "frozen", ZTerm may be executed with the LRF connected.  If the LRF does not respond to control commands sent via ZTerm, it is probably "frozen".

lrf_functions.h

Function proto-types and constant definitions related to the operation of the Laser Range Finder.

lrf_functions.c

float processReading(char *reading)

Convert string of ASCII digits into a double.  The reading obtained from the LRF begins with NULL (can be ignored ), followed by 3 ASCII SP (when reading is not saturated), followed by value and ending with ASCII CR and NL.  An out of range reading contains 4 ASCII "(" followed by 3 ASCII SP, CR and LF.

void lrfSetUp(SerialID port)

 Send all the desired operation commands to the lrf prior to obtaining any readings.

lrf_audio.h

Function proto-types and constant definitions specific to the audio output produced with the Apple Sound Manager and the Quick Time Music Architecture (QTMA).

lrf_audio.c

double midiNoteToFreq(int midiNote)

This function will convert the user provided argument 'midiNote' to its corresponding frequency.  The frequency is then returned.

int frequencyToMidiNote(double frequency)

 This function will convert the user provided argument 'midiNote' to its corresponding frequency.  The frequency is then returned.

int inverseSqrAmpMap(double distance, double exponent, int constant)

 This function will map a distance reading (user argument 'distance') to a corresponding amplitude value using a modified version of the inverse square law mapping.  The modification allows for any exponent value to be used (user argument 'exponent'), instead of an exponent value of 2.  The amplitude is then returned.

int reverseInvSqrAmpMap(double distance, double exponent, int constant)

This function will map a distance reading (user argument 'distance') to a corresponding amplitude value using a modified version of the inverse square law mapping.  The modification allows for any exponent value to be used (user argument 'exponent'), instead of an exponent value of 2.  The amplitude is then returned.  In addition, the mapping is reversed - larger distance corresponds to a greater amplitude whereas a smaller distance results in a smaller amplitude.

int playMidiNote (chanStruct *midiChannel, unsigned long note, int velocity)

This function will output the Midi note "theNote" using the QTMA using the provided Midi channel (instrument) to generate the note.

int silenceMidiNote (chanStruct *midiChannel, int note)

This function will silence the Midi note currently playing on the argument provided Midi channel.  If there is no Midi note being played by the channel, there will be no effect.  If there are no errors encountered, a value of 0 will be returned.

int chanSetup(chanStruct *midiChannel, int instrument)

This function will allocate and initialize the argument provided Midi Channel (which is used to generate and output the Midi notes).  If there are no errors encountered a value of 0 will be returned.

int disposeMidiChannel(chanStruct *midiChannel)

Dispose of an allocated Midi channel.  If there are no errors encountered a value of 0 will be returned.