aboutsummaryrefslogtreecommitdiff
path: root/hsm-web/Client/src/INA226.vue
blob: 1487fa3ad53c70ccc5f5126b6fc5678d8fde9e8f (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
<template>
  <h2>Battery Status</h2>
  <table>
    <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>