AS7265x functions for setting integration time, LEDs, collecting/reading data

Dependents:   IntegratingSphereController LaunchDay

Revision:
1:4d4e07dcc694
Parent:
0:3699cacb5a93
--- a/AS7265xfunctions.cpp	Thu Jan 24 01:27:45 2019 +0000
+++ b/AS7265xfunctions.cpp	Fri Apr 05 19:19:52 2019 +0000
@@ -7,6 +7,9 @@
 #define REG_DEV_SEL     0x4F
 #define REG_LED_CONFIG  0x07
 #define REG_INTEG_TIME  0x05
+#define REG_BANK_MODE   0x04
+#define REG_TEMP_SENSOR 0x06
+#define REG_GAIN_SET    0x04
 
 AS7265x::AS7265x(I2C i2c, int addr) : _i2c(i2c) {
   _addr = addr;
@@ -181,4 +184,26 @@
     /* divides by 2.8 because the sensor takes the value put into the function and multiplies it by 2.8 to get the integration
     time in ms. This way, the user can input how many ms they want the integration time to be */
     regWrite(REG_INTEG_TIME, setting);
-}
\ No newline at end of file
+}
+
+/* sets the bank mode of the sensor to either 0, 1, or 2. The input must be shifted ovre by 2 bits because the bank mode
+is controlled by bits 2 and 3 in this register */
+void AS7265x::setBank(int bankSetting) {  //bank setting and gain are controlled by different bits in the same register
+    char currentBankAndGain = regRead(REG_BANK_MODE);
+    currentBankAndGain = bankSetting<<2 | (currentBankAndGain & 0xF3); /* keeps the same value in the rest of the register, but
+    replaces bits 2 and 3 with what the user inputs */
+    regWrite(REG_BANK_MODE, currentBankAndGain);
+}
+
+// reads the temperature from the temperature sensor that is constantly taking the on-chip temperature
+float AS7265x::readTemp() {
+    return regRead(REG_TEMP_SENSOR);
+}
+
+// can be set to setting 0, 1, 2, or 3. setting 0: 1x.  setting 1: 3.7x.  setting 2: 16x.  setting 3: 64x.
+void AS7265x::setGain(int gain) { //shifted over 4 because gain is controlled by bits 4 and 5 in this register
+    char currentBankAndGain = regRead(REG_GAIN_SET);
+    currentBankAndGain = gain<<4 | (currentBankAndGain & 0xCF); /* keeps the same value in the rest of the register, but replaces 
+    bits 4 and 5 with whatever the user inputs */
+    regWrite(REG_GAIN_SET, currentBankAndGain); //bank mode and gain are controlled by different bits in the same register
+}