text: /**
   * ep-oc-mcu
   * Embedded Planet Open Core for Microcontrollers
   *
   * Built with ARM Mbed-OS
   *
   * Copyright (c) 2019 Embedded Planet, Inc.
   * SPDX-License-Identifier: Apache-2.0
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  #ifndef BME680_H
  #define BME680_H
  
  #include "bme680_driver.h"
  #include "drivers/I2C.h"
  
  #define BME680_DEFAULT_ADDRESS (0x76 << 1)  // The default I2C address (shifted for MBed 8 bit address)
  
  /**
   * BME680 Class for I2C usage.
   * Wraps the Bosch library for Mbed usage.
   */
  class BME680 {
  public:
      BME680(mbed::I2C* i2c, uint8_t addr = BME680_DEFAULT_ADDRESS);
  
      bool begin();
  
      bool setTemperatureOversampling(uint8_t os);
  
      bool setPressureOversampling(uint8_t os);
  
      bool setHumidityOversampling(uint8_t os);
  
      bool setIIRFilterSize(uint8_t fs);
  
      bool setGasHeater(uint16_t heaterTemp, uint16_t heaterTime);
  
      bool performReading();
  
      bool isGasHeatingSetupStable();
  
      int16_t getRawTemperature();
      uint32_t getRawPressure();
      uint32_t getRawHumidity();
      uint32_t getRawGasResistance();
  
      float getTemperature();
  
      float getPressure();
  
      float getHumidity();
  
      float getGasResistance();
  
  private:
      bool _filterEnabled, _tempEnabled, _humEnabled, _presEnabled, _gasEnabled;
      struct bme680_dev gas_sensor;
      struct bme680_field_data data;
      uint8_t _adr;
  
      // BME680 - hardware interface
      static int8_t i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
  
      static int8_t i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len);
  
      static void delay_msec(uint32_t ms);
  };
  
  #endif
  