Merge pull request #51 from stevoleeto/saveCode

Save generated Arduino code locally
zeedee
gasolin 2015-07-28 18:19:24 +08:00
commit c1be154c95
2 changed files with 13 additions and 0 deletions

View File

@ -31,6 +31,18 @@ function restore_blocks() {
}
}
/**
* Save Arduino generated code to local file.
*/
function saveCode() {
var fileName = window.prompt('What would you like to name your file?', 'BlocklyDuino')
//doesn't save if the user quits the save prompt
if(fileName){
var blob = new Blob([Blockly.Arduino.workspaceToCode()], {type: 'text/plain;charset=utf-8'});
saveAs(blob, fileName + '.ino');
}
}
/**
* Save blocks to local file.
* better include Blob and FileSaver for browser compatibility

View File

@ -300,6 +300,7 @@ function init() {
<button type="button" onclick="uploadClick()">Upload</button>
<button type="button" onclick="resetClick()">Reset</button>
<button onclick="discard()">Discard</button>
<button onclick="saveCode()">Save Arduino Code</button>
<button onclick="save()">Save XML</button>
<button id="fakeload">Load XML</button>
<input type="file" id="load" style="display: none;"/>