Skip to content

Commit

Permalink
fixing bug with in battery state function + enhancing the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Malick-Tammal committed Nov 5, 2024
1 parent c27f074 commit ce91d17
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
15 changes: 15 additions & 0 deletions lib/battery_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,26 @@ const execute = (command, callback) => {
});
};

// Converting number to boolean
// +
// Checking last state to return same velue

// Last state count (lsc)
let lsc;

const convertNumToBool = (num) => {
if (num === 1) {
lsc = num;
return false;
} else if (num === 2) {
lsc = num;
return true;
} else if (num === 0) {
if (lsc === 1) {
return false;
} else {
return true;
}
} else {
return "We can't determine";
}
Expand Down
50 changes: 33 additions & 17 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
"use strict";

const batteryInfo = require("./battery_info");
const bu = require("../lib/index");

console.clear();
console.log("Gathering Data ...");

batteryInfo()
.then((data) => {
console.clear();
const getInfo = () => {
bu.batteryInfo()
.then((data) => {
console.clear();

// Logging data
console.log("============================================");
console.log("============================================");
console.log("================ BATTERY_JS ================");
console.log("============================================");
console.log("============================================\n");
// Logging data
console.log("============================================");
console.log("============================================");
console.log("================ BATTERY_JS ================");
console.log("============================================");
console.log("============================================\n");

console.log("--------------------------------------------");
console.log(data);
console.log("============================================");
})
.catch((err) => {
console.log(err);
});
console.log("--------------------------------------------");
console.log(data);
console.log("============================================");

setInterval(() => {
bu.batteryState()
.then((data) => {
console.log(data);
})
.catch((err) => {
console.log(err);
});
}, 1000);
})
.catch((err) => {
console.log(err);
});
};
setTimeout(() => {
getInfo();
}, 2000);

0 comments on commit ce91d17

Please sign in to comment.