altb_pmic / Mbed 2 deprecated Test_optical_flow_PX4

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PX4Flow.h Source File

PX4Flow.h

00001 #ifndef _PX4FLOW_MBED_H
00002 #define _PX4FLOW_MBED_H
00003 
00004 # include <stdint.h>
00005 # include "mbed.h"
00006 
00007 // 7 Bit I2C Address of the Flow Module: Default 0x42 (user selectable bits 0,1,2)
00008 #define PX4FLOW_ADDRESS 0x42<<1
00009 
00010 // Commands
00011 #define    INTEGRAL_FRAME 0x16
00012 
00013 // integral frame
00014 #define    AVG_FLOW_X        0
00015 #define    AVG_FLOW_Y        2
00016 #define    AVG_QUAL          4
00017 #define    VALID_FRAME_COUNT 5
00018 #define    FRAME_COUNT_      6
00019 
00020 // Integral frame, only valid with modified firmware, see Git-branch IndNav from the Firmware
00021 typedef struct i2c_integral_frame {
00022     int16_t avg_flow_x;
00023     int16_t avg_flow_y;
00024     uint8_t avg_qual;
00025     uint8_t valid_frame_count;
00026     uint8_t frame_count;
00027 } i2c_integral_frame;
00028 
00029 
00030 class PX4Flow
00031 {
00032 public:
00033     
00034     PX4Flow(I2C& i2c);
00035     
00036     virtual ~PX4Flow();
00037 
00038     bool update_integral();
00039     
00040     float   avg_flow_x();        // avg flow x in mm/s
00041     float   avg_flow_y();        // avg flow y in mm/s
00042     uint8_t avg_qual();          // avg 0-255 linear quality measurement 0=bad, 255=best
00043     uint8_t valid_frame_count(); // nr. of valid frames (qual > 0) between i2c readings
00044     uint8_t frame_count();       // nr. of frames between i2c readings    
00045     uint8_t avg_qual_scaled();   // avg 0-255 linear quality measurement 0=bad, 255=best, scaled with N_valid_frame_count/N_frame_count
00046     
00047 private:
00048 
00049     DigitalOut dout1;
00050 
00051 protected:
00052 
00053     I2C i2c;
00054     
00055     // storage for sensordata
00056     char bufferI[7];
00057 
00058     char i2c_commands;
00059     
00060     struct i2c_integral_frame iframe;
00061 
00062     uint8_t  read8(char *buffer, const unsigned int& idx = 0);
00063     uint16_t read16(char *buffer, const unsigned int& idx = 0);
00064     uint32_t read32(char *buffer, const unsigned int& idx = 0);
00065 };
00066 
00067 #endif