add charging checks, made logging optional
parent
d4d4a7eaaa
commit
276bf0c7cd
|
|
@ -4,7 +4,7 @@
|
||||||
var storage=require("Storage");
|
var storage=require("Storage");
|
||||||
|
|
||||||
var logFile = "smartbattlog.json";
|
var logFile = "smartbattlog.json";
|
||||||
|
var doLogging=true;
|
||||||
function logBatterySample(entry) {
|
function logBatterySample(entry) {
|
||||||
let log = storage.readJSON(logFile, 1) || [];
|
let log = storage.readJSON(logFile, 1) || [];
|
||||||
|
|
||||||
|
|
@ -30,8 +30,16 @@
|
||||||
|
|
||||||
|
|
||||||
if (battChange <= 0) {
|
if (battChange <= 0) {
|
||||||
reason = "Skipped: battery rose or no change";
|
reason = "Skipped: battery fluctuated or no change";
|
||||||
data.battLastRecorded = batt;
|
if(Math.abs(battChange)<5){
|
||||||
|
//less than 6% difference, average percents
|
||||||
|
var newBatt=(batt+data.battLastRecorded)/2;
|
||||||
|
data.battLastRecorded = newBatt;
|
||||||
|
}else{
|
||||||
|
//probably charged, ignore average
|
||||||
|
data.battLastRecorded = batt;
|
||||||
|
}
|
||||||
|
|
||||||
storage.writeJSON(filename, data);
|
storage.writeJSON(filename, data);
|
||||||
} else if (deltaHours <= 0 || !isFinite(deltaHours)) {
|
} else if (deltaHours <= 0 || !isFinite(deltaHours)) {
|
||||||
reason = "Skipped: invalid time delta";
|
reason = "Skipped: invalid time delta";
|
||||||
|
|
@ -56,17 +64,18 @@
|
||||||
|
|
||||||
reason = "Drainage recorded: " + currentDrainage.toFixed(3) + "%/hr";
|
reason = "Drainage recorded: " + currentDrainage.toFixed(3) + "%/hr";
|
||||||
}
|
}
|
||||||
|
if(doLogging){
|
||||||
// Always log the sample
|
// Always log the sample
|
||||||
logBatterySample({
|
logBatterySample({
|
||||||
time: now,
|
time: now,
|
||||||
battNow: batt,
|
battNow: batt,
|
||||||
battLast: data.battLastRecorded,
|
battLast: data.battLastRecorded,
|
||||||
battChange: battChange,
|
battChange: battChange,
|
||||||
deltaHours: deltaHours,
|
deltaHours: deltaHours,
|
||||||
avgDrainage: data.avgBattDrainage,
|
avgDrainage: data.avgBattDrainage,
|
||||||
reason: reason
|
reason: reason
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -96,7 +105,7 @@
|
||||||
|
|
||||||
function deleteData(){
|
function deleteData(){
|
||||||
storage.erase(filename);
|
storage.erase(filename);
|
||||||
}
|
};
|
||||||
// Expose public API
|
// Expose public API
|
||||||
exports.record = recordBattery;
|
exports.record = recordBattery;
|
||||||
exports.deleteData = deleteData;
|
exports.deleteData = deleteData;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue