@robdobsn/raftjs 1.7.8 → 1.10.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +14 -0
- package/.gitattributes +11 -0
- package/.nvmrc +1 -0
- package/TODO.md +1 -0
- package/dist/react-native/RaftAttributeHandler.d.ts +14 -0
- package/dist/react-native/RaftAttributeHandler.js +375 -0
- package/dist/react-native/RaftAttributeHandler.js.map +1 -0
- package/dist/react-native/RaftChannel.d.ts +20 -0
- package/dist/react-native/RaftChannel.js +12 -0
- package/dist/react-native/RaftChannel.js.map +1 -0
- package/dist/react-native/RaftChannelBLE.native.d.ts +95 -0
- package/dist/react-native/RaftChannelBLE.native.js +483 -0
- package/dist/react-native/RaftChannelBLE.native.js.map +1 -0
- package/dist/react-native/RaftChannelBLE.web.d.ts +40 -0
- package/dist/react-native/RaftChannelBLE.web.js +302 -0
- package/dist/react-native/RaftChannelBLE.web.js.map +1 -0
- package/dist/react-native/RaftChannelBLEFactory.d.ts +10 -0
- package/dist/react-native/RaftChannelBLEFactory.js +17 -0
- package/dist/react-native/RaftChannelBLEFactory.js.map +1 -0
- package/dist/react-native/RaftChannelBLEScanner.native.d.ts +18 -0
- package/dist/react-native/RaftChannelBLEScanner.native.js +138 -0
- package/dist/react-native/RaftChannelBLEScanner.native.js.map +1 -0
- package/dist/react-native/RaftChannelSimulated.d.ts +42 -0
- package/dist/react-native/RaftChannelSimulated.js +1000 -0
- package/dist/react-native/RaftChannelSimulated.js.map +1 -0
- package/dist/react-native/RaftChannelWebSerial.d.ts +39 -0
- package/dist/react-native/RaftChannelWebSerial.js +329 -0
- package/dist/react-native/RaftChannelWebSerial.js.map +1 -0
- package/dist/react-native/RaftChannelWebSocket.d.ts +30 -0
- package/dist/react-native/RaftChannelWebSocket.js +222 -0
- package/dist/react-native/RaftChannelWebSocket.js.map +1 -0
- package/dist/react-native/RaftCommsStats.d.ts +39 -0
- package/dist/react-native/RaftCommsStats.js +128 -0
- package/dist/react-native/RaftCommsStats.js.map +1 -0
- package/dist/react-native/RaftConnEvents.d.ts +39 -0
- package/dist/react-native/RaftConnEvents.js +54 -0
- package/dist/react-native/RaftConnEvents.js.map +1 -0
- package/dist/react-native/RaftConnector.d.ts +248 -0
- package/dist/react-native/RaftConnector.js +658 -0
- package/dist/react-native/RaftConnector.js.map +1 -0
- package/dist/react-native/RaftCustomAttrHandler.d.ts +6 -0
- package/dist/react-native/RaftCustomAttrHandler.js +93 -0
- package/dist/react-native/RaftCustomAttrHandler.js.map +1 -0
- package/dist/react-native/RaftDeviceInfo.d.ts +71 -0
- package/dist/react-native/RaftDeviceInfo.js +50 -0
- package/dist/react-native/RaftDeviceInfo.js.map +1 -0
- package/dist/react-native/RaftDeviceManager.d.ts +61 -0
- package/dist/react-native/RaftDeviceManager.js +665 -0
- package/dist/react-native/RaftDeviceManager.js.map +1 -0
- package/dist/react-native/RaftDeviceMgrIF.d.ts +15 -0
- package/dist/react-native/RaftDeviceMgrIF.js +11 -0
- package/dist/react-native/RaftDeviceMgrIF.js.map +1 -0
- package/dist/react-native/RaftDeviceMsg.d.ts +9 -0
- package/dist/react-native/RaftDeviceMsg.js +11 -0
- package/dist/react-native/RaftDeviceMsg.js.map +1 -0
- package/dist/react-native/RaftDeviceStates.d.ts +37 -0
- package/dist/react-native/RaftDeviceStates.js +60 -0
- package/dist/react-native/RaftDeviceStates.js.map +1 -0
- package/dist/react-native/RaftFileHandler.d.ts +52 -0
- package/dist/react-native/RaftFileHandler.js +502 -0
- package/dist/react-native/RaftFileHandler.js.map +1 -0
- package/dist/react-native/RaftLog.d.ts +22 -0
- package/dist/react-native/RaftLog.js +63 -0
- package/dist/react-native/RaftLog.js.map +1 -0
- package/dist/react-native/RaftMiniHDLC.d.ts +18 -0
- package/dist/react-native/RaftMiniHDLC.js +383 -0
- package/dist/react-native/RaftMiniHDLC.js.map +1 -0
- package/dist/react-native/RaftMsgHandler.d.ts +62 -0
- package/dist/react-native/RaftMsgHandler.js +511 -0
- package/dist/react-native/RaftMsgHandler.js.map +1 -0
- package/dist/react-native/RaftMsgTrackInfo.d.ts +17 -0
- package/dist/react-native/RaftMsgTrackInfo.js +42 -0
- package/dist/react-native/RaftMsgTrackInfo.js.map +1 -0
- package/dist/react-native/RaftProtocolDefs.d.ts +30 -0
- package/dist/react-native/RaftProtocolDefs.js +48 -0
- package/dist/react-native/RaftProtocolDefs.js.map +1 -0
- package/dist/react-native/RaftStreamHandler.d.ts +38 -0
- package/dist/react-native/RaftStreamHandler.js +258 -0
- package/dist/react-native/RaftStreamHandler.js.map +1 -0
- package/dist/react-native/RaftStruct.d.ts +3 -0
- package/dist/react-native/RaftStruct.js +258 -0
- package/dist/react-native/RaftStruct.js.map +1 -0
- package/dist/react-native/RaftSysTypeManager.d.ts +16 -0
- package/dist/react-native/RaftSysTypeManager.js +78 -0
- package/dist/react-native/RaftSysTypeManager.js.map +1 -0
- package/dist/react-native/RaftSystemType.d.ts +30 -0
- package/dist/react-native/RaftSystemType.js +3 -0
- package/dist/react-native/RaftSystemType.js.map +1 -0
- package/dist/react-native/RaftSystemUtils.d.ts +136 -0
- package/dist/react-native/RaftSystemUtils.js +412 -0
- package/dist/react-native/RaftSystemUtils.js.map +1 -0
- package/dist/react-native/RaftTypes.d.ts +195 -0
- package/dist/react-native/RaftTypes.js +153 -0
- package/dist/react-native/RaftTypes.js.map +1 -0
- package/dist/react-native/RaftUpdateEvents.d.ts +33 -0
- package/dist/react-native/RaftUpdateEvents.js +46 -0
- package/dist/react-native/RaftUpdateEvents.js.map +1 -0
- package/dist/react-native/RaftUpdateManager.d.ts +61 -0
- package/dist/react-native/RaftUpdateManager.js +621 -0
- package/dist/react-native/RaftUpdateManager.js.map +1 -0
- package/dist/react-native/RaftUtils.d.ts +128 -0
- package/dist/react-native/RaftUtils.js +487 -0
- package/dist/react-native/RaftUtils.js.map +1 -0
- package/dist/react-native/RaftWifiTypes.d.ts +23 -0
- package/dist/react-native/RaftWifiTypes.js +43 -0
- package/dist/react-native/RaftWifiTypes.js.map +1 -0
- package/dist/react-native/main.d.ts +26 -0
- package/dist/react-native/main.js +51 -0
- package/dist/react-native/main.js.map +1 -0
- package/dist/web/RaftAttributeHandler.js +9 -6
- package/dist/web/RaftAttributeHandler.js.map +1 -1
- package/dist/web/RaftChannelBLE.web.js +8 -6
- package/dist/web/RaftChannelBLE.web.js.map +1 -1
- package/dist/web/RaftChannelSimulated.d.ts +10 -0
- package/dist/web/RaftChannelSimulated.js +662 -80
- package/dist/web/RaftChannelSimulated.js.map +1 -1
- package/dist/web/RaftChannelWebSerial.js +2 -2
- package/dist/web/RaftChannelWebSerial.js.map +1 -1
- package/dist/web/RaftChannelWebSocket.js +16 -1
- package/dist/web/RaftChannelWebSocket.js.map +1 -1
- package/dist/web/RaftConnector.d.ts +2 -0
- package/dist/web/RaftConnector.js +38 -15
- package/dist/web/RaftConnector.js.map +1 -1
- package/dist/web/RaftCustomAttrHandler.d.ts +2 -0
- package/dist/web/RaftCustomAttrHandler.js +54 -26
- package/dist/web/RaftCustomAttrHandler.js.map +1 -1
- package/dist/web/RaftDeviceInfo.d.ts +3 -1
- package/dist/web/RaftDeviceInfo.js +17 -3
- package/dist/web/RaftDeviceInfo.js.map +1 -1
- package/dist/web/RaftDeviceManager.d.ts +22 -1
- package/dist/web/RaftDeviceManager.js +210 -44
- package/dist/web/RaftDeviceManager.js.map +1 -1
- package/dist/web/RaftDeviceStates.d.ts +1 -1
- package/dist/web/RaftDeviceStates.js +2 -2
- package/dist/web/RaftDeviceStates.js.map +1 -1
- package/dist/web/RaftMsgHandler.js.map +1 -1
- package/dist/web/RaftStreamHandler.js +2 -1
- package/dist/web/RaftStreamHandler.js.map +1 -1
- package/dist/web/RaftStruct.js +197 -147
- package/dist/web/RaftStruct.js.map +1 -1
- package/dist/web/RaftUpdateManager.js +1 -1
- package/dist/web/RaftUpdateManager.js.map +1 -1
- package/dist/web/RaftUtils.d.ts +2 -0
- package/dist/web/RaftUtils.js +20 -0
- package/dist/web/RaftUtils.js.map +1 -1
- package/dist/web/main.d.ts +1 -0
- package/dist/web/main.js.map +1 -1
- package/eslint.config.mjs +33 -0
- package/examples/dashboard/package.json +36 -0
- package/examples/dashboard/src/CommandPanel.tsx +147 -0
- package/examples/dashboard/src/ConnManager.ts +166 -0
- package/examples/dashboard/src/DeviceActionsForm.tsx +133 -0
- package/examples/dashboard/src/DeviceAttrsForm.tsx +49 -0
- package/examples/dashboard/src/DeviceLineChart.tsx +163 -0
- package/examples/dashboard/src/DevicePanel.tsx +171 -0
- package/examples/dashboard/src/DevicesPanel.tsx +58 -0
- package/examples/dashboard/src/DispLedGrid.tsx +110 -0
- package/examples/dashboard/src/DispOneLed.tsx +20 -0
- package/examples/dashboard/src/LatencyTest.ts +130 -0
- package/examples/dashboard/src/LatencyTestPanel.tsx +92 -0
- package/examples/dashboard/src/Main.tsx +234 -0
- package/examples/dashboard/src/SettingsManager.ts +67 -0
- package/examples/dashboard/src/SettingsScreen.tsx +174 -0
- package/examples/dashboard/src/StatusPanel.tsx +71 -0
- package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +162 -0
- package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +91 -0
- package/examples/dashboard/src/SystemTypeGeneric/StateInfoGeneric.ts +30 -0
- package/examples/dashboard/src/SystemTypeGeneric/SystemTypeGeneric.ts +91 -0
- package/examples/dashboard/src/SystemTypeMarty/RICAddOn.ts +70 -0
- package/examples/dashboard/src/SystemTypeMarty/RICAddOnBase.ts +33 -0
- package/examples/dashboard/src/SystemTypeMarty/RICAddOnManager.ts +342 -0
- package/examples/dashboard/src/SystemTypeMarty/RICCommsStats.ts +170 -0
- package/examples/dashboard/src/SystemTypeMarty/RICHWElem.ts +123 -0
- package/examples/dashboard/src/SystemTypeMarty/RICLEDPatternChecker.ts +207 -0
- package/examples/dashboard/src/SystemTypeMarty/RICROSSerial.ts +464 -0
- package/examples/dashboard/src/SystemTypeMarty/RICServoFaultDetector.ts +146 -0
- package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +97 -0
- package/examples/dashboard/src/SystemTypeMarty/RICSystemUtils.ts +371 -0
- package/examples/dashboard/src/SystemTypeMarty/RICTypes.ts +20 -0
- package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +119 -0
- package/examples/dashboard/src/index.html +15 -0
- package/examples/dashboard/src/index.tsx +13 -0
- package/examples/dashboard/src/styles.css +408 -0
- package/examples/dashboard/tsconfig.json +18 -0
- package/jest.config.js +11 -0
- package/package.json +4 -7
- package/src/RaftAttributeHandler.ts +450 -0
- package/src/RaftChannel.ts +32 -0
- package/src/RaftChannelBLE.native.ts +617 -0
- package/src/RaftChannelBLE.web.ts +374 -0
- package/src/RaftChannelBLEFactory.ts +13 -0
- package/src/RaftChannelBLEScanner.native.ts +184 -0
- package/src/RaftChannelSimulated.ts +1176 -0
- package/src/RaftChannelWebSerial.ts +420 -0
- package/src/RaftChannelWebSocket.ts +272 -0
- package/src/RaftCommsStats.ts +142 -0
- package/src/RaftConnEvents.ts +58 -0
- package/src/RaftConnector.ts +785 -0
- package/src/RaftCustomAttrHandler.ts +117 -0
- package/src/RaftDeviceInfo.ts +125 -0
- package/src/RaftDeviceManager.ts +844 -0
- package/src/RaftDeviceMgrIF.ts +33 -0
- package/src/RaftDeviceMsg.ts +20 -0
- package/src/RaftDeviceStates.ts +92 -0
- package/src/RaftFileHandler.ts +668 -0
- package/src/RaftLog.ts +70 -0
- package/src/RaftMiniHDLC.ts +396 -0
- package/src/RaftMsgHandler.ts +812 -0
- package/src/RaftMsgTrackInfo.ts +51 -0
- package/src/RaftProtocolDefs.ts +46 -0
- package/src/RaftStreamHandler.ts +329 -0
- package/src/RaftStruct.ts +282 -0
- package/src/RaftSysTypeManager.ts +87 -0
- package/src/RaftSystemType.ts +34 -0
- package/src/RaftSystemUtils.ts +489 -0
- package/src/RaftTypes.ts +279 -0
- package/src/RaftUpdateEvents.ts +48 -0
- package/src/RaftUpdateManager.ts +781 -0
- package/src/RaftUtils.ts +514 -0
- package/src/RaftWifiTypes.ts +36 -0
- package/src/main.ts +39 -0
- package/testdata/TestDeviceTypeRecs.json +492 -0
- package/tsconfig.json +30 -0
- package/tsconfig.react-native.json +29 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import ConnManager from './ConnManager';
|
|
3
|
+
import { DeviceTypeAction } from '../../../src/RaftDeviceInfo';
|
|
4
|
+
import DispLEDGrid from './DispLedGrid';
|
|
5
|
+
|
|
6
|
+
const connManager = ConnManager.getInstance();
|
|
7
|
+
|
|
8
|
+
type DeviceActionsTableProps = {
|
|
9
|
+
deviceKey: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
interface InputValues {
|
|
13
|
+
[key: string]: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const DeviceActionsForm: React.FC<DeviceActionsTableProps> = ({ deviceKey }: DeviceActionsTableProps) => {
|
|
17
|
+
const deviceManager = connManager.getConnector().getSystemType()?.deviceMgrIF;
|
|
18
|
+
const [deviceActions, setDeviceActions] = useState<DeviceTypeAction[]>([]);
|
|
19
|
+
const [inputValues, setInputValues] = useState<InputValues>({});
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!deviceManager) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Wait a little while inline for the device to be ready
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
const deviceState = deviceManager.getDeviceState(deviceKey);
|
|
28
|
+
const { deviceTypeInfo } = deviceState;
|
|
29
|
+
const actions: DeviceTypeAction[] = deviceTypeInfo?.actions || [];
|
|
30
|
+
setDeviceActions(actions);
|
|
31
|
+
// Initialize input values
|
|
32
|
+
const initialValues: InputValues = actions.reduce((acc, action) => {
|
|
33
|
+
acc[action.n] =
|
|
34
|
+
action.d ??
|
|
35
|
+
(action.r
|
|
36
|
+
? action.r.length > 1
|
|
37
|
+
? (action.r[1] + action.r[0]) / 2
|
|
38
|
+
: 0
|
|
39
|
+
: 0);
|
|
40
|
+
return acc;
|
|
41
|
+
}, {} as InputValues);
|
|
42
|
+
setInputValues(initialValues);
|
|
43
|
+
}, 1000);
|
|
44
|
+
}, [deviceKey]);
|
|
45
|
+
|
|
46
|
+
const handleInputChange = (name: string, value: number) => {
|
|
47
|
+
setInputValues((prevValues: any) => ({
|
|
48
|
+
...prevValues,
|
|
49
|
+
[name]: value,
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleSendAction = (action: DeviceTypeAction, value: number) => {
|
|
54
|
+
// Send action to device
|
|
55
|
+
if (!deviceManager) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
deviceManager.sendAction(deviceKey, action, [value]);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
if (deviceActions.length === 0) {
|
|
62
|
+
return <></>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className="device-actions-form">
|
|
67
|
+
<table>
|
|
68
|
+
<thead>
|
|
69
|
+
<tr>
|
|
70
|
+
<th>Name</th>
|
|
71
|
+
<th>Value</th>
|
|
72
|
+
<th>Send</th>
|
|
73
|
+
</tr>
|
|
74
|
+
</thead>
|
|
75
|
+
<tbody>
|
|
76
|
+
{deviceActions.map((action) => {
|
|
77
|
+
if (action.f === "LEDPIX") {
|
|
78
|
+
return (
|
|
79
|
+
<tr key={action.n}>
|
|
80
|
+
<td>{action.n}</td>
|
|
81
|
+
<td colSpan={2}>
|
|
82
|
+
<DispLEDGrid
|
|
83
|
+
rows={action.NY || 1}
|
|
84
|
+
cols={action.NX || 1}
|
|
85
|
+
deviceKey={deviceKey}
|
|
86
|
+
deviceAction={action}
|
|
87
|
+
/>
|
|
88
|
+
</td>
|
|
89
|
+
</tr>
|
|
90
|
+
);
|
|
91
|
+
} else {
|
|
92
|
+
return (
|
|
93
|
+
<tr key={action.n}>
|
|
94
|
+
<td>{action.n}</td>
|
|
95
|
+
<td>
|
|
96
|
+
{action.t ? (
|
|
97
|
+
<input
|
|
98
|
+
type="number"
|
|
99
|
+
min={action.r?.[0] ?? 0}
|
|
100
|
+
max={action.r?.[1] ?? 100}
|
|
101
|
+
value={inputValues[action.n]}
|
|
102
|
+
onChange={(e) =>
|
|
103
|
+
handleInputChange(
|
|
104
|
+
action.n,
|
|
105
|
+
parseInt(e.target.value, 10)
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
/>
|
|
109
|
+
) : null}
|
|
110
|
+
</td>
|
|
111
|
+
<td>
|
|
112
|
+
<button
|
|
113
|
+
onClick={() =>
|
|
114
|
+
handleSendAction(
|
|
115
|
+
action,
|
|
116
|
+
inputValues[action.n]
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
>
|
|
120
|
+
Send
|
|
121
|
+
</button>
|
|
122
|
+
</td>
|
|
123
|
+
</tr>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
})}
|
|
127
|
+
</tbody>
|
|
128
|
+
</table>
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export default DeviceActionsForm;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { deviceAttrGetLatestFormatted, DeviceState } from '../../../src/RaftDeviceStates';
|
|
3
|
+
import ConnManager from './ConnManager';
|
|
4
|
+
|
|
5
|
+
const connManager = ConnManager.getInstance();
|
|
6
|
+
|
|
7
|
+
type DeviceAttributesTableProps = {
|
|
8
|
+
deviceKey: string;
|
|
9
|
+
lastUpdated: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const DeviceAttrsForm: React.FC<DeviceAttributesTableProps> = ({ deviceKey, lastUpdated }) => {
|
|
13
|
+
const deviceManager = connManager.getConnector().getSystemType()?.deviceMgrIF;
|
|
14
|
+
const deviceState: DeviceState | undefined = deviceManager?.getDeviceState(deviceKey);
|
|
15
|
+
|
|
16
|
+
if (!deviceState || Object.keys(deviceState.deviceAttributes).length === 0) {
|
|
17
|
+
return <></>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<div className="device-attrs-form">
|
|
22
|
+
<table>
|
|
23
|
+
<thead>
|
|
24
|
+
<tr>
|
|
25
|
+
<th>Name</th>
|
|
26
|
+
<th>Value</th>
|
|
27
|
+
<th>Units</th>
|
|
28
|
+
</tr>
|
|
29
|
+
</thead>
|
|
30
|
+
<tbody>
|
|
31
|
+
{Object.entries(deviceState.deviceAttributes)
|
|
32
|
+
.filter(([attributeName, attributeDetails]) => attributeDetails.visibleForm !== false)
|
|
33
|
+
.map(([attributeName, attributeDetails]) => {
|
|
34
|
+
const valStr = deviceAttrGetLatestFormatted(attributeDetails)
|
|
35
|
+
return (
|
|
36
|
+
<tr key={attributeName}>
|
|
37
|
+
<td>{attributeName}</td>
|
|
38
|
+
<td>{valStr}</td>
|
|
39
|
+
<td>{attributeDetails.units}</td>
|
|
40
|
+
</tr>
|
|
41
|
+
);
|
|
42
|
+
})}
|
|
43
|
+
</tbody>
|
|
44
|
+
</table>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default DeviceAttrsForm;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import React, { useEffect, useState, memo, useRef } from "react";
|
|
2
|
+
import { Chart as ChartJS, CategoryScale, LinearScale, PointElement, LineElement, ArcElement, Tooltip, Legend } from 'chart.js';
|
|
3
|
+
import { Line } from "react-chartjs-2";
|
|
4
|
+
import ConnManager from "./ConnManager";
|
|
5
|
+
import { DeviceState } from "../../../src/RaftDeviceStates";
|
|
6
|
+
import SettingsManager from "./SettingsManager";
|
|
7
|
+
|
|
8
|
+
const connManager = ConnManager.getInstance();
|
|
9
|
+
|
|
10
|
+
ChartJS.register(
|
|
11
|
+
CategoryScale,
|
|
12
|
+
LinearScale,
|
|
13
|
+
PointElement,
|
|
14
|
+
LineElement,
|
|
15
|
+
ArcElement,
|
|
16
|
+
Tooltip,
|
|
17
|
+
Legend
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export interface DeviceLineChartProps {
|
|
21
|
+
deviceKey: string;
|
|
22
|
+
lastUpdated: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface ChartJSData {
|
|
26
|
+
labels: string[];
|
|
27
|
+
datasets: {
|
|
28
|
+
label: string;
|
|
29
|
+
data: number[];
|
|
30
|
+
fill: boolean;
|
|
31
|
+
borderColor: string;
|
|
32
|
+
backgroundColor: string;
|
|
33
|
+
yAxisID: string;
|
|
34
|
+
}[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const DeviceLineChart: React.FC<DeviceLineChartProps> = memo(({ deviceKey, lastUpdated }) => {
|
|
38
|
+
|
|
39
|
+
const settingsManager = SettingsManager.getInstance();
|
|
40
|
+
const maxChartDataPoints = settingsManager.getSetting('maxChartDataPoints');
|
|
41
|
+
|
|
42
|
+
const deviceManager = connManager.getConnector().getSystemType()?.deviceMgrIF;
|
|
43
|
+
const deviceState: DeviceState | undefined = deviceManager?.getDeviceState(deviceKey);
|
|
44
|
+
// const { deviceAttributes, deviceTimeline } = deviceState;
|
|
45
|
+
const [chartData, setChartData] = useState<ChartJSData>({
|
|
46
|
+
labels: [],
|
|
47
|
+
datasets: []
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const options = {
|
|
51
|
+
responsive: true,
|
|
52
|
+
maintainAspectRatio: false,
|
|
53
|
+
animation: {
|
|
54
|
+
duration: 1, // default is 1000ms
|
|
55
|
+
},
|
|
56
|
+
scales: {}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const colourMapRef = useRef<{ [key: string]: string }>({
|
|
60
|
+
prox: "hsl(60, 70%, 60%)",
|
|
61
|
+
als: "hsl(0, 70%, 60%)",
|
|
62
|
+
white: "hsl(120, 70%, 60%)",
|
|
63
|
+
x: "hsl(240, 70%, 60%)",
|
|
64
|
+
y: "hsl(300, 70%, 60%)",
|
|
65
|
+
z: "hsl(0, 70%, 60%)",
|
|
66
|
+
ax: "hsl(230, 70%, 60%)",
|
|
67
|
+
ay: "hsl(323, 69.60%, 60.00%)",
|
|
68
|
+
az: "hsl(64, 69.60%, 60.00%)",
|
|
69
|
+
gx: "hsl(275, 70%, 60%)",
|
|
70
|
+
gy: "hsl(352, 69.60%, 60.00%)",
|
|
71
|
+
gz: "hsl(88, 69.60%, 60.00%)",
|
|
72
|
+
dist: "hsl(60, 70%, 60%)",
|
|
73
|
+
temperature: "hsl(360, 70%, 60%)",
|
|
74
|
+
humidity: "hsl(200, 70%, 60%)",
|
|
75
|
+
Red: "hsl(0, 70%, 60%)",
|
|
76
|
+
Green: "hsl(120, 70%, 60%)",
|
|
77
|
+
Blue: "hsl(240, 70%, 60%)",
|
|
78
|
+
ir0: "hsl(300, 70%, 60%)",
|
|
79
|
+
ir1: "hsl(278, 69.60%, 60.00%)",
|
|
80
|
+
ir2: "hsl(7, 69.60%, 60.00%)",
|
|
81
|
+
amb0: "hsl(231, 25.50%, 90.00%)",
|
|
82
|
+
battV: "hsl(194, 69.60%, 60.00%)",
|
|
83
|
+
powerBtn: "hsl(256, 69.60%, 60.00%)",
|
|
84
|
+
USB: "hsl(71, 69.60%, 60.00%)",
|
|
85
|
+
powerMan: "hsl(0, 69.60%, 60.00%)",
|
|
86
|
+
powerBtnLvl: "hsl(120, 69.60%, 60.00%)",
|
|
87
|
+
angle: "hsl(240, 69.60%, 60.00%)",
|
|
88
|
+
current: "hsl(300, 69.60%, 60.00%)",
|
|
89
|
+
state: "hsl(60, 69.60%, 60.00%)",
|
|
90
|
+
velocity: "hsl(120, 69.60%, 60.00%)",
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (!deviceState) return;
|
|
95
|
+
|
|
96
|
+
const labels = deviceState.deviceTimeline.timestampsUs.slice(-maxChartDataPoints).map(time => {
|
|
97
|
+
const seconds = time / 1e6; // Convert microseconds to seconds
|
|
98
|
+
return seconds.toFixed(3); // Format decimal places
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const uniqueAxes = new Map<string, { range: [number, number], units: string }>();
|
|
102
|
+
const datasets = Object.entries(deviceState.deviceAttributes)
|
|
103
|
+
.filter(([attributeName, attributeDetails]) => attributeDetails.visibleSeries !== false)
|
|
104
|
+
.map(([attributeName, attributeDetails]) => {
|
|
105
|
+
const data = attributeDetails.values.slice(-maxChartDataPoints);
|
|
106
|
+
let colour = colourMapRef.current[attributeName];
|
|
107
|
+
if (!colour) {
|
|
108
|
+
colour = `hsl(${Math.random() * 360}, 70%, 60%)`;
|
|
109
|
+
colourMapRef.current[attributeName] = colour;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Ensure range has a minimum width if all values are the same
|
|
113
|
+
const minVal = Math.min(...attributeDetails.range);
|
|
114
|
+
const maxVal = Math.max(...attributeDetails.range);
|
|
115
|
+
const rangeEnds: [number, number] = minVal === maxVal
|
|
116
|
+
? [minVal - 1, maxVal + 1]
|
|
117
|
+
: [minVal, maxVal];
|
|
118
|
+
|
|
119
|
+
const axisKey = `${rangeEnds[0]}-${rangeEnds[1]}-${attributeDetails.units}`;
|
|
120
|
+
if (!uniqueAxes.has(axisKey)) {
|
|
121
|
+
uniqueAxes.set(axisKey, { range: rangeEnds, units: attributeDetails.units });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
label: attributeName,
|
|
126
|
+
data: data,
|
|
127
|
+
fill: false,
|
|
128
|
+
borderColor: colour,
|
|
129
|
+
backgroundColor: colour,
|
|
130
|
+
yAxisID: axisKey
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const scales: { [key: string]: any } = {};
|
|
135
|
+
uniqueAxes.forEach((axis, key) => {
|
|
136
|
+
scales[key] = {
|
|
137
|
+
type: 'linear',
|
|
138
|
+
display: true,
|
|
139
|
+
position: 'left',
|
|
140
|
+
ticks: {
|
|
141
|
+
min: axis.range[0],
|
|
142
|
+
max: axis.range[1],
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Update options and chart data
|
|
148
|
+
options.scales = scales;
|
|
149
|
+
setChartData({ labels: labels.length ? labels : ['0.000'], datasets });
|
|
150
|
+
}, [lastUpdated]);
|
|
151
|
+
|
|
152
|
+
if (!deviceState || Object.keys(deviceState.deviceAttributes).length === 0) {
|
|
153
|
+
return <></>;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<div className="device-line-chart">
|
|
158
|
+
<Line data={chartData} options={options} />
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
export default DeviceLineChart;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import './styles.css';
|
|
3
|
+
import { DeviceState } from '../../../src/RaftDeviceStates';
|
|
4
|
+
import DeviceAttrsForm from './DeviceAttrsForm';
|
|
5
|
+
import DeviceActionsForm from './DeviceActionsForm';
|
|
6
|
+
import DeviceLineChart from './DeviceLineChart';
|
|
7
|
+
import ConnManager from './ConnManager';
|
|
8
|
+
import SettingsManager from './SettingsManager';
|
|
9
|
+
|
|
10
|
+
const connManager = ConnManager.getInstance();
|
|
11
|
+
|
|
12
|
+
export interface DevicePanelProps {
|
|
13
|
+
deviceKey: string;
|
|
14
|
+
lastUpdated: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const DevicePanel = ({ deviceKey, lastUpdated }: DevicePanelProps) => {
|
|
18
|
+
const deviceManager = connManager.getConnector().getSystemType()?.deviceMgrIF;
|
|
19
|
+
const deviceState: DeviceState | undefined = deviceManager?.getDeviceState(deviceKey);
|
|
20
|
+
|
|
21
|
+
// Gray out the device panel if the device is offline
|
|
22
|
+
const offlineClass = deviceState?.isOnline ? '' : 'offline';
|
|
23
|
+
|
|
24
|
+
const [timedChartUpdate, setTimedChartUpdate] = useState<number>(0);
|
|
25
|
+
const [menuOpen, setMenuOpen] = useState<boolean>(false);
|
|
26
|
+
const menuRef = useRef<HTMLDivElement>(null);
|
|
27
|
+
|
|
28
|
+
const settingsManager = SettingsManager.getInstance();
|
|
29
|
+
const [showCharts, setShowCharts] = useState(
|
|
30
|
+
settingsManager.getSetting('showCharts')
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const startTime = Date.now();
|
|
35
|
+
const updateChart = () => {
|
|
36
|
+
setTimedChartUpdate(Date.now());
|
|
37
|
+
};
|
|
38
|
+
const updateTimer = setInterval(updateChart, 500);
|
|
39
|
+
return () => clearInterval(updateTimer);
|
|
40
|
+
}, []);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
44
|
+
if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
|
|
45
|
+
setMenuOpen(false);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
49
|
+
return () => {
|
|
50
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
const handleCopyToClipboard = () => {
|
|
55
|
+
if (!deviceState) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const headers = ["Time (s)"];
|
|
59
|
+
const rows: string[][] = [];
|
|
60
|
+
|
|
61
|
+
const timestampsUs = deviceState.deviceTimeline.timestampsUs;
|
|
62
|
+
const attributes = deviceState.deviceAttributes;
|
|
63
|
+
|
|
64
|
+
// Collect headers and initialize rows with timestamps
|
|
65
|
+
Object.keys(attributes).forEach(attrName => {
|
|
66
|
+
headers.push(attrName);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
timestampsUs.forEach((timestampUs, index) => {
|
|
70
|
+
const row: string[] = [(timestampUs / 1000000.0).toString()];
|
|
71
|
+
Object.keys(attributes).forEach(attrName => {
|
|
72
|
+
const values = attributes[attrName].values;
|
|
73
|
+
row.push(values[index]?.toString() || "");
|
|
74
|
+
});
|
|
75
|
+
rows.push(row);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Create a tab-separated string
|
|
79
|
+
const csvContent = [headers.join("\t"), ...rows.map(row => row.join("\t"))].join("\n");
|
|
80
|
+
|
|
81
|
+
// Try using navigator.clipboard.writeText, with a fallback to document.execCommand
|
|
82
|
+
if (navigator.clipboard) {
|
|
83
|
+
navigator.clipboard.writeText(csvContent).then(() => {
|
|
84
|
+
console.log("Device values copied to clipboard");
|
|
85
|
+
}).catch(err => {
|
|
86
|
+
console.warn('Failed to copy: ', err);
|
|
87
|
+
fallbackCopyTextToClipboard(csvContent);
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
fallbackCopyTextToClipboard(csvContent);
|
|
91
|
+
}
|
|
92
|
+
setMenuOpen(false);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const fallbackCopyTextToClipboard = (text: string) => {
|
|
96
|
+
const textArea = document.createElement("textarea");
|
|
97
|
+
textArea.value = text;
|
|
98
|
+
|
|
99
|
+
// Avoid scrolling to bottom
|
|
100
|
+
textArea.style.top = "0";
|
|
101
|
+
textArea.style.left = "0";
|
|
102
|
+
textArea.style.position = "fixed";
|
|
103
|
+
|
|
104
|
+
document.body.appendChild(textArea);
|
|
105
|
+
textArea.focus();
|
|
106
|
+
textArea.select();
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
document.execCommand("copy");
|
|
110
|
+
// alert("Device values copied to clipboard!");
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.warn('Fallback: Oops, unable to copy', err);
|
|
113
|
+
alert("Failed to copy device values to clipboard");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
document.body.removeChild(textArea);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
let headerText = `Device ${deviceState?.deviceTypeInfo?.name}`;
|
|
120
|
+
let bracketsAdded = false;
|
|
121
|
+
if ((deviceState?.busName !== undefined) && (deviceState?.busName !== "") && (deviceState?.busName !== "0")) {
|
|
122
|
+
headerText += ` (Bus ${deviceState?.busName}`;
|
|
123
|
+
bracketsAdded = true;
|
|
124
|
+
}
|
|
125
|
+
if ((deviceState?.deviceAddress !== undefined) && (deviceState?.deviceAddress !== "") && (deviceState?.deviceAddress !== "0")) {
|
|
126
|
+
// See if we can identify I2C addresses - should start with two bytes of 0s and then have a byte which is slot and a byte which is address
|
|
127
|
+
const addrInt = parseInt(deviceState?.deviceAddress, 16);
|
|
128
|
+
if (addrInt < 65536) {
|
|
129
|
+
const slot = addrInt >> 8;
|
|
130
|
+
if (slot === 0)
|
|
131
|
+
headerText += ` Main Bus`;
|
|
132
|
+
else
|
|
133
|
+
headerText += ` Slot ${slot}`;
|
|
134
|
+
const address = ("00" + (addrInt & 0xFF).toString(16)).slice(-2);
|
|
135
|
+
headerText += ` Addr 0x${address}`;
|
|
136
|
+
} else {
|
|
137
|
+
headerText += ` Addr ${deviceState?.deviceAddress}`;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (bracketsAdded) {
|
|
141
|
+
headerText += `)`;
|
|
142
|
+
}
|
|
143
|
+
if (!deviceState?.isOnline) {
|
|
144
|
+
headerText += " (Offline)";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return (
|
|
148
|
+
<div className={`device-panel ${offlineClass}`}>
|
|
149
|
+
<div className="device-block-heading">
|
|
150
|
+
<div className="device-block-heading-text">{headerText}</div>
|
|
151
|
+
<div className="menu-icon always-enabled" onClick={() => setMenuOpen(!menuOpen)}>☰</div>
|
|
152
|
+
{menuOpen && (
|
|
153
|
+
<div className="dropdown-menu" ref={menuRef}>
|
|
154
|
+
<div className="menu-item always-enabled" onClick={handleCopyToClipboard}>Copy Values to Clipboard</div>
|
|
155
|
+
</div>
|
|
156
|
+
)}
|
|
157
|
+
</div>
|
|
158
|
+
<div className={`device-block-data`}>
|
|
159
|
+
<div className="device-attrs-and-actions">
|
|
160
|
+
<DeviceAttrsForm deviceKey={deviceKey} lastUpdated={lastUpdated} />
|
|
161
|
+
<DeviceActionsForm deviceKey={deviceKey} />
|
|
162
|
+
</div>
|
|
163
|
+
{showCharts &&
|
|
164
|
+
<DeviceLineChart deviceKey={deviceKey} lastUpdated={timedChartUpdate} />
|
|
165
|
+
}
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export default DevicePanel;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Component which uses the DeviceList component to display the list of devices
|
|
2
|
+
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
|
+
// import { DeviceAttributeState, DevicesState, DeviceState } from "../../../src/main";
|
|
5
|
+
// import { DeviceManager } from './DeviceManager';
|
|
6
|
+
// import DeviceScreen from './DeviceScreen';
|
|
7
|
+
import './styles.css';
|
|
8
|
+
import ConnManager from "./ConnManager";
|
|
9
|
+
import { DeviceAttributeState, DevicesState, DeviceState } from '../../../src/RaftDeviceStates';
|
|
10
|
+
import DevicePanel from './DevicePanel';
|
|
11
|
+
|
|
12
|
+
const connManager = ConnManager.getInstance();
|
|
13
|
+
|
|
14
|
+
export class DevicesPanelProps {
|
|
15
|
+
constructor(
|
|
16
|
+
) { }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default function DevicesPanel(props: DevicesPanelProps) {
|
|
20
|
+
const [lastUpdated, setLastUpdated] = useState<number>(0);
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
const deviceManager = connManager.getConnector().getSystemType()?.deviceMgrIF;
|
|
24
|
+
if (!deviceManager) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const onNewDevice = (deviceKey: string, newDeviceState: DeviceState) => {
|
|
29
|
+
setLastUpdated(Date.now());
|
|
30
|
+
};
|
|
31
|
+
deviceManager.addNewDeviceCallback(onNewDevice);
|
|
32
|
+
|
|
33
|
+
const onNewAttribute = (deviceKey: string, attribute: DeviceAttributeState) => {
|
|
34
|
+
setLastUpdated(Date.now());
|
|
35
|
+
}
|
|
36
|
+
deviceManager.addNewAttributeCallback(onNewAttribute);
|
|
37
|
+
|
|
38
|
+
const onNewAttributeData = (deviceKey: string, attribute: DeviceAttributeState) => {
|
|
39
|
+
setLastUpdated(Date.now());
|
|
40
|
+
// console.log(`New attribute data: ${deviceKey} ${attribute.name} ${attribute.values.length}`);
|
|
41
|
+
}
|
|
42
|
+
deviceManager.addAttributeDataCallback(onNewAttributeData);
|
|
43
|
+
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
const deviceManager = connManager.getConnector().getSystemType()?.deviceMgrIF;
|
|
47
|
+
let devicesState: DevicesState = {};
|
|
48
|
+
if (deviceManager)
|
|
49
|
+
devicesState = deviceManager.getDevicesState();
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div className="devices-container">
|
|
53
|
+
{Object.entries(devicesState).filter(([key, _]) => key !== 'getDeviceKey').map(([deviceKey, data]) => (
|
|
54
|
+
<DevicePanel key={deviceKey} deviceKey={deviceKey} lastUpdated={lastUpdated} />
|
|
55
|
+
))}
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import DispOneLED from './DispOneLed';
|
|
3
|
+
import ConnManager from './ConnManager';
|
|
4
|
+
import { DeviceTypeAction } from '../../../src/RaftDeviceInfo';
|
|
5
|
+
import { CirclePicker } from 'react-color';
|
|
6
|
+
|
|
7
|
+
const connManager = ConnManager.getInstance();
|
|
8
|
+
|
|
9
|
+
interface LEDGridProps {
|
|
10
|
+
rows: number;
|
|
11
|
+
cols: number;
|
|
12
|
+
deviceKey: string;
|
|
13
|
+
deviceAction: DeviceTypeAction;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const customColors = [
|
|
17
|
+
'#000000', // black
|
|
18
|
+
'#FFFFFF', // white
|
|
19
|
+
'#FF0000', // red
|
|
20
|
+
'#00FF00', // green
|
|
21
|
+
'#0000FF', // blue
|
|
22
|
+
'#FFFF00', // yellow
|
|
23
|
+
'#FF00FF', // pink
|
|
24
|
+
'#00FFFF', // cyan
|
|
25
|
+
'#FFA500', // orange
|
|
26
|
+
'#800080', // purple
|
|
27
|
+
'#808080', // gray
|
|
28
|
+
'#A52A2A', // brown
|
|
29
|
+
'#008000', // dark green
|
|
30
|
+
'#800000', // maroon
|
|
31
|
+
'#008080', // teal
|
|
32
|
+
'#000080', // navy
|
|
33
|
+
'#FFD700', // gold
|
|
34
|
+
'#FF4500', // orange red
|
|
35
|
+
'#FF6347', // tomato
|
|
36
|
+
// Add more custom colors as needed
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const DispLEDGrid: React.FC<LEDGridProps> = ({ rows, cols, deviceKey, deviceAction }) => {
|
|
40
|
+
// Initialize the grid with all LEDs turned off (black)
|
|
41
|
+
const [colors, setColors] = useState<string[][]>(
|
|
42
|
+
Array.from({ length: rows }, () => Array.from({ length: cols }, () => '#000000'))
|
|
43
|
+
);
|
|
44
|
+
const [activeLED, setActiveLED] = useState<{row: number, col: number} | null>(null);
|
|
45
|
+
|
|
46
|
+
const handleLEDClick = (row: number, col: number) => {
|
|
47
|
+
setActiveLED({ row, col });
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const hexToRgb = (hex: string): number[] => {
|
|
51
|
+
const r = parseInt(hex.slice(1, 3), 16);
|
|
52
|
+
const g = parseInt(hex.slice(3, 5), 16);
|
|
53
|
+
const b = parseInt(hex.slice(5, 7), 16);
|
|
54
|
+
return [r, g, b];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const handleChangeComplete = (color: any) => {
|
|
58
|
+
if (activeLED) {
|
|
59
|
+
const { row, col } = activeLED;
|
|
60
|
+
const newColors = colors.map((rowColors, rowIndex) =>
|
|
61
|
+
rowColors.map((colColor, colIndex) =>
|
|
62
|
+
rowIndex === row && colIndex === col ? color.hex : colColor
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
setColors(newColors);
|
|
66
|
+
setActiveLED(null); // Optionally close the picker automatically
|
|
67
|
+
|
|
68
|
+
// Convert into a list of RGB values
|
|
69
|
+
let colourList = [];
|
|
70
|
+
for (let i = 0; i < rows; i++) {
|
|
71
|
+
for (let j = 0; j < cols; j++) {
|
|
72
|
+
colourList.push(hexToRgb(newColors[i][j]));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Send result
|
|
77
|
+
const deviceManager = connManager.getConnector().getSystemType()?.deviceMgrIF;
|
|
78
|
+
if (deviceManager) {
|
|
79
|
+
deviceManager.sendCompoundAction(deviceKey, deviceAction, colourList);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<div>
|
|
86
|
+
<div style={{
|
|
87
|
+
display: 'grid',
|
|
88
|
+
gridTemplateColumns: `repeat(${cols}, 24px)`,
|
|
89
|
+
gridTemplateRows: `${rows === 1 ? '1fr' : `repeat(${rows}, 24px)`}`,
|
|
90
|
+
justifyContent: 'center',
|
|
91
|
+
width: `${cols * 24}px`
|
|
92
|
+
}}>
|
|
93
|
+
{colors.map((row, rowIndex) =>
|
|
94
|
+
row.map((color, colIndex) => (
|
|
95
|
+
<DispOneLED key={`${rowIndex}-${colIndex}`} color={color} onClick={() => handleLEDClick(rowIndex, colIndex)} />
|
|
96
|
+
))
|
|
97
|
+
)}
|
|
98
|
+
</div>
|
|
99
|
+
{activeLED && (
|
|
100
|
+
<CirclePicker
|
|
101
|
+
color={colors[activeLED.row][activeLED.col]}
|
|
102
|
+
colors={customColors}
|
|
103
|
+
onChangeComplete={handleChangeComplete}
|
|
104
|
+
/>
|
|
105
|
+
)}
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default DispLEDGrid;
|