Nespresso RGB Sensor / GroveColourSensor

Dependents:   ColorDetector ColorDetectorV2 offline_sync_k64f

Fork of GroveColourSensor by Brian Daniels

Revision:
3:a401a082d57e
Parent:
2:50cb56828ab9
Child:
4:f0e8304db2a3
diff -r 50cb56828ab9 -r a401a082d57e GroveColourSensor.cpp
--- a/GroveColourSensor.cpp	Wed Apr 15 19:13:11 2015 +0000
+++ b/GroveColourSensor.cpp	Tue Apr 28 16:09:30 2015 +0000
@@ -14,53 +14,23 @@
  * limitations under the License.
  */
 
-
 #include "GroveColourSensor.h"
 
-/**
-*   Constructor, doesn't affect the device at all.
-*
-* @param i2c A pointer to the initialized I2C instance.
-*
-*/
 GroveColourSensor::GroveColourSensor(I2C *i2c) : i2c(i2c) {
-    /* empty*/
+    // Empty
 }
 
-/**
-*   Powers up the color sensor.
-*
-*/
+
 bool GroveColourSensor::powerUp(void) {
     static const char powerUpCommand[] = {0x80, 0x03};
-    /* turn on the color sensor */
     return i2c->write((SEVEN_BIT_ADDRESS << 1), powerUpCommand, sizeof(powerUpCommand)) == 0;
 }
 
-/**
-*   Powers down the color sensor.
-*
-*/
 void GroveColourSensor::powerDown(void) {
     static const char powerDownCommand[] = {0x80, 0x00};
-    /* turn on the color sensor */
-    if (i2c->write((SEVEN_BIT_ADDRESS << 1), powerDownCommand, sizeof(powerDownCommand)) != 0) {
-        error("failed to power down the sensor");
-    }
+    return i2c->write((SEVEN_BIT_ADDRESS << 1), powerDownCommand, sizeof(powerDownCommand)) == 0;
 }
 
-/**
-*   Set the gain of the color sensor.
-*
-*   The following are valid gain values:
-*   
-*   0 - 1X gain
-*   1 - 4X gain
-*   2 - 16X gain
-*   3 - 64X gain
-*   
-* @param gain The gain value specified above.
-*/
 void GroveColourSensor::setGain(uint8_t gain) {
     // Set gain (0 Prescale)
     char gainRegValue = 0x00 | (gain << 4);
@@ -69,11 +39,6 @@
     i2c->write((SEVEN_BIT_ADDRESS << 1), gainCommand, sizeof(gainCommand));
 }
 
-/**
-*   Read a specific color.
-*   
-* @param colour The color to red (RED, GREEN, BLUE, or CLEAR).
-*/
 uint16_t GroveColourSensor::readColour(Colour_t colour) {
     char readColorRegistersCommand = 0xb0 + (2 * static_cast<unsigned>(colour));
     i2c->write((SEVEN_BIT_ADDRESS << 1), &readColorRegistersCommand, 1 /* size */);
@@ -83,20 +48,11 @@
     return colourValue;
 }
 
-/**
-*   Configures the color sensor to expect block reads.
-*
-*/
 void GroveColourSensor::setBlockRead() {
     char blockReadCommand = 0xD0;
     i2c->write((SEVEN_BIT_ADDRESS << 1), &blockReadCommand, 1);
 }
 
-/**
-*   Read the red, green, blue, and clear channels in one transaction. You must call setBlockRead() before calling this function.
-*   
-* @param sample A pointer to the RGBC instance you wish to populate.
-*/
 void GroveColourSensor::readBlock(RGBC *sample) {
     char tmpColours[8] = {0};
     
@@ -110,11 +66,6 @@
     }
 }
 
-/**
-*   Non enum version of readColour()
-*   
-* @param colour The integer corresponding to the color you wish to read.
-*/
 uint16_t GroveColourSensor::readColour(unsigned colour) {
     if (colour >= NUM_COLORS) {
         return 0;
@@ -123,12 +74,6 @@
     return readColour(static_cast<Colour_t>(colour));
 }
 
-/**
-*   Helper function to convert two bytes into a uint16_t.
-*   
-* @param lowByte Least signficant byte.
-* @param highByte Most signficant byte.
-*/
 uint16_t GroveColourSensor::bytesTo16bit(char lowByte, char highByte) {
     uint16_t res = 0;
     res |= lowByte;