Plant Monitoring CS

Dependencies:   HTS221

Committer:
titi9211
Date:
Thu Mar 26 10:01:31 2020 +0000
Revision:
62:4763f2aa486c
Parent:
59:169324c8e604
TSL2561

Who changed what in which revision?

UserRevisionLine numberNew contents of line
titi9211 59:169324c8e604 1 #ifndef TSL2591_H
titi9211 59:169324c8e604 2 #define TSL2591_H
titi9211 59:169324c8e604 3
titi9211 59:169324c8e604 4 #include "mbed.h"
titi9211 59:169324c8e604 5
titi9211 59:169324c8e604 6 #define TSL2591_ADDR (0x29)
titi9211 59:169324c8e604 7 #define TSL2591_ID (0x50)
titi9211 59:169324c8e604 8
titi9211 59:169324c8e604 9 #define TSL2591_CMD_BIT (0xA0)
titi9211 59:169324c8e604 10
titi9211 59:169324c8e604 11 #define TSL2591_EN_NPIEN (0x80)
titi9211 59:169324c8e604 12 #define TSL2591_EN_SAI (0x40)
titi9211 59:169324c8e604 13 #define TSL2591_EN_AIEN (0x10)
titi9211 59:169324c8e604 14 #define TSL2591_EN_AEN (0x02)
titi9211 59:169324c8e604 15 #define TSL2591_EN_PON (0x01)
titi9211 59:169324c8e604 16 #define TSL2591_EN_POFF (0x00)
titi9211 59:169324c8e604 17
titi9211 59:169324c8e604 18 #define TSL2591_LUX_DF (408.0F)
titi9211 59:169324c8e604 19 #define TSL2591_LUX_COEFB (1.64F) // CH0 coefficient
titi9211 59:169324c8e604 20 #define TSL2591_LUX_COEFC (0.59F) // CH1 coefficient A
titi9211 59:169324c8e604 21 #define TSL2591_LUX_COEFD (0.86F) // CH2 coefficient B
titi9211 59:169324c8e604 22
titi9211 59:169324c8e604 23 enum {
titi9211 59:169324c8e604 24 TSL2591_REG_ENABLE = 0x00,
titi9211 59:169324c8e604 25 TSL2591_REG_CONTROL = 0x01,
titi9211 59:169324c8e604 26 TSL2591_REG_THRES_AILTL = 0x04,
titi9211 59:169324c8e604 27 TSL2591_REG_THRES_AILTH = 0x05,
titi9211 59:169324c8e604 28 TSL2591_REG_THRES_AIHTL = 0x06,
titi9211 59:169324c8e604 29 TSL2591_REG_THRES_AIHTH = 0x07,
titi9211 59:169324c8e604 30 TSL2591_REG_THRES_NPAILTL = 0x08,
titi9211 59:169324c8e604 31 TSL2591_REG_THRES_NPAILTH = 0x09,
titi9211 59:169324c8e604 32 TSL2591_REG_THRES_NPAIHTL = 0x0A,
titi9211 59:169324c8e604 33 TSL2591_REG_THRES_NPAIHTH = 0x0B,
titi9211 59:169324c8e604 34 TSL2591_REG_PERSIST = 0x0C,
titi9211 59:169324c8e604 35 TSL2591_REG_PID = 0x11,
titi9211 59:169324c8e604 36 TSL2591_REG_ID = 0x12,
titi9211 59:169324c8e604 37 TSL2591_REG_STATUS = 0x13,
titi9211 59:169324c8e604 38 TSL2591_REG_CHAN0_L = 0x14,
titi9211 59:169324c8e604 39 TSL2591_REG_CHAN0_H = 0x15,
titi9211 59:169324c8e604 40 TSL2591_REG_CHAN1_L = 0x16,
titi9211 59:169324c8e604 41 TSL2591_REG_CHAN1_H = 0x17,
titi9211 59:169324c8e604 42 };
titi9211 59:169324c8e604 43
titi9211 59:169324c8e604 44 typedef enum {
titi9211 59:169324c8e604 45 TSL2591_GAIN_LOW = 0x00,
titi9211 59:169324c8e604 46 TSL2591_GAIN_MED = 0x01,
titi9211 59:169324c8e604 47 TSL2591_GAIN_HIGH = 0x02,
titi9211 59:169324c8e604 48 TSL2591_GAIN_MAX = 0x03,
titi9211 59:169324c8e604 49 } tsl2591Gain_t;
titi9211 59:169324c8e604 50
titi9211 59:169324c8e604 51 typedef enum {
titi9211 59:169324c8e604 52 TSL2591_INTT_100MS = 0x00,
titi9211 59:169324c8e604 53 TSL2591_INTT_200MS = 0x01,
titi9211 59:169324c8e604 54 TSL2591_INTT_300MS = 0x02,
titi9211 59:169324c8e604 55 TSL2591_INTT_400MS = 0x03,
titi9211 59:169324c8e604 56 TSL2591_INTT_500MS = 0x04,
titi9211 59:169324c8e604 57 TSL2591_INTT_600MS = 0x05,
titi9211 59:169324c8e604 58 } tsl2591IntegrationTime_t;
titi9211 59:169324c8e604 59
titi9211 59:169324c8e604 60 typedef enum {
titi9211 59:169324c8e604 61 TSL2591_PER_EVERY = 0x00,
titi9211 59:169324c8e604 62 TSL2591_PER_ANY = 0x01,
titi9211 59:169324c8e604 63 TSL2591_PER_2 = 0x02,
titi9211 59:169324c8e604 64 TSL2591_PER_3 = 0x03,
titi9211 59:169324c8e604 65 TSL2591_PER_5 = 0x04,
titi9211 59:169324c8e604 66 TSL2591_PER_10 = 0x05,
titi9211 59:169324c8e604 67 TSL2591_PER_15 = 0x06,
titi9211 59:169324c8e604 68 TSL2591_PER_20 = 0x07,
titi9211 59:169324c8e604 69 TSL2591_PER_25 = 0x08,
titi9211 59:169324c8e604 70 TSL2591_PER_30 = 0x09,
titi9211 59:169324c8e604 71 TSL2591_PER_35 = 0x0A,
titi9211 59:169324c8e604 72 TSL2591_PER_40 = 0x0B,
titi9211 59:169324c8e604 73 TSL2591_PER_45 = 0x0C,
titi9211 59:169324c8e604 74 TSL2591_PER_50 = 0x0D,
titi9211 59:169324c8e604 75 TSL2591_PER_55 = 0x0E,
titi9211 59:169324c8e604 76 TSL2591_PER_60 = 0x0F,
titi9211 59:169324c8e604 77 } tsl2591Persist_t;
titi9211 59:169324c8e604 78
titi9211 59:169324c8e604 79 class TSL2591
titi9211 59:169324c8e604 80 {
titi9211 59:169324c8e604 81 public:
titi9211 59:169324c8e604 82 TSL2591(I2C& tsl2591_i2c, uint8_t tsl2591_addr=TSL2591_ADDR);
titi9211 59:169324c8e604 83 bool init(void);
titi9211 59:169324c8e604 84 void enable(void);
titi9211 59:169324c8e604 85 void disable(void);
titi9211 59:169324c8e604 86 void setGain(tsl2591Gain_t gain);
titi9211 59:169324c8e604 87 void setTime(tsl2591IntegrationTime_t integ);
titi9211 59:169324c8e604 88 void getALS(void);
titi9211 59:169324c8e604 89 void calcLux(void);
titi9211 59:169324c8e604 90 volatile uint32_t rawALS;
titi9211 59:169324c8e604 91 volatile uint16_t ir;
titi9211 59:169324c8e604 92 volatile uint16_t full;
titi9211 59:169324c8e604 93 volatile uint16_t visible;
titi9211 59:169324c8e604 94 volatile uint32_t lux;
titi9211 59:169324c8e604 95
titi9211 59:169324c8e604 96 protected:
titi9211 59:169324c8e604 97 I2C _i2c;
titi9211 59:169324c8e604 98 uint8_t _addr;
titi9211 59:169324c8e604 99 bool _init;
titi9211 59:169324c8e604 100 tsl2591Gain_t _gain;
titi9211 59:169324c8e604 101 tsl2591IntegrationTime_t _integ;
titi9211 59:169324c8e604 102 };
titi9211 59:169324c8e604 103
titi9211 59:169324c8e604 104 #endif