CMPS03 Compass library with only PWM support. I2C support will be added shortly, while it will arrive, you may use MBED component library if you wish to use CMPS03 I2C interface

Dependents:   TestBoussole FRC_2018 0hackton_08_06_18 lib_FRC_2019 ... more

CMPS03.cpp

Committer:
gvaquette
Date:
2019-10-23
Revision:
5:7bfdf8ff9c5e
Parent:
3:3e9586433ce5

File content as of revision 5:7bfdf8ff9c5e:

#include "CMPS03.h"

CMPS03::CMPS03(PinName pwm) : _compass(pwm)
{
    _compass.rise(callback(this, &CMPS03::rise));
    _compass.fall(callback(this, &CMPS03::fall));
    _compass.enable_irq();
    _tim.start();
}

void CMPS03::rise(void)
{
    _startTime = _tim.read_us();
}

void CMPS03::fall(void)
{

    _stopTime = _tim.read_us();
    _pwmBearing = ((double)(_stopTime - _startTime - 1000)/100.0);
}


double CMPS03::getBearing(void)
{
    return _pwmBearing;
}

CMPS03::operator double()
{
    return _pwmBearing;
}