-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
55 lines (45 loc) · 1.39 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <thread>
// #include "onekey_usb.hpp"
#include "onekey_usb_bootloader_mode.hpp"
#include "onekey_usb_firmware_mode.hpp"
int main()
{
onekey::usb::bootloader::BOOTLOADER okusb_bl;
okusb_bl.usb_timeout_ms = 1000;
// thread control vars
std::atomic_bool thread_run_status = false;
std::atomic_bool thread_run_control = false;
// start thread then detach
thread_run_control = true;
std::thread thread_h = std::thread(
&onekey::usb::bootloader::BOOTLOADER::usb_service_routine, &okusb_bl, std::ref(thread_run_control),
std::ref(thread_run_status)
);
thread_h.detach();
bzh_utils::log::StdLog::Debug("thread_run_control -> " + std::string(thread_run_control ? "true" : "false"));
// wait for running
while ( !thread_run_status ) {};
// wait for Xs
auto counter = 0;
while ( thread_run_status )
{
std::this_thread::sleep_for(1000ms);
counter++;
bzh_utils::log::StdLog::Debug("Thread running count -> ", std::to_string(counter));
if ( counter >= 20)
{
break;
}
}
// stop thread
thread_run_control = false;
counter = 0;
while ( thread_run_status )
{
std::this_thread::sleep_for(1000ms);
counter++;
bzh_utils::log::StdLog::Debug("Thread stopping count -> ", std::to_string(counter));
}
return 0;
}