Skip to content

Commit

Permalink
Use address constants where provided (#6)
Browse files Browse the repository at this point in the history
* Use address constants where provided

* Add toggle setting for address constant display

* Fix prettier

* Bump version to 0.3.0
  • Loading branch information
charliefoxtwo authored Apr 1, 2024
1 parent c31d346 commit 238f345
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 73 deletions.
12 changes: 12 additions & 0 deletions electron/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface SettingsSchema {
lastModule: string;
lastCategory: string;
alwaysOnTop: boolean;
useAddressConstants: boolean;
}

export default class Settings {
Expand All @@ -29,6 +30,7 @@ export default class Settings {
lastModule: 'MetadataEnd',
lastCategory: 'Metadata',
alwaysOnTop: true,
useAddressConstants: true,
},
});
}
Expand Down Expand Up @@ -106,4 +108,14 @@ export default class Settings {
alwaysOnTop: newValue,
});
}

public get UseAddressConstants(): boolean {
return this.store.get('useAddressConstants');
}

public set UseAddressConstants(newValue: boolean) {
this.store.set({
useAddressConstants: newValue,
});
}
}
8 changes: 8 additions & 0 deletions electron/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ export const api = {
Settings.Instance.ShowArduinoData = value;
},

getUseAddressConstants: (): boolean => {
return Settings.Instance.UseAddressConstants;
},

setUseAddressConstants: (value: boolean) => {
Settings.Instance.UseAddressConstants = value;
},

getSettingsJsonPath: (): string => {
return Settings.Instance.JsonPath;
},
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bort",
"author": "charlie",
"version": "0.2.5",
"version": "0.3.0",
"description": "A tool for sending data to and viewing data from DCS-BIOS.",
"private": true,
"main": ".webpack/main",
Expand Down
3 changes: 3 additions & 0 deletions src/@types/Output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { OutputType } from './OutputType';

export default interface Output {
address: number;
address_mask_shift_identifier?: string;
address_mask_identifier?: string;
address_identifier?: string;
suffix: string;
mask?: number;
shift_by?: number;
Expand Down
16 changes: 15 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ interface AppState {
mode: PaletteMode;
showLiveData: boolean;
showArduinoData: boolean;
useAddressConstants: boolean;
}

export default class App extends Component<unknown, AppState> {
Expand All @@ -75,18 +76,21 @@ export default class App extends Component<unknown, AppState> {
mode: 'light',
showLiveData: true,
showArduinoData: false,
useAddressConstants: false,
};

this.toggleColorMode = this.toggleColorMode.bind(this);
this.toggleShowLiveData = this.toggleShowLiveData.bind(this);
this.toggleShowArduinoData = this.toggleShowArduinoData.bind(this);
this.toggleUseAddressConstants = this.toggleUseAddressConstants.bind(this);
}

public componentDidMount() {
this.setState({
mode: window.Main.getSettingsTheme(),
showLiveData: window.Main.getShowLiveData(),
showArduinoData: window.Main.getShowArduinoData(),
useAddressConstants: window.Main.getUseAddressConstants(),
});
}

Expand Down Expand Up @@ -114,8 +118,16 @@ export default class App extends Component<unknown, AppState> {
});
}

private toggleUseAddressConstants() {
const newValue = !this.state.useAddressConstants;
window.Main.setUseAddressConstants(newValue);
this.setState({
useAddressConstants: newValue,
});
}

