aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--src/sensehat/qsensehatsensors.cpp15
2 files changed, 17 insertions, 6 deletions
diff --git a/README.md b/README.md
index a6a568b..ed5d427 100644
--- a/README.md
+++ b/README.md
@@ -63,9 +63,5 @@ Sensors example:
return app.exec();
}
-Raspbian's default calibration from /etc is picked up automatically, similarly to the
-Python lib. Note however that this is a text file and numbers may not be parsable with
-locale settings that use a decimal separator other than the dot. If the orientation data
-is invalid, check this first.
-
-Orientation is converted to degrees in range 0..360. Other values are reported as-is.
+Raspbian's default calibration from /etc is picked up automatically, similarly to the Python
+lib. Orientation is converted to degrees in range 0..360. Other values are reported as-is.
diff --git a/src/sensehat/qsensehatsensors.cpp b/src/sensehat/qsensehatsensors.cpp
index 0baafef..ff52efd 100644
--- a/src/sensehat/qsensehatsensors.cpp
+++ b/src/sensehat/qsensehatsensors.cpp
@@ -81,6 +81,20 @@ public:
QVector3D orientation;
};
+class CLocale
+{
+public:
+ CLocale() {
+ oldLoc = QByteArray(setlocale(LC_ALL, 0));
+ setlocale(LC_ALL, "C");
+ }
+ ~CLocale() {
+ setlocale(LC_ALL, oldLoc.constData());
+ }
+private:
+ QByteArray oldLoc;
+};
+
QSenseHatSensorsPrivate::~QSenseHatSensorsPrivate()
{
delete rtpressure;
@@ -91,6 +105,7 @@ QSenseHatSensorsPrivate::~QSenseHatSensorsPrivate()
void QSenseHatSensorsPrivate::open()
{
+ CLocale c; // to avoid decimal separator trouble in the ini file
const QString configFileName = QStringLiteral("RTIMULib.ini");
const QString defaultConfig = QStringLiteral("/etc/") + configFileName;
const QString writableConfigDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/sense_hat");