espruino
Version:
Command Line Interface and library for Communications with Espruino JavaScript Microcontrollers
40 lines (34 loc) • 1.29 kB
JavaScript
/**
Copyright 2014 Gordon Williams (gw@pur3.co.uk)
This Source Code is subject to the terms of the Mozilla Public
License, v2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
------------------------------------------------------------------
Ability to set the current time in Espruino
------------------------------------------------------------------
**/
;
(function(){
function init() {
Espruino.Core.Config.add("SET_TIME_ON_WRITE", {
section : "Communications",
name : "Set Current Time",
description : "When sending code, set Espruino's clock to the current time",
type : "boolean",
defaultValue : true,
onChange : function(newValue) { }
});
// When code is sent to Espruino, append code to set the current time
Espruino.addProcessor("transformForEspruino", function(code, callback) {
if (Espruino.Config.SET_TIME_ON_WRITE) {
var time = new Date();
code = "setTime("+(time.getTime()/1000)+");E.setTimeZone("+(-time.getTimezoneOffset()/60)+")\n"+code;
}
callback(code);
});
}
Espruino.Plugins.SetTime = {
init : init,
sortOrder : 1100, // after pretty much everything, speficically saveOnSend
};
}());