diff options
Diffstat (limited to 'source/stmdsp/stmdsp.cpp')
-rw-r--r-- | source/stmdsp/stmdsp.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/source/stmdsp/stmdsp.cpp b/source/stmdsp/stmdsp.cpp index c835257..294e98f 100644 --- a/source/stmdsp/stmdsp.cpp +++ b/source/stmdsp/stmdsp.cpp @@ -92,8 +92,7 @@ namespace stmdsp m_serial->write(cmd.data(), cmd.size()); success = true; } catch (...) { - m_serial.release(); - log("Lost connection!"); + handle_disconnect(); } } @@ -110,8 +109,7 @@ namespace stmdsp m_serial->read(dest, dest_size); success = true; } catch (...) { - m_serial.release(); - log("Lost connection!"); + handle_disconnect(); } } @@ -160,12 +158,11 @@ namespace stmdsp m_is_running = true; } - void device::continuous_start_measure() { - if (try_command({'M'})) - m_is_running = true; + void device::measurement_start() { + try_command({'M'}); } - uint32_t device::continuous_start_get_measurement() { + uint32_t device::measurement_read() { uint32_t count = 0; try_read({'m'}, reinterpret_cast<uint8_t *>(&count), sizeof(uint32_t)); return count / 2; @@ -195,8 +192,7 @@ namespace stmdsp } } catch (...) { - m_serial.release(); - log("Lost connection!"); + handle_disconnect(); } } @@ -227,8 +223,7 @@ namespace stmdsp } } catch (...) { - m_serial.release(); - log("Lost connection!"); + handle_disconnect(); } } @@ -253,8 +248,7 @@ namespace stmdsp m_serial->write(request, 3); m_serial->write((uint8_t *)buffer, size * sizeof(dacsample_t)); } catch (...) { - m_serial.release(); - log("Lost connection!"); + handle_disconnect(); } } else { try { @@ -264,8 +258,7 @@ namespace stmdsp else m_serial->write((uint8_t *)buffer, size * sizeof(dacsample_t)); } catch (...) { - m_serial.release(); - log("Lost connection!"); + handle_disconnect(); } } @@ -297,8 +290,7 @@ namespace stmdsp m_serial->write(request, 3); m_serial->write(buffer, size); } catch (...) { - m_serial.release(); - log("Lost connection!"); + handle_disconnect(); } } } @@ -320,9 +312,19 @@ namespace stmdsp bool running = ret.first == RunStatus::Running; if (m_is_running != running) m_is_running = running; + } else if (m_disconnect_error_flag) { + m_disconnect_error_flag = false; + return {RunStatus::Idle, Error::GUIDisconnect}; } return ret; } -} + + void device::handle_disconnect() + { + m_disconnect_error_flag = true; + m_serial.release(); + log("Lost connection!"); + } +} // namespace stmdsp |