Gsma Version
Dependents: GSMACode stripReader
att160826.h
00001 #include "pca9548.h" 00002 #include "sfh7779.h" 00003 00004 #define SENSORS_PER_STRIP 8 00005 00006 typedef struct { 00007 bool present; 00008 sfh7779_measurements_t sample; 00009 } sfh7779_data_t; 00010 00011 typedef struct { 00012 sfh7779_data_t sensor[SENSORS_PER_STRIP]; 00013 } att160826_data_t; 00014 00015 class ATT160826 00016 { 00017 public: 00018 /** 00019 * Constructor 00020 * 00021 * @param i2c I2C class servicing the strip 00022 * @param addr_3bit address of the strip (A0-A2 of I2C multiplexer) 00023 * Valid values are 0-7 00024 * @param reset optional DigitalOut class that resets the strip 00025 * Not needed if hardware reset is not used or if reset 00026 * is not managed by the class. 00027 */ 00028 ATT160826(I2C * i2c, uint8_t addr_3bit, DigitalOut * reset = NULL) { 00029 _pca9548 = new PCA9548(i2c, addr_3bit, reset); 00030 for (int x = 0; x < SENSORS_PER_STRIP; x++) { 00031 _sfh7779[x] = new SFH7779(i2c); 00032 } 00033 } 00034 00035 /** 00036 * Destructor 00037 */ 00038 ~ATT160826() { 00039 if (_pca9548) { 00040 delete _pca9548; 00041 } 00042 for (int x = 0; x < SENSORS_PER_STRIP; x++) { 00043 if (_sfh7779[x]) { 00044 delete _sfh7779[x]; 00045 } 00046 } 00047 } 00048 00049 /** 00050 * Sample all sensors on the strip (proximity, visual ambient light, and infrared ambient light). 00051 * Sensors are all activated, sampled, and then placed in standby mode to conserve power consumption. 00052 * 00053 * @param att160826_data pointer to a buffer which will be filled with a sensor data 00054 * 00055 * @returns true if successfull 00056 */ 00057 bool scan(att160826_data_t * att160826_data) { 00058 00059 // Clear all previous measurements before starting the scan 00060 memset(att160826_data, 0, sizeof(att160826_data_t)); 00061 00062 if (_pca9548) { 00063 // Enable all sensors 00064 for (int x = 0; x < SENSORS_PER_STRIP; x++) { 00065 int channel_idx = x; 00066 bool ok = _pca9548->select_channel(channel_idx) 00067 && _sfh7779[x] 00068 && _sfh7779[x]->enable(); 00069 att160826_data->sensor[x].present = ok; 00070 } 00071 00072 // Collect data from all sensors (throw away 1st sample and keep 2nd) 00073 for (int y = 0; y < 1; y++) { 00074 for (int x = 0; x < SENSORS_PER_STRIP; x++) { 00075 int channel_idx = x; 00076 if (att160826_data->sensor[x].present && 00077 _pca9548->select_channel(channel_idx)) { 00078 _sfh7779[x]->read(&(att160826_data->sensor[x].sample), 500); 00079 } 00080 } 00081 } 00082 /* 00083 // Disable all sensors 00084 for (int x = 0; x < SENSORS_PER_STRIP; x++) { 00085 int channel_idx = x; 00086 bool ok = _pca9548->select_channel(channel_idx) 00087 && _sfh7779[x]->disable(); 00088 } 00089 */ 00090 // Disconnect all sensors from the I2C bus 00091 _pca9548->reset(); 00092 } 00093 00094 return true; 00095 } 00096 00097 protected: 00098 PCA9548 * _pca9548; 00099 SFH7779 * _sfh7779[SENSORS_PER_STRIP]; 00100 };
Generated on Sat Jul 16 2022 04:59:17 by
