<!DOCTYPE module SYSTEM "module.dtd">

<module name="px4flow_i2c" dir="optical_flow">
  <doc>
    <description>PX4FLOW optical flow sensor connected over i2c bus</description>
    <configure name="PX4FLOW_I2C_DEV" value="i2c2" description="I2C device to use for px4flow"/>
    <configure name="PX4FLOW_I2C_ADDR" value="0x84" description="slave address of px4flow"/>
    <configure name="REQUEST_INT_FRAME" value="1" description="request i2c_integral_frame, default TRUE"/>
    <configure name="PX4FLOW_NOISE_STDDEV" value="1.0" description="standard deviation of the flow measurement (if known)"/>
    <configure name="USE_PX4FLOW_AGL" value="1" description="update AGL measurements from onboard sonar"/>
    <configure name="PX4FLOW_COMPENSATE_ROTATION" value="1" description="compensate AGL measurements for body rotation"/>
    <configure name="PX4FLOW_MEDIAN_LENGTH" value="7" description="Median filter length for the px4flow measurements"/>
  </doc>

  <settings>
    <dl_settings NAME="optical flow">
      <dl_settings NAME="px4flow">
        <dl_setting MAX="1" MIN="0" STEP="1" VAR="px4flow.compensate_rotation" shortname="derotate_agl"/>
        <dl_setting MAX="1" MIN="0" STEP="1" VAR="px4flow.update_agl" shortname="update_agl"/>
        <dl_setting MAX="10" MIN="0" STEP="0.1" VAR="px4flow.stddev" shortname="stddev"/>
      </dl_settings>
    </dl_settings>
  </settings>

  <header>
    <file name="px4flow_i2c.h"/>
  </header>
  <init fun="px4flow_i2c_init()"/>
  <periodic fun="px4flow_i2c_downlink()" freq="4" autorun="FALSE"/> <!-- for debug -->
  <periodic fun="px4flow_i2c_periodic()" freq="50"/> <!-- poll px4flow for data, see https://pixhawk.org/modules/px4flow for details -->
  <makefile>
    <configure name="PX4FLOW_I2C_DEV" default="i2c1" case="lower|upper"/>
    <configure name="PX4FLOW_I2C_ADDR" default="0x84"/> <!-- 0x42 + additional zero at the end to make 8 bit address -->
    <configure name="REQUEST_INT_FRAME" default="1"/>
    <configure name="PX4FLOW_NOISE_STDDEV" default="1.0"/>
    <configure name="USE_PX4FLOW_AGL" default="1"/>
    <configure name="PX4FLOW_COMPENSATE_ROTATION" default="1"/>
    <configure name="PX4FLOW_MEDIAN_LENGTH" default="7"/>
    <define name="PX4FLOW_I2C_DEV" value="$(PX4FLOW_I2C_DEV_LOWER)"/>
    <define name="USE_$(PX4FLOW_I2C_DEV_UPPER)"/>
    <define name="PX4FLOW_I2C_ADDR" value="$(PX4FLOW_I2C_ADDR)"/>
    <define name="REQUEST_INT_FRAME" value="$(REQUEST_INT_FRAME)"/>
    <define name="PX4FLOW_NOISE_STDDEV" value="$(PX4FLOW_NOISE_STDDEV)"/>
    <define name="USE_PX4FLOW_AGL" value="$(USE_PX4FLOW_AGL)"/>
    <define name="PX4FLOW_COMPENSATE_ROTATION" value="$(PX4FLOW_COMPENSATE_ROTATION)"/>
    <define name="PX4FLOW_MEDIAN_LENGTH" value="$(PX4FLOW_MEDIAN_LENGTH)"/>
    <file name="px4flow_i2c.c"/>
  </makefile>
</module>


