Browse Source

Add reset and samplerate ioctl to HMC5883 driver

sbg
Julian Oes 12 years ago
parent
commit
658276e1cc
  1. 29
      src/drivers/hmc5883/hmc5883.cpp

29
src/drivers/hmc5883/hmc5883.cpp

@ -191,6 +191,11 @@ private: @@ -191,6 +191,11 @@ private:
*/
void stop();
/**
* Reset the device
*/
int reset();
/**
* Perform the on-sensor scale calibration routine.
*
@ -365,6 +370,9 @@ HMC5883::init() @@ -365,6 +370,9 @@ HMC5883::init()
if (I2C::init() != OK)
goto out;
/* reset the device configuration */
reset();
/* allocate basic report buffers */
_num_reports = 2;
_reports = new struct mag_report[_num_reports];
@ -381,9 +389,6 @@ HMC5883::init() @@ -381,9 +389,6 @@ HMC5883::init()
if (_mag_topic < 0)
debug("failed to create sensor_mag object");
/* set range */
set_range(_range_ga);
ret = OK;
/* sensor is ok, but not calibrated */
_sensor_ok = true;
@ -542,7 +547,6 @@ int @@ -542,7 +547,6 @@ int
HMC5883::ioctl(struct file *filp, int cmd, unsigned long arg)
{
switch (cmd) {
case SENSORIOCSPOLLRATE: {
switch (arg) {
@ -633,13 +637,15 @@ HMC5883::ioctl(struct file *filp, int cmd, unsigned long arg) @@ -633,13 +637,15 @@ HMC5883::ioctl(struct file *filp, int cmd, unsigned long arg)
return _num_reports - 1;
case SENSORIOCRESET:
/* XXX implement this */
return -EINVAL;
return reset();
case MAGIOCSSAMPLERATE:
/* same as pollrate because device is in single measurement mode*/
return ioctl(filp, SENSORIOCSPOLLRATE, arg);
case MAGIOCGSAMPLERATE:
/* not supported, always 1 sample per poll */
return -EINVAL;
/* same as pollrate because device is in single measurement mode*/
return ioctl(filp, SENSORIOCGPOLLRATE, 0);
case MAGIOCSRANGE:
return set_range(arg);
@ -702,6 +708,13 @@ HMC5883::stop() @@ -702,6 +708,13 @@ HMC5883::stop()
work_cancel(HPWORK, &_work);
}
int
HMC5883::reset()
{
/* set range */
return set_range(_range_ga);
}
void
HMC5883::cycle_trampoline(void *arg)
{

Loading…
Cancel
Save