Docs: power calculator -- solar by month (December first), board battery/panel, I2C sensors
Changelog: - Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d23beff8ac
commit
6a1d87679d
4 files changed
+216
-29
No files matched your search
@@ -22,10 +22,14 @@
|
||||
preamble: 'preamble (symbols)', tx_dbm: 'TX power (dBm)',
|
||||
tx_ma: 'TX current (mA), estimate', rx_extra: 'extra current while receiving (mA), estimate',
|
||||
usable_pct: 'usable capacity (%)', voltage: 'battery voltage (V)',
|
||||
sun_h: 'full-sun hours per day', charge_eff_pct: 'charging efficiency (%), estimate',
|
||||
charge_eff_pct: 'charging efficiency (%), estimate', month: 'Month', orient: 'Panel faces',
|
||||
sensors: 'I2C sensors', sensors_hint: 'datasheet estimate for how this firmware reads them',
|
||||
covers: 'panel covers it', emptyafter: 'battery empty after {n} days in {m} (starting full)',
|
||||
night: 'the battery does not carry the {h} h night of {m}: it lasts {x} h',
|
||||
nightshort: 'but not through the night', monthbal: 'balance per month (mAh/day)', bal_in: 'balance in', perdayu: 'mAh/day',
|
||||
unavailable: 'not in this firmware',
|
||||
avg: 'average current', autonomy: 'autonomy', days: 'days', perday: 'per day',
|
||||
indefinitely: 'indefinitely', balance: 'daily balance', nosun: 'without sun',
|
||||
balance: 'daily balance', nosun: 'without sun', sensorline: 'I2C sensor',
|
||||
measured: 'measured', estimate: 'estimate',
|
||||
part_node: 'node', part_tx: 'TX', part_rx: 'RX',
|
||||
base: 'whole node', borrowed: 'taken from', fwoffset: 'firmware difference measured on',
|
||||
@@ -47,10 +51,14 @@
|
||||
preamble: 'preambule (symboly)', tx_dbm: 'vysílací výkon (dBm)',
|
||||
tx_ma: 'proud při vysílání (mA), odhad', rx_extra: 'proud navíc při příjmu (mA), odhad',
|
||||
usable_pct: 'využitelná kapacita (%)', voltage: 'napětí baterie (V)',
|
||||
sun_h: 'hodin plného slunce za den', charge_eff_pct: 'účinnost nabíjení (%), odhad',
|
||||
charge_eff_pct: 'účinnost nabíjení (%), odhad', month: 'Měsíc', orient: 'Panel míří na',
|
||||
sensors: 'Čidla na I2C', sensors_hint: 'odhad z datasheetu podle toho, jak je tento firmware čte',
|
||||
covers: 'panel stačí', emptyafter: 'baterie prázdná po {n} dnech, měsíc {m} (z plné)',
|
||||
night: 'baterie neutáhne {h} h noci (měsíc {m}): vydrží {x} h',
|
||||
nightshort: 'ale noc nevydrží', monthbal: 'bilance po měsících (mAh/den)', bal_in: 'bilance, měsíc', perdayu: 'mAh/den',
|
||||
unavailable: 'tento firmware nemá',
|
||||
avg: 'průměrný proud', autonomy: 'výdrž', days: 'dní', perday: 'za den',
|
||||
indefinitely: 'nekonečno', balance: 'denní bilance', nosun: 'bez slunce',
|
||||
balance: 'denní bilance', nosun: 'bez slunce', sensorline: 'čidlo na I2C',
|
||||
measured: 'změřeno', estimate: 'odhad',
|
||||
part_node: 'uzel', part_tx: 'TX', part_rx: 'RX',
|
||||
base: 'celý uzel', borrowed: 'převzato z', fwoffset: 'rozdíl firmwarů změřený na',
|
||||
@@ -102,10 +110,11 @@
|
||||
sf: td.sf, bw: td.bw, cr: td.cr, preamble: td.preamble, tx_dbm: td.tx_dbm,
|
||||
rx_extra: d.traffic.rx_extra.value,
|
||||
mah: b.mah, usable_pct: b.usable_pct, voltage: b.voltage,
|
||||
panel_w: b.panel_w, sun_h: b.sun_h, charge_eff_pct: b.charge_eff_pct
|
||||
panel_w: b.panel_w, charge_eff_pct: b.charge_eff_pct,
|
||||
month: d.solar.default_month, orient: d.solar.orientation[0].id, sensors: {}
|
||||
};
|
||||
this.s.tx_ma = this.txCurrent(this.s.tx_dbm);
|
||||
this.applyDefaults();
|
||||
this.applyDefaults(true);
|
||||
this.build();
|
||||
}
|
||||
|
||||
@@ -127,8 +136,12 @@
|
||||
};
|
||||
|
||||
// board defaults, then what the firmware ships with; options it lacks are pinned off
|
||||
P.applyDefaults = function () {
|
||||
// boardChanged: also the battery and panel the board ships with
|
||||
P.applyDefaults = function (boardChanged) {
|
||||
var self = this, def = Object.assign({}, this.board().defaults, this.fw().defaults);
|
||||
if (boardChanged) ['mah', 'panel_w'].forEach(function (k) {
|
||||
self.s[k] = def[k] != null ? def[k] : self.d.battery[k];
|
||||
});
|
||||
Object.keys(this.d.settings).forEach(function (k) {
|
||||
var vals = self.d.settings[k];
|
||||
if (!self.available(k)) self.s[k] = vals.indexOf('off') >= 0 ? 'off' : vals[0];
|
||||
@@ -169,18 +182,30 @@
|
||||
};
|
||||
};
|
||||
|
||||
// solar gain in mAh per day in month m (1..12)
|
||||
P.solarGain = function (m) {
|
||||
var s = this.s, so = this.d.solar;
|
||||
var f = so.orientation.filter(function (o) { return o.id === s.orient; })[0].factor;
|
||||
return s.panel_w * so.sun_h[m - 1] * f * (s.charge_eff_pct / 100) / s.voltage * 1000;
|
||||
};
|
||||
P.monthName = function (m) {
|
||||
return new Date(2026, m - 1, 15).toLocaleString(this.lang === 'cs' ? 'cs-CZ' : 'en-GB', { month: 'long' });
|
||||
};
|
||||
|
||||
P.range = function (v) { return Array.isArray(v) ? [Math.min(v[0], v[1]), Math.max(v[0], v[1])] : [v, v]; };
|
||||
|
||||
P.pickBaseline = function () {
|
||||
var s = this.s, keys = Object.keys(this.d.settings);
|
||||
var rows = this.d.values.filter(function (v) { return v.kind === 'baseline' && v.board === s.board; });
|
||||
var bid = s.board, like = this.board().like;
|
||||
var rows = this.d.values.filter(function (v) { return v.kind === 'baseline' && v.board === bid; });
|
||||
if (!rows.length && like) rows = this.d.values.filter(function (v) { return v.kind === 'baseline' && v.board === like; });
|
||||
var same = rows.filter(function (v) { return v.firmware === s.firmware; });
|
||||
var pool = same.length ? same : rows;
|
||||
function diff(v) { return keys.filter(function (k) { return v.settings[k] !== s[k]; }).length; }
|
||||
pool.sort(function (a, b) {
|
||||
return diff(a) - diff(b) || (b.measured - a.measured) || (a.firmware === 'tth' ? -1 : 1);
|
||||
});
|
||||
return { row: pool[0], borrowed: !same.length };
|
||||
return { row: pool[0], borrowed: !same.length, boardBorrowed: pool[0].board !== bid };
|
||||
};
|
||||
|
||||
// delta rows of one option between two values, best match first:
|
||||
@@ -226,8 +251,9 @@
|
||||
P.compute = function () {
|
||||
var self = this, s = this.s, d = this.d, lines = [];
|
||||
var pb = this.pickBaseline(), b = pb.row;
|
||||
var u = b.uncertainty || 0, bmeas = b.measured && !pb.borrowed;
|
||||
var bnote = b.firmware !== s.firmware ? this.t('borrowed') + ' ' + this.n(this.fwById(b.firmware)) : null;
|
||||
var u = b.uncertainty || 0, bmeas = b.measured && !pb.borrowed && !pb.boardBorrowed;
|
||||
var bnote = pb.boardBorrowed ? this.t('borrowed') + ' ' + this.n(this.boardById(b.board)) :
|
||||
b.firmware !== s.firmware ? this.t('borrowed') + ' ' + this.n(this.fwById(b.firmware)) : null;
|
||||
lines.push({ part: 'node', label: this.t('base') + ' (' + this.settingsText(b) + ')', lo: b.value - u, hi: b.value + u,
|
||||
approx: b.approx, measured: bmeas, row: b, note: bnote || (b['note_' + this.lang] || b.note_en) });
|
||||
|
||||
@@ -262,6 +288,13 @@
|
||||
});
|
||||
});
|
||||
|
||||
d.sensors.list.forEach(function (x) {
|
||||
if (!s.sensors[x.id]) return;
|
||||
var v = x[s.firmware] != null ? x[s.firmware] : x['*'];
|
||||
lines.push({ part: 'node', label: self.t('sensorline') + ': ' + x.name, lo: v, hi: v, measured: false,
|
||||
row: { source: d.sensors.source }, note: x.how });
|
||||
});
|
||||
|
||||
var at = this.airtime(), tr = this.traffic();
|
||||
var tx = tr.tx * at / 3600 * s.tx_ma, rx = tr.rx * at / 3600 * s.rx_extra;
|
||||
var ms = this.fmt(at * 1000, 0);
|
||||
@@ -370,6 +403,20 @@
|
||||
this.field(this.t('mah'), this.num('mah', { step: 100 })),
|
||||
this.field(this.t('panel_w'), this.num('panel_w', { step: 0.5 }), this.t('panel_hint'))
|
||||
]));
|
||||
var months = [];
|
||||
for (var m = 1; m <= 12; m++) months.push({ v: m, t: this.monthName(m) });
|
||||
form.appendChild(el('div', { 'class': 'pc-two pc-sel' }, [
|
||||
this.field(this.t('month'), this.select('month', months)),
|
||||
el('div', { 'class': 'pc-field' }, [el('span', { 'class': 'pc-label', text: this.t('orient') }),
|
||||
this.seg('orient', d.solar.orientation.map(function (o) { return { v: o.id, t: self.n(o) }; }))])
|
||||
]));
|
||||
var chips = el('div', { 'class': 'pc-chips' }, d.sensors.list.map(function (x) {
|
||||
var cb = el('input', { type: 'checkbox', 'data-sensor': x.id });
|
||||
cb.checked = !!s.sensors[x.id];
|
||||
return el('label', { 'class': 'pc-chip', title: x.how }, [cb, x.name]);
|
||||
}));
|
||||
form.appendChild(el('div', { 'class': 'pc-field' }, [el('span', { 'class': 'pc-label', text: this.t('sensors') }), chips,
|
||||
el('div', { 'class': 'pc-hint' }, [this.t('sensors_hint') + ' ', this.badge(false)])]));
|
||||
|
||||
// advanced
|
||||
var adv = el('details', { 'class': 'pc-adv', 'data-open': 'adv' });
|
||||
@@ -389,7 +436,6 @@
|
||||
grid.appendChild(this.field(this.t('rx_extra'), this.num('rx_extra')));
|
||||
grid.appendChild(this.field(this.t('usable_pct'), this.num('usable_pct', { step: 5 })));
|
||||
grid.appendChild(this.field(this.t('voltage'), this.num('voltage', { step: 0.1 })));
|
||||
grid.appendChild(this.field(this.t('sun_h'), this.num('sun_h', { step: 0.5 })));
|
||||
grid.appendChild(this.field(this.t('charge_eff_pct'), this.num('charge_eff_pct', { step: 5 })));
|
||||
adv.appendChild(grid);
|
||||
adv.appendChild(el('p', { 'class': 'pc-hint', text: this.t('override_hint') }));
|
||||
@@ -397,10 +443,11 @@
|
||||
|
||||
form.addEventListener('input', function (ev) {
|
||||
var t = ev.target, k = t.name;
|
||||
if (t.hasAttribute('data-sensor')) { s.sensors[t.getAttribute('data-sensor')] = t.checked; self.render(); return; }
|
||||
if (!k) return;
|
||||
if (t.tagName === 'SELECT') {
|
||||
s[k] = isNaN(+t.value) ? t.value : +t.value;
|
||||
if (k === 'board' || k === 'firmware') self.applyDefaults();
|
||||
if (k === 'board' || k === 'firmware') self.applyDefaults(k === 'board');
|
||||
self.build();
|
||||
return;
|
||||
}
|
||||
@@ -461,13 +508,27 @@
|
||||
|
||||
// the two big numbers
|
||||
var rng = r.hi - r.lo > 0.005 ? this.fmt(r.lo) + ' … ' + this.fmt(r.hi) + ' mA' : '';
|
||||
var autoBig, autoSub;
|
||||
var autoBig, autoSub, autoLabel = this.t('autonomy'), warnNight = null, strip = null, autoBad = false;
|
||||
if (s.panel_w > 0) {
|
||||
var gain = s.panel_w * s.sun_h * (s.charge_eff_pct / 100) / s.voltage * 1000, bal = gain - perDay;
|
||||
var balTxt = this.t('balance') + ' ' + (bal >= 0 ? '+' : '−') + this.fmt(Math.abs(bal), 0) + ' mAh';
|
||||
if (bal >= 0) { autoBig = '∞'; autoSub = this.t('indefinitely') + ' · ' + balTxt; }
|
||||
else { autoBig = this.fmt(usable / -bal, 1); autoSub = this.t('days') + ' · ' + balTxt; }
|
||||
autoSub += ' · ' + this.t('nosun') + ' ' + this.fmt(usable / perDay, 1) + ' ' + this.t('days');
|
||||
var mn = this.monthName(s.month), bal = this.solarGain(s.month) - perDay;
|
||||
autoLabel = this.t('bal_in') + ' ' + mn;
|
||||
autoBig = (bal >= 0 ? '+' : '−') + this.fmt(Math.abs(bal), 0);
|
||||
autoBad = bal < 0;
|
||||
autoSub = this.t('perdayu') + ' · ' + (bal >= 0 ? this.t('covers') :
|
||||
this.t('emptyafter').replace('{n}', this.fmt(usable / -bal, 1)).replace('{m}', mn)) +
|
||||
' · ' + this.t('nosun') + ' ' + this.fmt(usable / perDay, 1) + ' ' + this.t('days');
|
||||
strip = el('div', { 'class': 'pc-strip' });
|
||||
for (var m = 1; m <= 12; m++) {
|
||||
var bm = this.solarGain(m) - perDay, ab = Math.abs(bm);
|
||||
var txt = (bm >= 0 ? '+' : '−') + (ab >= 1000 ? this.fmt(ab / 1000, 1) + 'k' : this.fmt(ab, 0));
|
||||
strip.appendChild(el('span', { 'class': (bm < 0 ? 'pc-neg' : 'pc-pos') + (m === +s.month ? ' pc-cur' : ''),
|
||||
title: this.monthName(m) + ': ' + txt + ' ' + this.t('perdayu') }, [
|
||||
el('b', { text: this.monthName(m).slice(0, 3) }), el('span', { text: txt })]));
|
||||
}
|
||||
// the cell must carry the night of that month (said only when it does not)
|
||||
var nh = this.d.solar.night_h[s.month - 1], lasts = usable / mid;
|
||||
if (lasts < nh) warnNight = this.t('night').replace('{h}', this.fmt(nh, 0)).replace('{m}', mn).replace('{x}', this.fmt(lasts, 1));
|
||||
if (warnNight) { autoBad = true; autoSub = autoSub.replace(this.t('covers'), '⚠ ' + this.t('nightshort')); }
|
||||
} else {
|
||||
autoBig = this.fmt(usable / perDay, 1);
|
||||
autoSub = this.t('days') + ' · ' + this.fmt(perDay, 0) + ' mAh ' + this.t('perday');
|
||||
@@ -476,11 +537,21 @@
|
||||
el('div', {}, [el('div', { 'class': 'pc-label', text: this.t('avg') }),
|
||||
el('div', { 'class': 'pc-bignum' }, [this.fmt(mid, mid >= 10 ? 1 : 2), el('span', { 'class': 'pc-unit', text: ' mA' })]),
|
||||
el('div', { 'class': 'pc-sub', text: rng || ' ' })]),
|
||||
el('div', {}, [el('div', { 'class': 'pc-label', text: this.t('autonomy') }),
|
||||
el('div', { 'class': 'pc-bignum', text: autoBig }),
|
||||
el('div', {}, [el('div', { 'class': 'pc-label', text: autoLabel }),
|
||||
el('div', { 'class': 'pc-bignum' + (autoBad ? ' pc-bad' : ''), text: autoBig }),
|
||||
el('div', { 'class': 'pc-sub', text: autoSub })])
|
||||
]));
|
||||
|
||||
if (strip) {
|
||||
var so = this.d.solar;
|
||||
out.appendChild(el('div', { 'class': 'pc-label pc-strip-t', text: this.t('monthbal') }));
|
||||
out.appendChild(strip);
|
||||
out.appendChild(el('div', { 'class': 'pc-hint' }, [this.badge(false), ' ', this.srcLink(so.source)]));
|
||||
// the model is optimistic for a real mast: say what one of ours did
|
||||
out.appendChild(el('div', { 'class': 'pc-hint' }, ['⚠ ' + so['field_note_' + this.lang] + ' · ', this.srcLink(so.field_source)]));
|
||||
}
|
||||
if (warnNight) out.appendChild(el('div', { 'class': 'pc-warn', text: '⚠ ' + warnNight }));
|
||||
|
||||
// split node / TX / RX
|
||||
var tot = r.parts.node + r.parts.tx + r.parts.rx || 1, bar = el('div', { 'class': 'pc-bar', role: 'img',
|
||||
'aria-label': ['node', 'tx', 'rx'].map(function (p) { return self.t('part_' + p) + ' ' + self.fmt(r.parts[p]) + ' mA'; }).join(', ') });
|
||||
@@ -511,8 +582,8 @@
|
||||
tb.appendChild(el('tr', {}, [el('td', {}, info), el('td', { 'class': 'pc-num', text: val })]));
|
||||
});
|
||||
if (s.panel_w > 0) {
|
||||
var g = s.panel_w * s.sun_h * (s.charge_eff_pct / 100) / s.voltage * 1000;
|
||||
tb.appendChild(el('tr', {}, [el('td', {}, [this.t('solar') + ' ', this.badge(false)]), el('td', { 'class': 'pc-num', text: this.fmt(g, 0) + ' mAh' })]));
|
||||
var g = this.solarGain(s.month);
|
||||
tb.appendChild(el('tr', {}, [el('td', {}, [this.t('solar') + ' (' + this.monthName(s.month) + ') ', this.badge(false)]), el('td', { 'class': 'pc-num', text: this.fmt(g, 0) + ' mAh' })]));
|
||||
}
|
||||
det.appendChild(el('table', { 'class': 'pc-lines' }, [tb]));
|
||||
det.appendChild(el('p', { 'class': 'pc-hint', text: this.t('foot').replace('{a}', this.fmt(r.airtime * 1000, 0)).replace('{v}', this.fmt(r.voltage, 2)) }));
|
||||
|
||||
Reference in new issue
Block a user