diff --git a/background_tasks/linker.html b/background_tasks/linker.html index 219e4e69..d6fe24e9 100644 --- a/background_tasks/linker.html +++ b/background_tasks/linker.html @@ -58,6 +58,9 @@ case 'SENSORS_SCAN': ipcRenderer.send('SENSORS_SCAN', { data: parsedJSON.data }); break; + case 'SENSORS_READ': + ipcRenderer.send('SENSORS_READ', { data: parsedJSON.data }); + break; case 'START_MUL_MET': ipcRenderer.send('MUL_MET_DATA', { data: parsedJSON.data, prefix: parsedJSON.prefix }); break; diff --git a/public/electron.js b/public/electron.js index 8b438b1d..43dd5296 100644 --- a/public/electron.js +++ b/public/electron.js @@ -149,3 +149,7 @@ ipcMain.on('FETCH_LA', (event, args) => { ipcMain.on('SENSORS_SCAN', (event, args) => { mainWindow.webContents.send('SENSORS_SCAN', args); }); + +ipcMain.on('SENSORS_READ', (event, args) => { + mainWindow.webContents.send('SENSORS_READ', args); +}); diff --git a/scripts/sensors.py b/scripts/sensors.py index 55613021..9861049d 100644 --- a/scripts/sensors.py +++ b/scripts/sensors.py @@ -47,7 +47,7 @@ def read(self): data = sensor.getRaw() self.file_write.update_buffer( - "SENSORS", timestamp=timestamp, datetime=datetime_data, data='scan', value=data) + "SENSOR_DATA", timestamp=timestamp, datetime=datetime_data, data='sensor_data', value=data) time.sleep(0.25) output = {'type': 'SENSORS_READ', 'data': data} diff --git a/src/screen/Sensors/Sensors.js b/src/screen/Sensors/Sensors.js index 33ca1331..645d4ef1 100644 --- a/src/screen/Sensors/Sensors.js +++ b/src/screen/Sensors/Sensors.js @@ -40,9 +40,15 @@ const knownSensors = [ id: 0x68, name: 'MPU6050', }, + { + id: 0x29, + name: 'VL53LXX', // TODO: implement in Python lib + description: 'Time-of-flight', + }, { id: 0x40, name: 'SHT21', + description: 'Temperature and humidity', }, { id: 0x49, @@ -61,7 +67,9 @@ const SensorList = ({ sensors = [], onReadSensor = () => {} }) => ( {sensors.map((item, index) => { return ( onReadSensor(item)}> - {item.name} + + {item.name} {item.description} + ); })} @@ -77,6 +85,7 @@ class Sensors extends Component { isScanned: false, sensorList: [], data: null, + sensorData: null, }; } @@ -96,11 +105,18 @@ class Sensors extends Component { sensorList: filterKnownSensors(args.data), }); }); + ipcRenderer.on('SENSORS_READ', (event, args) => { + this.setState({ + isScanned: true, + sensorData: args.data, + }); + }); // this.getConfigFromDevice(); } componentWillUnmount() { ipcRenderer.removeAllListeners('SENSORS_SCAN'); + ipcRenderer.removeAllListeners('SENSORS_READ'); } getConfigFromDevice = debounce(() => { @@ -118,8 +134,20 @@ class Sensors extends Component { command: 'SENSORS_SCAN', }); }, 500); + + onReadSensor = debounce(sensor => { + // TODO: use sensor and implement switch over it + // TODO: can we find a generic interface? + console.info({ sensor }); + const { isConnected } = this.props; + isConnected && + loadBalancer.sendData(ipcRenderer, 'linker', { + command: 'SENSORS_READ', + }); + }, 500); + render() { - const { data, isScanned, sensorList } = this.state; + const { data, isScanned, sensorList, sensorData } = this.state; return ( @@ -140,12 +168,13 @@ class Sensors extends Component { Detected sensors console.info({ sensor })} + onReadSensor={this.onReadSensor} /> ) : ( No sensors detected ))} + Sensor data:
{JSON.stringify(sensorData)}
Known sensors
{JSON.stringify(data)}
diff --git a/src/screen/Sensors/styles.js b/src/screen/Sensors/styles.js index 3a61b4db..cd0d0d0f 100644 --- a/src/screen/Sensors/styles.js +++ b/src/screen/Sensors/styles.js @@ -5,6 +5,7 @@ export const Container = styled.div` display: flex; flex-direction: column; align-items: center; + background-color: ${props => props.theme.common.white}; `; export const Wrapper = styled.div`