apds9930: enable sensor before read out sensor data

Changes in library:
- enableProximity() function is to enable or disable proximity sensor
- enableIlluminance() function is to enable or disable illuminance sensor
- run clang-format

Changes in example:
- proximity and illuminance kernel IIO-based driver init state is power off,
  require enable before read out sensor data. Sleep time is needed after
  enable, the sleep time may vary on different platform.
- run clang-format

Signed-off-by: Lay, Kuan Loon <kuan.loon.lay@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Lay, Kuan Loon
2016-06-20 15:42:19 +08:00
committed by Mihai Tudor Panu
parent 40fe6654eb
commit e64f192fb7
3 changed files with 47 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -41,7 +41,7 @@ APDS9930::APDS9930(int device)
APDS9930::~APDS9930()
{
if(m_iio)
if (m_iio)
mraa_iio_close(m_iio);
}
@ -60,3 +60,25 @@ APDS9930::getProximity()
mraa_iio_read_int(m_iio, "in_proximity_raw", &iio_value);
return iio_value;
}
bool
APDS9930::enableProximity(bool enable)
{
if (enable)
mraa_iio_write_int(m_iio, "in_proximity_en", 1);
else
mraa_iio_write_int(m_iio, "in_proximity_en", 0);
return true;
}
bool
APDS9930::enableIlluminance(bool enable)
{
if (enable)
mraa_iio_write_int(m_iio, "in_illuminance_en", 1);
else
mraa_iio_write_int(m_iio, "in_illuminance_en", 0);
return true;
}

View File

@ -1,6 +1,6 @@
/*
* Author: Lay, Kuan Loon <kuan.loon.lay@intel.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2016 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -75,6 +75,16 @@ class APDS9930
* @return Proximity value
*/
int getProximity();
/**
* Enable proximity
* @param enable state
*/
bool enableProximity(bool enable);
/**
* Enable illuminance
* @param enable state
*/
bool enableIlluminance(bool enable);
private:
mraa_iio_context m_iio;