mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 16:55:36 +03:00
loggin tab, initial work on IO
This commit is contained in:
parent
da42cf878d
commit
fa90030759
6 changed files with 138 additions and 0 deletions
83
tabs/logging.js
Normal file
83
tabs/logging.js
Normal file
|
@ -0,0 +1,83 @@
|
|||
function tab_initialize_logging() {
|
||||
ga_tracker.sendAppView('Logging');
|
||||
GUI.active_tab = 'logging';
|
||||
|
||||
$('#content').load("./tabs/logging.html", process_html);
|
||||
|
||||
function process_html() {
|
||||
// translate to user-selected language
|
||||
localize();
|
||||
|
||||
// UI hooks
|
||||
$('a.log_file').click(prepare_file);
|
||||
|
||||
$('a.logging').click(function() {
|
||||
if (fileEntry.isFile) {
|
||||
// TODO:
|
||||
// grab enabled properties
|
||||
// grab refresh rate
|
||||
// start data polling timer
|
||||
// start buffer flushing sequence & timer (keep fileWriter.readyState in mind)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// IO related methods
|
||||
var fileEntry = null;
|
||||
var fileWriter = null;
|
||||
|
||||
function prepare_file() {
|
||||
// create or load the file
|
||||
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'bf_data_log', accepts: [{extensions: ['csv']}]}, function(entry) {
|
||||
if (!entry) {
|
||||
console.log('No file selected');
|
||||
return;
|
||||
}
|
||||
|
||||
fileEntry = entry;
|
||||
|
||||
// echo/console log path specified
|
||||
chrome.fileSystem.getDisplayPath(fileEntry, function(path) {
|
||||
console.log('Log file path: ' + path);
|
||||
});
|
||||
|
||||
// change file entry from read only to read/write
|
||||
chrome.fileSystem.getWritableEntry(fileEntry, function(fileEntryWritable) {
|
||||
// check if file is writable
|
||||
chrome.fileSystem.isWritableEntry(fileEntryWritable, function(isWritable) {
|
||||
if (isWritable) {
|
||||
fileEntry = fileEntryWritable;
|
||||
|
||||
prepare_writer();
|
||||
} else {
|
||||
console.log('File appears to be read only, sorry.');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function prepare_writer() {
|
||||
fileEntry.createWriter(function(writer) {
|
||||
fileWriter = writer;
|
||||
|
||||
fileWriter.onerror = function(e) {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
fileWriter.onwriteend = function() {
|
||||
// console.log('Data written');
|
||||
};
|
||||
}, function(e) {
|
||||
console.error(e);
|
||||
});
|
||||
}
|
||||
|
||||
function append_to_file(data) {
|
||||
if (fileWriter.position < fileWriter.length) {
|
||||
fileWriter.seek(fileWriter.length);
|
||||
}
|
||||
|
||||
fileWriter.write(new Blob([data + '\n'], {type: 'text/plain'}));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue