Skip to content

Commit 4c8be59

Browse files
committed
fix: max instruction was dupplicated but skipped
1 parent 3e93577 commit 4c8be59

2 files changed

Lines changed: 15 additions & 19 deletions

File tree

sources/camera/camerainstruction.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,25 @@ CameraInstruction::CameraInstruction(uint8_t unit, uint8_t selector, const vecto
9191
* false if the maximum control has already been set
9292
*/
9393
bool CameraInstruction::next() noexcept
94-
{
94+
{
95+
if (curCtrl == maxCtrl)
96+
return false;
97+
9598
for (unsigned i = 0; i < curCtrl.size(); ++i)
9699
{
97100
uint16_t nextCtrli = static_cast<uint16_t>(curCtrl[i] + 1);
98101
if (nextCtrli > maxCtrl[i])
99102
curCtrl[i] = minCtrl[i]; // simulate "overflow"
100-
else
103+
else
101104
{
102105
curCtrl[i] = static_cast<uint8_t>(nextCtrli);
103106
logDebugCtrl("new current:", curCtrl);
104107
return true;
105-
}
108+
}
106109
}
107110

111+
// all are in overflow (should never arrive!)
108112
setMaxAsCur();
109-
110113
return false;
111114
}
112115

sources/driver/finder.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,22 @@ unique_ptr<vector<unique_ptr<Driver>>> Finder::find()
119119
{
120120
CameraInstruction instruction(camera, unit, selector);
121121
const CameraInstruction initInstruction = instruction; // copy for reset later
122-
123-
if (!instruction.setMinAsCur()) // if no min instruction exists
124-
if (!instruction.next()) // start from the next one
125-
continue; // if no next, skip
126-
122+
123+
instruction.setMinAsCur();
127124
unsigned negAnswerCounter = 0;
128-
do
129-
{
125+
while (negAnswerCounter < negAnswerLimit && instruction.next())
126+
{
127+
if (negAnswerCounter == negAnswerLimit - 1)
128+
instruction.setMaxAsCur();
129+
130130
if (camera.apply(instruction) && camera.isEmitterWorking())
131131
{
132132
drivers->push_back(createDriverFromInstruction(instruction, unit, selector));
133133
if (drivers->size() == emitters) // all emitters are configured
134134
return drivers;
135135
}
136136
++negAnswerCounter;
137-
138-
if (negAnswerCounter == negAnswerLimit - 1)
139-
{
140-
instruction.setMaxAsCur();
141-
continue;
142-
}
143-
144-
} while (negAnswerCounter < negAnswerLimit && instruction.next());
137+
}
145138

146139
camera.apply(initInstruction);
147140
Logger::debug("");

0 commit comments

Comments
 (0)