Bug fixes
This commit is contained in:
@@ -4,6 +4,7 @@ const fs = require("fs");
|
||||
|
||||
const can_conf = require("./app/config/can.conf");
|
||||
const map_conf = require("./app/config/map.conf");
|
||||
const path = require("path");
|
||||
|
||||
var map_rpm = [];
|
||||
var map_throttle = [];
|
||||
@@ -26,13 +27,14 @@ const brake_current_id = (0x02 << 5) | can_conf.controller.id;
|
||||
const erpm_id = (0x20 << 5) | can_conf.controller.id;
|
||||
|
||||
function parseMap(filename) {
|
||||
loaded_map_data = [];
|
||||
let name = "";
|
||||
let map = [];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
csv.parseFile(`app/storage/${filename}`, { comment: "#" })
|
||||
csv.parseFile(path.join(__dirname, map_conf.map_storage_path, filename), { comment: "#" })
|
||||
.on('error', error => reject(error))
|
||||
.on('data', row => loaded_map_data.push(row))
|
||||
.on('end', () => { loaded_map_name = filename; resolve() });
|
||||
.on('data', row => map.push(row))
|
||||
.on('end', () => { name = filename; resolve([name, map]) });
|
||||
});
|
||||
}
|
||||
|
||||
@@ -71,14 +73,9 @@ function getMapIndex(array, input) {
|
||||
map_throttle[i] = i * (map_conf.max_throttle / map_conf.steps);
|
||||
}
|
||||
|
||||
if (fs.existsSync(map_conf.selected_map_path)) {
|
||||
const enabled_map_name = fs.readFileSync(map_conf.selected_map_path);
|
||||
|
||||
if (enabled_map_name != "") {
|
||||
if (loaded_map_name != enabled_map_name) {
|
||||
await parseMap(enabled_map_name);
|
||||
}
|
||||
}
|
||||
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"));
|
||||
[loaded_map_name, loaded_map_data] = await parseMap(enabled_map_name);
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -107,13 +104,13 @@ channel.addListener("onMessage", async function (message) {
|
||||
console.log("==INVOKE ERPM==");
|
||||
if (enabled) {
|
||||
console.log("enabled");
|
||||
if (fs.existsSync(map_conf.selected_map_path)) {
|
||||
const enabled_map_name = fs.readFileSync(map_conf.selected_map_path);
|
||||
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) {
|
||||
await parseMap(enabled_map_name);
|
||||
[loaded_map_name, loaded_map_data] = await parseMap(enabled_map_name);
|
||||
}
|
||||
|
||||
const ERPM = message.data[0] << 3 * 8 | message.data[1] << 2 * 8 | message.data[2] << 8 | message.data[3];
|
||||
|
||||
Reference in New Issue
Block a user