Skip to content

Commit

Permalink
- Added auto reconnection on disconnect.
Browse files Browse the repository at this point in the history
- new UI based on wt is in work.
  • Loading branch information
dx6nxr committed Jan 20, 2025
1 parent 380c766 commit bbcf495
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 14,134 deletions.
12 changes: 12 additions & 0 deletions WindowsApp_test/Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,23 @@
#ifndef IDC_STATIC
#define IDC_STATIC -1
#define IDB_BUTTON 1000
//slider boxes
#define IDC_COMBOBOX1 1001
#define IDC_COMBOBOX2 1002
#define IDC_COMBOBOX3 1003
#define IDC_COMBOBOX4 1004
//button boxes
#define IDC_BUTTONBOX1 1005
#define IDC_BUTTONBOX2 1006
#define IDC_BUTTONBOX3 1007
#define IDC_BUTTONBOX4 1008
#define IDC_BUTTONBOX5 1009
#define IDC_BUTTONBOX6 1010
#define IDC_BUTTONBOX7 1011
#define IDC_BUTTONBOX8 1012

#define IDC_CHOOSE_SERIAL 1066
//buttons
#define IDB_CHOOSE_SERIAL_BTN 1067
#define IDB_CONNECT_SERIAL_BTN 1068
#define IDB_SAVE_PRESET_BTN 1069
Expand Down
47 changes: 31 additions & 16 deletions WindowsApp_test/SaveLoadPreset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ using json = nlohmann::json;
struct Configuration {
std::wstring com_port;
std::vector<std::string> sliders;
std::vector<unsigned short int> buttons;
bool isValid = false;
};

// Function to write data to a JSON file
bool writeToJson(const std::vector<std::string> sliders, std::wstring com_port) {
bool writeToJson(const std::vector<std::string> sliders, std::wstring com_port, std::vector<unsigned short int> keyMaps) {
try {
json data;
data["com_port"] = com_port;
for (int i = 0; i < sliders.size(); i++) {
data["slider"]["slider" + std::to_string(i + 1)] = sliders[i];
data["sliders"]["slider" + std::to_string(i + 1)] = sliders[i];
}
for (int i = 0; i < keyMaps.size(); i++) {
data["buttons"]["button" + std::to_string(i + 1)] = keyMaps[i];
}

std::ofstream outfile("config.txt");
if (outfile.is_open()) {
outfile << data.dump(4);
outfile.close();
std::cout << "Data written to " << "config.txt" << std::endl;
return true;
}
else {
Expand All @@ -40,8 +44,6 @@ bool writeToJson(const std::vector<std::string> sliders, std::wstring com_port)

// Function to read data from a JSON file
Configuration readFromJson() {
std::wstring com_port;
std::vector<std::string> sliders;
Configuration config;
try {
std::ifstream infile("config.txt");
Expand All @@ -54,22 +56,35 @@ Configuration readFromJson() {
}
else {
std::cerr << "Invalid JSON structure in " << "config.txt" << std::endl;
return config;
}
if (data.contains("slider") &&
data["slider"].contains("slider1") &&
data["slider"].contains("slider2") &&
data["slider"].contains("slider3") &&
data["slider"].contains("slider4"))
if (data.contains("sliders"))
{
config.sliders.push_back(data["slider"]["slider1"].get<std::string>());
config.sliders.push_back(data["slider"]["slider2"].get<std::string>());
config.sliders.push_back(data["slider"]["slider3"].get<std::string>());
config.sliders.push_back(data["slider"]["slider4"].get<std::string>());
return config;
config.sliders.push_back(data["sliders"]["slider1"].get<std::string>());
config.sliders.push_back(data["sliders"]["slider2"].get<std::string>());
config.sliders.push_back(data["sliders"]["slider3"].get<std::string>());
config.sliders.push_back(data["sliders"]["slider4"].get<std::string>());
}
else {
std::cerr << "Invalid JSON structure in " << "config.txt" << std::endl;
return config;
}
if (data.contains("buttons"))
{
config.buttons.push_back(data["buttons"]["button1"].get<unsigned short int>());
config.buttons.push_back(data["buttons"]["button2"].get<unsigned short int>());
config.buttons.push_back(data["buttons"]["button3"].get<unsigned short int>());
config.buttons.push_back(data["buttons"]["button4"].get<unsigned short int>());
config.buttons.push_back(data["buttons"]["button5"].get<unsigned short int>());
config.buttons.push_back(data["buttons"]["button6"].get<unsigned short int>());
config.buttons.push_back(data["buttons"]["button7"].get<unsigned short int>());
config.buttons.push_back(data["buttons"]["button8"].get<unsigned short int>());
config.isValid = true;
return config;
}
else {
std::cerr << "Invalid JSON structure in " << "config.txt" << std::endl;
return config;
return config;
}
}
else {
Expand Down
4 changes: 3 additions & 1 deletion WindowsApp_test/SaveLoadPreset.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
struct Configuration {
std::wstring com_port;
std::vector<std::string> sliders;
std::vector<unsigned short int> buttons;
bool isValid = false;
};

// Forward declaration of json (if you don't want to include json.hpp in the header)
Expand All @@ -13,5 +15,5 @@ namespace nlohmann {
}

// Function prototypes
bool writeToJson(const std::vector<std::string> sliders, std::wstring com_port);
bool writeToJson(const std::vector<std::string> sliders, std::wstring com_port, std::vector<unsigned short int> keyMaps);
Configuration readFromJson();
Loading

0 comments on commit bbcf495

Please sign in to comment.