Skip to content

Commit

Permalink
Add erase and force flash as flashing options
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlampley committed Jun 19, 2023
1 parent 9e7b712 commit 6d9de92
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 22 deletions.
28 changes: 28 additions & 0 deletions graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@
"description": null,
"fields": null,
"inputFields": [
{
"name": "erase",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"defaultValue": "false",
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "firmware",
"description": null,
Expand Down Expand Up @@ -681,6 +697,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "platform",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "priorTargetName",
"description": null,
Expand Down
4 changes: 4 additions & 0 deletions src/api/src/graphql/inputs/BuildFlashFirmwareInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ export default class BuildFlashFirmwareInput {
@Field()
userDefinesTxt: string;

@Field()
erase: boolean;

constructor() {
this.type = BuildJobType.Build;
this.firmware = new FirmwareVersionDataInput();
this.target = 'DIY_2400_TX_ESP32_SX1280_E28_via_UART';
this.userDefinesMode = UserDefinesMode.UserInterface;
this.userDefines = [];
this.userDefinesTxt = '';
this.erase = false;
}
}
7 changes: 6 additions & 1 deletion src/api/src/models/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export default class Device {
@Field({ nullable: true })
priorTargetName?: string | null;

@Field({ nullable: true })
platform?: string | null;

constructor(
id: string,
name: string,
Expand All @@ -53,7 +56,8 @@ export default class Device {
parent?: string | null,
abbreviatedName?: string | null,
luaName?: string | null,
priorTargetName?: string | null
priorTargetName?: string | null,
platform?: string | null
) {
this.id = id;
this.name = name;
Expand All @@ -67,5 +71,6 @@ export default class Device {
this.abbreviatedName = abbreviatedName;
this.luaName = luaName;
this.priorTargetName = priorTargetName;
this.platform = platform;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export default class BinaryConfigurator {
flags.push([firmwareBinaryPath]);
}

if (params.erase) {
flags.push(['--erase']);
}

return flags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export default class DeviceDescriptionsLoader {
undefined,
undefined,
config.lua_name,
config.prior_target_name
config.prior_target_name,
config.platform
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface BuildFlashFirmwareParams {
userDefinesMode: UserDefinesMode;
userDefines: UserDefine[];
userDefinesTxt: string;
erase: boolean;
}
4 changes: 4 additions & 0 deletions src/ui/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export enum BuildFirmwareStep {
}

export type BuildFlashFirmwareInput = {
readonly erase?: Scalars['Boolean'];
readonly firmware?: FirmwareVersionDataInput;
readonly serialDevice?: InputMaybe<Scalars['String']>;
readonly target?: Scalars['String'];
Expand Down Expand Up @@ -112,6 +113,7 @@ export type Device = {
readonly luaName?: Maybe<Scalars['String']>;
readonly name: Scalars['String'];
readonly parent?: Maybe<Scalars['String']>;
readonly platform?: Maybe<Scalars['String']>;
readonly priorTargetName?: Maybe<Scalars['String']>;
readonly targets: ReadonlyArray<Target>;
readonly userDefines: ReadonlyArray<UserDefine>;
Expand Down Expand Up @@ -466,6 +468,7 @@ export type AvailableFirmwareTargetsQuery = {
readonly verifiedHardware: boolean;
readonly luaName?: string | null;
readonly priorTargetName?: string | null;
readonly platform?: string | null;
readonly targets: ReadonlyArray<{
readonly __typename?: 'Target';
readonly id: string;
Expand Down Expand Up @@ -866,6 +869,7 @@ export const AvailableFirmwareTargetsDocument = gql`
verifiedHardware
luaName
priorTargetName
platform
}
}
`;
Expand Down
1 change: 1 addition & 0 deletions src/ui/gql/queries/availableFirmwareTargets.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ query availableFirmwareTargets(
verifiedHardware
luaName
priorTargetName
platform
}
}
106 changes: 86 additions & 20 deletions src/ui/views/ConfiguratorView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ import {
Button,
Card,
CardContent,
Checkbox,
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
Divider,
IconButton,
List,
ListItem,
ListItemIcon,
ListItemText,
Tooltip,
Typography,
} from '@mui/material';
import SettingsIcon from '@mui/icons-material/Settings';
import { ipcRenderer } from 'electron';
Expand Down Expand Up @@ -423,6 +429,26 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
return deviceType === DeviceType.ExpressLRS && isTX;
}, [deviceType, isTX]);

const eraseSupported = useMemo(() => {
if (!deviceTarget || !device) {
return false;
}
if (deviceTarget.flashingMethod === FlashingMethod.UART) {
return true;
}
if (
deviceTarget.flashingMethod === FlashingMethod.BetaflightPassthrough &&
device.platform === 'esp8285'
) {
return true;
}
if (deviceTarget?.flashingMethod === FlashingMethod.EdgeTxPassthrough) {
return true;
}

return false;
}, [deviceTarget, device]);

useEffect(() => {
if (firmwareVersionData && isTX && hasLuaScript) {
fetchLuaScript({
Expand Down Expand Up @@ -466,6 +492,9 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
setWifiDevice(newWifiDevice);
}, []);

const [erase, setErase] = useState<boolean>(false);
const [forceFlash, setForceFlash] = useState<boolean>(false);

const [serialPortRequired, setSerialPortRequired] = useState<boolean>(false);
const [wifiDeviceRequired, setWifiDeviceRequired] = useState<boolean>(false);

Expand Down Expand Up @@ -591,6 +620,7 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
userDefinesMode: deviceOptionsFormData.userDefinesMode,
userDefines,
serialDevice: uploadPort,
erase,
};
buildFlashFirmwareMutation({
variables: {
Expand Down Expand Up @@ -618,7 +648,14 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
}, [buildInProgress, response]);

const onBuild = () => sendJob(BuildJobType.Build);
const onBuildAndFlash = () => sendJob(BuildJobType.BuildAndFlash);
const onBuildAndFlash = () => {
if (forceFlash) {
sendJob(BuildJobType.ForceFlash);
} else {
sendJob(BuildJobType.BuildAndFlash);
}
};

const onForceFlash = () => sendJob(BuildJobType.ForceFlash);

const deviceTargetRef = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -909,6 +946,49 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
onChange={onWifiDevice}
/>
)}
<Typography variant="h6" sx={styles.categoryTitle}>
Flashing Options
</Typography>
<List>
{eraseSupported && (
<ListItem
dense
selected={erase}
button
onClick={() => {
setErase(!erase);
}}
>
<ListItemIcon sx={styles.icon}>
<Checkbox
edge="start"
checked={erase}
tabIndex={-1}
disableRipple
/>
</ListItemIcon>
<ListItemText>Erase Before Flash</ListItemText>
</ListItem>
)}
<ListItem
dense
selected={forceFlash}
button
onClick={() => {
setForceFlash(!forceFlash);
}}
>
<ListItemIcon sx={styles.icon}>
<Checkbox
edge="start"
checked={forceFlash}
tabIndex={-1}
disableRipple
/>
</ListItemIcon>
<ListItemText>Force Flash</ListItemText>
</ListItem>
</List>
{deviceTarget?.flashingMethod !== FlashingMethod.UART &&
deviceTarget?.flashingMethod !== FlashingMethod.Passthrough &&
deviceTarget?.flashingMethod !==
Expand All @@ -927,28 +1007,14 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
</Button>
)}
{deviceTarget?.flashingMethod !== FlashingMethod.Stock_BL && (
<SplitButton
<Button
sx={styles.button}
size="large"
variant="contained"
options={[
{
label: 'Build & Flash',
value: BuildJobType.BuildAndFlash,
},
{
label: 'Force Flash',
value: BuildJobType.ForceFlash,
},
]}
onButtonClick={(value: string | null) => {
if (value === BuildJobType.BuildAndFlash) {
onBuildAndFlash();
} else if (value === BuildJobType.ForceFlash) {
onForceFlash();
}
}}
/>
onClick={onBuildAndFlash}
>
Build & Flash
</Button>
)}
</div>
</CardContent>
Expand Down

0 comments on commit 6d9de92

Please sign in to comment.