Skip to content

Commit

Permalink
added auto advance setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Eike Ahmels committed Oct 26, 2024
1 parent 4d3b7df commit 9cd729e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
13 changes: 11 additions & 2 deletions components/SettingFieldGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</div>
</template>
<script setup lang="ts">
import { coerce, compare } from 'semver';
import type { EepromLayoutKeys } from '~/src/eeprom';
const escStore = useEscStore();
Expand All @@ -24,12 +25,14 @@ interface SwitchType {
field: EepromLayoutKeys;
name: string;
minEepromVersion?: number;
minFirmwareVersion?: string;
}
interface SettingFieldGroupProps {
title: string;
cols: number;
eepromVersion?: number;
firmwareVersion?: string;
switches?: SwitchType[];
}
Expand All @@ -39,18 +42,24 @@ const props = withDefaults(defineProps<SettingFieldGroupProps>(), {
title: '',
cols: 3,
eepromVersion: 0,
firmwareVersion: '',
switches: () => []
});
const filteredSwitches = computed(() => props.switches.filter(s => !s.minEepromVersion || props.eepromVersion >= s.minEepromVersion));
const semverFirmwareVersion = props.firmwareVersion?.replace(/(v[0-9]+)\.0?([0-9])/i, '$1.$2') ?? '0.0';
const filteredSwitches = computed(() => props.switches
.filter(s => (!s.minEepromVersion || props.eepromVersion >= s.minEepromVersion) &&
(!s.minFirmwareVersion || compare(coerce(semverFirmwareVersion)!, coerce(s.minFirmwareVersion)!) >= 0))
);
const model = (field: EepromLayoutKeys) => computed({
get: () => {
return escStore.firstValidEscData?.data.settings[field] === 1;
},
set: (_val) => {
emits('change', {
value: escStore.firstValidEscData?.data.settings[field] === 0 ? 1 : 0,
value: [0, 255].includes(escStore.firstValidEscData?.data.settings[field] as number) ? 1 : 0,
field
});
}
Expand Down
8 changes: 5 additions & 3 deletions pages/configurator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<SettingFieldGroup
title="Motor"
:eeprom-version="escStore.firstValidEscData?.data.settings.LAYOUT_REVISION as number"
:firmware-version="`${escStore.firstValidEscData?.data.settings.MAIN_REVISION}.${escStore.firstValidEscData?.data.settings.SUB_REVISION}`"
:cols="3"
:switches="[{
field: 'STUCK_ROTOR_PROTECTION',
Expand All @@ -103,9 +104,9 @@
field: 'COMPLEMENTARY_PWM',
name: 'Complementary PWM'
}, {
field: 'AUTO_TIMING',
field: 'AUTO_ADVANCE',
name: 'Auto timing advance',
minEepromVersion: 3
minFirmwareVersion: 'v2.16'
}]"
@change="onSettingsChange"
>
Expand All @@ -119,7 +120,7 @@
:step="7.5"
:display-factor="7.5"
unit="°"
:disabled="(v: number) => escStore.firstValidEscData?.data.settings.AUTO_TIMING === 1"
:disabled="(v: number) => escStore.firstValidEscData?.data.settings.AUTO_ADVANCE === 1"
@change="onSettingsChange"
/>
<SettingField
Expand Down Expand Up @@ -415,6 +416,7 @@ const onSettingsChange = ({ field, value, individual }: { field: EepromLayoutKey
for (let i = 0; i < escStore.selectedEscInfo.length; ++i) {
escStore.selectedEscInfo[i].settings[field] = value;
escStore.selectedEscInfo[i].settingsDirty = true;
console.log(field, value, individual, escStore.selectedEscInfo[0].settings[field]);
}
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/eeprom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ export const EepromLayout = {
offset: 0x2E,
size: 1
},
AUTO_ADVANCE: {
offset: 0x2F,
size: 1
},
STARTUP_MELODY: {
offset: 0x30,
size: 128
},
AUTO_TIMING: {
offset: 0xB0,
size: 1
}
};

Expand Down

0 comments on commit 9cd729e

Please sign in to comment.