aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-06 13:25:27 +0100
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>2015-12-06 12:41:44 +0000
commit9aa21b66d59945ed5551e7d4d25af2f914f1cc99 (patch)
treec6f9bc375e44132fe3f55ed38ec9fc2b96943e93
parentece0924b856c905ce54e97446ea24d7c89a61746 (diff)
Set a suitable locale automatically to avoid issues with the ini fileHEADmaster
Change-Id: Ie988518e9411d9c704e8616dbb513ef7ffc0abb3 Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
-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");