update handler sim to make it a bit simpler. Thought the atomics fixed a bug but I don't think it did...

This commit is contained in:
MatthewColvin 2023-10-18 20:07:45 -05:00
parent 29f58d406f
commit c7a8987d3b
2 changed files with 14 additions and 26 deletions

View file

@ -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;
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();
}
mIsScanThreadDone = false;
mFakeScanThread = std::thread([this] {
std::vector<WifiInfo> info =
std::vector(std::begin(wifis), std::end(wifis));
std::this_thread::sleep_for(std::chrono::seconds(2));
mScanNotification->notify(info);
mIsScanThreadDone = true;
});
}
}

View file

@ -15,11 +15,7 @@ public:
wifiStatus GetStatus() override { return mCurrentStatus; };
private:
// Since they have not started consider them "done"
std::atomic<bool> mIsScanThreadDone = true;
std::atomic<bool> 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");
};