Code refactor
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -73,7 +73,6 @@ setEventListeners(commit, async () => {
|
||||
}
|
||||
} catch (error) {
|
||||
alert(`Add unsuccessful. ${error.message}`);
|
||||
console.error(error.message);
|
||||
}
|
||||
} else {
|
||||
alert("Nothing to commit.");
|
||||
|
||||
@@ -59,7 +59,6 @@ setEventListeners(remove, async () => {
|
||||
}
|
||||
} catch (error) {
|
||||
alert(`Remove unsuccessful. ${error.message}`);
|
||||
console.error(error.message);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -115,7 +114,6 @@ setEventListeners(commit, async () => {
|
||||
}
|
||||
} catch (error) {
|
||||
alert(`Edit unsuccessful. ${error.message}`);
|
||||
console.error(error.message);
|
||||
}
|
||||
} else {
|
||||
alert("Nothing to commit.");
|
||||
|
||||
Reference in New Issue
Block a user