diff --git a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp index 0e31da6..8b3bab5 100644 --- a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp +++ b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.cpp @@ -7,19 +7,15 @@ wifiHandlerSim::wifiHandlerSim() {} void wifiHandlerSim::begin() {} void wifiHandlerSim::connect(std::string ssid, std::string password) { - while (!mIsStatusThreadDone.load()) { - } if (mFakeStatusThread.joinable()) { mFakeStatusThread.join(); + mCurrentStatus.ssid = ssid; + mCurrentStatus.isConnected = true; + mFakeStatusThread = std::thread([this] { + std::this_thread::sleep_for(std::chrono::seconds(1)); + mStatusUpdate->notify(mCurrentStatus); + }); } - mCurrentStatus.ssid = ssid; - mCurrentStatus.isConnected = true; - mIsStatusThreadDone = false; - mFakeStatusThread = std::thread([this] { - std::this_thread::sleep_for(std::chrono::seconds(1)); - mStatusUpdate->notify(mCurrentStatus); - mIsStatusThreadDone = true; - }); } static const WifiInfo wifis[] = { @@ -27,17 +23,13 @@ static const WifiInfo wifis[] = { WifiInfo("Low Signal Wifi", -65), WifiInfo("No Signal Wifi", -90)}; void wifiHandlerSim::scan() { - while (!mIsScanThreadDone.load()) { - } if (mFakeScanThread.joinable()) { mFakeScanThread.join(); + mFakeScanThread = std::thread([this] { + std::vector info = + std::vector(std::begin(wifis), std::end(wifis)); + std::this_thread::sleep_for(std::chrono::seconds(2)); + mScanNotification->notify(info); + }); } - mIsScanThreadDone = false; - mFakeScanThread = std::thread([this] { - std::vector info = - std::vector(std::begin(wifis), std::end(wifis)); - std::this_thread::sleep_for(std::chrono::seconds(2)); - mScanNotification->notify(info); - mIsScanThreadDone = true; - }); } diff --git a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp index 439763d..ee5022b 100644 --- a/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp +++ b/Platformio/HAL/Targets/Simulator/wifiHandlerSim/wifiHandlerSim.hpp @@ -15,11 +15,7 @@ public: wifiStatus GetStatus() override { return mCurrentStatus; }; private: - // Since they have not started consider them "done" - std::atomic mIsScanThreadDone = true; - std::atomic mIsStatusThreadDone = true; - - std::thread mFakeScanThread; - std::thread mFakeStatusThread; + std::thread mFakeScanThread = std::thread([] {}); + std::thread mFakeStatusThread = std::thread([] {}); wifiStatus mCurrentStatus = wifiStatus(true, "172.0.0.1", "FakeNet"); }; \ No newline at end of file