Some variables and some mandatory variables, and some mandatory functions
Sensor.prototype.count=0;
Sensor.prototype.clock_manager; //MANDATORY
A main function with some object variables:
function Sensor(i_d,ty_pe,pa_ir,inte_rval) {
this.id=i_d; //MANDATORY
this.type=ty_pe; //MANDATORY
this.pair=pa_ir; //can be any kind of string or value MANDATORY
this.interval=inte_rval; //since Sensors should have a clock this defines the interval MANDATORY
//if this sensor is only a panel for Console so you don't need to add anything to Page
//MANDATORY
var temp=this.create_display("hello world!");
}
//MANDATORY can be empty
Sensor.prototype.create_display=function(pair){
//this produces the standard Sensor Panel
var temp='<div id='+pair+'"_container" class="'+pair+' borderclass" style="border-radius:5px;border:solid 1px #ddd; float: left; margin:5px; padding: 20px; width: 200px;"><div class="close" id="'+this.id+'" style="cursor: pointer; cursor: hand;width:30px;height:30px;position:absolute;margin-left:-20px;margin-top:-20px;background-image:url(\'http://s23.postimg.org/77ue1gcw7/1454132136_fileclose.png\');background-size:30px 30px;"></div>'+pair+'</div>';
//appends the newly generated sensor to the Page $("#page").append(temp);
};
//MANDATORY
Sensor.prototype.create_panel=function(){
//this produces a Manager Panel for the Console
var temp='<div id='+pair+'"_container" class="'+pair+' borderclass" style="border-radius:5px;border:solid 1px #ddd; float: left; margin:5px; padding: 20px; width: 200px;"><div class="close" id="'+this.id+'" style="cursor: pointer; cursor: hand;width:30px;height:30px;position:absolute;margin-left:-20px;margin-top:-20px;background-image:url(\'http://s23.postimg.org/77ue1gcw7/1454132136_fileclose.png\');background-size:30px 30px;"></div>Hallo World!</div>';
$("#Console").append(temp);
};
//a Sensor must have a loop function
//MANDATORY
Sensor.prototype.loop=function() {
this.getinfo(this,this.pair);
}
//stop loop with given interval
//MANDATORY
Sensor.prototype.start=function(inte_rval){
this.clock_manager=window.setInterval("Sensors["+this.id+"].loop()",inte_rval||this.interval);
};
//stop loop, quite important , always remember to do it if possible
//MANDATORY
Sensor.prototype.stop=function(){
window.clearInterval(this.clock_manager);
};
Sensor.prototype.CUSTOM_FUNCTION=function(variable){
var temp=0;
return temp;
};
Of course a Sensor has a serie of events triggered by its GUI components:
$(document).ready(function() {
//SENSOR 1 close button
//this is the standard button, you should always use it according to standard look and feel
$(".close").click(function() {
$(this).parent().fadeOut(500, function(){ $(this).hide(); });
//$("#"+$(this).parent().attr('class')).prop("checked",false);
//$("#"+$(this).parent().attr('class')+"label").prop("color","white");
c[$(this).attr('id')].stop();
});
$(".close").mouseover(function() {
$(this).css('background-image','url(http://s15.postimg.org/fd3kyanxz/light_fileclose.png)');
});
$(".close").mouseout(function() {
$(this).css('background-image','url(http://s23.postimg.org/77ue1gcw7/1454132136_fileclose.png)');
});
//Add more custom events here
});
1) Go to http://paste.ee
2) paste the code as javascript
3) get the generated page URL (example: https://paste.ee/p/fS4o7)
4) raw code can be found at https://paste.ee/r/fS4o7
5) extract the code https://paste.ee/p/fS4o7
6) you just built your first Custom Sensor, the codig for it will be 5-fS4o7
If your Sensor contains a Panel for the Console you find it at:
http://cryptosensor.overgrid.com/display.html?&c=5-fS4o7
or simply
http://cryptosensor.overgrid.com/display.html?&c=fS4o7
If your Sensor is a Simple Custom Sensor/machine/module you find it at:
http://cryptosensor.overgrid.com/display.html?&s=fS4o7