<commit_before>/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: <EMAIL>
**
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "hybrisadaptor.h"
#include "deviceadaptor.h"

#include <QDebug>
#include <QCoreApplication>
#include <QTimer>

#include <hardware/hardware.h>
#include <hardware/sensors.h>

#ifndef SENSOR_TYPE_ACCELEROMETER
#define SENSOR_TYPE_ACCELEROMETER (1)
#endif
#ifndef SENSOR_TYPE_MAGNETIC_FIELD
#define SENSOR_TYPE_MAGNETIC_FIELD (2)
#endif
#ifndef SENSOR_TYPE_ORIENTATION
#define SENSOR_TYPE_ORIENTATION (3)
#endif
#ifndef SENSOR_TYPE_GYROSCOPE
#define SENSOR_TYPE_GYROSCOPE (4)
#endif
#ifndef SENSOR_TYPE_LIGHT
#define SENSOR_TYPE_LIGHT (5)
#endif
#ifndef SENSOR_TYPE_PRESSURE
#define SENSOR_TYPE_PRESSURE (6)
#endif
#ifndef SENSOR_TYPE_TEMPERATURE
#define SENSOR_TYPE_TEMPERATURE (7)
#endif
#ifndef SENSOR_TYPE_PROXIMITY
#define SENSOR_TYPE_PROXIMITY (8)
#endif
#ifndef SENSOR_TYPE_GRAVITY
#define SENSOR_TYPE_GRAVITY (9)
#endif
#ifndef SENSOR_TYPE_LINEAR_ACCELERATION
#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
#endif
#ifndef SENSOR_TYPE_ROTATION_VECTOR
#define SENSOR_TYPE_ROTATION_VECTOR (11)
#endif
#ifndef SENSOR_TYPE_RELATIVE_HUMIDITY
#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
#endif
#ifndef SENSOR_TYPE_AMBIENT_TEMPERATURE
#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
#endif
//#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
//#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
//#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
//#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
//#define SENSOR_TYPE_STEP_DETECTOR (18)
//#define SENSOR_TYPE_STEP_COUNTER (19)
//#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)

static QHash<QString,int> HybrisAdaptor_sensorTypes()
{
    QHash<QString,int> types;
    types["accelerometer"] = SENSOR_TYPE_ACCELEROMETER;
    types["magnetomoter"] = SENSOR_TYPE_MAGNETIC_FIELD;
    types["orientation"] = SENSOR_TYPE_ORIENTATION;
    types["gyroscope"] = SENSOR_TYPE_GYROSCOPE;
    types["light"] = SENSOR_TYPE_LIGHT;
    types["pressure"] = SENSOR_TYPE_PRESSURE;
    types["temperature"] = SENSOR_TYPE_TEMPERATURE;
    types["proximity"] = SENSOR_TYPE_PROXIMITY;
    types["gravity"] = SENSOR_TYPE_GRAVITY;
    types["lacceration"] = SENSOR_TYPE_LINEAR_ACCELERATION;
    return types;
}

Q_GLOBAL_STATIC(HybrisManager, hybrisManager)

HybrisManager::HybrisManager(QObject *parent)
    : QObject(parent)
    , device(NULL)
    , sensorList(NULL)
    , module(NULL)
    , sensorsCount(0)
    , sensorMap()
    , registeredAdaptors()
    , adaptorReader(parent)
{
    init();
}

HybrisManager::~HybrisManager()
{
    closeAllSensors();
}

HybrisManager *HybrisManager::instance()
{
    HybrisManager *priv = hybrisManager();
    return priv;
}

void HybrisManager::init()
{
    int errorCode = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
    if (errorCode != 0) {
        qDebug() << "hw_get_module() failed" <<  strerror(-errorCode);
        return ;
    }

    if (!openSensors()) {
        sensordLogW() << "Cannot open sensors";
        return;
    }

    sensorsCount = module->get_sensors_list(module, &sensorList);

    for (int i = 0 ; i < sensorsCount ; i++) {
        sensorMap.insert(sensorList[i].type, i);
    }
}<commit_msg>[sensorfw] Fixes MER#1223. ignore hybris compass raw sensor<commit_after>/****************************************************************************
**
** Copyright (C) 2013 Jolla Ltd
** Contact: <EMAIL>
**
**
** $QT_BEGIN_LICENSE:LGPL$
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "hybrisadaptor.h"
#include "deviceadaptor.h"

#include <QDebug>
#include <QCoreApplication>
#include <QTimer>

#include <hardware/hardware.h>
#include <hardware/sensors.h>

