mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-03 05:57:40 -05:00
refactor: Get rid of this->m_
This commit is contained in:
@@ -12,35 +12,35 @@
|
||||
namespace hex::plugin::windows {
|
||||
|
||||
ViewTTYConsole::ViewTTYConsole() : View::Window("hex.windows.view.tty_console.name") {
|
||||
this->m_comPorts = getAvailablePorts();
|
||||
this->m_transmitDataBuffer.resize(0xFFF, 0x00);
|
||||
this->m_receiveDataBuffer.reserve(0xFFF);
|
||||
this->m_receiveDataBuffer.push_back(0x00);
|
||||
m_comPorts = getAvailablePorts();
|
||||
m_transmitDataBuffer.resize(0xFFF, 0x00);
|
||||
m_receiveDataBuffer.reserve(0xFFF);
|
||||
m_receiveDataBuffer.push_back(0x00);
|
||||
}
|
||||
|
||||
void ViewTTYConsole::drawContent() {
|
||||
ImGuiExt::Header("hex.windows.view.tty_console.config"_lang, true);
|
||||
|
||||
bool connected = this->m_portHandle != INVALID_HANDLE_VALUE;
|
||||
bool connected = m_portHandle != INVALID_HANDLE_VALUE;
|
||||
|
||||
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, connected);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, connected ? 0.5F : 1.0F);
|
||||
|
||||
ImGui::Combo(
|
||||
"hex.windows.view.tty_console.port"_lang, &this->m_selectedPort, [](void *data, int idx) {
|
||||
"hex.windows.view.tty_console.port"_lang, &m_selectedPort, [](void *data, int idx) {
|
||||
auto &ports = *static_cast<std::vector<std::pair<std::string, std::string>> *>(data);
|
||||
|
||||
return ports[idx].first.c_str();
|
||||
},
|
||||
&this->m_comPorts,
|
||||
this->m_comPorts.size());
|
||||
&m_comPorts,
|
||||
m_comPorts.size());
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("hex.windows.view.tty_console.reload"_lang))
|
||||
this->m_comPorts = getAvailablePorts();
|
||||
m_comPorts = getAvailablePorts();
|
||||
|
||||
ImGui::Combo(
|
||||
"hex.windows.view.tty_console.baud"_lang, &this->m_selectedBaudRate, [](void *data, int idx) {
|
||||
"hex.windows.view.tty_console.baud"_lang, &m_selectedBaudRate, [](void *data, int idx) {
|
||||
hex::unused(data);
|
||||
|
||||
return ViewTTYConsole::BaudRates[idx];
|
||||
@@ -49,7 +49,7 @@ namespace hex::plugin::windows {
|
||||
ViewTTYConsole::BaudRates.size());
|
||||
|
||||
ImGui::Combo(
|
||||
"hex.windows.view.tty_console.num_bits"_lang, &this->m_selectedNumBits, [](void *data, int idx) {
|
||||
"hex.windows.view.tty_console.num_bits"_lang, &m_selectedNumBits, [](void *data, int idx) {
|
||||
hex::unused(data);
|
||||
|
||||
return ViewTTYConsole::NumBits[idx];
|
||||
@@ -58,7 +58,7 @@ namespace hex::plugin::windows {
|
||||
ViewTTYConsole::NumBits.size());
|
||||
|
||||
ImGui::Combo(
|
||||
"hex.windows.view.tty_console.stop_bits"_lang, &this->m_selectedStopBits, [](void *data, int idx) {
|
||||
"hex.windows.view.tty_console.stop_bits"_lang, &m_selectedStopBits, [](void *data, int idx) {
|
||||
hex::unused(data);
|
||||
|
||||
return ViewTTYConsole::StopBits[idx];
|
||||
@@ -67,7 +67,7 @@ namespace hex::plugin::windows {
|
||||
ViewTTYConsole::StopBits.size());
|
||||
|
||||
ImGui::Combo(
|
||||
"hex.windows.view.tty_console.parity_bits"_lang, &this->m_selectedParityBits, [](void *data, int idx) {
|
||||
"hex.windows.view.tty_console.parity_bits"_lang, &m_selectedParityBits, [](void *data, int idx) {
|
||||
hex::unused(data);
|
||||
|
||||
return ViewTTYConsole::ParityBits[idx];
|
||||
@@ -75,14 +75,14 @@ namespace hex::plugin::windows {
|
||||
nullptr,
|
||||
ViewTTYConsole::ParityBits.size());
|
||||
|
||||
ImGui::Checkbox("hex.windows.view.tty_console.cts"_lang, &this->m_hasCTSFlowControl);
|
||||
ImGui::Checkbox("hex.windows.view.tty_console.cts"_lang, &m_hasCTSFlowControl);
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopItemFlag();
|
||||
|
||||
ImGui::NewLine();
|
||||
|
||||
if (this->m_portHandle == INVALID_HANDLE_VALUE) {
|
||||
if (m_portHandle == INVALID_HANDLE_VALUE) {
|
||||
if (ImGui::Button("hex.windows.view.tty_console.connect"_lang))
|
||||
if (!this->connect())
|
||||
RequestOpenErrorPopup::post("hex.windows.view.tty_console.connect_error"_lang);
|
||||
@@ -94,15 +94,15 @@ namespace hex::plugin::windows {
|
||||
ImGui::NewLine();
|
||||
|
||||
if (ImGui::Button("hex.windows.view.tty_console.clear"_lang)) {
|
||||
std::scoped_lock lock(this->m_receiveBufferMutex);
|
||||
std::scoped_lock lock(m_receiveBufferMutex);
|
||||
|
||||
this->m_receiveDataBuffer.clear();
|
||||
this->m_wrapPositions.clear();
|
||||
m_receiveDataBuffer.clear();
|
||||
m_wrapPositions.clear();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::Checkbox("hex.windows.view.tty_console.auto_scroll"_lang, &this->m_shouldAutoScroll);
|
||||
ImGui::Checkbox("hex.windows.view.tty_console.auto_scroll"_lang, &m_shouldAutoScroll);
|
||||
|
||||
ImGuiExt::Header("hex.windows.view.tty_console.console"_lang);
|
||||
|
||||
@@ -110,21 +110,21 @@ namespace hex::plugin::windows {
|
||||
consoleSize.y -= ImGui::GetTextLineHeight() + ImGui::GetStyle().FramePadding.y * 4;
|
||||
if (ImGui::BeginChild("##scrolling", consoleSize, true, ImGuiWindowFlags_HorizontalScrollbar)) {
|
||||
ImGuiListClipper clipper;
|
||||
clipper.Begin(this->m_wrapPositions.size(), ImGui::GetTextLineHeight());
|
||||
clipper.Begin(m_wrapPositions.size(), ImGui::GetTextLineHeight());
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1));
|
||||
while (clipper.Step()) {
|
||||
std::scoped_lock lock(this->m_receiveBufferMutex);
|
||||
std::scoped_lock lock(m_receiveBufferMutex);
|
||||
|
||||
for (int i = clipper.DisplayStart + 1; i < clipper.DisplayEnd; i++) {
|
||||
ImGui::TextUnformatted(this->m_receiveDataBuffer.data() + this->m_wrapPositions[i - 1], this->m_receiveDataBuffer.data() + this->m_wrapPositions[i]);
|
||||
ImGui::TextUnformatted(m_receiveDataBuffer.data() + m_wrapPositions[i - 1], m_receiveDataBuffer.data() + m_wrapPositions[i]);
|
||||
}
|
||||
|
||||
if (!this->m_receiveDataBuffer.empty() && !this->m_wrapPositions.empty())
|
||||
if (static_cast<size_t>(clipper.DisplayEnd) >= this->m_wrapPositions.size() - 1)
|
||||
ImGui::TextUnformatted(this->m_receiveDataBuffer.data() + this->m_wrapPositions.back());
|
||||
if (!m_receiveDataBuffer.empty() && !m_wrapPositions.empty())
|
||||
if (static_cast<size_t>(clipper.DisplayEnd) >= m_wrapPositions.size() - 1)
|
||||
ImGui::TextUnformatted(m_receiveDataBuffer.data() + m_wrapPositions.back());
|
||||
|
||||
if (this->m_shouldAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
|
||||
if (m_shouldAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
|
||||
ImGui::SetScrollHereY(0.0F);
|
||||
}
|
||||
}
|
||||
@@ -133,18 +133,18 @@ namespace hex::plugin::windows {
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::PushItemWidth(-1);
|
||||
if (ImGui::InputText("##transmit", this->m_transmitDataBuffer.data(), this->m_transmitDataBuffer.size() - 2, ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
auto size = strlen(this->m_transmitDataBuffer.data());
|
||||
if (ImGui::InputText("##transmit", m_transmitDataBuffer.data(), m_transmitDataBuffer.size() - 2, ImGuiInputTextFlags_EnterReturnsTrue)) {
|
||||
auto size = strlen(m_transmitDataBuffer.data());
|
||||
|
||||
this->m_transmitDataBuffer[size + 0] = '\n';
|
||||
this->m_transmitDataBuffer[size + 1] = 0x00;
|
||||
m_transmitDataBuffer[size + 0] = '\n';
|
||||
m_transmitDataBuffer[size + 1] = 0x00;
|
||||
|
||||
this->transmitData(this->m_transmitDataBuffer);
|
||||
this->transmitData(m_transmitDataBuffer);
|
||||
ImGui::SetKeyboardFocusHere(0);
|
||||
}
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsItemHovered() && this->m_portHandle != INVALID_HANDLE_VALUE && !this->m_transmitting)
|
||||
if (ImGui::IsMouseReleased(ImGuiMouseButton_Right) && ImGui::IsItemHovered() && m_portHandle != INVALID_HANDLE_VALUE && !m_transmitting)
|
||||
ImGui::OpenPopup("ConsoleMenu");
|
||||
|
||||
if (ImGui::BeginPopup("ConsoleMenu")) {
|
||||
@@ -183,11 +183,11 @@ namespace hex::plugin::windows {
|
||||
}
|
||||
|
||||
bool ViewTTYConsole::connect() {
|
||||
if (this->m_comPorts.empty() || static_cast<size_t>(this->m_selectedPort) >= this->m_comPorts.size()) {
|
||||
if (m_comPorts.empty() || static_cast<size_t>(m_selectedPort) >= m_comPorts.size()) {
|
||||
RequestOpenErrorPopup::post("hex.windows.view.tty_console.no_available_port"_lang);
|
||||
return true; // If false, connect_error error popup will override this error popup
|
||||
}
|
||||
this->m_portHandle = ::CreateFile((R"(\\.\)" + this->m_comPorts[this->m_selectedPort].first).c_str(),
|
||||
m_portHandle = ::CreateFile((R"(\\.\)" + m_comPorts[m_selectedPort].first).c_str(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0,
|
||||
nullptr,
|
||||
@@ -195,27 +195,27 @@ namespace hex::plugin::windows {
|
||||
FILE_FLAG_OVERLAPPED,
|
||||
nullptr);
|
||||
|
||||
if (this->m_portHandle == INVALID_HANDLE_VALUE)
|
||||
if (m_portHandle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
auto closeHandle = SCOPE_GUARD { CloseHandle(this->m_portHandle); };
|
||||
auto closeHandle = SCOPE_GUARD { CloseHandle(m_portHandle); };
|
||||
|
||||
if (!::SetupComm(this->m_portHandle, 10000, 10000))
|
||||
if (!::SetupComm(m_portHandle, 10000, 10000))
|
||||
return false;
|
||||
|
||||
DCB serialParams;
|
||||
serialParams.DCBlength = sizeof(DCB);
|
||||
|
||||
if (!::GetCommState(this->m_portHandle, &serialParams))
|
||||
if (!::GetCommState(m_portHandle, &serialParams))
|
||||
return false;
|
||||
|
||||
serialParams.BaudRate = std::stoi(ViewTTYConsole::BaudRates[this->m_selectedBaudRate]);
|
||||
serialParams.ByteSize = std::stoi(ViewTTYConsole::NumBits[this->m_selectedNumBits]);
|
||||
serialParams.StopBits = this->m_selectedStopBits;
|
||||
serialParams.Parity = this->m_selectedParityBits;
|
||||
serialParams.fOutxCtsFlow = this->m_hasCTSFlowControl;
|
||||
serialParams.BaudRate = std::stoi(ViewTTYConsole::BaudRates[m_selectedBaudRate]);
|
||||
serialParams.ByteSize = std::stoi(ViewTTYConsole::NumBits[m_selectedNumBits]);
|
||||
serialParams.StopBits = m_selectedStopBits;
|
||||
serialParams.Parity = m_selectedParityBits;
|
||||
serialParams.fOutxCtsFlow = m_hasCTSFlowControl;
|
||||
|
||||
if (!::SetCommState(this->m_portHandle, &serialParams))
|
||||
if (!::SetCommState(m_portHandle, &serialParams))
|
||||
return false;
|
||||
|
||||
COMMTIMEOUTS timeouts;
|
||||
@@ -225,12 +225,12 @@ namespace hex::plugin::windows {
|
||||
timeouts.WriteTotalTimeoutConstant = 500;
|
||||
timeouts.WriteTotalTimeoutMultiplier = 100;
|
||||
|
||||
if (!::SetCommTimeouts(this->m_portHandle, &timeouts))
|
||||
if (!::SetCommTimeouts(m_portHandle, &timeouts))
|
||||
return false;
|
||||
|
||||
closeHandle.release();
|
||||
|
||||
this->m_receiveThread = std::jthread([this](const std::stop_token &token) {
|
||||
m_receiveThread = std::jthread([this](const std::stop_token &token) {
|
||||
bool waitingOnRead = false;
|
||||
OVERLAPPED overlapped = { };
|
||||
|
||||
@@ -238,19 +238,19 @@ namespace hex::plugin::windows {
|
||||
ON_SCOPE_EXIT { ::CloseHandle(&overlapped); };
|
||||
|
||||
auto addByte = [this](char byte) {
|
||||
std::scoped_lock lock(this->m_receiveBufferMutex);
|
||||
std::scoped_lock lock(m_receiveBufferMutex);
|
||||
|
||||
if (byte >= 0x20 && byte <= 0x7E) {
|
||||
this->m_receiveDataBuffer.back() = byte;
|
||||
this->m_receiveDataBuffer.push_back(0x00);
|
||||
m_receiveDataBuffer.back() = byte;
|
||||
m_receiveDataBuffer.push_back(0x00);
|
||||
} else if (byte == '\n' || byte == '\r') {
|
||||
if (this->m_receiveDataBuffer.empty())
|
||||
if (m_receiveDataBuffer.empty())
|
||||
return;
|
||||
|
||||
u32 wrapPos = this->m_receiveDataBuffer.size() - 1;
|
||||
u32 wrapPos = m_receiveDataBuffer.size() - 1;
|
||||
|
||||
if (this->m_wrapPositions.empty() || this->m_wrapPositions.back() != wrapPos)
|
||||
this->m_wrapPositions.push_back(wrapPos);
|
||||
if (m_wrapPositions.empty() || m_wrapPositions.back() != wrapPos)
|
||||
m_wrapPositions.push_back(wrapPos);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -259,7 +259,7 @@ namespace hex::plugin::windows {
|
||||
|
||||
char byte = 0;
|
||||
if (!waitingOnRead) {
|
||||
if (::ReadFile(this->m_portHandle, &byte, sizeof(char), &bytesRead, &overlapped)) {
|
||||
if (::ReadFile(m_portHandle, &byte, sizeof(char), &bytesRead, &overlapped)) {
|
||||
addByte(byte);
|
||||
} else if (::GetLastError() == ERROR_IO_PENDING) {
|
||||
waitingOnRead = true;
|
||||
@@ -268,7 +268,7 @@ namespace hex::plugin::windows {
|
||||
byte = 0;
|
||||
switch (::WaitForSingleObject(overlapped.hEvent, 500)) {
|
||||
case WAIT_OBJECT_0:
|
||||
if (::GetOverlappedResult(this->m_portHandle, &overlapped, &bytesRead, false)) {
|
||||
if (::GetOverlappedResult(m_portHandle, &overlapped, &bytesRead, false)) {
|
||||
addByte(byte);
|
||||
waitingOnRead = false;
|
||||
}
|
||||
@@ -283,18 +283,18 @@ namespace hex::plugin::windows {
|
||||
}
|
||||
|
||||
bool ViewTTYConsole::disconnect() {
|
||||
::SetCommMask(this->m_portHandle, EV_TXEMPTY);
|
||||
this->m_receiveThread.request_stop();
|
||||
this->m_receiveThread.join();
|
||||
::SetCommMask(m_portHandle, EV_TXEMPTY);
|
||||
m_receiveThread.request_stop();
|
||||
m_receiveThread.join();
|
||||
|
||||
::CloseHandle(this->m_portHandle);
|
||||
this->m_portHandle = INVALID_HANDLE_VALUE;
|
||||
::CloseHandle(m_portHandle);
|
||||
m_portHandle = INVALID_HANDLE_VALUE;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewTTYConsole::transmitData(std::vector<char> &data) {
|
||||
if (this->m_transmitting)
|
||||
if (m_transmitting)
|
||||
return;
|
||||
|
||||
TaskManager::createBackgroundTask("Transmitting data", [&, this](auto&) {
|
||||
@@ -303,19 +303,19 @@ namespace hex::plugin::windows {
|
||||
overlapped.hEvent = ::CreateEvent(nullptr, true, false, nullptr);
|
||||
ON_SCOPE_EXIT { ::CloseHandle(&overlapped); };
|
||||
|
||||
this->m_transmitting = true;
|
||||
m_transmitting = true;
|
||||
|
||||
DWORD bytesWritten = 0;
|
||||
if (!::WriteFile(this->m_portHandle, data.data(), strlen(data.data()), &bytesWritten, &overlapped)) {
|
||||
if (!::WriteFile(m_portHandle, data.data(), strlen(data.data()), &bytesWritten, &overlapped)) {
|
||||
if (::GetLastError() == ERROR_IO_PENDING) {
|
||||
::GetOverlappedResult(this->m_portHandle, &overlapped, &bytesWritten, true);
|
||||
::GetOverlappedResult(m_portHandle, &overlapped, &bytesWritten, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (bytesWritten > 0)
|
||||
data[0] = 0x00;
|
||||
|
||||
this->m_transmitting = false;
|
||||
m_transmitting = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user