Skip to content

Commit

Permalink
Add warning messages for uncommon user define configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgelenas committed Apr 19, 2021
1 parent b37e725 commit 0fc3b30
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
68 changes: 68 additions & 0 deletions src/ui/components/UserDefinesAdvisor/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, { FunctionComponent } from 'react';
import { Alert, makeStyles } from '@material-ui/core';
import { DeviceOptionsFormData } from '../DeviceOptionsForm';
import { UserDefineKey, UserDefinesMode } from '../../gql/generated/types';

interface UserDefinesAdvisorProps {
deviceOptionsFormData: DeviceOptionsFormData;
}

const useStyles = makeStyles((theme) => ({
container: {
marginBottom: theme.spacing(2),
},
}));

const UserDefinesAdvisor: FunctionComponent<UserDefinesAdvisorProps> = ({
deviceOptionsFormData,
}) => {
const styles = useStyles();
const messages: string[] = [];
if (deviceOptionsFormData.userDefinesMode === UserDefinesMode.UserInterface) {
const isUserDefine = (
key: UserDefineKey,
enabledValue: boolean
): boolean => {
const value = deviceOptionsFormData.userDefineOptions.find(
(item) => item.key === key
);
if (value?.enabled === enabledValue) {
return true;
}
return false;
};

if (isUserDefine(UserDefineKey.UART_INVERTED, false)) {
messages.push(
'Disabling UART_INVERTED is uncommon. Please make sure that your transmitter supports that.'
);
}

if (isUserDefine(UserDefineKey.FEATURE_OPENTX_SYNC, false)) {
messages.push(
'Disabling FEATURE_OPENTX_SYNC is uncommon. Keeping it disabled will prevent the ExpressLRS LUA script from communicating with the TX module properly.'
);
}

if (isUserDefine(UserDefineKey.NO_SYNC_ON_ARM, true)) {
messages.push(
'NO_SYNC_ON_ARM is an advanced performance option. Make sure to read the documentation on how it works.'
);
}
}
return (
<div>
{messages.length > 0 && (
<div className={styles.container}>
{messages.map((message, idx) => (
<Alert key={idx} severity="warning">
{message}
</Alert>
))}
</div>
)}
</div>
);
};

export default UserDefinesAdvisor;
1 change: 0 additions & 1 deletion src/ui/components/UserDefinesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ const UserDefinesList: FunctionComponent<UserDefinesListProps> = (props) => {
</ListItem>
</>
)}

{item.type === UserDefineKind.Enum && item.enabled && (
<ListItem className={styles.complimentaryItem}>
<Omnibox
Expand Down
5 changes: 5 additions & 0 deletions src/ui/views/ConfiguratorView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import UserDefinesValidator from './UserDefinesValidator';
import ApplicationStorage from '../../storage';
import persistDeviceOptions from '../../storage/commands/persistDeviceOptions';
import mergeWithDeviceOptionsFromStorage from '../../storage/commands/mergeWithDeviceOptionsFromStorage';
import UserDefinesAdvisor from '../../components/UserDefinesAdvisor';

export const validateFirmwareVersionData = (
data: FirmwareVersionDataInput
Expand Down Expand Up @@ -461,6 +462,10 @@ const ConfiguratorView: FunctionComponent = () => {
<CardTitle icon={<SettingsIcon />} title="Actions" />
<Divider />
<CardContent>
<UserDefinesAdvisor
deviceOptionsFormData={deviceOptionsFormData}
/>

<Button
className={styles.button}
size="large"
Expand Down

0 comments on commit 0fc3b30

Please sign in to comment.