feat: integriere Systemspannungen und Temperaturen mit Redux Thunk und Slice
- Neues Slice systemVoltTempSlice.ts erstellt für Speicherung von Spannungen und Verlauf - Thunk fetchSystemVoltTempThunk.ts implementiert für asynchrones Laden der Systemwerte - Service fetchSystemVoltTempService.ts verwendet API /api/cpl/systemVoltTempAPIHandler - Mock-Daten in systemVoltTempMockData.js definiert - system.tsx auf Redux umgestellt: useSelector für Werte und Verlauf, fetch per Thunk - store.ts angepasst: systemVoltTempSlice hinzugefügt - Chart.js Darstellung von Spannungen und Temperaturen mit Echtzeit-Update alle 5 Sekunden
This commit is contained in:
38
redux/slices/systemVoltTempSlice.ts
Normal file
38
redux/slices/systemVoltTempSlice.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// /redux/slices/systemVoltTempSlice.ts
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface VoltagesState {
|
||||
voltages: { [key: string]: number };
|
||||
history: { time: number; [key: string]: number }[];
|
||||
}
|
||||
|
||||
const initialState: VoltagesState = {
|
||||
voltages: {
|
||||
"+5V": 0,
|
||||
"+15V": 0,
|
||||
"-15V": 0,
|
||||
"-98V": 0,
|
||||
"ADC Temp": 0,
|
||||
"CPU Temp": 0,
|
||||
},
|
||||
history: [],
|
||||
};
|
||||
|
||||
const systemVoltTempSlice = createSlice({
|
||||
name: "systemVoltTemp",
|
||||
initialState,
|
||||
reducers: {
|
||||
setVoltages(state, action: PayloadAction<{ [key: string]: number }>) {
|
||||
state.voltages = action.payload;
|
||||
},
|
||||
addHistory(
|
||||
state,
|
||||
action: PayloadAction<{ time: number; [key: string]: number }>
|
||||
) {
|
||||
state.history.push(action.payload);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setVoltages, addHistory } = systemVoltTempSlice.actions;
|
||||
export default systemVoltTempSlice.reducer;
|
||||
Reference in New Issue
Block a user