Skip to content

Commit

Permalink
add default poll rate and smooth time
Browse files Browse the repository at this point in the history
  • Loading branch information
aarron-lee committed May 8, 2024
1 parent a6cd56c commit 78d3732
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/backend/alsListener.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ export const smoothTimeInfo = {
step: 50
};

let pollingRate = 100; // Time in milliseconds
let smoothTime = 500; // Time in milliseconds
export const DEFAULT_POLLING_RATE = 100;
export const DEFAULT_SMOOTH_TIME = 500;

let pollingRate = DEFAULT_POLLING_RATE; // Time in milliseconds
let smoothTime = DEFAULT_SMOOTH_TIME; // Time in milliseconds
const stepCount = 10; // Less steps = smoother transition

let previousAlsValues = Array(75).fill(-1); // Increase length to increase read times (less sensitive to changes)
Expand Down
9 changes: 7 additions & 2 deletions src/redux-modules/uiSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
getServerApi
} from '../backend/utils';
import {
DEFAULT_POLLING_RATE,
DEFAULT_SMOOTH_TIME,
clearAlsListener,
enableAlsListener,
setPollRate,
Expand Down Expand Up @@ -35,8 +37,8 @@ const initialState: UiStateType = {
currentDisplayName: undefined,
pluginVersionNum: '',
alsInfo: {
pollingRate: 100,
smoothTime: 500
pollingRate: DEFAULT_POLLING_RATE,
smoothTime: DEFAULT_SMOOTH_TIME
}
};

Expand Down Expand Up @@ -76,7 +78,10 @@ export const uiSlice = createSlice({
state.alsEnabled = Boolean(action.payload?.alsEnabled);
}
if (action.payload?.alsInfo) {
const { pollingRate, smoothTime } = action.payload.alsInfo;
state.alsInfo = action.payload.alsInfo;
setPollRate(pollingRate || DEFAULT_POLLING_RATE);
setSmoothTime(smoothTime || DEFAULT_SMOOTH_TIME);
}
});
builder.addCase(setCurrentGameId, (state, action) => {
Expand Down

0 comments on commit 78d3732

Please sign in to comment.