codegen:
  instance: bme680
  includes: ['driver/i2c.h', 'driver/bme680.h', 'driver/bme680_util.h']
  flags: ['drivers=bme680', 'arch_drivers=i2c']
  setup:
  - i2c.setup();
  - struct bme680_field_data sensordata;
  - bme680.intf = BME680_I2C_INTF;
  - bme680.read = bme680_i2c_read;
  - bme680.write = bme680_i2c_write;
  - bme680.delay_ms = bme680_delay_ms;
  - bme680.amb_temp = 25;

dummygen:
  enum:
    rf24_pa_dbm_e:
      - RF24_PA_MIN
      - RF24_PA_LOW
      - RF24_PA_HIGH
      - RF24_PA_MAX
      - RF24_PA_ERROR
    rf24_datarate_e:
      - RF24_1MBPS
      - RF24_2MBPS
      - RF24_250KBPS
    rf24_crclength_e:
      - RF24_CRC_DISABLED
      - RF24_CRC_8
      - RF24_CRC_16

parameters:
- power_mode
- humidity_oversampling
- pressure_oversampling
- temperature_oversampling
- gas_enabled
- heater_duration_ms
- heater_temperature_degc
- iir_filter

parameter_normalization:
  humidity_oversampling:
    enum:
      BME680_OS_NONE: 0
      BME680_OS_1X: 1
      BME680_OS_2X: 2
      BME680_OS_4X: 4
      BME680_OS_8X: 8
      BME680_OS_16X: 16
  pressure_oversampling:
    enum:
      BME680_OS_NONE: 0
      BME680_OS_1X: 1
      BME680_OS_2X: 2
      BME680_OS_4X: 4
      BME680_OS_8X: 8
      BME680_OS_16X: 16
  temperature_oversampling:
    enum:
      BME680_OS_NONE: 0
      BME680_OS_1X: 1
      BME680_OS_2X: 2
      BME680_OS_4X: 4
      BME680_OS_8X: 8
      BME680_OS_16X: 16

states:
  - UNINITIALIZED
  - SLEEP
  - SLEEP_PENDING_ATTR
  - FORCED

transition:
  init:
    src: [UNINITIALIZED, SLEEP, FORCED]
    dst: SLEEP
    set_param:
      power_mode: BME680_SLEEP_MODE
      humidity_oversampling: BME680_OS_NONE
      pressure_oversampling: BME680_OS_NONE
      temperature_oversampling: BME680_OS_NONE
      gas_enabled: BME680_RUN_GAS_DISABLE
      heater_duration_ms: 0
  setPowerMode:
    loop: [SLEEP, SLEEP_PENDING_ATTR]
    arguments:
    - name: mode
      values: ['BME680_SLEEP_MODE', 'BME680_FORCED_MODE']
      parameter: power_mode
  setHumidityOversampling:
    src: [SLEEP, SLEEP_PENDING_ATTR]
    dst: SLEEP_PENDING_ATTR
    arguments:
    - name: os
      values: ['BME680_OS_NONE', 'BME680_OS_1X', 'BME680_OS_2X', 'BME680_OS_4X', 'BME680_OS_8X', 'BME680_OS_16X']
      parameter: humidity_oversampling
  setPressureOversampling:
    src: [SLEEP, SLEEP_PENDING_ATTR]
    dst: SLEEP_PENDING_ATTR
    arguments:
    - name: os
      values: ['BME680_OS_NONE', 'BME680_OS_1X', 'BME680_OS_2X', 'BME680_OS_4X', 'BME680_OS_8X', 'BME680_OS_16X']
      parameter: pressure_oversampling
  setTemperatureOversampling:
    src: [SLEEP, SLEEP_PENDING_ATTR]
    dst: SLEEP_PENDING_ATTR
    arguments:
    - name: os
      values: ['BME680_OS_NONE', 'BME680_OS_1X', 'BME680_OS_2X', 'BME680_OS_4X', 'BME680_OS_8X', 'BME680_OS_16X']
      parameter: temperature_oversampling
  setFilter:
    src: [SLEEP, SLEEP_PENDING_ATTR]
    dst: SLEEP_PENDING_ATTR
    arguments:
    - name: filter
      values: ['BME680_FILTER_SIZE_0', 'BME680_FILTER_SIZE_1', 'BME680_FILTER_SIZE_3', 'BME680_FILTER_SIZE_7', 'BME680_FILTER_SIZE_15', 'BME680_FILTER_SIZE_31', 'BME680_FILTER_SIZE_63', 'BME680_FILTER_SIZE_127']
      parameter: iir_filter
  setRunGas:
    src: [SLEEP, SLEEP_PENDING_ATTR]
    dst: SLEEP_PENDING_ATTR
    arguments:
    - name: enabled
      values: ['BME680_RUN_GAS_DISABLE', 'BME680_RUN_GAS_ENABLE']
      parameter: gas_enabled
  setHeaterDuration:
    src: [SLEEP, SLEEP_PENDING_ATTR]
    dst: SLEEP_PENDING_ATTR
    arguments:
    - name: ms
      values: [10, 30, 60, 100, 150, 200]
      parameter: heater_duration_ms
  setHeaterTemp:
    src: [SLEEP, SLEEP_PENDING_ATTR]
    dst: SLEEP_PENDING_ATTR
    arguments:
    - name: degc
      values: [100, 150, 200, 250, 300]
      parameter: heater_temperature_degc
  configure:
    src: [SLEEP, SLEEP_PENDING_ATTR]
    dst: SLEEP_PENDING_ATTR
    arguments:
    - name: os_hum
      values: ['BME680_OS_NONE', 'BME680_OS_1X', 'BME680_OS_2X', 'BME680_OS_4X', 'BME680_OS_8X', 'BME680_OS_16X']
      parameter: humidity_oversampling
    - name: os_pres
      values: ['BME680_OS_NONE', 'BME680_OS_1X', 'BME680_OS_2X', 'BME680_OS_4X', 'BME680_OS_8X', 'BME680_OS_16X']
      parameter: pressure_oversampling
    - name: os_temp
      values: ['BME680_OS_NONE', 'BME680_OS_1X', 'BME680_OS_2X', 'BME680_OS_4X', 'BME680_OS_8X', 'BME680_OS_16X']
      parameter: temperature_oversampling
    - name: run_gas
      values: ['BME680_RUN_GAS_DISABLE', 'BME680_RUN_GAS_ENABLE']
      parameter: gas_enabled
    - name: heatr_dur
      values: [10, 30, 60, 100, 150, 200]
      parameter: heater_duration_ms
    - name: heatr_temp
      values: [100, 150, 200, 250, 300]
      parameter: heater_temperature_degc
  setSensorSettings:
    src: [SLEEP_PENDING_ATTR]
    dst: SLEEP
    arguments:
    - name: desired_settings
      values: ['BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_GAS_SENSOR_SEL']
  setSensorMode:
    src: [SLEEP]
    dst: FORCED
    codegen:
      delay_after_ms: 300
  getSensorData:
    src: [FORCED]
    dst: SLEEP
    arguments:
      - name: data
        values: ['&sensordata']
