EMG project for Biorobotics, works with 2 EMG inputs
Fork of HIDScope by
HIDScope.cpp@4:e1ae1ed26c4c, 2015-10-26 (annotated)
- Committer:
- bvgool
- Date:
- Mon Oct 26 12:20:28 2015 +0000
- Revision:
- 4:e1ae1ed26c4c
- Parent:
- 0:79e3f3072f3b
THis works on HIDscope for two inputs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomlankhorst | 0:79e3f3072f3b | 1 | #include "HIDScope.h" |
tomlankhorst | 0:79e3f3072f3b | 2 | |
tomlankhorst | 0:79e3f3072f3b | 3 | HIDScope::HIDScope(int channels) : hid(64,64) |
tomlankhorst | 0:79e3f3072f3b | 4 | { |
tomlankhorst | 0:79e3f3072f3b | 5 | bufferData = new float[channels](); |
tomlankhorst | 0:79e3f3072f3b | 6 | channelCount = channels; |
tomlankhorst | 0:79e3f3072f3b | 7 | scopeData.length = 64; |
tomlankhorst | 0:79e3f3072f3b | 8 | } |
tomlankhorst | 0:79e3f3072f3b | 9 | |
tomlankhorst | 0:79e3f3072f3b | 10 | void HIDScope::set(int ch, float val) |
tomlankhorst | 0:79e3f3072f3b | 11 | { |
tomlankhorst | 0:79e3f3072f3b | 12 | bufferData[ch] = val; |
tomlankhorst | 0:79e3f3072f3b | 13 | } |
tomlankhorst | 0:79e3f3072f3b | 14 | |
tomlankhorst | 0:79e3f3072f3b | 15 | void HIDScope::set(int ch, int val) |
tomlankhorst | 0:79e3f3072f3b | 16 | { |
tomlankhorst | 0:79e3f3072f3b | 17 | set(ch,(float)val); |
tomlankhorst | 0:79e3f3072f3b | 18 | } |
tomlankhorst | 0:79e3f3072f3b | 19 | |
tomlankhorst | 0:79e3f3072f3b | 20 | void HIDScope::set(int ch, bool val) |
tomlankhorst | 0:79e3f3072f3b | 21 | { |
tomlankhorst | 0:79e3f3072f3b | 22 | set(ch,(val ? 1.0f : 0.0f)); |
tomlankhorst | 0:79e3f3072f3b | 23 | } |
tomlankhorst | 0:79e3f3072f3b | 24 | |
tomlankhorst | 0:79e3f3072f3b | 25 | void HIDScope::set(int ch, double val) |
tomlankhorst | 0:79e3f3072f3b | 26 | { |
tomlankhorst | 0:79e3f3072f3b | 27 | set(ch,(float)val); |
tomlankhorst | 0:79e3f3072f3b | 28 | } |
tomlankhorst | 0:79e3f3072f3b | 29 | |
tomlankhorst | 0:79e3f3072f3b | 30 | void HIDScope::send() |
tomlankhorst | 0:79e3f3072f3b | 31 | { |
tomlankhorst | 0:79e3f3072f3b | 32 | for(int ch=0; ch<channelCount; ch++) |
tomlankhorst | 0:79e3f3072f3b | 33 | memcpy(&scopeData.data[ch*4], &bufferData[ch], 4); // Copy a 4 byte float to the char array |
tomlankhorst | 0:79e3f3072f3b | 34 | |
tomlankhorst | 0:79e3f3072f3b | 35 | // Send non blocking, can be adjusted to blocking (hid.send) |
tomlankhorst | 0:79e3f3072f3b | 36 | hid.sendNB(&scopeData); |
tomlankhorst | 0:79e3f3072f3b | 37 | } |