//-/////////////////////////////////////////////////////////////////////////////
//-                                                                           //
//-               This file is part of the Buildbotics firmware.              //
//-                                                                           //
//-      Copyright (c) 2015 - 2021, Buildbotics LLC, All rights reserved.     //
//-                                                                           //
//-       This Source describes Open Hardware and is licensed under the       //
//-                               CERN-OHL-S v2.                              //
//-                                                                           //
//-       You may redistribute and modify this Source and make products       //
//-  using it under the terms of the CERN-OHL-S v2 (https:/cern.ch/cern-ohl). //
//-         This Source is distributed WITHOUT ANY EXPRESS OR IMPLIED         //
//-  WARRANTY, INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS //
//-   FOR A PARTICULAR PURPOSE. Please see the CERN-OHL-S v2 for applicable   //
//-                                conditions.                                //
//-                                                                           //
//-              Source location: https://github.com/buildbotics              //
//-                                                                           //
//-    As per CERN-OHL-S v2 section 4, should You produce hardware based on   //
//-  these sources, You must maintain the Source Location clearly visible on  //
//-  the external case of the CNC Controller or other product you make using  //
//-                                this Source.                               //
//-                                                                           //
//-              For more information, email info@buildbotics.com             //
//-                                                                           //
//-/////////////////////////////////////////////////////////////////////////////

script#power-template(type="text/x-template")
  .power
    table.pwr_fault
      tr
        th.header(colspan=5).
          Power Faults
          #[span(v-if="state.pwr_version") (Version {{state.pwr_version}})]
      tr
        th(:class="{error: state.under_voltage}") Under voltage
        td(:class="{error: state.under_voltage}")
          | {{state.under_voltage ? 'True' : 'False'}}
        th.separator
        th(:class="{error: state.over_voltage}") Over voltage
        td(:class="{error: state.over_voltage}")
          | {{state.over_voltage ? 'True' : 'False'}}
      tr
        th(:class="{error: state.over_current}") Over current
        td(:class="{error: state.over_current}")
          | {{state.over_current ? 'True' : 'False'}}
        th.separator
        th(:class="{error: state.sense_error}", :title="sense_error")
          | Sense error
        td(:class="{error: state.sense_error}")
          | {{state.sense_error ? 'True' : 'False'}}
      tr
        th(:class="{error: state.shunt_overload}") Shunt overload
        td(:class="{error: state.shunt_overload}")
          | {{state.shunt_overload ? 'True' : 'False'}}
        th.separator
        th(:class="{error: state.shunt_error}") Shunt error
        td(:class="{error: state.shunt_error}")
          | {{state.shunt_error ? 'True' : 'False'}}
      tr(v-if="state.pwr_version_int < 0x100")
        th(:class="{error: state.load1_shutdown}") Load 1 shutdown
        td(:class="{error: state.load1_shutdown}")
          | {{state.load1_shutdown ? 'True' : 'False'}}
        th.separator
        th(:class="{error: state.load2_shutdown}") Load 2 shutdown
        td(:class="{error: state.load2_shutdown}")
          | {{state.load2_shutdown ? 'True' : 'False'}}
      tr
        th(:class="{error: state.motor_under_voltage}") Motor under volt
        td(:class="{error: state.motor_under_voltage}")
          | {{state.motor_under_voltage ? 'True' : 'False'}}
        th.separator
        th(:class="{error: state.motor_overload}") Motor overload
        td(:class="{error: state.motor_overload}")
          | {{state.motor_overload ? 'True' : 'False'}}

      tr
        th(:class="{error: state.power_shutdown}") Power shutdown
        td(:class="{error: state.power_shutdown}")
          | {{state.power_shutdown ? 'True' : 'False'}}
        th.separator
        th(:class="{error: state.gate_error}") Gate error
        td(:class="{error: state.gate_error}")
          | {{state.gate_error ? 'True' : 'False'}}

    table.motor_fault
      tr
        th.header(colspan=99)
          | Motor Faults
          .fa(:class="motor_fault_class()", title="General motor driver fault")

      tr
        th Motor
        th(title="Overtemperature fault"): .fa.fa-thermometer-full
        th(title="Overcurrent motor channel A") A #[.fa.fa-bolt]
        th(title="Predriver fault motor channel A")
          | A #[.fa.fa-exclamation-triangle]
        th(title="Overcurrent motor channel B") B #[.fa.fa-bolt]
        th(title="Predriver fault motor channel B")
          | B #[.fa.fa-exclamation-triangle]
        th(title="Driver communication failure"): .fa.fa-handshake-o
        th(title="Reset all motor flags")
          .fa.fa-eraser(@click="motor_reset()")

      tr(v-for="motor in [0, 1, 2, 3]")
        td {{motor}}
        td: .fa(:class="motor_fault_class(motor, 0)",
          title="Overtemperature fault")
        td: .fa(:class="motor_fault_class(motor, 1)",
          title="Overcurrent motor channel A")
        td: .fa(:class="motor_fault_class(motor, 3)",
          title="Predriver fault motor channel A")
        td: .fa(:class="motor_fault_class(motor, 2)",
          title="Overcurrent motor channel B")
        td: .fa(:class="motor_fault_class(motor, 4)",
          title="Predriver fault motor channel B")
        td: .fa(:class="motor_fault_class(motor, 8)",
          title="Driver communication failure")
        td(:title="'Reset motor ' + motor + ' flags'")
          .fa.fa-eraser(@click="motor_reset(motor)")

    table.measurements
      tr
        th.header(colspan=5) Measurements

      tr
        td {{state.vin | fixed 1}} V
        th Input Voltage
        th.separator
        td {{watts | fixed 2}} W
        th Motor Power

      tr
        td {{state.vout | fixed 1}} V
        th Motor Voltage
        th.separator
        td {{state.motor | fixed 2}} A
        th Motor Current

      tr(v-if="state.pwr_version_int < 0x100")
        td {{state.load1 | fixed 2}} A
        th Load 1
        th.separator
        td {{state.load2 | fixed 2}} A
        th Load 2

      tr
        td {{state.temp | fixed 0}} ℃
        th Board Temp
        th.separator
        td(:class="{'error': 80 <= state.rpi_temp}")
          | {{state.rpi_temp | fixed 0}} ℃
        th RPi Temp
