Library containing Crazyflie 2.0 sensors drivers: - LPS25H (barometer) - MPU9250 (IMU) - PMW3901 (optical flow) - VL53L0X (range)
Dependents: Drones-Controlador controladoatitude_cteste Drone_Controlador_Atitude optical_test
Diff: PMW3901/PMW3901.h
- Revision:
- 6:c7bc001826ba
- Parent:
- 5:1ef8b91a0318
- Child:
- 7:56608cce81ee
diff -r 1ef8b91a0318 -r c7bc001826ba PMW3901/PMW3901.h --- a/PMW3901/PMW3901.h Fri May 04 23:03:00 2018 +0000 +++ b/PMW3901/PMW3901.h Tue May 08 13:35:42 2018 +0000 @@ -3,6 +3,9 @@ #include "mbed.h" +// +#define PRODUCT_ID 0x00 +// #define MOTION 0x02 // Accelerometer output register addresses #define DELTA_X_L 0x03 @@ -18,17 +21,25 @@ * #include "USBSerial.h" * #include "PMW3901.h" * + * // Declare serial object * USBSerial pc; + * // Declare sensor object with correpondent SPI pins (miso, mosi, sclk, csel) * PMW3901 flow(PA_7,PA_6,PA_5,PB_4); * + * // Main program * int main() * { + * // Initialize sensor * flow.init(); + * // Infinite loop * while(1); * { + * // Read data from sensor * flow.read(); - pc.printf("Optical flow []: %d %d \n\n", flow.x, flow.y); - * wait(1); + * // Print data from sensor + * pc.printf("Optical flow []: %6.2f %6.2f \n\n", flow.x, flow.y); + * // Wait 0.5 seconds + * wait(0.5); * } * } * @endcode @@ -41,20 +52,24 @@ PMW3901(PinName mosi, PinName miso, PinName sclk, PinName csel); /** Initialize optical flow */ - int init(); + bool init(); /** **/ void read(); - /** Optical flow data in x-axis **/ - int16_t x; - /** Optical flow data in y-axis **/ - int16_t y; + /** Optical flow data in x-axis (px) **/ + float x; + /** Optical flow data in y-axis (px) **/ + float y; private: /** SPI bus */ SPI spi; /** Chip select */ DigitalOut cs; + /** **/ + void setup_spi(); + /** **/ + bool test_spi(); /** **/ void setup_flow(); /** **/