Skip to content

Instantly share code, notes, and snippets.

@cabanm
Created February 16, 2017 15:21
Show Gist options
  • Save cabanm/aa1520017c9e428916758dc18807dc0b to your computer and use it in GitHub Desktop.
Save cabanm/aa1520017c9e428916758dc18807dc0b to your computer and use it in GitHub Desktop.
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