1 /* Medfield sensor plugins
2 * Copyright (C) 2013 Intel Corporation
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; version 2.1.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301USA
18 #include "ms5607processors.h"
25 const int BUFSIZE = 128;
27 int Ms5607Reader::mCalibdata [] = {UNSET, UNSET,UNSET,UNSET,
28 UNSET,UNSET,UNSET,UNSET
30 int Ms5607Reader::mAdc1 = 0;
31 int Ms5607Reader::mAdc2 = 0;
32 long long int Ms5607Reader::mDT = 0;
33 long long int Ms5607Reader::mOFF = 0;
34 long long int Ms5607Reader::mSENS = 0;
36 Ms5607Reader::Ms5607Reader()
39 find_input_device_by_name("ms5607_pressure");
40 find_device_from_udev("baro");
44 bool Ms5607Reader::enable()
46 if (BaseProcessor::enable()) {
47 const int maxLines = sizeof(mCalibdata)/sizeof(mCalibdata[0]);
49 if (mCalibdata[0] == UNSET) {
50 std::string tmp = mSysfsPath;
52 std::fstream f(tmp.c_str(),std::ios::in);
55 while (f.good() && goodLines < maxLines) {
62 mCalibdata[goodLines++] = value;
65 if (goodLines != maxLines) {
66 mCalibdata[0] = UNSET;
76 for (int i = 0; i < 8; i++)
77 std::cout <<i <<" " <<mCalibdata[i] <<"\n";
82 void Ms5607Reader::process_input_events(const std::vector <input_event *> &events)
84 BaseProcessor::process_input_events(events);
85 if (events.size() == 2) {
89 //These calculations are from mail
90 mDT = mAdc2 - (mCalibdata[5] <<8);
91 mOFF = (((long long) mCalibdata[2]) <<17) + ((mCalibdata[4]*mDT)>>6);
92 mSENS = (((long long)mCalibdata[1]) <<16) + ((mCalibdata[3] * mDT) >>7);
97 TemperatureProcessor::TemperatureProcessor()
99 mName = "Temperature";
102 bool TemperatureProcessor::fill_values(unsigned int type, int &count,
103 data_unit_idx_t &unit,
104 data_accuracy &accuracy)
107 accuracy = ACCURACY_NORMAL;
109 //This calculation was received in mail
110 mValues[0] = (2000 + (mDT * (mCalibdata[6]) >>23)) / 100.0;
114 PressureProcessor::PressureProcessor()
119 bool PressureProcessor::fill_values(unsigned int type, int &count,
120 data_unit_idx_t &unit,
121 data_accuracy &accuracy)
124 accuracy = ACCURACY_NORMAL;
126 //This calculation was received in mail
127 mValues[0] = (((mAdc1 * (mSENS >>21)) - mOFF) >> 15) / 100000.0;