Skip to content

Commit 159bc8d

Browse files
committed
Update VoltageDividerMonitorTest.cpp
1 parent 0abc2d9 commit 159bc8d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

CD_CI/UnitTests/VoltageDividerMonitorTest/VoltageDividerMonitorTest.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131
VoltageDividerMonitor *hardware = nullptr;
3232
int receivedBatteryLevel = 999;
33-
std::counting_semaphore<1> received{1};
34-
bool waiting;
33+
bool running = false;
34+
std::binary_semaphore producer{0};
35+
std::binary_semaphore consumer{0};
3536

3637
//------------------------------------------------------------------
3738
// MOCKS
@@ -53,17 +54,18 @@ class BatteryCalibrationMock : public BatteryCalibrationService
5354

5455
void get_current_battery_level(const BatteryStatus &status)
5556
{
57+
if(!running)
58+
return;
59+
producer.acquire();
5660
// std::cout << "get_current_battery_level" << std::endl;
5761
receivedBatteryLevel = status.stateOfCharge.value_or(0);
58-
received.release();
59-
waiting = false;
62+
consumer.release();
6063
}
6164

6265
void waitFor(std::string message = "")
6366
{
64-
waiting = true;
65-
while (waiting)
66-
received.acquire();
67+
producer.release();
68+
consumer.acquire();
6769
}
6870

6971
//------------------------------------------------------------------
@@ -74,7 +76,6 @@ void waitFor(std::string message = "")
7476

7577
void test1()
7678
{
77-
7879
std::cout << "- test 1 (ADC value injection)-" << std::endl;
7980
internals::hal::gpio::setFakeADCReading({2000});
8081

@@ -166,6 +167,7 @@ int main()
166167
batteryMonitor::setPeriod(1);
167168
internals::batteryMonitor::getReady();
168169
OnStart::notify();
170+
running = true;
169171

170172
test1();
171173
test2();

0 commit comments

Comments
 (0)