iorodeo avatar iorodeo committed a61d7af

Added method to color sensor class to allow selecting the sensors frequency
scaling. Changed the default frequency scaling from 20% to 100% to enable
measurement of higher concentrations. Set python development FAKE_MEASURE
flag back to False - left it on by mistake on last commit.

Comments (0)

Files changed (4)

firmware/ColorSensor.cpp

     pinMode(S3, OUTPUT); 
     pinMode(FO, INPUT);
 
-    // Set frequency scaling 
-    digitalWrite(S0,HIGH);
-    digitalWrite(S1,LOW);
-    //digitalWrite(S1,HIGH);
+    setOutputFreqScale(OUTPUT_FREQSCALE_100);
 
     timeoutCountMax = DFLT_TIMEOUT_COUNT_MAX;
     pulseInWait = DFLT_PULSE_IN_WAIT;
     digitalWrite(S2,HIGH);
     digitalWrite(S3,LOW);
 }
+
+void ColorSensor::setOutputFreqScale(FreqScale value) {
+    switch (value)
+    {
+        case OUTPUT_FREQSCALE_0:
+            digitalWrite(S0,LOW); 
+            digitalWrite(S1,LOW);
+            break;
+            
+        case OUTPUT_FREQSCALE_2:
+            digitalWrite(S0,LOW); 
+            digitalWrite(S1,HIGH);
+            break;
+
+        case OUTPUT_FREQSCALE_20:
+            digitalWrite(S0,HIGH);
+            digitalWrite(S1,LOW);
+            break;
+
+        default:
+            digitalWrite(S0,HIGH);
+            digitalWrite(S1,HIGH);
+            break;
+    }
+}

firmware/ColorSensor.h

 #include "WProgram.h"
 #endif
 
-//const uint32_t DFLT_PULSE_IN_WAIT = 250000;
-const uint32_t DFLT_PULSE_IN_WAIT = 50000;
+const uint32_t DFLT_PULSE_IN_WAIT = 250000;
 const uint16_t DFLT_TIMEOUT_COUNT_MAX = 10;
 
+enum FreqScale 
+{
+    OUTPUT_FREQSCALE_0, 
+    OUTPUT_FREQSCALE_2,
+    OUTPUT_FREQSCALE_20,
+    OUTPUT_FREQSCALE_100
+};
+
 class ColorSensor {
     public:
         uint8_t S0; // Control Pins
         void setChannelGreen();
         void setChannelBlue();
         void setChannelClear();
+        void setOutputFreqScale(FreqScale value);
 };
 #endif
 

firmware/firmware.pde

 void setup() {
     Serial.begin(9600);
     colorimeter.initialize();
-    colorimeter.numSamples = 500;
+    colorimeter.numSamples = 50;
 }
 
 void loop() {

python/Colorimeter/colorimeter/constants.py

 import os
 
 # Development
-#DEVEL_FAKE_MEASURE = False 
-DEVEL_FAKE_MEASURE = True 
+DEVEL_FAKE_MEASURE = False 
+#DEVEL_FAKE_MEASURE = True 
 
 # Serial ports
 DFLT_PORT_WINDOWS = 'com1' 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.