forked from betaflight/blackbox-log-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export of spectrum analyzer data to Csv file (betaflight#779)
* The 'Convert to Csv' button is added at the spectrum analyzer chart * The spectrum export Worker is added * The spectrum exporter is added * The exportSpectrumToCSV method is added into graph_spectrum * The action handler is addedto spectrum export button * The spectrum export button is enabled for spectrum by frequency only * The 4 spaces tabs are replaced to 2 space tab * unused library link is removed * Code issues are resolved * Code issues are resolved * Code style improvement * The export buttons tooltip text is changed Co-authored-by: Mark Haslinghuis <[email protected]> * Code style improvement Co-authored-by: Mark Haslinghuis <[email protected]> * Code style improvement Co-authored-by: Mark Haslinghuis <[email protected]> * Code style improvement * Update index.html --------- Co-authored-by: Mark Haslinghuis <[email protected]>
- Loading branch information
1 parent
ec62bca
commit 3269938
Showing
7 changed files
with
160 additions
and
61 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
onmessage = function(event) { | ||
const columnDelimiter = event.data.opts.columnDelimiter; | ||
const fftOutput = event.data.fftOutput; | ||
const spectrumDataLength = fftOutput.length / 2; | ||
const frequencyStep = 0.5 * event.data.blackBoxRate / spectrumDataLength; | ||
|
||
let outText = "freq" + columnDelimiter + "value" + "\n"; | ||
for (let index = 0; index < spectrumDataLength; index += 10) { | ||
const frequency = frequencyStep * index; | ||
outText += frequency.toString() + columnDelimiter + fftOutput[index].toString() + "\n"; | ||
} | ||
|
||
postMessage(outText); | ||
}; |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @typedef {object} ExportOptions | ||
* @property {string} columnDelimiter | ||
* @property {string} stringDelimiter | ||
* @property {boolean} quoteStrings | ||
*/ | ||
|
||
/** | ||
* @constructor | ||
* @param {object} fftOutput | ||
* @param {ExportOptions} [opts={}] | ||
*/ | ||
export function SpectrumExporter(fftData, opts = {}) { | ||
opts = _.merge( | ||
{ | ||
columnDelimiter: ",", | ||
quoteStrings: true, | ||
}, | ||
opts, | ||
); | ||
|
||
/** | ||
* @param {function} success is a callback triggered when export is done | ||
*/ | ||
function dump(success) { | ||
const worker = new Worker("/js/webworkers/spectrum-export-worker.js"); | ||
|
||
worker.onmessage = (event) => { | ||
success(event.data); | ||
worker.terminate(); | ||
}; | ||
|
||
worker.postMessage({fftOutput: fftData.fftOutput, | ||
blackBoxRate: fftData.blackBoxRate, | ||
opts: opts}); | ||
} | ||
|
||
// exposed functions | ||
return { | ||
dump: dump, | ||
}; | ||
} |