In the previous tutorial, we can get the RMS or Mean value through the sample code CustomAlgorithm.zip. This tutorial will modify the sample code to get the RMS and Mean value at the same time.
Find the following code from customAlgo.c.
double* CustomAlgo(uint16_t chIndex, void *rawData, DeviceInfo devInfo, char* customParams, uint32_t* outCount)
{
uint32_t* raw = (uint32_t*)rawData;
double inputRange = devInfo.inputRange == B10 ? 10.0 : 1.25;
double scalingFactor = inputRange/8388607.0*1000.0/devInfo.sensor.sensitivity;//for convert rawData to g
const uint32_t COUNT = 1;
double* data = (double*)malloc(sizeof(double) * COUNT);
double* gArray = (double*)malloc(sizeof(double) * devInfo.dataCount);
raw = raw + chIndex*devInfo.dataCount;
*outCount = COUNT;
for(int i = 0; i < devInfo.dataCount; i++)
gArray[i] = scalingFactor*(((raw[i] & 0x00800000) == 0x00800000) ? (int32_t)(raw[i] | 0xFF000000) : (int32_t)raw[i]);
if(strcmp(customParams, "rms")==0)
data[0] = GetRms(gArray, devInfo.dataCount);
else
data[0] = GetMean(gArray, devInfo.dataCount);
free(gArray);
return data;
}
Modify COUNT to 2 in line 34.
const uint32_t COUNT = 2;
Modify conditions, then save and deploy the code.
if(strcmp(customParams, "rms")==0)
{
data[0] = GetRms(gArray, devInfo.dataCount);
}
else if(strcmp(customParams,"mean")==0)
{
data[0] = GetMean(gArray, devInfo.dataCount);
}
else if(strcmp(customParams,"both")==0)
{
data[0]=GetRms(gArray,devInfo.dataCount);
data[1]=GetMean(gArray,devInfo.dataCount);
}
Please refer to the previous tutorial.
Enter both in customization parameter.
Click Data Capture and the data will be displayed at Customization key of returned JSON data.
In this way you can get the RMS and the Mean value at the same time.