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