Skip to content

Commit

Permalink
fix: remove config.json first
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryyip committed Sep 29, 2024
1 parent 2c9975c commit dad68b6
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 99 deletions.
126 changes: 126 additions & 0 deletions src/global-defines.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ exports.grpNameTransZh = {
"Particulate Matter": "颗粒物",
"Carbon Dioxide":"二氧化碳",
"Carbon Dioxide Concentration": "二氧化碳浓度",
"Noise": "噪声",
"Sound Pressure Level": "声压级",
"Total Solar Radiation": "太阳总辐射",
"Sunlight Duration": "日照时长",
"GlobalDefinesEnd": "-"
}

Expand Down Expand Up @@ -126,4 +130,126 @@ exports.slaveGroupDefines = {
"42": [],
}

exports.ngSkus = {
"101991044": "v2_2in1",
"101991045": "v2_2in1",
"101991021": "v2_5in1",
"101991232": "v2_6in1_light",
"101991022": "v2_7in1",
"101991023": "v2_8in1",
"101991024": "v2_10in1",
"101991025": "v2_10in1_carbon",
"101991063": "v2_11in1_noise",
"101991102": "v2_7in1_tsr",
"101991103": "v2_10in1_tsr",
"101991104": "v2_11in1_tsr_noise",
"101991050": "v2_7in1_radar",
"101991141": "v2_7in1_radar_tsr",
"101991202": "single_radar",
"101991062": "v2_9in1",
"101991061": "v2_6in1"
}
exports.ngSensorTypes = {
"v2_2in1":["G2"],
"v2_5in1":["G1_THP", "G2"],
"v2_6in1":["G1_THP", "G4", "G6"],
"v2_6in1_light":["G1_THPL", "G2"],
"v2_7in1":["G1_THPL", "G2", "G3"],
"v2_8in1":["G1_THP", "G2", "G4", "G6"],
"v2_9in1":["G1_THPL", "G2", "G3", "G4"],
"v2_10in1":["G1_THPL", "G2", "G3", "G4", "G5"],
"v2_10in1_carbon":["G1_THPL", "G2", "G3", "G4", "G5"],
"v2_11in1_noise":["G1_THPL", "G2", "G3", "G4", "G5", "G6"],
"unknown":["G1_THPL", "G2", "G3", "G4", "G5", "G6"],
"v2_7in1_tsr":["G1_THP_TSR", "G2", "G3"],
"v2_10in1_tsr":["G1_THP_TSR", "G2", "G3", "G4", "G5"],
"v2_11in1_tsr_noise":["G1_THP_TSR", "G2", "G3", "G4", "G5", "G6"],
"v2_7in1_radar":["G1_THPL", "G2", "G3"],
"v2_7in1_radar_tsr":["G1_THP_TSR", "G2", "G3"],
"single_radar": ["G3"]
}

