Forked HIDScope
Dependents: Read_potentiometer
Fork of HIDScope by
HIDScope.h@5:80d551456856, 2016-10-06 (annotated)
- Committer:
- tomlankhorst
- Date:
- Thu Oct 06 12:54:02 2016 +0000
- Revision:
- 5:80d551456856
- Parent:
- 2:9c9226db4fb1
- Child:
- 6:188304906687
USBDevice 1 revision back
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomlankhorst | 0:79e3f3072f3b | 1 | #ifndef _HIDSCOPE_H_ |
tomlankhorst | 0:79e3f3072f3b | 2 | #define _HIDSCOPE_H_ |
tomlankhorst | 0:79e3f3072f3b | 3 | |
tomlankhorst | 0:79e3f3072f3b | 4 | #include "mbed.h" |
tomlankhorst | 0:79e3f3072f3b | 5 | #include "USBHID.h" |
tomlankhorst | 0:79e3f3072f3b | 6 | |
tomlankhorst | 1:e44574634162 | 7 | /** A simple HID (Human Interface Device) scope |
tomlankhorst | 1:e44574634162 | 8 | * - Up to 6 channels of float data is transmitted in a single HID message (64 byte) |
tomlankhorst | 2:9c9226db4fb1 | 9 | * - Theoretical maximum samplerate of 1kHz (due to HID specifications) |
tomlankhorst | 2:9c9226db4fb1 | 10 | * - Data can be parsed using a client-side server |
tomlankhorst | 2:9c9226db4fb1 | 11 | * |
tomlankhorst | 2:9c9226db4fb1 | 12 | * See the following repository for PC software: https://bitbucket.org/tomlankhorst/hidscope |
tomlankhorst | 1:e44574634162 | 13 | * |
tomlankhorst | 1:e44574634162 | 14 | * Example: |
tomlankhorst | 1:e44574634162 | 15 | * @code |
tomlankhorst | 1:e44574634162 | 16 | * #include "mbed.h" |
tomlankhorst | 2:9c9226db4fb1 | 17 | * #include "HIDScope.h" // Require the HIDScope library |
tomlankhorst | 1:e44574634162 | 18 | * |
tomlankhorst | 2:9c9226db4fb1 | 19 | * HIDScope scope(2); // Instantize a 2-channel HIDScope object |
tomlankhorst | 2:9c9226db4fb1 | 20 | * Ticker scopeTimer; // Instantize the timer for sending data to the PC |
tomlankhorst | 1:e44574634162 | 21 | * |
tomlankhorst | 2:9c9226db4fb1 | 22 | * AnalogIn a0(A0); // Using an analog input to obtain data |
tomlankhorst | 1:e44574634162 | 23 | * |
tomlankhorst | 1:e44574634162 | 24 | * int main() |
tomlankhorst | 1:e44574634162 | 25 | * { |
tomlankhorst | 1:e44574634162 | 26 | * |
tomlankhorst | 2:9c9226db4fb1 | 27 | * // Attach the HIDScope::send function to the timer at a 10.000 us interval (100 Hz) |
tomlankhorst | 2:9c9226db4fb1 | 28 | * scopeTimer.attach_us(&scope, &HIDScope::send, 1e4); |
tomlankhorst | 1:e44574634162 | 29 | * |
tomlankhorst | 2:9c9226db4fb1 | 30 | * // Read from the analog input in an endless loop. Two channels are written each iteration. |
tomlankhorst | 2:9c9226db4fb1 | 31 | * // Note that the control loop can run at a different frequency (1 kHz in this case) |
tomlankhorst | 2:9c9226db4fb1 | 32 | * while(1){ |
tomlankhorst | 1:e44574634162 | 33 | * scope.set(0, a0.read()); |
tomlankhorst | 1:e44574634162 | 34 | * scope.set(1, a0.read()); |
tomlankhorst | 1:e44574634162 | 35 | * wait_us(1000); |
tomlankhorst | 1:e44574634162 | 36 | * }; |
tomlankhorst | 1:e44574634162 | 37 | * |
tomlankhorst | 1:e44574634162 | 38 | * } |
tomlankhorst | 1:e44574634162 | 39 | * @endcode |
tomlankhorst | 0:79e3f3072f3b | 40 | */ |
tomlankhorst | 0:79e3f3072f3b | 41 | class HIDScope { |
tomlankhorst | 0:79e3f3072f3b | 42 | public: |
tomlankhorst | 0:79e3f3072f3b | 43 | ///Instantiate the HID Scope |
tomlankhorst | 5:80d551456856 | 44 | HIDScope(int channels, bool non_blocking = true); |
tomlankhorst | 0:79e3f3072f3b | 45 | |
tomlankhorst | 0:79e3f3072f3b | 46 | /** Sets the current channel value |
tomlankhorst | 0:79e3f3072f3b | 47 | @param ch : integer channel no (0-6) |
tomlankhorst | 0:79e3f3072f3b | 48 | @param val : float value |
tomlankhorst | 0:79e3f3072f3b | 49 | @return void |
tomlankhorst | 0:79e3f3072f3b | 50 | */ |
tomlankhorst | 0:79e3f3072f3b | 51 | void set(int ch, float val); |
tomlankhorst | 0:79e3f3072f3b | 52 | |
tomlankhorst | 0:79e3f3072f3b | 53 | /** Sets the current channel value |
tomlankhorst | 0:79e3f3072f3b | 54 | @param ch : integer channel no (0-6) |
tomlankhorst | 0:79e3f3072f3b | 55 | @param val : integer value |
tomlankhorst | 0:79e3f3072f3b | 56 | @return void |
tomlankhorst | 0:79e3f3072f3b | 57 | */ |
tomlankhorst | 0:79e3f3072f3b | 58 | void set(int ch, int val); |
tomlankhorst | 0:79e3f3072f3b | 59 | |
tomlankhorst | 0:79e3f3072f3b | 60 | /** Sets the current channel value |
tomlankhorst | 0:79e3f3072f3b | 61 | @param ch : integer channel no (0-6) |
tomlankhorst | 0:79e3f3072f3b | 62 | @param val : boolean value |
tomlankhorst | 0:79e3f3072f3b | 63 | @return void |
tomlankhorst | 0:79e3f3072f3b | 64 | */ |
tomlankhorst | 0:79e3f3072f3b | 65 | void set(int ch, bool val); |
tomlankhorst | 0:79e3f3072f3b | 66 | |
tomlankhorst | 0:79e3f3072f3b | 67 | /** Sets the current channel value |
tomlankhorst | 0:79e3f3072f3b | 68 | @param ch : double channel no (0-6) |
tomlankhorst | 0:79e3f3072f3b | 69 | @param val : float value |
tomlankhorst | 0:79e3f3072f3b | 70 | @return void |
tomlankhorst | 0:79e3f3072f3b | 71 | */ |
tomlankhorst | 0:79e3f3072f3b | 72 | void set(int ch, double val); |
tomlankhorst | 0:79e3f3072f3b | 73 | |
tomlankhorst | 0:79e3f3072f3b | 74 | /** Sends the channel data to the HID client |
tomlankhorst | 0:79e3f3072f3b | 75 | @return void |
tomlankhorst | 0:79e3f3072f3b | 76 | */ |
tomlankhorst | 0:79e3f3072f3b | 77 | void send(); |
tomlankhorst | 0:79e3f3072f3b | 78 | private: |
tomlankhorst | 5:80d551456856 | 79 | bool send_non_blocking; |
tomlankhorst | 0:79e3f3072f3b | 80 | USBHID hid; |
tomlankhorst | 0:79e3f3072f3b | 81 | HID_REPORT scopeData; |
tomlankhorst | 0:79e3f3072f3b | 82 | float* bufferData; |
tomlankhorst | 0:79e3f3072f3b | 83 | int channelCount; |
tomlankhorst | 0:79e3f3072f3b | 84 | }; |
tomlankhorst | 0:79e3f3072f3b | 85 | |
tomlankhorst | 0:79e3f3072f3b | 86 | #endif |