Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MS3DMGX2.h
00001 #ifndef MS3DMGX2Library 00002 #define MS3DMGX2Library 00003 00004 #include "stdint.h" 00005 #include "mbed.h" 00006 00007 class MS3DMGX2 00008 { 00009 private: 00010 ///////////////////// 00011 //Serial PC; 00012 ////////////////////////// 00013 00014 Serial DataLines; 00015 volatile unsigned char Buffer[87];//volatile is for interrupted access 00016 volatile unsigned char BufferEnd; 00017 volatile unsigned char PacketSize; 00018 bool Checksum(unsigned char Index, unsigned char Length); 00019 void FillSerialBuffer(); 00020 00021 public: 00022 MS3DMGX2(PinName tx, PinName rx); 00023 //serial output, serial input 00024 ~MS3DMGX2(); 00025 //release resources 00026 unsigned char BufferStart; 00027 00028 unsigned char CommandByte; 00029 unsigned char ResponseLength; 00030 unsigned char Continuous; 00031 00032 00033 bool Readable(); 00034 00035 bool Mode(unsigned char Selection); 00036 //argument sets operating mode; 00037 //set flag 0x08 to 0 for polled modes, or 1 for interrupt modes; 00038 //set flag 0x04 to 0 for synchronous modes, or 1 for asynchronous modes; 00039 //set flags 0x03 to 0 for pwm, 1 for analog, or 2 for serial; 00040 //asynchronous modes read user input command, measures and calculates 00041 //output, and writes the data packet to the serial buffer every 10 ms; 00042 //interrupt modes automatically read the packet into the buffer provided 00043 //by AttachInterruptBuffer with the selected input method every 10 ms 00044 //if in an asynchronous mode, or 10 ms after RequestSyncRead is called; 00045 //interrupt mode interrupts are generated if there are bytes on the 00046 //serial buffer and are only cleared if the serial buffer is emptied; 00047 //default is 0 00048 //void AttachInterruptBuffer(float* Buffer); 00049 //if interrupts are used, user must provide address to write result to 00050 //void AttachInterruptFunction(); 00051 //this overload reattaches the native interrupt function 00052 //void AttachInterruptFunction(void (*Function)()); 00053 //this overload attaches a function to the serial interrupt 00054 //template<class Class> void AttachInterruptFunction 00055 // (Class* Object, void (Class::*Function)()); 00056 //this overload attaches a member function to the serial interrupt; 00057 //to change the interrupt function, call one of the 00058 //"AttachInterruptFunction" overloads with pointers to the desired function; 00059 //changes polled mode to interrupt equivalent; 00060 //the interrupt will not be cleared until the serial buffer is emptied 00061 void RequestSyncRead(); 00062 //this tells the device to prepare a synchronous reading; 00063 //must be called at least 10 ms before the reading is needed; 00064 //changes asynchronous mode to synchronous equivalent 00065 void DiscardSerialBuffer(); 00066 //the serial port has a buffer and only the oldest data is read from it; 00067 //the buffer has limited space and, when full, the newest data is discarded; 00068 //this method allows the user to empty the buffer of old data so new data is used 00069 bool Read(float* Data); 00070 //get a reading from the device in the set mode; 00071 //RequestSyncRead() must be called at least 10 ms 00072 //before this method can be called in a synchronous mode; 00073 //may be called at any time during asynchronous mode; 00074 //it is assumed that the input buffer has enough 00075 //room to accomodate the desired data packet 00076 //operator float*(); 00077 //shorthand for taking a reading; 00078 //ex: "float reading[packetlength]; reading = MB1210Object;" 00079 }; 00080 00081 #endif
Generated on Sun Jul 24 2022 10:35:28 by
1.7.2