Created
February 16, 2017 15:21
-
-
Save cabanm/aa1520017c9e428916758dc18807dc0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<int> ViconData::footswitchAnalogToVector(double analog_val) { | |
int sensor_count = 4; | |
float discrete_max = (float)pow(2.0, 4)-1; | |
float analog_max = 4; | |
int discrete_val = (int)floor(analog_val * discrete_max / analog_max + 0.5); | |
vector<int> ret; | |
for (int i = 0; i < sensor_count; i++) { | |
if (discrete_val&1) | |
ret.push_back(1); | |
else | |
ret.push_back(0); | |
discrete_val>>=1; | |
} | |
reverse(ret.begin(),ret.end()); | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment