enricocirignaco / van_logic_board

0 stars 0 forks source link

battery gage won't change color #5

Closed enricocirignaco closed 2 years ago

enricocirignaco commented 2 years ago

question posted on stack overflow

enricocirignaco commented 2 years ago

issue found and fixed. changes must be applied to van software. The following code must be applied too the parser node of the battery gauge

// calculate power
msg.payload = Math.round((msg.payload.I/1000) * (msg.payload.V/1000));

// if charger is on and battery is not full (not absorption nor float state)
if(global.get("output_state.charger") && msg.payload.CS !=4 && msg.payload.CS !=5){
    const charger_power = Math.round(4*msg.payload.V/1000);
    msg.payload = msg.payload + charger_power;
}

// ui stuff --> change gage color if is charging or discharging
if(msg.payload > 0 && context.get("color") != "green" ){
    context.set("color", "green");
}
else if(msg.payload <= 0 && context.get("color") != "red") {
    context.set("color", "red");
}
else {
    // remove sign
    msg.payload = Math.abs(msg.payload);
    return msg;
}

// remove sign
msg.payload = Math.abs(msg.payload);
msg.ui_control = 
{
    "gtype": "gage",
    "colors": [context.get("color"), context.get("color"), context.get("color")],
};

return msg;