/* NTElectrode_safa class */
  
function NTElectrode_safa(module, symbol, addr, type)
{
    // call base when not typed dynamically (see change_class_type()) 
    // otherwise, the base object is already constructed
    if(!this._dynamically_typed)
        NTElectrode(module, symbol, addr, null)
}

NTElectrode_safa.prototype.OnLinkClicked = function()
{
    var vname_signal    = this._name + "_signal";
    var vname_f_signal  = this._name + "_f_signal"; 
    var vname_baseline  = this._name + "_baseline";
    var vname_noise     = this._name + "_noise";
    var vname_evnt_cnt  = this._name + "_entry_event_cnt";
    var vname_deadband  = this._name + "_deadband_cnt";
    var vname_deadband_h  = this._name + "_deadband_h";
    var vname_deadband_l  = this._name + "_deadband_l";
    
    var ok =
        this.DefineSignalVariable(vname_signal) && 
        this.DefineFilteredSignalVariable(vname_f_signal) &&
        this.DefineBaselineVariable(vname_baseline) && 
        this.DefineNoiseVariable(vname_noise) &&
        this.DefineEventCntVariable(vname_evnt_cnt) &&
        this.DefineDeadBandVariable(vname_deadband) &&
        this.DefineDeadBandHighVariable(vname_deadband_h) &&
        this.DefineDeadBandLowVariable(vname_deadband_l);

    // scope variables
    var vars = [ 
        {"variable":vname_signal, "visible":true, "y_block":0 }, 
        {"variable":vname_f_signal, "visible":true, "y_block":0 }, 
        {"variable":vname_baseline, "visible":true, "y_block":0 },
        {"variable":vname_deadband_h, "visible":true, "y_block":0 },
        {"variable":vname_deadband_l, "visible":true, "y_block":0 },
        {"variable":vname_noise, "visible":true, "y_block":1 },
        {"variable":vname_evnt_cnt, "visible":true, "y_block":2 },
        {"variable":vname_deadband, "visible":true, "y_block":2 },
    ]; 

    // scope Y-blocks
    var yblocks = [
        { "laxis_label":"raw signal", "join_class":0, "laxis_min_auto":true, "laxis_max_auto":true },
        { "laxis_label":"noise", "join_class":1, "laxis_min_auto":true, "laxis_max_auto":true },
        { "laxis_label":"counters", "join_class":2, "laxis_min_auto":true, "laxis_max_auto":true },
    ];

    // scope definition
    var def = {};
    def["var_info"] = vars;
    def["yblock_info"] = yblocks;
    def["scope_period"] = 0.025;
    def["auto_delete"] = true;
    def["href"] = DOC_PATH+"group__electrodes.html#details";

    this.CreateScope(def);
}
NTElectrode_safa.prototype.GetKeydetGui = function()
{
    var str = "";
    str += "keydetectortype: "+this._keydettype;
    str += "<table id=\""+this._id+"keydet\">";
    str += "<tr><th>filtered_signal</th><th>noise</th>";
    str +="</tr>"
    str += "<tr><td>0</td><td>0</td>"
    str +="</tr>"

    str += "</table>"
    return str;
}
NTElectrode_safa.prototype.UpdateGuiKeydetRaw = function(shieldding)
{
    var tbl = document.getElementById(this._id+shieldding+"keydet");
    var tmp;
    if(tbl)
    {
        var row = tbl.rows[1];
        row.cells[0].innerHTML = this.GetVar(shieldding + "keydetector_data->predicted_signal");
        row.cells[1].innerHTML = this.GetVar(shieldding + "keydetector_data->noise");
    }
}