diff --git a/electron/Settings.ts b/electron/Settings.ts index 4f3efb2..b6a80c2 100644 --- a/electron/Settings.ts +++ b/electron/Settings.ts @@ -9,6 +9,7 @@ interface SettingsSchema { lastModule: string; lastCategory: string; alwaysOnTop: boolean; + useAddressConstants: boolean; } export default class Settings { @@ -29,6 +30,7 @@ export default class Settings { lastModule: 'MetadataEnd', lastCategory: 'Metadata', alwaysOnTop: true, + useAddressConstants: true, }, }); } @@ -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, + }); + } } diff --git a/electron/bridge.ts b/electron/bridge.ts index d5e604c..1a0e265 100644 --- a/electron/bridge.ts +++ b/electron/bridge.ts @@ -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; }, diff --git a/package-lock.json b/package-lock.json index 8ced388..60512fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bort", - "version": "0.2.5", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bort", - "version": "0.2.5", + "version": "0.3.0", "license": "MIT", "dependencies": { "@emotion/react": "^11.9.0", diff --git a/package.json b/package.json index 5339ac6..5e53406 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/@types/Output.ts b/src/@types/Output.ts index 72cd6c3..311ee79 100644 --- a/src/@types/Output.ts +++ b/src/@types/Output.ts @@ -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; diff --git a/src/App.tsx b/src/App.tsx index 58f4aa6..8dd501f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -65,6 +65,7 @@ interface AppState { mode: PaletteMode; showLiveData: boolean; showArduinoData: boolean; + useAddressConstants: boolean; } export default class App extends Component { @@ -75,11 +76,13 @@ export default class App extends Component { 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() { @@ -87,6 +90,7 @@ export default class App extends Component { mode: window.Main.getSettingsTheme(), showLiveData: window.Main.getShowLiveData(), showArduinoData: window.Main.getShowArduinoData(), + useAddressConstants: window.Main.getUseAddressConstants(), }); } @@ -114,8 +118,16 @@ export default class App extends Component { }); } + 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, }); @@ -139,8 +151,10 @@ export default class App extends Component { onThemeToggle={this.toggleColorMode} onShowLiveDataToggle={this.toggleShowLiveData} onShowArduinoCodeToggle={this.toggleShowArduinoData} + onUseAddressConstantsToggle={this.toggleUseAddressConstants} showLiveData={showLiveData} showArduinoData={showArduinoData} + useAddressConstants={useAddressConstants} /> diff --git a/src/components/Category/Category.tsx b/src/components/Category/Category.tsx index 8dd6d20..53e0e05 100644 --- a/src/components/Category/Category.tsx +++ b/src/components/Category/Category.tsx @@ -12,6 +12,7 @@ export interface CategoryProps { focusedRef?: React.RefObject; showLiveData: boolean; showArduinoData: boolean; + useAddressConstants: boolean; } export default class Category extends Component { @@ -20,8 +21,16 @@ export default class Category extends Component { } 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 ( {categoryName} @@ -35,6 +44,7 @@ export default class Category extends Component { key={e[1].identifier} showLiveData={showLiveData} showArduinoData={showArduinoData} + useAddressConstants={useAddressConstants} /> ))} diff --git a/src/components/Control/Control.tsx b/src/components/Control/Control.tsx index 58d3b17..bef203d 100644 --- a/src/components/Control/Control.tsx +++ b/src/components/Control/Control.tsx @@ -13,6 +13,7 @@ export interface ControlProps { moduleName: string; showLiveData: boolean; showArduinoData: boolean; + useAddressConstants: boolean; control: ControlItem; } @@ -39,7 +40,7 @@ export default class Control extends Component { } 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 ( @@ -73,6 +74,7 @@ export default class Control extends Component { key={x.type} showLiveData={showLiveData} showArduinoData={showArduinoData} + useAddressConstants={useAddressConstants} /> ))} diff --git a/src/components/ControlReference/ControlReference.tsx b/src/components/ControlReference/ControlReference.tsx index 752eaab..9398fc1 100644 --- a/src/components/ControlReference/ControlReference.tsx +++ b/src/components/ControlReference/ControlReference.tsx @@ -37,8 +37,10 @@ export interface ControlReferenceProps { onThemeToggle: () => void; onShowLiveDataToggle: () => void; onShowArduinoCodeToggle: () => void; + onUseAddressConstantsToggle: () => void; showLiveData: boolean; showArduinoData: boolean; + useAddressConstants: boolean; } export interface ControlReferenceState { @@ -293,8 +295,16 @@ export default class ControlReference extends Component + + + } + label="Use address constants" + /> + {hasLoadedModules ? ( module ? ( @@ -443,6 +465,7 @@ export default class ControlReference extends Component ) : ( ; showLiveData: boolean; showArduinoData: boolean; + useAddressConstants: boolean; } export default class Module extends Component { @@ -20,8 +21,16 @@ export default class Module extends Component { } 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 ( @@ -35,6 +44,7 @@ export default class Module extends Component { showArduinoData={showArduinoData} focusedComponent={focusedComponent} focusedRef={focusedRef} + useAddressConstants={useAddressConstants} /> ) : ( Object.entries(module).map((e, i) => ( @@ -47,6 +57,7 @@ export default class Module extends Component { showLiveData={showLiveData} showArduinoData={showArduinoData} focusedRef={focusedRef} + useAddressConstants={useAddressConstants} /> )) )} diff --git a/src/components/Output/Output.tsx b/src/components/Output/Output.tsx index e142492..b72d905 100644 --- a/src/components/Output/Output.tsx +++ b/src/components/Output/Output.tsx @@ -13,6 +13,7 @@ export interface OutputProps { output: OutputItem; showLiveData: boolean; showArduinoData: boolean; + useAddressConstants: boolean; } export default class Output extends Component { @@ -42,12 +43,24 @@ export default class Output extends Component { } private snippetForInterface(): ReactNode { - const { identifier, output } = this.props; + const { identifier, output, useAddressConstants } = this.props; switch (output.type) { case OutputType.INTEGER: - return ; + return ( + + ); case OutputType.STRING: - return ; + return ( + + ); } console.error('no snippet!'); diff --git a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerBufferSnippet/IntegerBufferSnippet.tsx b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerBufferSnippet/IntegerBufferSnippet.tsx index ad46d41..3d2c09d 100644 --- a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerBufferSnippet/IntegerBufferSnippet.tsx +++ b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerBufferSnippet/IntegerBufferSnippet.tsx @@ -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 { +export default class IntegerBufferSnippet extends Component { 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`); @@ -22,8 +17,10 @@ export default class IntegerBufferSnippet extends Component }
- 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}); ); } diff --git a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerSnippetBlock.tsx b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerSnippetBlock.tsx index 8652b09..f700c8b 100644 --- a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerSnippetBlock.tsx +++ b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerSnippetBlock.tsx @@ -1,37 +1,47 @@ import { Component, ReactNode } from 'react'; -import Output from '../../../../@types/Output'; import OutputSnippetBlock from '../OutputSnippetBlock'; import IntegerBufferSnippet from './IntegerBufferSnippet/IntegerBufferSnippet'; +import { IntegerSnippetProps } from './IntegerSnippetProps'; import LedSnippet from './LedSnippet/LedSnippet'; import ServoSnippet from './ServoSnippet/ServoSnippet'; -export interface IntegerSnippetBlockProps { - controlIdentifier: string; - output: Output; -} - -export default class IntegerSnippetBlock extends Component { - constructor(props: IntegerSnippetBlockProps) { +export default class IntegerSnippetBlock extends Component { + constructor(props: IntegerSnippetProps) { super(props); this.snippetsForInput = this.snippetsForInput.bind(this); } private *snippetsForInput(): Iterable { - const { controlIdentifier, output } = this.props; + const { controlIdentifier, output, useAddressConstants } = this.props; yield ( ); if (output.max_value == 1) { - yield ; + yield ( + + ); } else if (output.max_value == 65535) { - yield ; + yield ( + + ); } } diff --git a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerSnippetProps.tsx b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerSnippetProps.tsx new file mode 100644 index 0000000..e900d00 --- /dev/null +++ b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/IntegerSnippetProps.tsx @@ -0,0 +1,7 @@ +import Output from '../../../../@types/Output'; + +export interface IntegerSnippetProps { + controlIdentifier: string; + output: Output; + useAddressConstants: boolean; +} diff --git a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/LedSnippet/LedSnippet.tsx b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/LedSnippet/LedSnippet.tsx index b9414ac..5e90612 100644 --- a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/LedSnippet/LedSnippet.tsx +++ b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/LedSnippet/LedSnippet.tsx @@ -1,23 +1,20 @@ import { Component, ReactNode } from 'react'; -import Output from '../../../../../@types/Output'; import Snippet from '../../../Snippet'; import Variable from '../../../Variable/Variable'; +import { IntegerSnippetProps } from '../IntegerSnippetProps'; -export interface LedSnippetProps { - controlIdentifier: string; - output: Output; -} - -export default class LedSnippet extends Component { +export default class LedSnippet extends Component { public render(): ReactNode { - const { controlIdentifier, output } = this.props; + const { controlIdentifier, output, useAddressConstants } = this.props; const methodName = Snippet.snakeToCamelCase(controlIdentifier); return ( - DcsBios::LED {methodName}({Snippet.toHex(output.address)}, {Snippet.toHex(output.mask)},{' '} - PIN); + DcsBios::LED {methodName}( + {(useAddressConstants && output.address_mask_identifier) || + `${Snippet.toHex(output.address)}, ${Snippet.toHex(output.mask)}`} + , PIN); ); } diff --git a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/ServoSnippet/ServoSnippet.tsx b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/ServoSnippet/ServoSnippet.tsx index 0a9b65a..b5cd5e5 100644 --- a/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/ServoSnippet/ServoSnippet.tsx +++ b/src/components/Snippet/OutputSnippet/IntegerSnippetBlock/ServoSnippet/ServoSnippet.tsx @@ -1,23 +1,19 @@ import { Component, ReactNode } from 'react'; -import Output from '../../../../../@types/Output'; import Snippet from '../../../Snippet'; import Variable from '../../../Variable/Variable'; +import { IntegerSnippetProps } from '../IntegerSnippetProps'; -export interface ServoSnippetProps { - controlIdentifier: string; - output: Output; -} - -export default class ServoSnippet extends Component { +export default class ServoSnippet extends Component { public render(): ReactNode { - const { controlIdentifier, output } = this.props; + const { controlIdentifier, output, useAddressConstants } = this.props; const methodName = Snippet.snakeToCamelCase(controlIdentifier); return ( - DcsBios::ServoOutput {methodName}({Snippet.toHex(output.address)}, PIN,{' '} - 544, 2400); + DcsBios::ServoOutput {methodName}( + {(useAddressConstants && output.address_identifier) || Snippet.toHex(output.address)},{' '} + PIN, 544, 2400); ); } diff --git a/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringBufferSnippet/StringBufferSnippet.tsx b/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringBufferSnippet/StringBufferSnippet.tsx index e6c4bdb..00f0c43 100644 --- a/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringBufferSnippet/StringBufferSnippet.tsx +++ b/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringBufferSnippet/StringBufferSnippet.tsx @@ -1,16 +1,11 @@ import { Component, ReactNode } from 'react'; -import Output from '../../../../../@types/Output'; import Snippet from '../../../Snippet'; +import { StringSnippetProps } from '../StringSnippetProps'; -export interface StringBufferSnippetProps { - controlIdentifier: string; - output: Output; -} - -export default class StringBufferSnippet extends Component { +export default class StringBufferSnippet extends Component { public render(): ReactNode { - const { controlIdentifier, output } = this.props; + const { controlIdentifier, output, useAddressConstants } = this.props; const methodName = Snippet.snakeToCamelCase(`${controlIdentifier}${output.suffix}_Buffer`); const callbackMethodName = Snippet.snakeToCamelCase(`on_${controlIdentifier}_change`); @@ -22,7 +17,8 @@ export default class StringBufferSnippet extends Component }
- DcsBios::StringBuffer<{output.max_length}> {methodName}({Snippet.toHex(output.address)},{' '} + DcsBios::StringBuffer<{output.max_length}> {methodName}( + {(useAddressConstants && output.address_identifier) || Snippet.toHex(output.address)},{' '} {callbackMethodName}); ); diff --git a/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringSnippetBlock.tsx b/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringSnippetBlock.tsx index 22ffa71..4dcee1a 100644 --- a/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringSnippetBlock.tsx +++ b/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringSnippetBlock.tsx @@ -1,21 +1,20 @@ import { Component, ReactNode } from 'react'; -import Output from '../../../../@types/Output'; import OutputSnippetBlock from '../OutputSnippetBlock'; import StringBufferSnippet from './StringBufferSnippet/StringBufferSnippet'; +import { StringSnippetProps } from './StringSnippetProps'; -export interface StringSnippetBlockProps { - controlIdentifier: string; - output: Output; -} - -export default class StringSnippetBlock extends Component { +export default class StringSnippetBlock extends Component { public render(): ReactNode { - const { controlIdentifier, output } = this.props; + const { controlIdentifier, output, useAddressConstants } = this.props; return ( - + ); } diff --git a/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringSnippetProps.tsx b/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringSnippetProps.tsx new file mode 100644 index 0000000..a5bbd50 --- /dev/null +++ b/src/components/Snippet/OutputSnippet/StringSnippetBlock/StringSnippetProps.tsx @@ -0,0 +1,7 @@ +import Output from '../../../../@types/Output'; + +export interface StringSnippetProps { + controlIdentifier: string; + output: Output; + useAddressConstants: boolean; +}