A simple but very effective scope. Up to 6 channels of 32 bit float data at 1 kHz.

Dependencies:   USBDevice

Dependents:   HIDScope TEST Project5-Motorcontrol EMG_HIDScope_Gr6 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HIDScope.h Source File

HIDScope.h

00001 #ifndef _HIDSCOPE_H_
00002 #define _HIDSCOPE_H_
00003 
00004 #include "mbed.h"
00005 #include "USBHID.h"
00006 
00007 #if MBED_LIBRARY_VERSION != 119
00008 /*    #error HIDScope: Please select MBED revision 119 as newer versions have some known problems with HID devices. */
00009 #endif
00010 
00011 /** A simple HID (Human Interface Device) scope
00012  * - Up to 6 channels of float data is transmitted in a single HID message (64 byte)
00013  * - Theoretical maximum samplerate of 1kHz (due to HID specifications)
00014  * - Data can be parsed using a client-side server
00015  *
00016  * See the following repository for PC software: https://bitbucket.org/tomlankhorst/hidscope
00017  *
00018  * There seem to be some issues with newest MBED revisions. Please select revision 119 for the time being.
00019  * 
00020  * Example:
00021  * @code
00022  * #include "mbed.h"
00023  * #include "HIDScope.h"        // Require the HIDScope library
00024  *
00025  * HIDScope    scope(2);        // Instantize a 2-channel HIDScope object
00026  * Ticker      scopeTimer;      // Instantize the timer for sending data to the PC 
00027  * 
00028  * AnalogIn    a0(A0);          // Using an analog input to obtain data 
00029  * 
00030  * int main()
00031  * {
00032  *   
00033  *   // Attach the HIDScope::send function to the timer at a 10.000 us interval (100 Hz)
00034  *   scopeTimer.attach_us(&scope, &HIDScope::send, 1e4);
00035  *   
00036  *   // Read from the analog input in an endless loop. Two channels are written each iteration. 
00037  *   // Note that the control loop can run at a different frequency (1 kHz in this case)
00038  *   while(1){
00039  *       scope.set(0, a0.read());
00040  *       scope.set(1, a0.read());
00041  *       wait_us(1000);
00042  *   };    
00043  *   
00044  * }
00045  * @endcode
00046 */
00047 class HIDScope {
00048     public: 
00049         ///Instantiate the HID Scope
00050         HIDScope(int channels, bool non_blocking = true);
00051         
00052         /** Sets the current channel value
00053           @param ch : integer channel no (0-6)
00054           @param val : float value
00055           @return void
00056         */
00057         void set(int ch, float val);
00058         
00059         /** Sets the current channel value
00060           @param ch : integer channel no (0-6)
00061           @param val : integer value
00062           @return void
00063         */
00064         void set(int ch, int val);
00065         
00066         /** Sets the current channel value
00067           @param ch : integer channel no (0-6)
00068           @param val : boolean value
00069           @return void
00070         */
00071         void set(int ch, bool val);
00072         
00073         /** Sets the current channel value
00074           @param ch : double channel no (0-6)
00075           @param val : float value
00076           @return void
00077         */
00078         void set(int ch, double val);
00079         
00080         /** Sends the channel data to the HID client
00081           @return void
00082         */
00083         void send();
00084     private:
00085         bool send_non_blocking;
00086         USBHID hid;
00087         HID_REPORT scopeData;
00088         float* bufferData;
00089         int channelCount;
00090 };
00091 
00092 #endif