|
| 1 | +<template> |
| 2 | + <div class="battery-icon"> |
| 3 | + <div class="quad-status-contents"> |
| 4 | + <div |
| 5 | + class="battery-status" |
| 6 | + :class="classes" |
| 7 | + :style="{ width: batteryWidth + '%' }" |
| 8 | + /> |
| 9 | + </div> |
| 10 | + </div> |
| 11 | +</template> |
| 12 | +<script> |
| 13 | +const NO_BATTERY_VOLTAGE_MAXIMUM = 1.8; // Maybe is better to add a call to MSP_BATTERY_STATE but is not available for all versions |
| 14 | +
|
| 15 | +export default { |
| 16 | + props: { |
| 17 | + voltage: { |
| 18 | + type: Number, |
| 19 | + default: 0, |
| 20 | + }, |
| 21 | + vbatmincellvoltage: { |
| 22 | + type: Number, |
| 23 | + default: 1, |
| 24 | + }, |
| 25 | + vbatmaxcellvoltage: { |
| 26 | + type: Number, |
| 27 | + default: 1, |
| 28 | + }, |
| 29 | + vbatwarningcellvoltage: { |
| 30 | + type: Number, |
| 31 | + default: 1, |
| 32 | + }, |
| 33 | + }, |
| 34 | + computed: { |
| 35 | + nbCells() { |
| 36 | + let nbCells = Math.floor(this.voltage / this.vbatmaxcellvoltage) + 1; |
| 37 | + if (this.voltage === 0) { |
| 38 | + nbCells = 1; |
| 39 | + } |
| 40 | + return nbCells; |
| 41 | + }, |
| 42 | + min() { |
| 43 | + return this.vbatmincellvoltage * this.nbCells; |
| 44 | + }, |
| 45 | + max() { |
| 46 | + return this.vbatmaxcellvoltage * this.nbCells; |
| 47 | + }, |
| 48 | + warn() { |
| 49 | + return this.vbatwarningcellvoltage * this.nbCells; |
| 50 | + }, |
| 51 | + isEmpty() { |
| 52 | + return ( |
| 53 | + this.voltage < this.min && this.voltage > NO_BATTERY_VOLTAGE_MAXIMUM |
| 54 | + ); |
| 55 | + }, |
| 56 | + classes() { |
| 57 | + if (this.batteryState) { |
| 58 | + return { |
| 59 | + "state-ok": this.batteryState === 0, |
| 60 | + "state-warning": this.batteryState === 1, |
| 61 | + "state-empty": this.batteryState === 2, |
| 62 | + // TODO: BATTERY_NOT_PRESENT |
| 63 | + // TODO: BATTERY_INIT |
| 64 | + }; |
| 65 | + } |
| 66 | + const isWarning = this.voltage < this.warn; |
| 67 | + return { |
| 68 | + "state-empty": this.isEmpty, |
| 69 | + "state-warning": isWarning, |
| 70 | + "state-ok": !this.isEmpty && !isWarning, |
| 71 | + }; |
| 72 | + }, |
| 73 | + batteryWidth() { |
| 74 | + return this.isEmpty |
| 75 | + ? 100 |
| 76 | + : ((this.voltage - this.min) / (this.max - this.min)) * 100; |
| 77 | + }, |
| 78 | + }, |
| 79 | +}; |
| 80 | +</script> |
| 81 | + |
| 82 | +<style> |
| 83 | +.quad-status-contents { |
| 84 | + display: inline-block; |
| 85 | + margin-top: 10px; |
| 86 | + margin-left: 14px; |
| 87 | + height: 10px; |
| 88 | + width: 31px; |
| 89 | +} |
| 90 | +
|
| 91 | +.quad-status-contents progress::-webkit-progress-bar { |
| 92 | + height: 12px; |
| 93 | + background-color: #eee; |
| 94 | +} |
| 95 | +
|
| 96 | +.quad-status-contents progress::-webkit-progress-value { |
| 97 | + background-color: #bcf; |
| 98 | +} |
| 99 | +
|
| 100 | +.battery-icon { |
| 101 | + background-image: url(../../images/icons/cf_icon_bat_grey.svg); |
| 102 | + background-size: contain; |
| 103 | + background-position: center; |
| 104 | + display: inline-block; |
| 105 | + height: 30px; |
| 106 | + width: 60px; |
| 107 | + transition: none; |
| 108 | + margin-top: 4px; |
| 109 | + margin-left: -4px; |
| 110 | + background-repeat: no-repeat; |
| 111 | +} |
| 112 | +
|
| 113 | +.battery-status { |
| 114 | + height: 11px; |
| 115 | +} |
| 116 | +
|
| 117 | +@keyframes error-blinker { |
| 118 | + 0% { |
| 119 | + background-color: transparent; |
| 120 | + } |
| 121 | + 50% { |
| 122 | + background-color: var(--error); |
| 123 | + } |
| 124 | +} |
| 125 | +
|
| 126 | +.battery-status.state-ok { |
| 127 | + background-color: #59aa29; |
| 128 | +} |
| 129 | +.battery-status.state-warning { |
| 130 | + background-color: var(--error); |
| 131 | +} |
| 132 | +
|
| 133 | +.battery-status.state-empty { |
| 134 | + animation: error-blinker 1s linear infinite; |
| 135 | +} |
| 136 | +</style> |
0 commit comments