library
Dependencies: HIDScope USBDevice
Fork of HIDScope by
Revision 0:79e3f3072f3b, committed 2014-09-08
- Comitter:
- tomlankhorst
- Date:
- Mon Sep 08 09:26:53 2014 +0000
- Child:
- 1:e44574634162
- Commit message:
- Initial version (v0.1)
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HIDScope.cpp Mon Sep 08 09:26:53 2014 +0000 @@ -0,0 +1,37 @@ +#include "HIDScope.h" + +HIDScope::HIDScope(int channels) : hid(64,64) +{ + bufferData = new float[channels](); + channelCount = channels; + scopeData.length = 64; +} + +void HIDScope::set(int ch, float val) +{ + bufferData[ch] = val; +} + +void HIDScope::set(int ch, int val) +{ + set(ch,(float)val); +} + +void HIDScope::set(int ch, bool val) +{ + set(ch,(val ? 1.0f : 0.0f)); +} + +void HIDScope::set(int ch, double val) +{ + set(ch,(float)val); +} + +void HIDScope::send() +{ + for(int ch=0; ch<channelCount; ch++) + memcpy(&scopeData.data[ch*4], &bufferData[ch], 4); // Copy a 4 byte float to the char array + + // Send non blocking, can be adjusted to blocking (hid.send) + hid.sendNB(&scopeData); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HIDScope.h Mon Sep 08 09:26:53 2014 +0000 @@ -0,0 +1,56 @@ +#ifndef _HIDSCOPE_H_ +#define _HIDSCOPE_H_ + +#include "mbed.h" +#include "USBHID.h" + +/**A simple HID (Human Interface Device) scope +- Up to 6 channels of float data is transmitted in a single HID message (64 byte) +- Theoretical maximum samplerate of 1kHz +- Data can be parsed using a client-side server like NodeJS +*/ +class HIDScope { + public: + ///Instantiate the HID Scope + HIDScope(int channels); + + /** Sets the current channel value + @param ch : integer channel no (0-6) + @param val : float value + @return void + */ + void set(int ch, float val); + + /** Sets the current channel value + @param ch : integer channel no (0-6) + @param val : integer value + @return void + */ + void set(int ch, int val); + + /** Sets the current channel value + @param ch : integer channel no (0-6) + @param val : boolean value + @return void + */ + void set(int ch, bool val); + + /** Sets the current channel value + @param ch : double channel no (0-6) + @param val : float value + @return void + */ + void set(int ch, double val); + + /** Sends the channel data to the HID client + @return void + */ + void send(); + private: + USBHID hid; + HID_REPORT scopeData; + float* bufferData; + int channelCount; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Mon Sep 08 09:26:53 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/USBDevice/#5bf05f9b3c7b