Skip to content

Commit

Permalink
frontend part :)
Browse files Browse the repository at this point in the history
  • Loading branch information
orangecms committed Feb 20, 2021
1 parent c55cbb7 commit b2b4590
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
3 changes: 3 additions & 0 deletions background_tasks/linker.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
2 changes: 1 addition & 1 deletion scripts/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
35 changes: 32 additions & 3 deletions src/screen/Sensors/Sensors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -61,7 +67,9 @@ const SensorList = ({ sensors = [], onReadSensor = () => {} }) => (
{sensors.map((item, index) => {
return (
<SensorTab key={index} onClick={() => onReadSensor(item)}>
<SensorTitle>{item.name}</SensorTitle>
<SensorTitle>
{item.name} {item.description}
</SensorTitle>
</SensorTab>
);
})}
Expand All @@ -77,6 +85,7 @@ class Sensors extends Component {
isScanned: false,
sensorList: [],
data: null,
sensorData: null,
};
}

Expand All @@ -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(() => {
Expand All @@ -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 (
<Container>
Expand All @@ -140,12 +168,13 @@ class Sensors extends Component {
<TitleWrapper>Detected sensors</TitleWrapper>
<SensorList
sensors={sensorList}
onReadSensor={sensor => console.info({ sensor })}
onReadSensor={this.onReadSensor}
/>
</>
) : (
<TitleWrapper>No sensors detected</TitleWrapper>
))}
Sensor data: <pre>{JSON.stringify(sensorData)}</pre>
<TitleWrapper>Known sensors</TitleWrapper>
<SensorList sensors={knownSensors} />
<pre>{JSON.stringify(data)}</pre>
Expand Down
1 change: 1 addition & 0 deletions src/screen/Sensors/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit b2b4590

Please sign in to comment.