Code refactor

This commit is contained in:
2025-06-07 10:12:47 +02:00
parent 146816184c
commit e9296b44be
3 changed files with 0 additions and 14 deletions
-11
View File
@@ -82,33 +82,25 @@ function getMapIndex(array, input) {
channel.addListener("onMessage", async function (message) {
switch (message.id) {
case can_conf.selector.id:
console.log("==INVOKE SELECTOR==");
if (Buffer.compare(message.data, can_conf.selector.command) == 0) {
console.log("enable");
enabled = true;
} else {
console.log("disable");
enabled = false;
}
break;
case can_conf.apps_id:
console.log("==INVOKE APPS==");
const apps_percentage = ((message.data[1] << 8) | message.data[0]) / 1000;
throttle_output = loaded_map_data[getMapIndex(map_throttle, apps_percentage)][2];
console.log(throttle_output);
break;
case erpm_id:
console.log("==INVOKE ERPM==");
if (enabled) {
console.log("enabled");
if (fs.existsSync(path.join(__dirname, map_conf.map_storage_path, "selected"))) {
const enabled_map_name = fs.readFileSync(path.join(__dirname, map_conf.map_storage_path, "selected"));
if (enabled_map_name != "") {
console.log("map selected");
if (loaded_map_name != enabled_map_name) {
[loaded_map_name, loaded_map_data] = await parseMap(enabled_map_name);
}
@@ -117,15 +109,12 @@ channel.addListener("onMessage", async function (message) {
let max_current = loaded_map_data[getMapIndex(map_rpm, ERPM / can_conf.motor_poles)][(throttle_output > 0) ? 0 : 1];
let current = throttle_output * max_current * 10;
console.log(max_current);
console.log(current);
channel.send({
id: (throttle_output > 0) ? current_id : brake_current_id,
ext: false,
data: Buffer.from([(current >> 8) & 0xFF, current & 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
});
} else {
console.log("map not selected");
channel.send({
id: brake_current_id,
ext: false,