Skip to content

Commit

Permalink
Start gpio storage
Browse files Browse the repository at this point in the history
  • Loading branch information
GLDuval committed May 3, 2023
1 parent fe82542 commit c3e310e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/renderer/store/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { initialState as inputState } from '@/renderer/store/modules/input';
import { initialState as debugTabState } from '@/renderer/store/modules/debugTab';
import { initialState as launchFilesState } from '@/renderer/store/modules/launchFiles';
import { initialState as armPresetsState } from '@/renderer/store/modules/armPresets';
import { initialState as gpioPinsState } from '@/renderer/store/modules/gpioPins';
import { log } from '@/renderer/logger';

export const defaultState: GlobalState = {
Expand All @@ -15,6 +16,7 @@ export const defaultState: GlobalState = {
debugTab: debugTabState,
launchFiles: launchFilesState,
armPresets: armPresetsState,
gpioPins: gpioPinsState,
};

// WARN
Expand Down
52 changes: 52 additions & 0 deletions src/renderer/store/modules/gpioPins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { GlobalState } from '@/renderer/store/store';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { nanoid } from 'nanoid';

export interface GpioPinsState {
id: string;
name: string;
topicName: string;
isOn: boolean;
}

export const initialState: GpioPinsState[] = [
{
id: nanoid(),
name: 'LED 1',
topicName: '',
isOn: false,
},
{
id: nanoid(),
name: 'LED 2',
topicName: '',
isOn: false,
},
{
id: nanoid(),
name: 'LED 3',
topicName: '',
isOn: false,
},
];

export const gpioPinsSlice = createSlice({
name: 'gpioPins',
initialState,
reducers: {
togglePin: (state, { payload }: PayloadAction<string>) => {
const element = state.find((element) => element.id === payload);
if (element) {
element.isOn = !element.isOn;
}
},
addPin: (state, { payload }: PayloadAction<GpioPinsState>) => {
state.push(payload);
},
removePin: (state, { payload }: PayloadAction<GpioPinsState>) => {
state = state.filter((pin) => pin.id !== payload.id);
},
},
});

export const selectAllPins = (state: GlobalState) => state.gpioPins;
2 changes: 2 additions & 0 deletions src/renderer/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { configureStore, AnyAction, combineReducers } from '@reduxjs/toolkit';
import { throttle } from 'lodash';
import { launchFilesSlice } from './modules/launchFiles';
import { armPresetsSlice } from './modules/armPresets';
import { gpioPinsSlice } from './modules/gpioPins';

const appReducer = combineReducers({
feed: feedSlice.reducer,
Expand All @@ -19,6 +20,7 @@ const appReducer = combineReducers({
debugTab: debugTabSlice.reducer,
launchFiles: launchFilesSlice.reducer,
armPresets: armPresetsSlice.reducer,
gpioPins: gpioPinsSlice.reducer,
});

export type GlobalState = ReturnType<typeof appReducer>;
Expand Down

0 comments on commit c3e310e

Please sign in to comment.