AT&T IoT hackster.io contest entry: Carpal2

Dependencies:   FXOS8700CQ Pubnub_mbed2_sync WNCInterface mbed-rtos mbed

Committer:
cswiger
Date:
Sat Dec 24 17:31:00 2016 +0000
Revision:
2:fe8e935b9342
Parent:
0:d2425a595807
added Ignition awareness so Carpal2 will resume working after car has been turned off and back on.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cswiger 0:d2425a595807 1 /* ===================================================================
cswiger 0:d2425a595807 2 Copyright © 2016, AVNET Inc.
cswiger 0:d2425a595807 3
cswiger 0:d2425a595807 4 Licensed under the Apache License, Version 2.0 (the "License");
cswiger 0:d2425a595807 5 you may not use this file except in compliance with the License.
cswiger 0:d2425a595807 6 You may obtain a copy of the License at
cswiger 0:d2425a595807 7
cswiger 0:d2425a595807 8 http://www.apache.org/licenses/LICENSE-2.0
cswiger 0:d2425a595807 9
cswiger 0:d2425a595807 10 Unless required by applicable law or agreed to in writing,
cswiger 0:d2425a595807 11 software distributed under the License is distributed on an
cswiger 0:d2425a595807 12 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
cswiger 0:d2425a595807 13 either express or implied. See the License for the specific
cswiger 0:d2425a595807 14 language governing permissions and limitations under the License.
cswiger 0:d2425a595807 15
cswiger 0:d2425a595807 16 ======================================================================== */
cswiger 0:d2425a595807 17
cswiger 0:d2425a595807 18 #ifndef HTS221_H_
cswiger 0:d2425a595807 19 #define HTS221_H_
cswiger 0:d2425a595807 20
cswiger 0:d2425a595807 21 class HTS221 {
cswiger 0:d2425a595807 22 public:
cswiger 0:d2425a595807 23 HTS221(void);
cswiger 0:d2425a595807 24 int begin(void);
cswiger 0:d2425a595807 25 int activate(void);
cswiger 0:d2425a595807 26 int deactivate(void);
cswiger 0:d2425a595807 27
cswiger 0:d2425a595807 28 int bduActivate(void);
cswiger 0:d2425a595807 29 int bduDeactivate(void);
cswiger 0:d2425a595807 30
cswiger 0:d2425a595807 31 int readHumidity(void);
cswiger 0:d2425a595807 32 double readTemperature(void);
cswiger 0:d2425a595807 33 private:
cswiger 0:d2425a595807 34 int storeCalibration(void);
cswiger 0:d2425a595807 35 unsigned char _h0_rH, _h1_rH;
cswiger 0:d2425a595807 36 unsigned int _T0_degC, _T1_degC;
cswiger 0:d2425a595807 37 unsigned int _H0_T0, _H1_T0;
cswiger 0:d2425a595807 38 unsigned int _T0_OUT, _T1_OUT;
cswiger 0:d2425a595807 39 double _temperature;
cswiger 0:d2425a595807 40 int _humidity;
cswiger 0:d2425a595807 41 unsigned char _address;
cswiger 0:d2425a595807 42
cswiger 0:d2425a595807 43 unsigned char readRegister(unsigned char slaveAddress, unsigned char regToRead);
cswiger 0:d2425a595807 44 int writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite);
cswiger 0:d2425a595807 45 };
cswiger 0:d2425a595807 46
cswiger 0:d2425a595807 47 #define HTS221_ADDRESS 0xBF
cswiger 0:d2425a595807 48
cswiger 0:d2425a595807 49 //Define a few of the registers that we will be accessing on the HTS221
cswiger 0:d2425a595807 50 #define WHO_AM_I 0x0F
cswiger 0:d2425a595807 51 #define WHO_AM_I_RETURN 0xBC //This read-only register contains the device identifier, set to BCh
cswiger 0:d2425a595807 52
cswiger 0:d2425a595807 53 #define AVERAGE_REG 0x10 // To configure humidity/temperature average.
cswiger 0:d2425a595807 54 #define AVERAGE_DEFAULT 0x1B
cswiger 0:d2425a595807 55
cswiger 0:d2425a595807 56 /*
cswiger 0:d2425a595807 57 * [7] PD: power down control
cswiger 0:d2425a595807 58 * (0: power-down mode; 1: active mode)
cswiger 0:d2425a595807 59 *
cswiger 0:d2425a595807 60 * [6:3] Reserved
cswiger 0:d2425a595807 61 *
cswiger 0:d2425a595807 62 * [2] BDU: block data update
cswiger 0:d2425a595807 63 * (0: continuous update; 1: output registers not updated until MSB and LSB reading)
cswiger 0:d2425a595807 64 The BDU bit is used to inhibit the output register update between the reading of the upper
cswiger 0:d2425a595807 65 and lower register parts. In default mode (BDU = ?0?), the lower and upper register parts are
cswiger 0:d2425a595807 66 updated continuously. If it is not certain whether the read will be faster than output data rate,
cswiger 0:d2425a595807 67 it is recommended to set the BDU bit to ?1?. In this way, after the reading of the lower (upper)
cswiger 0:d2425a595807 68 register part, the content of that output register is not updated until the upper (lower) part is
cswiger 0:d2425a595807 69 read also.
cswiger 0:d2425a595807 70 *
cswiger 0:d2425a595807 71 * [1:0] ODR1, ODR0: output data rate selection (see table 17)
cswiger 0:d2425a595807 72 */
cswiger 0:d2425a595807 73 #define CTRL_REG1 0x20
cswiger 0:d2425a595807 74 #define POWER_UP 0x80
cswiger 0:d2425a595807 75 #define BDU_SET 0x4
cswiger 0:d2425a595807 76 #define ODR0_SET 0x1 // setting sensor reading period 1Hz
cswiger 0:d2425a595807 77
cswiger 0:d2425a595807 78 #define CTRL_REG2 0x21
cswiger 0:d2425a595807 79 #define CTRL_REG3 0x22
cswiger 0:d2425a595807 80 #define REG_DEFAULT 0x00
cswiger 0:d2425a595807 81
cswiger 0:d2425a595807 82 #define STATUS_REG 0x27
cswiger 0:d2425a595807 83 #define TEMPERATURE_READY 0x1
cswiger 0:d2425a595807 84 #define HUMIDITY_READY 0x2
cswiger 0:d2425a595807 85
cswiger 0:d2425a595807 86 #define HUMIDITY_L_REG 0x28
cswiger 0:d2425a595807 87 #define HUMIDITY_H_REG 0x29
cswiger 0:d2425a595807 88 #define TEMP_L_REG 0x2A
cswiger 0:d2425a595807 89 #define TEMP_H_REG 0x2B
cswiger 0:d2425a595807 90 /*
cswiger 0:d2425a595807 91 * calibration registry should be read for temperature and humidity calculation.
cswiger 0:d2425a595807 92 * Before the first calculation of temperature and humidity,
cswiger 0:d2425a595807 93 * the master reads out the calibration coefficients.
cswiger 0:d2425a595807 94 * will do at init phase
cswiger 0:d2425a595807 95 */
cswiger 0:d2425a595807 96 #define CALIB_START 0x30
cswiger 0:d2425a595807 97 #define CALIB_END 0x3F
cswiger 0:d2425a595807 98 /*
cswiger 0:d2425a595807 99 #define CALIB_T0_DEGC_X8 0x32
cswiger 0:d2425a595807 100 #define CALIB_T1_DEGC_X8 0x33
cswiger 0:d2425a595807 101 #define CALIB_T1_T0_MSB 0x35
cswiger 0:d2425a595807 102 #define CALIB_T0_OUT_L 0x3C
cswiger 0:d2425a595807 103 #define CALIB_T0_OUT_H 0x3D
cswiger 0:d2425a595807 104 #define CALIB_T1_OUT_L 0x3E
cswiger 0:d2425a595807 105 #define CALIB_T1_OUT_H 0x3F
cswiger 0:d2425a595807 106 */
cswiger 0:d2425a595807 107
cswiger 0:d2425a595807 108 #endif