Added printing of data to the end of session not during session

Fork of SI1141_auto_sense by MF Doom

Revision:
9:31d4e955ee92
Parent:
8:70933bf445af
Child:
10:a89555c4f62a
--- a/SI1143.cpp	Tue May 20 21:33:31 2014 +0000
+++ b/SI1143.cpp	Fri May 23 21:34:54 2014 +0000
@@ -71,15 +71,18 @@
     command(PARAM_SET + (PS_ADC_COUNTER & 0x1F));
     
     //Turn up the juice on PS ACD GAIN!
-    write_reg(PARAM_WR, 0x04);
+    write_reg(PARAM_WR, 0x00);
     command(PARAM_SET + (PS_ADC_GAIN & 0x1F));
     
     
-    write_reg(INT_CFG,0);
-    write_reg(IRQ_ENABLE,0);
+    write_reg(INT_CFG,0x01); // Configure Interrupts 
+    write_reg(IRQ_ENABLE,0x04); // Enable PS1
     write_reg(IRQ_MODE1,0);
     write_reg(IRQ_MODE2,0);
     
+    write_reg(MEAS_RATE,0x94); //0x84 - wakes up every 10 ms
+    write_reg(PS_RATE,0x08); //0x84 - wakes up every time measurement clock wakes up
+    
     //write_reg(PS_ADC_MISC,0x24);
     //write_reg(PS1_ADCMUX,0x03);
 }
@@ -141,7 +144,7 @@
     bias3 = get_ps3(repeat);
 }
 
-int SI1143::get_ps1(int repeat) // Read the data for the first LED
+int SI1143::get_ps1(int repeat) // Read the data for the first LED (Used in forced mode)
 {
     int stack = 0;
     
@@ -163,6 +166,27 @@
     return PS1;
 }
 
+void SI1143::start_ps_auto()
+{
+    command(PS_AUTO);
+}    
+
+int SI1143::read_ps1() // Read the data for the first LED (Used in autonomous mode)
+{
+    
+
+    LowB = read_reg(PS1_DATA0,1);
+    HighB = read_reg(PS1_DATA1,1);
+    PS1 = (HighB * 256) + LowB;
+    
+    if(PS1 > bias1)
+        PS1 = PS1 - bias1;
+    else
+        PS1 = 0;
+    
+    return PS1;
+}
+
 int SI1143::get_ps2(int repeat) // Read the data for the second LED
 {
     int stack = 0;
@@ -240,3 +264,8 @@
     
     return IR;
 }
+
+void SI1143::clear_int() // Clear Interrupt register when an interrupt occurs.
+{
+    write_reg(IRQ_STATUS, 0x3F); // Writes one to every interrupt status, thereby clearing them
+}
\ No newline at end of file