Skip to content

Commit e41e249

Browse files
committed
Added locate features
1 parent 4bf66ab commit e41e249

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/master/GoProMaster.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,25 @@ void GoProMaster::presetSwitch(const std::string server, const std::string targe
301301
}).detach();
302302
}
303303

304+
void GoProMaster::locate(const std::string server, const std::string target){
305+
std::lock_guard<std::mutex> lock(locate_mtx);
306+
int32_t index = haslocate(server, target);
307+
if(index == -1){
308+
locates.push_back(std::pair<std::string, std::string>(server, target));
309+
}else{
310+
locates.erase(locates.begin() + index);
311+
}
312+
}
313+
314+
int32_t GoProMaster::haslocate(const std::string server, const std::string target){
315+
std::lock_guard<std::mutex> lock(locate_mtx);
316+
for(int32_t i = 0; i < locates.size(); i++){
317+
auto& s = locates.at(i);
318+
if(s.first == server && s.second == target) return i;
319+
}
320+
return -1;
321+
}
322+
304323
void GoProMaster::apply(const std::string& ip, const int32_t id, const int32_t value){
305324
std::thread([=](){
306325
for (auto& s : servers) {
@@ -392,8 +411,13 @@ void GoProMaster::update(){
392411
mediaQueryFinish.insert_or_assign(s->ip, true);
393412
s->client.send(get_status.dump());
394413
}
414+
415+
std::lock_guard<std::mutex> lock(locate_mtx);
416+
for (auto& s : locates) {
417+
presetSwitch(s.first, s.second, 0);
418+
}
395419

396-
std::this_thread::sleep_for(std::chrono::seconds(3));
420+
std::this_thread::sleep_for(std::chrono::seconds(2));
397421
}
398422
}
399423

src/master/GoProMaster.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ class GoProMaster {
8989
void download_last_media(const std::string dir, bool put_finish);
9090

9191
void presetSwitch(const std::string server, const std::string target, int32_t mode);
92+
void locate(const std::string server, const std::string target);
93+
int32_t haslocate(const std::string server, const std::string target);
9294
void apply(const std::string& ip, const int32_t id, const int32_t value);
9395
void applyAll(const std::string& ip, const json& res);
9496

@@ -111,6 +113,7 @@ class GoProMaster {
111113
* This will prevent race condition
112114
*/
113115
std::mutex camera_mtx;
116+
std::mutex locate_mtx;
114117

115118
// ----------------------------------------------------------
116119
//
@@ -134,6 +137,10 @@ class GoProMaster {
134137
* All websocket servers record for master
135138
*/
136139
std::vector<std::shared_ptr<ServerConnection>> servers;
140+
/**
141+
* All the locate records
142+
*/
143+
std::vector<std::pair<std::string, std::string>> locates;
137144
/**
138145
* Basically a update thread, THere is a while true loop in it,
139146
* And when done is true, it automatically escape the loop

src/master/windows/commands.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,17 @@ void CommandWindow::render_local(){
102102
if(ImGui::Button("Connect", button_4size)) master->command_only(info.server, "usb_on", info.ip); ImGui::SameLine();
103103
if(ImGui::Button("Disconnect", button_4size)) master->command_only(info.server, "usb_off", info.ip); ImGui::SameLine();
104104
if(ImGui::Button("Shutdown", button_4size)) master->command_only(info.server, "usb_on", info.ip); ImGui::SameLine();
105-
if(ImGui::Button("Locate", button_4size)) master->presetSwitch(info.server, info.ip, 0);
105+
int32_t lo = master->haslocate(info.server, info.ip);
106+
if(lo == -1){
107+
if(ImGui::Button("Locate", button_4size)) master->locate(info.server, info.ip);
108+
}else{
109+
if(ImGui::Button("UnLocate", button_4size)) master->locate(info.server, info.ip);
110+
}
106111

107112
ImGui::Dummy(ImVec2(0, 20));
108113
ImGui::Separator();
109114
ImGui::Dummy(ImVec2(0, 20));
110115

111-
112-
113116
if(state->current_status_items[std::to_string(PRESET_ID)].is_number_integer()){
114117

115118
int32_t cuccrent_select = state->current_status_items[std::to_string(PRESET_ID)].get<int32_t>();

0 commit comments

Comments
 (0)