Skip to content

Commit e6f3243

Browse files
Add COCCON Spain Enclosure code frame (9)
Add UI code
1 parent 6362d88 commit e6f3243

File tree

8 files changed

+121
-0
lines changed

8 files changed

+121
-0
lines changed

packages/ui/src/components/configuration/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ConfigSectionCamtracker from './sections/config-section-camtracker';
99
import ConfigSectionMeasurementTriggers from './sections/config-section-measurement-triggers';
1010
import ConfigSectionOpus from './sections/config-section-opus';
1111
import ConfigSectionTUMEnclosure from './sections/config-section-tum-enclosure';
12+
import ConfigSectionCOCCONSpainEnclosure from './sections/config-section-coccon-spain-enclosure';
1213
import ConfigSectionHelios from './sections/config-section-helios';
1314
import ConfigSectionUpload from './sections/config-section-upload';
1415
import ConfigElementLine from './rows/config-element-line';
@@ -29,6 +30,7 @@ export default {
2930
ConfigSectionMeasurementTriggers,
3031
ConfigSectionOpus,
3132
ConfigSectionTUMEnclosure,
33+
ConfigSectionCOCCONSpainEnclosure,
3234
ConfigSectionHelios,
3335
ConfigSectionUpload,
3436
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { configurationComponents, essentialComponents } from '../..';
2+
import { useConfigStore } from '../../../utils/zustand-utils/config-zustand';
3+
import { Button } from '../../ui/button';
4+
5+
export default function ConfigSectionCOCCONSpainEnclosure() {
6+
const { centralConfig, localConfig, setLocalConfigItem } = useConfigStore();
7+
8+
const centralSectionConfig = centralConfig?.coccon_spain_enclosure;
9+
const localSectionConfig = localConfig?.coccon_spain_enclosure;
10+
11+
function addDefault() {
12+
setLocalConfigItem('coccon_spain_enclosure', {
13+
ip: '10.10.0.4',
14+
});
15+
}
16+
17+
function setNull() {
18+
setLocalConfigItem('coccon_spain_enclosure', null);
19+
}
20+
21+
if (localSectionConfig === undefined || centralSectionConfig === undefined) {
22+
return <></>;
23+
}
24+
25+
if (localSectionConfig === null) {
26+
return (
27+
<div className="relative space-y-2 text-sm flex-col-left">
28+
<Button onClick={addDefault}>set up now</Button>
29+
<essentialComponents.PreviousValue
30+
previousValue={
31+
centralSectionConfig !== null
32+
? JSON.stringify(centralSectionConfig)
33+
.replace(/":/g, '": ')
34+
.replace(/,"/g, ', "')
35+
: undefined
36+
}
37+
/>
38+
{centralSectionConfig !== null && (
39+
<div className="absolute -top-2.5 -left-1 w-1 h-[calc(100%+0.625rem)] -translate-x-2.5 bg-blue-300" />
40+
)}
41+
</div>
42+
);
43+
}
44+
45+
return (
46+
<>
47+
<div>
48+
<Button onClick={setNull}>remove configuration</Button>
49+
</div>
50+
<configurationComponents.ConfigElementLine />
51+
<configurationComponents.ConfigElementText
52+
title="IP"
53+
value={localSectionConfig.ip}
54+
setValue={(v: string) => setLocalConfigItem('coccon_spain_enclosure.ip', v)}
55+
oldValue={centralSectionConfig !== null ? centralSectionConfig.ip : 'null'}
56+
/>
57+
</>
58+
);
59+
}

packages/ui/src/components/overview/system-state.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,29 @@ export function SystemState() {
9393
</StatePanel>
9494
</div>
9595
)}
96+
{centralConfig.coccon_spain_enclosure !== null && (
97+
<div className="grid w-full grid-cols-4 px-4 pb-1 text-sm gap-x-1">
98+
<StatePanel title="Cover Angle">
99+
{renderString(coreState.coccon_spain_enclosure_state.actors.cover_position)}
100+
</StatePanel>
101+
<StatePanel title="Temperature">
102+
{renderString(coreState.coccon_spain_enclosure_state.sensors.temperature, {
103+
appendix: ' °C',
104+
})}
105+
</StatePanel>
106+
<StatePanel title="Humidity">
107+
{renderString(coreState.coccon_spain_enclosure_state.sensors.humidity, {
108+
appendix: ' rH',
109+
})}
110+
</StatePanel>
111+
<StatePanel title="Helios Edge Pixels">
112+
{renderNumber(
113+
lastEdgeFractionValue === null ? null : lastEdgeFractionValue * 100,
114+
{ appendix: ' %' }
115+
)}
116+
</StatePanel>
117+
</div>
118+
)}
96119
{coreState?.tum_enclosure_state.state.rain === true &&
97120
coreState?.tum_enclosure_state.state.cover_closed === false && (
98121
<div className="w-full px-4 mb-4 -mt-2 text-sm">

packages/ui/src/custom-types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export namespace customTypes {
1818
| 'error_email'
1919
| 'measurement_triggers'
2020
| 'tum_enclosure'
21+
| 'coccon_spain_enclosure'
2122
| 'helios'
2223
| 'upload';
2324
export type config = {
@@ -72,6 +73,9 @@ export namespace customTypes {
7273
version: number;
7374
controlled_by_user: boolean;
7475
};
76+
coccon_spain_enclosure: null | {
77+
ip: string;
78+
};
7579
helios: null | {
7680
camera_id: number;
7781
evaluation_size: number;
@@ -146,6 +150,9 @@ export namespace customTypes {
146150
version?: number;
147151
controlled_by_user?: boolean;
148152
};
153+
coccon_spain_enclosure?: null | {
154+
ip?: string;
155+
};
149156
helios?: null | {
150157
camera_id?: number;
151158
evaluation_size?: number;

packages/ui/src/tabs/configuration-tab.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const hardwareSections: {
4343
icon: React.ForwardRefExoticComponent<IconProps & React.RefAttributes<Icon>>;
4444
}[] = [
4545
{ key: 'tum_enclosure', label: 'TUM Enclosure', icon: IconCpu },
46+
{ key: 'coccon_spain_enclosure', label: 'COCCON Spain Enclosure', icon: IconCpu },
4647
{ key: 'helios', label: 'Helios', icon: IconCpu },
4748
];
4849

@@ -170,6 +171,9 @@ export default function ConfigurationTab() {
170171
{activeKey === 'tum_enclosure' && (
171172
<configurationComponents.ConfigSectionTUMEnclosure />
172173
)}
174+
{activeKey === 'coccon_spain_enclosure' && (
175+
<configurationComponents.ConfigSectionCOCCONSpainEnclosure />
176+
)}
173177
{activeKey === 'helios' && <configurationComponents.ConfigSectionHelios />}
174178
{activeKey === 'upload' && <configurationComponents.ConfigSectionUpload />}
175179
{configIsDiffering() && (

packages/ui/src/utils/zustand-utils/config-zustand.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export const configSchema = z.object({
7373
controlled_by_user: z.boolean(),
7474
})
7575
.nullable(),
76+
coccon_spain_enclosure: z
77+
.object({
78+
ip: z.string(),
79+
})
80+
.nullable(),
7681
helios: z
7782
.object({
7883
camera_id: intSchema,

packages/ui/src/utils/zustand-utils/core-state-zustand.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ const coreStateSchema = z.object({
4848
spectrometer: z.boolean().nullable(),
4949
}),
5050
}),
51+
coccon_spain_enclosure_state: z.object({
52+
last_full_fetch: z.string().nullable(),
53+
actors: z.object({
54+
fan_speed: z.number().nullable(),
55+
cover_position: z.number().nullable(),
56+
}),
57+
sensors: z.object({
58+
humidity: z.number().nullable(),
59+
temperature: z.number().nullable(),
60+
wind_direction: z.number().nullable(),
61+
wind_speed: z.number().nullable(),
62+
}),
63+
}),
5164
operating_system_state: z.object({
5265
cpu_usage: z.array(z.number()).nullable(),
5366
memory_usage: z.number().nullable(),

packages/ui/src/utils/zustand-utils/logs-zustand.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface LogsStore {
1010
system_monitor: string[] | undefined;
1111
upload: string[] | undefined;
1212
tum_enclosure: string[] | undefined;
13+
coccon_spain_enclosure: string[] | undefined;
1314
helios: string[] | undefined;
1415
};
1516
uiLogs: { timestamp: number; text: string; details: string }[];
@@ -27,6 +28,7 @@ export const useLogsStore = create<LogsStore>()((set) => ({
2728
system_monitor: undefined,
2829
upload: undefined,
2930
tum_enclosure: undefined,
31+
coccon_spain_enclosure: undefined,
3032
helios: undefined,
3133
},
3234
uiLogs: [],
@@ -42,6 +44,7 @@ export const useLogsStore = create<LogsStore>()((set) => ({
4244
| 'system_monitor'
4345
| 'upload'
4446
| 'tum_enclosure'
47+
| 'coccon_spain_enclosure'
4548
| 'helios']: string[];
4649
} = {
4750
all: [],
@@ -52,6 +55,7 @@ export const useLogsStore = create<LogsStore>()((set) => ({
5255
system_monitor: [],
5356
upload: [],
5457
tum_enclosure: [],
58+
coccon_spain_enclosure: [],
5559
helios: [],
5660
};
5761
let currentCategory:
@@ -62,6 +66,7 @@ export const useLogsStore = create<LogsStore>()((set) => ({
6266
| 'system_monitor'
6367
| 'upload'
6468
| 'tum_enclosure'
69+
| 'coccon_spain_enclosure'
6570
| 'helios' = 'main';
6671
allLogs.forEach((logLine) => {
6772
if (logLine.trim().length > 0) {
@@ -84,6 +89,9 @@ export const useLogsStore = create<LogsStore>()((set) => ({
8489
case 'tum-enclosure':
8590
currentCategory = 'tum_enclosure';
8691
break;
92+
case 'coccon-spain-enclosure':
93+
currentCategory = 'coccon_spain_enclosure';
94+
break;
8795
case 'upload':
8896
currentCategory = 'upload';
8997
break;

0 commit comments

Comments
 (0)