exports.ngGroupDefines = {
"G1_THP":
{
"grpNameShort": "G1",
"grpName": "THP",
"meas": {
"AT": { "name": "Air Temperature", "unit": "#", "unitSuffix": "" },
"AH": { "name": "Air Humidity", "unit": "%RH", "unitSuffix": "" },
"AP": { "name": "Air Pressure", "unit": "#", "unitSuffix": "" }
}
},
"G1_THPL":
{
"grpNameShort": "G1",
"grpName": "THPL",
"meas": {
"AT": { "name": "Air Temperature", "unit": "#", "unitSuffix": "" },
"AH": { "name": "Air Humidity", "unit": "%RH", "unitSuffix": "" },
"AP": { "name": "Air Pressure", "unit": "#", "unitSuffix": "" },
"LX": { "name": "Light Intensity", "unit": "Lux", "unitSuffix": "" }
}
},
"G1_THP_TSR":
{
"grpNameShort": "G1",
"grpName": "THPL",
"meas": {
"AT": { "name": "Air Temperature", "unit": "#", "unitSuffix": "" },
"AH": { "name": "Air Humidity", "unit": "%RH", "unitSuffix": "" },
"AP": { "name": "Air Pressure", "unit": "#", "unitSuffix": "" },
"TSR": { "name": "Total Solar Radiation", "unit": "W/m²", "unitSuffix": "" },
"SD": { "name": "Sunlight Duration", "unit": "h", "unitSuffix": "" }
}
},
"G2":
{
"grpNameShort": "G2",
"grpName": "Wind",
"meas": {
"DN": { "name": "Min. Wind Direction", "unit": "°", "unitSuffix": "" },
"DM": { "name": "Max. Wind Direction", "unit": "°", "unitSuffix": "" },
"DA": { "name": "Avg. Wind Direction", "unit": "°", "unitSuffix": "" },
"SN": { "name": "Min. Wind Speed", "unit": "#", "unitSuffix": "" },
"SM": { "name": "Max. Wind Speed", "unit": "#", "unitSuffix": "" },
"SA": { "name": "Avg. Wind Speed", "unit": "#", "unitSuffix": "" }
}
},
"G3":
{
"grpNameShort": "G3",
"grpName": "Precipitation",
"meas": {
"RA": { "name": "Rain Accumulation", "unit": "#", "unitSuffix": "" },
"RD": { "name": "Rain Duration", "unit": "s", "unitSuffix": "" },
"RI": { "name": "Rain Intensity", "unit": "#", "unitSuffix": "/h" },
"RP": { "name": "Rain Peak Intensity", "unit": "#", "unitSuffix": "/h" }
}
},
"G4":
{
"grpNameShort": "G4",
"grpName": "Particulate Matter",
"meas": {
"PM2.5": { "name": "PM2.5", "unit": "ug/m³", "unitSuffix": "" },
"PM10": { "name": "PM10", "unit": "ug/m³", "unitSuffix": "" }
}
},
"G5":
{
"grpNameShort": "G5",
"grpName": "Carbon Dioxide",
"meas": {
"CO2": { "name": "Carbon Dioxide Concentration", "unit": "ppm", "unitSuffix": "" }
}
},
"G6":
{
"grpNameShort": "G6",
"grpName": "Noise",
"meas": {
"NOISE": { "name": "Sound Pressure Level", "unit": "dB", "unitSuffix": "" }
}
}
}
20 changes: 0 additions & 20 deletions src/plugins/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,11 @@ import commonMessages from '../locale/common'
const Store = require('electron-store')
const store = new Store()
import { formatLocale } from "../utils"
const fs = require('fs')
// const logger = require("electron-log")

Vue.use(VueI18n)

let initLocale = store.get('selectedLocale') || navigator.language || 'en'

// Update locale message if we have config.json
let filePath = './config.json'
try{
fs.accessSync(filePath, fs.constants.R_OK)
let data = fs.readFileSync(filePath, {
encoding: 'utf8'
})
let cfg = JSON.parse(data)
for (let name in cfg['ngGrpNameTransZh']) {
commonMessages["zh"][name] = cfg['ngGrpNameTransZh'][name]
}
// logger.debug('init locale: ', commonMessages)

} catch(error) {
// logger.warn('error when read config.json:', error)
// logger.warn('skip reading config.json')
}