public render() {
const { mode, showLiveData, showArduinoData } = this.state;
const { mode, showLiveData, showArduinoData, useAddressConstants } = this.state;
const theme = responsiveFontSizes(createTheme(getDesignTokens(mode)), {
factor: 5,
});
Expand All @@ -139,8 +151,10 @@ export default class App extends Component<unknown, AppState> {
onThemeToggle={this.toggleColorMode}
onShowLiveDataToggle={this.toggleShowLiveData}
onShowArduinoCodeToggle={this.toggleShowArduinoData}
onUseAddressConstantsToggle={this.toggleUseAddressConstants}
showLiveData={showLiveData}
showArduinoData={showArduinoData}
useAddressConstants={useAddressConstants}
/>
</ThemeProvider>
</React.StrictMode>
Expand Down
14 changes: 12 additions & 2 deletions src/components/Category/Category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface CategoryProps {
focusedRef?: React.RefObject<HTMLDivElement>;
showLiveData: boolean;
showArduinoData: boolean;
useAddressConstants: boolean;
}

export default class Category extends Component<CategoryProps> {
Expand All @@ -20,8 +21,16 @@ export default class Category extends Component<CategoryProps> {
}

public render(): ReactNode {
const { moduleName, categoryName, category, focusedComponent, focusedRef, showLiveData, showArduinoData } =
this.props;
const {
moduleName,
categoryName,
category,
focusedComponent,
focusedRef,
showLiveData,
showArduinoData,
useAddressConstants,
} = this.props;
return (
<Stack spacing={2} className="category">
<Typography variant={'h2'}>{categoryName}</Typography>
Expand All @@ -35,6 +44,7 @@ export default class Category extends Component<CategoryProps> {
key={e[1].identifier}
showLiveData={showLiveData}
showArduinoData={showArduinoData}
useAddressConstants={useAddressConstants}
/>
</div>
))}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Control/Control.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ControlProps {
moduleName: string;
showLiveData: boolean;
showArduinoData: boolean;
useAddressConstants: boolean;
control: ControlItem;
}

Expand All @@ -39,7 +40,7 @@ export default class Control extends Component<ControlProps> {
}

public render(): ReactNode {
const { moduleName, control, showLiveData, showArduinoData } = this.props;
const { moduleName, control, showLiveData, showArduinoData, useAddressConstants } = this.props;
const hasInputs = control.inputs.length > 0;
const hasOutputs = control.outputs.length > 0;
return (
Expand Down Expand Up @@ -73,6 +74,7 @@ export default class Control extends Component<ControlProps> {
key={x.type}
showLiveData={showLiveData}
showArduinoData={showArduinoData}
useAddressConstants={useAddressConstants}
/>
))}
</IOContainer>
Expand Down
27 changes: 25 additions & 2 deletions src/components/ControlReference/ControlReference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export interface ControlReferenceProps {
onThemeToggle: () => void;
onShowLiveDataToggle: () => void;
onShowArduinoCodeToggle: () => void;
onUseAddressConstantsToggle: () => void;
showLiveData: boolean;
showArduinoData: boolean;
useAddressConstants: boolean;
}

export interface ControlReferenceState {
Expand Down Expand Up @@ -293,8 +295,16 @@ export default class ControlReference extends Component<ControlReferenceProps, C
}

public render(): ReactNode {
const { theme, onThemeToggle, onShowLiveDataToggle, onShowArduinoCodeToggle, showLiveData, showArduinoData } =
this.props;
const {
theme,
onThemeToggle,
onShowLiveDataToggle,
onShowArduinoCodeToggle,
onUseAddressConstantsToggle,
showLiveData,
showArduinoData,
useAddressConstants,
} = this.props;
const {
modules,
moduleNames,
Expand Down Expand Up @@ -432,6 +442,18 @@ export default class ControlReference extends Component<ControlReferenceProps, C
label="Show arduino scaffold code"
/>
</Grid>
<Grid xs={12} sm={6} md={4} lg={3} xl={2}>
<FormControlLabel
control={
<Checkbox
checked={useAddressConstants}
onChange={onUseAddressConstantsToggle}
name="constants"
/>
}
label="Use address constants"
/>
</Grid>
<Grid xs={12}>
{hasLoadedModules ? (
module ? (
Expand All @@ -443,6 +465,7 @@ export default class ControlReference extends Component<ControlReferenceProps, C
focusedRef={focusedRef ?? undefined}
showLiveData={showLiveData}
showArduinoData={showArduinoData}
useAddressConstants={useAddressConstants}
/>
) : (
<Box
Expand Down
15 changes: 13 additions & 2 deletions src/components/Module/Module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface ModuleProps {
focusedRef?: React.RefObject<HTMLDivElement>;
showLiveData: boolean;
showArduinoData: boolean;
useAddressConstants: boolean;
}

export default class Module extends Component<ModuleProps> {
Expand All @@ -20,8 +21,16 @@ export default class Module extends Component<ModuleProps> {
}

public render(): ReactNode {
const { module, moduleName, categoryName, focusedComponent, focusedRef, showLiveData, showArduinoData } =
this.props;
const {
module,
moduleName,
categoryName,
focusedComponent,
focusedRef,
showLiveData,
showArduinoData,
useAddressConstants,
} = this.props;
const category = module[categoryName];

return (
Expand All @@ -35,6 +44,7 @@ export default class Module extends Component<ModuleProps> {
showArduinoData={showArduinoData}
focusedComponent={focusedComponent}
focusedRef={focusedRef}
useAddressConstants={useAddressConstants}
/>
) : (
Object.entries(module).map((e, i) => (
Expand All @@ -47,6 +57,7 @@ export default class Module extends Component<ModuleProps> {
showLiveData={showLiveData}
showArduinoData={showArduinoData}
focusedRef={focusedRef}
useAddressConstants={useAddressConstants}
/>
))
)}
Expand Down
19 changes: 16 additions & 3 deletions src/components/Output/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface OutputProps {
output: OutputItem;
showLiveData: boolean;
showArduinoData: boolean;
useAddressConstants: boolean;
}

export default class Output extends Component<OutputProps> {
Expand Down Expand Up @@ -42,12 +43,24 @@ export default class Output extends Component<OutputProps> {
}

private snippetForInterface(): ReactNode {
const { identifier, output } = this.props;
const { identifier, output, useAddressConstants } = this.props;
switch (output.type) {
case OutputType.INTEGER:
return <IntegerSnippetBlock controlIdentifier={identifier} output={output} />;
return (
<IntegerSnippetBlock
controlIdentifier={identifier}
output={output}
useAddressConstants={useAddressConstants}
/>
);
case OutputType.STRING:
return <StringSnippetBlock controlIdentifier={identifier} output={output} />;
return (
<StringSnippetBlock
controlIdentifier={identifier}
output={output}
useAddressConstants={useAddressConstants}
/>
);
}

console.error('no snippet!');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { Component, ReactNode } from 'react';

import Output from '../../../../../@types/Output';
import Snippet from '../../../Snippet';
import { IntegerSnippetProps } from '../IntegerSnippetProps';

export interface IntegerBufferSnippetProps {
controlIdentifier: string;
output: Output;
}

export default class IntegerBufferSnippet extends Component<IntegerBufferSnippetProps> {
export default class IntegerBufferSnippet extends Component<IntegerSnippetProps> {
public render(): ReactNode {
const { controlIdentifier, output } = this.props;
const { controlIdentifier, output, useAddressConstants } = this.props;
const methodName = Snippet.snakeToCamelCase(`${controlIdentifier}_Buffer`);
const callbackMethodName = Snippet.snakeToCamelCase(`on_${controlIdentifier}_change`);

Expand All @@ -22,8 +17,10 @@ export default class IntegerBufferSnippet extends Component<IntegerBufferSnippet
<br />
&#125;
<br />
DcsBios::IntegerBuffer {methodName}({Snippet.toHex(output.address)}, {Snippet.toHex(output.mask)},{' '}
{output.shift_by}, {callbackMethodName});
DcsBios::IntegerBuffer {methodName}(
{(useAddressConstants && output.address_mask_shift_identifier) ||
`${Snippet.toHex(output.address)}, ${Snippet.toHex(output.mask)}, ${output.shift_by}`}
, {callbackMethodName});
</Snippet>
);
}
Expand Down
Loading

0 comments on commit 238f345

Please sign in to comment.