Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Dim FreqX(20), MagX(20), RmsX As Double
Dim FreqY(20), MagY(20), RmsY As Double
Dim FreqZ(20), MagZ(20), RmsZ As Double
End Sub
void PassDoubleArrayToB4R(B4R::Array* b4rArrayPtr, const double* sourceData, int dataCount, int startIndex = 0) {
if (b4rArrayPtr == nullptr) {
Serial.println("Error1: B4R::Array is not inited");
return;
}
if (b4rArrayPtr->data == nullptr) {
Serial.println("Error2: B4R::Array data is null");
return;
}
double* targetArray = (double*)b4rArrayPtr->data;
int availableSpace = b4rArrayPtr->length - startIndex;
// Copy with bounds check
int elementsToCopy = (dataCount < availableSpace) ? dataCount : availableSpace;
for (int i = 0; i < elementsToCopy; i++) {
targetArray[startIndex + i] = sourceData[i];
}
}
Usage:
// axle X
double passing[MAX_PEAKS];
for (int i = 0; i < MAX_PEAKS; i++) passing[i] = 0;
for (int i = 0; i < peakCountX; i++) passing[i] = peaksX[i].frequency;
PassDoubleArrayToB4R(b4r_espmpu6050_fft::_freqx, passing, peakCountX);
for (int i = 0; i < MAX_PEAKS; i++) passing[i] = 0;
for (int i = 0; i < peakCountX; i++) passing[i] = peaksX[i].amplitude;
PassDoubleArrayToB4R(b4r_espmpu6050_fft::_magx, passing, peakCountX);
Such sub helps to pass the data, but ... it's wrongly interpreted as the doubles...