let i18n = new VueI18n({
locale: formatLocale(initLocale),
fallbackLocale: 'en',
Expand Down
47 changes: 13 additions & 34 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ import VeLine from 'v-charts/lib/line.common'
import { slaveGroupDefines,
miscGroupDefine,
changableUnitsMeasMap,
displayStrForUnit
displayStrForUnit,
ngSkus,
ngSensorTypes,
ngGroupDefines
} from '@/global-defines'
import compareVersions from 'compare-versions'
Expand Down Expand Up @@ -331,14 +334,14 @@ export default {
displaySlaveGroups() {
this.slaveGroups = []
this.slaveGroupShortNames = []
if (this.sensorType !== 'unknown' && this.sensorType in this.ngSensorTypes)
if (this.sensorType !== 'unknown' && this.sensorType in ngSensorTypes)
{
// for gen2 device
for (const grp of this.ngSensorTypes[this.sensorType])
for (const grp of ngSensorTypes[this.sensorType])
{
for (const measName in this.ngGroupDefines[grp]["meas"])
for (const measName in ngGroupDefines[grp]["meas"])
{
this.units[measName] = this.ngGroupDefines[grp]["meas"][measName]["unit"]
this.units[measName] = ngGroupDefines[grp]["meas"][measName]["unit"]
this.values[measName] = "##"
this.dataPoints[measName] = {
columns: ['time', 'value'],
Expand All @@ -347,8 +350,8 @@ export default {
}
//add grp last, because this will trigger the re-render
//before this, units and values should be updated first
this.slaveGroups.push(JSON.parse(JSON.stringify(this.ngGroupDefines[grp]))) //deep copy
this.slaveGroupShortNames.push(this.ngGroupDefines[grp]["grpNameShort"])
this.slaveGroups.push(JSON.parse(JSON.stringify(ngGroupDefines[grp]))) //deep copy
this.slaveGroupShortNames.push(ngGroupDefines[grp]["grpNameShort"])
}
}
else
Expand Down Expand Up @@ -458,30 +461,6 @@ export default {
this.plotPointNum = parseInt(store.get('plotPointNum', 10)) //points
this.pollInterval = parseInt(store.get('dataPollInterval', 2)) //sec
this.ngSkus = {}
this.ngSensorTypes = {}
this.ngGroupDefines = {}
// Can't work if we can not read ng-config(config.json)
try{
// console.log("sendSync read-ng-config")
let result = ipcRenderer.sendSync('read-ng-config')
let ngCfg = JSON.parse(result)
console.log(ngCfg)
if ("ngSkus" in ngCfg && "ngSensorTypes" in ngCfg && "ngGroupDefines" in ngCfg) {
this.ngSkus = ngCfg['ngSkus']
this.ngSensorTypes = ngCfg['ngSensorTypes']
this.ngGroupDefines = ngCfg['ngGroupDefines']
}
else {
console.log('read ng config file error: corruptted')
this.$message.error(this.$t('Failed in reading config.json: corruptted'))
}
} catch(error) {
console.log('read ng config file error:', error)
this.$message.error(this.$t('Failed in reading config.json: not existed'))
}
//init properties for responsive rendering
// for (const i2cAddr in slaveGroupDefines) {
// for (const grp of slaveGroupDefines[i2cAddr]) {
Expand All @@ -495,8 +474,8 @@ export default {
// }
// }
// }
for (const grp in this.ngGroupDefines) {
for (const measName in this.ngGroupDefines[grp]["meas"]) {
for (const grp in ngGroupDefines) {
for (const measName in ngGroupDefines[grp]["meas"]) {
this.$set(this.units, measName, '#')
this.$set(this.values, measName, "##")
this.$set(this.dataPoints, measName, {
Expand Down Expand Up @@ -596,7 +575,7 @@ export default {
this.swVersion = SW
this.dateOfManu = MD
this.devName = NA
if (this.sku in this.ngSkus) this.sensorType = this.ngSkus[this.sku]
if (this.sku in ngSkus) this.sensorType = ngSkus[this.sku]
else this.sensorType = 'unknown' // or gen1 devices
if (this.hIntervalCheckDevInfo) {
Expand Down
57 changes: 18 additions & 39 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,10 @@ import { slaveGroupDefines,
miscGroupDefine,
changableUnitsMeasMap,
displayStrForUnit,
units
units,
ngSkus,
ngSensorTypes,
ngGroupDefines
} from '@/global-defines'
import { compare2Objects } from '@/utils'
import compareVersions from 'compare-versions'
Expand Down Expand Up @@ -1006,13 +1009,13 @@ export default {
// this.configMap.G1 = []
// this.configMap.G2 = []
// this.configMap.G3 = []
if (this.sensorType !== 'unknown' && this.sensorType in this.ngSensorTypes) {
if (this.sensorType !== 'unknown' && this.sensorType in ngSensorTypes) {
// for gen2 device
for (const grp of this.ngSensorTypes[this.sensorType])
for (const grp of ngSensorTypes[this.sensorType])
{
for (const measName in this.ngGroupDefines[grp]["meas"])
for (const measName in ngGroupDefines[grp]["meas"])
{
let optionItem = {value: measName, label: measName + ' - ' + this.$t(this.ngGroupDefines[grp]["meas"][measName]["name"])}
let optionItem = {value: measName, label: measName + ' - ' + this.$t(ngGroupDefines[grp]["meas"][measName]["name"])}
this.optionsG0.push(optionItem)
if (grp === "G1_THP" || grp === "G1_THPL" || grp == "G1_THP_TSR") {
this.optionsS1G1.push(optionItem)
Expand Down Expand Up @@ -1084,13 +1087,13 @@ export default {
this.unitOptions = unitOptions1
this.showG0 = this.optionsG0.length > 0
this.showS1G1 = this.showS1G2 = this.showS1G3 = '1' in this.i2cAddrInCurrentCfg
if (this.sensorType !== 'unknown' && this.sensorType in this.ngSensorTypes) {
if (this.sensorType !== 'unknown' && this.sensorType in ngSensorTypes) {
// for gen2 device
if (this.ngSensorTypes[this.sensorType].indexOf("G4") !== -1) this.showS2G4 = true;
if (ngSensorTypes[this.sensorType].indexOf("G4") !== -1) this.showS2G4 = true;
else this.showS2G4 = false;
if (this.ngSensorTypes[this.sensorType].indexOf("G5") !== -1) this.showS17G5 = true;
if (ngSensorTypes[this.sensorType].indexOf("G5") !== -1) this.showS17G5 = true;
else this.showS17G5 = false;
if (this.ngSensorTypes[this.sensorType].indexOf("G6") !== -1) this.showG6 = true;
if (ngSensorTypes[this.sensorType].indexOf("G6") !== -1) this.showG6 = true;
else this.showG6 = false;
this.showG9 = this.showG9Ht || this.showG9Tilt
this.guiRendered = true
Expand All @@ -1107,12 +1110,12 @@ export default {
async readFromDeviceAsync() {
let regList = [...this.commonRegs]
if (this.sensorType !== 'unknown' && this.sensorType in this.ngSensorTypes) {
if (this.sensorType !== 'unknown' && this.sensorType in ngSensorTypes) {
// for gen2 device
regList = [...regList, ...this.slaveRegs['1']]
if (this.ngSensorTypes[this.sensorType].indexOf("G4") !== -1) regList = [...regList, ...this.slaveRegs['2']]
if (this.ngSensorTypes[this.sensorType].indexOf("G5") !== -1) regList = [...regList, ...this.slaveRegs['17']]
if (this.ngSensorTypes[this.sensorType].indexOf("G6") !== -1) regList = [...regList, ...this.slaveRegs['18']]
if (ngSensorTypes[this.sensorType].indexOf("G4") !== -1) regList = [...regList, ...this.slaveRegs['2']]
if (ngSensorTypes[this.sensorType].indexOf("G5") !== -1) regList = [...regList, ...this.slaveRegs['17']]
if (ngSensorTypes[this.sensorType].indexOf("G6") !== -1) regList = [...regList, ...this.slaveRegs['18']]
}
else {
// for gen1 device
Expand Down Expand Up @@ -1525,30 +1528,6 @@ export default {
//load config
this.appConfig.dataPollInterval = parseInt(store.get('dataPollInterval', 2))
this.appConfig.plotPointNum = parseInt(store.get('plotPointNum', 10))
this.ngSkus = {}
this.ngSensorTypes = {}
this.ngGroupDefines = {}
// Can't work if we can not read ng-config(config.json)
try{
// console.log("sendSync read-ng-config")
let result = ipcRenderer.sendSync('read-ng-config')
let ngCfg = JSON.parse(result)
console.log(ngCfg)
if ("ngSkus" in ngCfg && "ngSensorTypes" in ngCfg && "ngGroupDefines" in ngCfg) {
this.ngSkus = ngCfg['ngSkus']
this.ngSensorTypes = ngCfg['ngSensorTypes']
this.ngGroupDefines = ngCfg['ngGroupDefines']
}
else {
console.log('read ng config file error: corruptted')
this.$message.error(this.$t('Failed in reading config.json: corruptted'))
}
} catch(error) {
console.log('read ng config file error:', error)
this.$message.error(this.$t('Failed in reading config.json: not existed'))
}
},
mounted() {
//ap-addr-got
Expand Down Expand Up @@ -1597,7 +1576,7 @@ export default {
this.hwVersion = HW
this.swVersion = SW
this.devName = NA
if (this.sku in this.ngSkus) this.sensorType = this.ngSkus[this.sku]
if (this.sku in ngSkus) this.sensorType = ngSkus[this.sku]
else this.sensorType = 'unknown' // or gen1 devices
console.log("hwVersion: ", this.hwVersion)
console.log("sensorType: ", this.sensorType)
Expand All @@ -1613,7 +1592,7 @@ export default {
this.hwVersion = HW
this.swVersion = SW
this.devName = NA
if (this.sku in this.ngSkus) this.sensorType = this.ngSkus[this.sku]
if (this.sku in ngSkus) this.sensorType = ngSkus[this.sku]
else this.sensorType = 'unknown' // or gen1 devices
console.log("dev-info-got hwVersion: ", this.hwVersion)
console.log("dev-info-got sensorType: ", this.sensorType)
Expand Down
6 changes: 0 additions & 6 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ module.exports = {
'appId': 'cc.seeed.sensecap.tools.one',
'productName': 'SenseCAP One Configuration Tool',
'copyright': 'Copyright ©2008-2024 Seeed Technology Co.,Ltd.',
'extraFiles':[
{
'from':'./config.json',
'to':'.',
}
],
'nsis': {
'installerIcon': 'build/icon.ico',
'installerHeader': 'build/icon.png',
Expand Down

0 comments on commit dad68b6

Please sign in to comment.