Skip to content

Commit cc23be2

Browse files
committed
frontend part :)
1 parent 23ef00c commit cc23be2

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

background_tasks/linker.html

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
case 'SENSORS_SCAN':
6060
ipcRenderer.send('SENSORS_SCAN', { data: parsedJSON.data });
6161
break;
62+
case 'SENSORS_READ':
63+
ipcRenderer.send('SENSORS_READ', { data: parsedJSON.data });
64+
break;
6265
case 'START_MUL_MET':
6366
ipcRenderer.send('MUL_MET_DATA', { data: parsedJSON.data, prefix: parsedJSON.prefix });
6467
break;

public/electron.js

+4
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ ipcMain.on('FETCH_LA', (event, args) => {
149149
ipcMain.on('SENSORS_SCAN', (event, args) => {
150150
mainWindow.webContents.send('SENSORS_SCAN', args);
151151
});
152+
153+
ipcMain.on('SENSORS_READ', (event, args) => {
154+
mainWindow.webContents.send('SENSORS_READ', args);
155+
});

scripts/sensors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def read(self):
4747
data = sensor.getRaw()
4848

4949
self.file_write.update_buffer(
50-
"SENSORS", timestamp=timestamp, datetime=datetime_data, data='scan', value=data)
50+
"SENSOR_DATA", timestamp=timestamp, datetime=datetime_data, data='sensor_data', value=data)
5151
time.sleep(0.25)
5252

5353
output = {'type': 'SENSORS_READ', 'data': data}

src/screen/Sensors/Sensors.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@ const knownSensors = [
4040
id: 0x68,
4141
name: 'MPU6050',
4242
},
43+
{
44+
id: 0x29,
45+
name: 'VL53LXX', // TODO: implement in Python lib
46+
description: 'Time-of-flight',
47+
},
4348
{
4449
id: 0x40,
4550
name: 'SHT21',
51+
description: 'Temperature and humidity',
4652
},
4753
{
4854
id: 0x49,
@@ -61,7 +67,9 @@ const SensorList = ({ sensors = [], onReadSensor = () => {} }) => (
6167
{sensors.map((item, index) => {
6268
return (
6369
<SensorTab key={index} onClick={() => onReadSensor(item)}>
64-
<SensorTitle>{item.name}</SensorTitle>
70+
<SensorTitle>
71+
{item.name} {item.description}
72+
</SensorTitle>
6573
</SensorTab>
6674
);
6775
})}
@@ -77,6 +85,7 @@ class Sensors extends Component {
7785
isScanned: false,
7886
sensorList: [],
7987
data: null,
88+
sensorData: null,
8089
};
8190
}
8291

@@ -96,11 +105,18 @@ class Sensors extends Component {
96105
sensorList: filterKnownSensors(args.data),
97106
});
98107
});
108+
ipcRenderer.on('SENSORS_READ', (event, args) => {
109+
this.setState({
110+
isScanned: true,
111+
sensorData: args.data,
112+
});
113+
});
99114
// this.getConfigFromDevice();
100115
}
101116

102117
componentWillUnmount() {
103118
ipcRenderer.removeAllListeners('SENSORS_SCAN');
119+
ipcRenderer.removeAllListeners('SENSORS_READ');
104120
}
105121

106122
getConfigFromDevice = debounce(() => {
@@ -118,8 +134,20 @@ class Sensors extends Component {
118134
command: 'SENSORS_SCAN',
119135
});
120136
}, 500);
137+
138+
onReadSensor = debounce(sensor => {
139+
// TODO: use sensor and implement switch over it
140+
// TODO: can we find a generic interface?
141+
console.info({ sensor });
142+
const { isConnected } = this.props;
143+
isConnected &&
144+
loadBalancer.sendData(ipcRenderer, 'linker', {
145+
command: 'SENSORS_READ',
146+
});
147+
}, 500);
148+
121149
render() {
122-
const { data, isScanned, sensorList } = this.state;
150+
const { data, isScanned, sensorList, sensorData } = this.state;
123151

124152
return (
125153
<Container>
@@ -140,12 +168,13 @@ class Sensors extends Component {
140168
<TitleWrapper>Detected sensors</TitleWrapper>
141169
<SensorList
142170
sensors={sensorList}
143-
onReadSensor={sensor => console.info({ sensor })}
171+
onReadSensor={this.onReadSensor}
144172
/>
145173
</>
146174
) : (
147175
<TitleWrapper>No sensors detected</TitleWrapper>
148176
))}
177+
Sensor data: <pre>{JSON.stringify(sensorData)}</pre>
149178
<TitleWrapper>Known sensors</TitleWrapper>
150179
<SensorList sensors={knownSensors} />
151180
<pre>{JSON.stringify(data)}</pre>

src/screen/Sensors/styles.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const Container = styled.div`
55
display: flex;
66
flex-direction: column;
77
align-items: center;
8+
background-color: ${props => props.theme.common.white};
89
`;
910

1011
export const Wrapper = styled.div`

0 commit comments

Comments
 (0)