// global variables
var hbNodeID = 24;
var hbIntervall = 2000;
var timerId = 0;

// functions
function sendHB() {
    can.sendBaseFrame(0x700 + hbNodeID, 1, 0x7f, 0,0,0,0,0,0,0);
}

function startHB() {
    
    hbIntervall = myDialog.findChild("spHB").value;
    hbNodeID =  myDialog.findChild("dial").value;
	    
    timerId = util.every(hbIntervall, "sendHB()");
}

function stopHB() {
    util.deleteTimer( timerId );
}

// load UI file
if (util.loadUIFile("example4.ui", "myDialog") === true) {

    // find UI button
    var b1 = myDialog.findChild("btnStart");
    var b2 = myDialog.findChild("btnStartHb");
    var b3 = myDialog.findChild("btnStopHb");
    var dial = myDialog.findChild("dial");
    var lbl = myDialog.findChild("lblNode");

    var con = myDialog.findChild("connect");
    var discon = myDialog.findChild("disconnect");

    con.clicked.connect(canconnection.connect);
    discon.clicked.connect(canconnection.disconnect);

    // connect buttons and functions
    b1.clicked.connect(nmt.startNetwork);
    b2.clicked.connect(startHB);
    b3.clicked.connect(stopHB);
    dial.valueChanged.connect(lbl.setText);
    
    // connect wheel and label
    
} else {
    util.print("Error: Cannot load UI file");
}
