diff --git a/plugins/shure/main.js b/plugins/shure/main.js index f63b0e6..13f2134 100644 --- a/plugins/shure/main.js +++ b/plugins/shure/main.js @@ -15,17 +15,6 @@ exports.config = { return msg.toString().indexOf('DEVICE_ID'); }, }, - fields: [ - { - key: 'chanCount', - label: 'Chan', - type: 'textinput', - value: '4', - action(device) { - // device.plugin.heartbeat(device); - }, - }, - ], }; const blankChannel = { @@ -45,7 +34,9 @@ const blankChannel = { rx_rf_lvl: 0, }; -exports.ready = function ready(device) { +exports.ready = function ready(_device) { + const device = _device; + device.data.channelCount = 0; device.data.channels = [ {}, _.clone(blankChannel), @@ -55,7 +46,8 @@ exports.ready = function ready(device) { ]; }; -exports.data = function data(device, message) { +exports.data = function data(_device, message) { + const device = _device; let msgStr = message.toString(); if (!msgStr.startsWith('< ')) { @@ -65,59 +57,60 @@ exports.data = function data(device, message) { msgStr = msgStr.slice(2).slice(0, -1); const msgs = msgStr.split('><'); - msgs.forEach((msg, i) => { - msg = msg.trim(); + msgs.forEach((ms, i) => { + const msg = ms.trim(); const m = msg.split(' '); + const chi = Number(m[1]); + const ch = device.data.channels[chi]; - // console.log(msg); - - const ch = device.data.channels[Number(m[1])]; - - // console.log(m); - - if (m[0] == 'REP') { - if (m[2] == 'CHAN_NAME') { + if (m[0] === 'REP') { + if (m[2] === 'CHAN_NAME') { ch.chan_name = msg.substring(17).slice(0, -2).trim(); - } else if (m[2] == 'BATT_RUN_TIME') { + if (device.data.channelCount < chi) { + device.data.channelCount = chi; + } + device.draw(); + } else if (m[2] === 'BATT_RUN_TIME') { ch.batt_run_time = Number(m[3]); - } else if (m[2] == 'BATT_TEMP_F') { + } else if (m[2] === 'BATT_TEMP_F') { ch.batt_temp_f = Number(m[3]); - } else if (m[2] == 'BATT_HEALTH') { + } else if (m[2] === 'BATT_HEALTH') { ch.batt_health = Number(m[3]); - } else if (m[2] == 'BATT_BARS') { + } else if (m[2] === 'BATT_BARS') { ch.batt_bars = Number(m[3]); - } else if (m[2] == 'AUDIO_GAIN') { + } else if (m[2] === 'AUDIO_GAIN') { ch.audio_gain = Number(m[3]) - 18; - } else if (m[2] == 'AUDIO_MUTE') { + } else if (m[2] === 'AUDIO_MUTE') { ch.audio_mute = m[3]; - } else if (m[2] == 'TX_MUTE_BUTTON_STATUS') { + } else if (m[2] === 'TX_MUTE_BUTTON_STATUS') { ch.tx_mute_button_status = m[3]; - } else if (m[2] == 'AUDIO_LVL') { + } else if (m[2] === 'AUDIO_LVL') { ch.audio_lvl = Number(m[3]); - } else if (m[2] == 'RX_RF_LVL') { + } else if (m[2] === 'RX_RF_LVL') { ch.rx_rf_lvl = Number(m[3]) - 128; - } else if (m[2] == 'RF_ANTENNA') { + } else if (m[2] === 'RF_ANTENNA') { ch.rf_antenna = m[3]; - } else if (m[2] == 'TX_TYPE') { + } else if (m[2] === 'TX_TYPE') { ch.tx_type = m[3]; - } else if (m[1] == 'DEVICE_ID') { + } else if (m[1] === 'DEVICE_ID') { const id = msg.substring(15).slice(0, -1).trim(); this.deviceInfoUpdate(device, 'defaultName', id); - } else if (m[1] == 'FW_VER') { + } else if (m[1] === 'FW_VER') { device.data.version = m[2].substring(1); } - } else if (m[0] == 'SAMPLE') { + } else if (m[0] === 'SAMPLE') { ch.rf_antenna = m[3]; ch.rx_rf_lvl = Number(m[4]) - 128; ch.audio_lvl = Number(m[5]); + if (chi === 4) { + device.draw(); + } } }); - - device.draw(); }; exports.heartbeat = function heartbeat(device) { device.send('< GET 0 ALL >'); - device.send('< SET 0 METER_RATE 00200 >'); + device.send('< SET 0 METER_RATE 00100 >'); device.send('< SAMPLE 0 AUDIO_LVL>'); };