Temperature sensor library for Sequana BLE Lab.

Committer:
lru
Date:
Fri Mar 22 10:08:18 2019 +0000
Revision:
1:b99360c421a7
Parent:
0:680362180482
Corrected TempSensor API description.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lru 0:680362180482 1 /*
lru 0:680362180482 2 * Copyright (c) 2017-2019 Future Electronics
lru 0:680362180482 3 *
lru 0:680362180482 4 * Licensed under the Apache License, Version 2.0 (the "License");
lru 0:680362180482 5 * you may not use this file except in compliance with the License.
lru 0:680362180482 6 * You may obtain a copy of the License at
lru 0:680362180482 7 *
lru 0:680362180482 8 * http://www.apache.org/licenses/LICENSE-2.0
lru 0:680362180482 9 *
lru 0:680362180482 10 * Unless required by applicable law or agreed to in writing, software
lru 0:680362180482 11 * distributed under the License is distributed on an "AS IS" BASIS,
lru 0:680362180482 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
lru 0:680362180482 13 * See the License for the specific language governing permissions and
lru 0:680362180482 14 * limitations under the License.
lru 0:680362180482 15 */
lru 0:680362180482 16
lru 0:680362180482 17 #ifndef TEMP_SENSOR_H_
lru 0:680362180482 18 #define TEMP_SENSOR_H_
lru 0:680362180482 19
lru 0:680362180482 20 #include <stdint.h>
lru 0:680362180482 21 #include "Sensor.h"
lru 0:680362180482 22 #include "Hs3001Driver.h"
lru 0:680362180482 23
lru 0:680362180482 24 /** Tempereature Sensor based on HS3001 chip
lru 0:680362180482 25 */
lru 0:680362180482 26 class TempSensor : public Sensor<int16_t> {
lru 0:680362180482 27 public:
lru 0:680362180482 28 /** Create and initialize sensor interface.
lru 0:680362180482 29 *
lru 1:b99360c421a7 30 * @param i2c I2C bus to use
lru 1:b99360c421a7 31 * @param address I2C address to use to select sensor on a bus
lru 0:680362180482 32 */
lru 0:680362180482 33 TempSensor(I2C &i2c, uint8_t address) : _driver(i2c, address) {}
lru 0:680362180482 34
lru 0:680362180482 35 /** Schedule measurement process.
lru 0:680362180482 36 */
lru 0:680362180482 37 virtual void start(EventQueue& ev_queue)
lru 0:680362180482 38 {
lru 0:680362180482 39 // start new measurement cycle
lru 0:680362180482 40 _driver.start_conversion();
lru 0:680362180482 41 // set up updater() function to be called every second (1000ms)
lru 0:680362180482 42 ev_queue.call_every(1000, callback(this, &TempSensor::updater));
lru 0:680362180482 43 }
lru 0:680362180482 44
lru 0:680362180482 45 protected:
lru 0:680362180482 46 void updater()
lru 0:680362180482 47 {
lru 0:680362180482 48 uint16_t humidity;
lru 0:680362180482 49 int16_t temperature;
lru 0:680362180482 50
lru 0:680362180482 51 // read last measured temperature value and update
lru 0:680362180482 52 // characteristic value if new value is available
lru 0:680362180482 53 if (_driver.read(humidity, temperature) == Hs3001Driver::STATUS_OK) {
lru 0:680362180482 54 update_value(temperature);
lru 0:680362180482 55 }
lru 0:680362180482 56
lru 0:680362180482 57 // start new measurement cycle
lru 0:680362180482 58 _driver.start_conversion();
lru 0:680362180482 59 }
lru 0:680362180482 60
lru 0:680362180482 61 Hs3001Driver _driver;
lru 0:680362180482 62 };
lru 0:680362180482 63
lru 0:680362180482 64 #endif // TEMP_SENSOR_H_