Interface class for the Max Botix ultrasonic range finder model 1210. It includes input methods for PWM, Analog, and Serial. A PwmIn class was created to allow the PWM input to be read. Now includes automatic range update via interrupts.
Diff: MB1210.h
- Revision:
- 4:a615b75d4126
- Parent:
- 3:05183e50a923
diff -r 05183e50a923 -r a615b75d4126 MB1210.h --- a/MB1210.h Thu Aug 26 18:25:19 2010 +0000 +++ b/MB1210.h Sat Aug 28 07:59:29 2010 +0000 @@ -21,12 +21,17 @@ float UnitFactor; float PwmScalingFactor; float AnalogScalingFactor; - unsigned short Range; + float Range; + float* InterruptBuffer; + + void Interrupt(); public: MB1210(PinName pw, PinName an, PinName tx, PinName rx); //pulse width modulation input, analog input, serial output, serial input; - //specify NC if pin is not used + //specify NC if pin is not used; + //if the pulse width pin is used, interrupts will perform a + //few microseconds of calculations every time a reading is taken ~MB1210(); //deallocates PwmInput, AnalogInput, SerialOutput, and SerailInput void SoundVelocity(float MetersPerSecond); @@ -43,9 +48,19 @@ //default is cm void Mode(char Selection); //argument sets operating mode; - //0 to 2 for synchronous modes, 4 to 6 for asynchronous modes; - //0 and 4 for pwm, 1 and 5 for analog, 2 and 6 for serial; + //set flag 0x08 to 0 for polled modes, or 1 for interrupt modes; + //set flag 0x04 to 0 for synchronous modes, or 1 for asynchronous modes; + //set flags 0x03 to 0 for pwm, 1 for analog, or 2 for serial; + //asynchronous modes generate pulse width interrupts, prepare an + //analog reading, and send a 5 byte serial reading every 99 ms; + //interrupt modes automatically read the range into the buffer provided + //by AttachInterruptBuffer with the selected input method every 99 ms + //if in an asynchronous mode, or 99 ms after RequestSyncRead is called; + //the rx pin must be connected to use an interrupt mode; + //the tx pin must be connected to use a synchronous mode; //default is 0 + void AttachInterruptBuffer(float* Buffer); + //if interrupts are used, user must provide address to write result to void RequestSyncRead(); //this tells the device to prepare a synchronous range reading; //must be called at least 99 ms before the reading is needed; @@ -59,11 +74,6 @@ //RequestSyncRead() must be called at least 99 ms //before this method can be called in a synchronous mode; //may be called at any time during asynchronous mode; - void Read(char* Buffer); - //overloaded to take advantage of Serial ASCII string output; - //Buffer must be 3 bytes; 3 digit ASCII number - //measures range in cm regardless of selected unit; - //uses serial input method regardless of selected mode. operator float(); //shorthand for taking a range reading; //ex: "float reading = MB1210Object;"