Skip to content

Commit a2dc906

Browse files
committed
Update correct ESC when esc index does not equal array index #434
1 parent 864afc3 commit a2dc906

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

src/Components/Flash/Escs/Esc/__tests__/index.test.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ describe('Esc', () => {
341341
}));
342342

343343
const esc = {
344+
index: 0,
344345
firmwareName: 'Bluejay',
345346
layoutRevision: 207,
346347
settings: { DITHERING: 0 },
@@ -374,6 +375,7 @@ describe('Esc', () => {
374375
}));
375376

376377
const esc = {
378+
index: 0,
377379
firmwareName: 'Bluejay',
378380
layoutRevision: 207,
379381
settings: { DITHERING: 1 },

src/Containers/App/escsSlice.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import { createSlice } from '@reduxjs/toolkit';
22

3+
/**
4+
* NOTE: The individual array holds individual ESC settings, the actual index
5+
* in the array does not represent the actual index of the ESC. If for
6+
* example only one ESC is attached, the individual length will have a
7+
* length of 1. The actual index of the ESC must be reat from that object.
8+
*
9+
* Eg.: Only one ESC is attached to motor pin 2 an an FC where 4 ESCs
10+
* are expected. The individual array will have a length of 1, but
11+
* at index 0 it will have the settings for the ESC attached to motor
12+
* pin 2.
13+
*/
14+
315
const initialState = {
416
connected: 0,
517
master: {},
@@ -42,10 +54,16 @@ export const escsSlice = createSlice({
4254
settings,
4355
} = action.payload;
4456

45-
state.individual[index] = {
46-
...state.individual[index],
47-
...settings,
48-
};
57+
for(let i = 0; i < state.individual.length; i += 1) {
58+
if(state.individual[i].index === index) {
59+
state.individual[i] = {
60+
...state.individual[i],
61+
...settings,
62+
};
63+
64+
break;
65+
}
66+
}
4967
},
5068
},
5169
});

src/changelog.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
{
33
"title": "Unreleased",
44
"items": [
5-
"AM32: Fix running brake range",
5+
"Bugfix: Fix running brake range on AM32",
6+
"Bugfix: Update correct ESC when only a single ESC is attached (when multiple would be expected)",
7+
"Bugfix: Allow recovery via UI if ESC can still be read, but previous flash failed",
68
"Bluejay: Adjust min/max startup power defaults",
79
"Enhancement: Show checklist when chosing new firmware version",
810
"Enhancement: Link to release notes of new versions if available",

0 commit comments

Comments
 (0)