Skip to content

Commit

Permalink
Now use global index on filtered view to actually change correct setting
Browse files Browse the repository at this point in the history
  • Loading branch information
kglovern committed Jan 25, 2024
1 parent 6a48775 commit e8d58d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/app/containers/Firmware/components/HalSettings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import CategoryTag from 'Containers/Firmware/components/Settings/CategoryTag';

const HalSettings = ({ descriptions }) => {
const { settings, setSettings, setSettingsToApply } = useContext(FirmwareContext);

console.log(settings);
const handleSettingsChange = (index) => (value) => {
setSettingsToApply(true);
setSettings(prev => {
console.log(`index: ${index}`);
const updated = [...prev];
console.log(updated[index]);

updated[index].value = value;
console.log(updated);
return updated;
});
};
Expand Down Expand Up @@ -66,7 +70,7 @@ const HalSettings = ({ descriptions }) => {
</div>
</div>
<div className={styles.settingsControl}>
<InputElement info={info} setting={setting} onChange={handleSettingsChange(index)} />
<InputElement info={info} setting={setting} onChange={handleSettingsChange(setting.globalIndex)} />
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/app/containers/Firmware/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import styles from './index.styl';
import { collectUserUsageData } from '../../lib/heatmap';

const getFilteredEEPROM = (settings, eeprom = {}, halDescriptions = {}, halGroups = {}) => {
return Object.keys(eeprom).map((setting) => {
return Object.keys(eeprom).map((setting, index) => {
const properties = settings.find(obj => {
return obj.setting === setting;
});
Expand All @@ -29,6 +29,7 @@ const getFilteredEEPROM = (settings, eeprom = {}, halDescriptions = {}, halGroup

return {
...properties || {},
globalIndex: index,
setting: setting,
value: eeprom[setting],
...halData,
Expand Down
5 changes: 3 additions & 2 deletions src/app/containers/Firmware/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ export const convertValueToArray = (value, possibilities) => {
};

export const applyNewSettings = (settings, eeprom, setSettingsToApply) => {
console.log(settings);

let index22 = 200; // index of $22 - default is 200 because we have less eeprom values than that, so it will never be set to this value
let index2021 = -1; // index of $20 or $21, whichever comes first
let changedSettings = settings
Expand All @@ -162,9 +164,8 @@ export const applyNewSettings = (settings, eeprom, setSettingsToApply) => {
changedSettings[index22] = changedSettings[index2021];
changedSettings[index2021] = setting22;
}

changedSettings.push('$$'); // Add setting refresh to end so tool updates values
controller.command('gcode', changedSettings);
controller.command('gcode', '$$'); //Needed so next time wizard is opened changes are reflected
setSettingsToApply(false);
Toaster.pop({
msg: 'Firmware Settings Updated',
Expand Down

0 comments on commit e8d58d3

Please sign in to comment.