Digital_Light_ISL29035.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. Digital_Light_ISL29035.h
  3. A library for ISL29035
  4. Copyright (c) 2017 seeed technology inc.
  5. Website : www.seeed.cc
  6. Author : Jack
  7. Create Time:
  8. Change Log :
  9. The MIT License (MIT)
  10. Permission is hereby granted, free of charge, to any person obtaining a copy
  11. of this software and associated documentation files (the "Software"), to deal
  12. in the Software without restriction, including without limitation the rights
  13. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. copies of the Software, and to permit persons to whom the Software is
  15. furnished to do so, subject to the following conditions:
  16. The above copyright notice and this permission notice shall be included in
  17. all copies or substantial portions of the Software.
  18. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. THE SOFTWARE.
  25. */
  26. #ifndef Digital_Light_ISL29035_H
  27. #define Digital_Light_ISL29035_H
  28. #include <Arduino.h>
  29. #define ISL29035_I2C_ADDRESS 0x44 //the 7bits i2c address
  30. #define COMMAND_I 0x00
  31. #define COMMAND_II 0x01
  32. #define DATA_L 0x02
  33. #define DATA_H 0x03
  34. #define INT_LT_L 0x04
  35. #define INT_LT_H 0x05
  36. #define INT_HT_L 0x06
  37. #define INT_HT_H 0x07
  38. #define CHIP_ID 0x0f
  39. #define OPMODE_ALS_ONCE ((0x1)<<5)
  40. #define OPMODE_IR_ONCE ((0x2)<<5)
  41. #define OPMODE_ALS_CONTI ((0x5)<<5)
  42. #define OPMODE_IR_CONTI ((0x6)<<5)
  43. #define FULL_SCALE_LUX_RANGE0 1000
  44. #define FULL_SCALE_LUX_RANGE1 4000
  45. #define FULL_SCALE_LUX_RANGE2 16000
  46. #define FULL_SCALE_LUX_RANGE3 64000
  47. #define DEFAULT_LUX_RANGE_INDEX 1 //should be [0,3]
  48. #define INTEGRATION_TIME3 0.0256 //ms, this also configure the ADC to 4bits
  49. #define INTEGRATION_TIME2 0.41 //ms, this also configure the ADC to 8bits
  50. #define INTEGRATION_TIME1 6.5 //ms, this also configure the ADC to 12bits
  51. #define INTEGRATION_TIME0 105 //ms, this also configure the ADC to 16bits
  52. #define DEFAULT_INTEGRATION_TIME_INDEX 1 //should be [0,3]
  53. class DigitalLightISL29035 {
  54. public:
  55. DigitalLightISL29035();
  56. int init(void);
  57. /**
  58. Set the full scale range for lux measurement.
  59. A lower range offers better resolution, it's suitable in a dim env,
  60. while in light env, a higher range should be selected.
  61. 0: 1000 lux, 1: 4000 lux, 2: 16000 lux, 3: 64000 lux
  62. default index is 0.
  63. */
  64. int setFullScaleLuxRangeIndex(int range_index);
  65. /**
  66. Set the integration time.
  67. 0: 105ms, 1: 6.5ms, 2: 0.41ms, 3: 0.0256
  68. default index is 0.
  69. */
  70. int setIntegrationTimeIndex(int intg_time_index);
  71. /**
  72. This sensor has builtin IR rejection when measuring ambient light.
  73. */
  74. uint32_t readVisibleLux();
  75. uint32_t readIRLux();
  76. int32_t readEV();
  77. void test();
  78. private:
  79. uint8_t _full_scale_lux_range;
  80. uint8_t _integration_time;
  81. uint32_t _adc_count_max[4];
  82. float _intg_time[4];
  83. uint32_t _ranges[4];
  84. uint8_t readRegister(int deviceAddress, int address);
  85. void writeRegister(int deviceAddress, int address, uint8_t val);
  86. uint16_t readData();
  87. uint16_t measure(uint8_t what);
  88. };
  89. extern DigitalLightISL29035 ISL29035;
  90. #endif