loggin tab, initial work on IO
parent
da42cf878d
commit
fa90030759
|
@ -59,6 +59,9 @@
|
|||
"tab9": {
|
||||
"message": "CLI"
|
||||
},
|
||||
"tab10": {
|
||||
"message": "Logging"
|
||||
},
|
||||
|
||||
"serialPortOpened": {
|
||||
"message": "Serial port <span style=\"color: green\">successfully</span> opened with ID: $1"
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
<link type="text/css" rel="stylesheet" href="./tabs/motor_outputs.css" media="all" />
|
||||
<link type="text/css" rel="stylesheet" href="./tabs/sensors.css" media="all" />
|
||||
<link type="text/css" rel="stylesheet" href="./tabs/cli.css" media="all" />
|
||||
<link type="text/css" rel="stylesheet" href="./tabs/logging.css" media="all" />
|
||||
<link type="text/css" rel="stylesheet" href="./tabs/firmware_flasher.css" media="all" />
|
||||
|
||||
<script type="text/javascript" src="./js/libraries/google-analytics-bundle.js"></script>
|
||||
|
@ -44,6 +45,7 @@
|
|||
<script type="text/javascript" src="./tabs/motor_outputs.js"></script>
|
||||
<script type="text/javascript" src="./tabs/sensors.js"></script>
|
||||
<script type="text/javascript" src="./tabs/cli.js"></script>
|
||||
<script type="text/javascript" src="./tabs/logging.js"></script>
|
||||
<script type="text/javascript" src="./tabs/firmware_flasher.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -105,6 +107,7 @@
|
|||
<li class="tab_motor_outputs"><a href="#" i18n="tab7"></a></li>
|
||||
<li class="tab_sensors"><a href="#" i18n="tab8"></a></li>
|
||||
<li class="tab_cli"><a href="#" i18n="tab9"></a></li>
|
||||
<li class="tab_logging"><a href="#" i18n="tab10"></a></li>
|
||||
</ul>
|
||||
<div class="clear-both"></div>
|
||||
</div>
|
||||
|
|
3
main.js
3
main.js
|
@ -102,6 +102,9 @@ $(document).ready(function() {
|
|||
case 'tab_cli':
|
||||
tab_initialize_cli();
|
||||
break;
|
||||
case 'tab_logging':
|
||||
tab_initialize_logging();
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
.tab-logging {
|
||||
}
|
||||
.tab-logging .note {
|
||||
padding: 5px;
|
||||
border: 1px dashed silver;
|
||||
}
|
||||
.tab-logging .properties {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.tab-logging .buttons {
|
||||
margin-top: 10px;
|
||||
}
|
||||
.tab-logging .buttons a {
|
||||
display: block;
|
||||
float: left;
|
||||
|
||||
margin-right: 10px;
|
||||
|
||||
height: 28px;
|
||||
line-height: 28px;
|
||||
|
||||
padding: 0 15px 0 15px;
|
||||
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
|
||||
border: 1px solid silver;
|
||||
background-color: #ececec;
|
||||
}
|
||||
.tab-logging .buttons a:hover {
|
||||
background-color: #dedcdc;
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<div class="tab-logging">
|
||||
<div class="note">
|
||||
Data will be logged in this tab <span style="color: red">only</span>, leaving this tab will <span style="color: red">cancel</span> logging and application will return to its normal <strong>"configurator"</strong> operation.<br />
|
||||
Logged <strong>CSV</strong> data will respect properties order below, some of the properties will log more then 1 field, in that case please consult documentation or sourcecode
|
||||
to find out the order and amount of fields per property.<br />
|
||||
You are free to select the global update period, data will be written into the log file every 1 second.
|
||||
</div>
|
||||
<div class="properties">
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<a href="#" class="log_file">Select Log File</a>
|
||||
<a href="#" class="logging">Start Logging</a>
|
||||
</div>
|
||||
</div>
|
|
@ -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…
Reference in New Issue