aboutsummaryrefslogtreecommitdiff
path: root/hsm-web/Client/src/INA226.vue
blob: dec961bb4420989299ab97e937e27861f899fbc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<template>
  <h2>Battery Status</h2>
  <table id='tina226'>
    <tbody>
      <tr>
        <td>{{ fmt(reading.voltage, 'V') }}</td>
        <td>{{ fmt(reading.current, 'A') }}</td>
        <td>{{ fmt(reading.power,   'W') }}</td>
      </tr>
    </tbody>
  </table>
</template>

<script>
import axios  from 'axios'
import config from './config'

export default {
  data() {
    return {
      reading: {
        voltage: 0,
        current: 0,
        power:   0
      }
    }
  },
  mounted() {
    this.getReading()
  },
  methods: {
    async getReading() {
      const res    = await axios.get(config.api + '/ina226')
      this.reading = res.data

      setTimeout(this.getReading, 1000)
    },
    fmt(val, sfx) {
      return val.toFixed(2) + sfx
    }
  }
}
</script>

<style>
#tina226 td {
  border:      1.5px solid #2aa198;
  color:       #2aa198;
  font-family: monospace;
  font-size:   14px;
  padding:     5px;
}
</style>