POC1.5 prototype 2 x color sensor 2 x LM75B 3 x AnalogIn 1 x accel

Dependencies:   mbed vt100

Revision:
5:eba500888787
Parent:
4:aa67eddf0ab1
Child:
6:44ca704f2bc1
--- a/af_utils/af_attriburtes.cpp	Tue Dec 05 00:18:45 2017 +0000
+++ b/af_utils/af_attriburtes.cpp	Tue Dec 05 00:46:52 2017 +0000
@@ -336,14 +336,16 @@
         }            
         break ;        
     case ATTR_COLOR0_CALIBRATE: /* calibrate color0 */
-        if (sensor[1] && value[0]) { /* do calibration! */
-            ((edge_color*)sensor[1])->calibrate(color0_target, color0_pwm, 10) ;
-            afero->setAttribute32(ATTR_COLOR0_PWM_R, color0_pwm[0]) ;
-            afero->setAttribute32(ATTR_COLOR0_PWM_G, color0_pwm[1]) ;
-            afero->setAttribute32(ATTR_COLOR0_PWM_B, color0_pwm[2]) ;
+        if (sensor[1]) {
+            afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
+            if (value[0]) { /* do calibration! */
+                ((edge_color*)sensor[1])->calibrate(color0_target, color0_pwm, 10) ;
+                afero->setAttribute32(ATTR_COLOR0_PWM_R, color0_pwm[0]) ;
+                afero->setAttribute32(ATTR_COLOR0_PWM_G, color0_pwm[1]) ;
+                afero->setAttribute32(ATTR_COLOR0_PWM_B, color0_pwm[2]) ;
+                afero->setAttributeBool(ATTR_COLOR0_CALIBRATE, false) ;
+            }
         }
-        afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
-        afero->setAttributeBool(ATTR_COLOR0_CALIBRATE, false) ;
         break ;
     case ATTR_COLOR1_ENABLE: /* color1 enable */
         if (sensor[2]) {
@@ -389,20 +391,23 @@
     case ATTR_COLOR1_PWM_TARGET: /* color0 pwm calibration target */
         if (sensor[2]) {
             color1_target[0] = (value[1] << 8) | value[0] ;
-            color1_target[1] = color0_target[0] ;
-            color1_target[2] = color0_target[1] ;
+            color1_target[1] = color1_target[0] ;
+            color1_target[2] = color1_target[1] ;
             afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
         }            
         break ;   
     case ATTR_COLOR1_CALIBRATE: /* calibrate color1 */
-        if (sensor[2] && value[0]) { /* do calibration! */
-            ((edge_color*)sensor[2])->calibrate(color1_target, color1_pwm, 10) ;
-            afero->setAttribute32(ATTR_COLOR1_PWM_R, color1_pwm[0]) ;
-            afero->setAttribute32(ATTR_COLOR1_PWM_G, color1_pwm[1]) ;
-            afero->setAttribute32(ATTR_COLOR1_PWM_B, color1_pwm[2]) ;
+        if (sensor[2]) {
+            if (value[0]) { /* do calibration! */
+                afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
+                ((edge_color*)sensor[2])->calibrate(color1_target, color1_pwm, 10) ;
+                afero->setAttribute32(ATTR_COLOR1_PWM_R, color1_pwm[0]) ;
+                afero->setAttribute32(ATTR_COLOR1_PWM_G, color1_pwm[1]) ;
+                afero->setAttribute32(ATTR_COLOR1_PWM_B, color1_pwm[2]) ;
+                afero->setAttributeBool(ATTR_COLOR1_CALIBRATE, false) ;
+            }
         }
-        afero->setAttributeComplete(requestId, attributeId, valueLen, value) ;
-        afero->setAttributeBool(ATTR_COLOR1_CALIBRATE, false) ;
+
         break ;
     case ATTR_TEMP0_ENABLE: /* temp0 is used to control temp-sensors */
         if (sensor[3]) {