Forked HIDScope

Dependencies:   USBDevice

Fork of HIDScope by Sjoerd Barts

Committer:
sjoerdbarts
Date:
Fri Oct 07 09:11:12 2016 +0000
Revision:
8:2c5104f9f580
Parent:
0:79e3f3072f3b
Child:
5:80d551456856
Initial working code

Who changed what in which revision?

UserRevisionLine numberNew 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 }