diff --git a/AdaptiveBrightness/sensor_driver.cpp b/AdaptiveBrightness/sensor_driver.cpp index 9243c02..b19524c 100644 --- a/AdaptiveBrightness/sensor_driver.cpp +++ b/AdaptiveBrightness/sensor_driver.cpp @@ -1,5 +1,7 @@ #include "sensor_driver.hpp" +#include + #include #include #include @@ -146,5 +148,20 @@ bool SensorDriver::isValidSensor(const QString& serialPortName) const return false; } - return false; + const auto version = parseVersionResponse(response); + return version == "AdaptiveBrightness v1.2"; +} + +std::string SensorDriver::parseVersionResponse(const QByteArray& response) const +{ + const auto versionRegex = std::regex("[a-zA-Z]+ v[0-9]\\.[0-9]"); + const auto strResponse = response.toStdString(); + std::smatch versionMatch; + + if(std::regex_search(strResponse, versionMatch, versionRegex)) { + qDebug(ltr("Found version match: '%1'").arg(QString().fromStdString(versionMatch[0].str()))); + return versionMatch[0]; + } + + return {}; } diff --git a/AdaptiveBrightness/sensor_driver.hpp b/AdaptiveBrightness/sensor_driver.hpp index b164601..697422b 100644 --- a/AdaptiveBrightness/sensor_driver.hpp +++ b/AdaptiveBrightness/sensor_driver.hpp @@ -29,4 +29,5 @@ class SensorDriver { private: bool getSensorCommandResponse(const QString& serialPortName, QByteArray command, QByteArray& response) const; bool isValidSensor(const QString& serialPortName) const; + std::string parseVersionResponse(const QByteArray& response) const; };