#ifndef SENSOR_TYPE_ACCELEROMETER
#define SENSOR_TYPE_ACCELEROMETER (1)
#endif
#ifndef SENSOR_TYPE_MAGNETIC_FIELD
#define SENSOR_TYPE_MAGNETIC_FIELD (2)
#endif
#ifndef SENSOR_TYPE_ORIENTATION
#define SENSOR_TYPE_ORIENTATION (3)
#endif
#ifndef SENSOR_TYPE_GYROSCOPE
#define SENSOR_TYPE_GYROSCOPE (4)
#endif
#ifndef SENSOR_TYPE_LIGHT
#define SENSOR_TYPE_LIGHT (5)
#endif
#ifndef SENSOR_TYPE_PRESSURE
#define SENSOR_TYPE_PRESSURE (6)
#endif
#ifndef SENSOR_TYPE_TEMPERATURE
#define SENSOR_TYPE_TEMPERATURE (7)
#endif
#ifndef SENSOR_TYPE_PROXIMITY
#define SENSOR_TYPE_PROXIMITY (8)
#endif
#ifndef SENSOR_TYPE_GRAVITY
#define SENSOR_TYPE_GRAVITY (9)
#endif
#ifndef SENSOR_TYPE_LINEAR_ACCELERATION
#define SENSOR_TYPE_LINEAR_ACCELERATION (10)
#endif
#ifndef SENSOR_TYPE_ROTATION_VECTOR
#define SENSOR_TYPE_ROTATION_VECTOR (11)
#endif
#ifndef SENSOR_TYPE_RELATIVE_HUMIDITY
#define SENSOR_TYPE_RELATIVE_HUMIDITY (12)
#endif
#ifndef SENSOR_TYPE_AMBIENT_TEMPERATURE
#define SENSOR_TYPE_AMBIENT_TEMPERATURE (13)
#endif
//#define SENSOR_TYPE_MAGNETIC_FIELD_UNCALIBRATED (14)
//#define SENSOR_TYPE_GAME_ROTATION_VECTOR (15)
//#define SENSOR_TYPE_GYROSCOPE_UNCALIBRATED (16)
//#define SENSOR_TYPE_SIGNIFICANT_MOTION (17)
//#define SENSOR_TYPE_STEP_DETECTOR (18)
//#define SENSOR_TYPE_STEP_COUNTER (19)
//#define SENSOR_TYPE_GEOMAGNETIC_ROTATION_VECTOR (20)

static QHash<QString,int> HybrisAdaptor_sensorTypes()
{
    QHash<QString,int> types;
    types["accelerometer"] = SENSOR_TYPE_ACCELEROMETER;
    types["magnetomoter"] = SENSOR_TYPE_MAGNETIC_FIELD;
    types["orientation"] = SENSOR_TYPE_ORIENTATION;
    types["gyroscope"] = SENSOR_TYPE_GYROSCOPE;
    types["light"] = SENSOR_TYPE_LIGHT;
    types["pressure"] = SENSOR_TYPE_PRESSURE;
    types["temperature"] = SENSOR_TYPE_TEMPERATURE;
    types["proximity"] = SENSOR_TYPE_PROXIMITY;
    types["gravity"] = SENSOR_TYPE_GRAVITY;
    types["lacceration"] = SENSOR_TYPE_LINEAR_ACCELERATION;
    return types;
}

Q_GLOBAL_STATIC(HybrisManager, hybrisManager)

HybrisManager::HybrisManager(QObject *parent)
    : QObject(parent)
    , device(NULL)
    , sensorList(NULL)
    , module(NULL)
    , sensorsCount(0)
    , sensorMap()
    , registeredAdaptors()
    , adaptorReader(parent)
{
    init();
}

HybrisManager::~HybrisManager()
{
    closeAllSensors();
}

HybrisManager *HybrisManager::instance()
{
    HybrisManager *priv = hybrisManager();
    return priv;
}

void HybrisManager::init()
{
    int errorCode = hw_get_module(SENSORS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
    if (errorCode != 0) {
        qDebug() << "hw_get_module() failed" <<  strerror(-errorCode);
        return ;
    }

    if (!openSensors()) {
        sensordLogW() << "Cannot open sensors";
        return;
    }

    sensorsCount = module->get_sensors_list(module, &sensorList);

    for (int i = 0 ; i < sensorsCount ; i++) {
        // some devices have compass and compass raw,
        // ignore compass raw. compass has range 360
        if (sensorList[i].type != SENSOR_TYPE_ORIENTATION
                || sensorList[i].maxRange == 360)
        sensorMap.insert(sensorList[i].type, i);
    }
}
{'fraction_non_alphanumeric': 0.1421256400649432, 'fraction_numerical': 0.012239290620706882, 'mean_word_length': 5.695652173913044, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3911428', 'n_tokens_mistral': 2976, 'n_tokens_neox': 2867, 'n_words': 568}