ArduSat API
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
SAT_Lum.h
Go to the documentation of this file.
1 
35 #ifndef _SAT_Lum_H_
36 #define _SAT_Lum_H_
37 
38 #if ARDUINO >= 100
39  #include <Arduino.h>
40 #else
41  #include <WProgram.h>
42 #endif
43 #include <OnboardCommLayer.h>
44 
45 #define SAT_Lum_VISIBLE 2 // channel 0 - channel 1
46 #define SAT_Lum_INFRARED 1 // channel 1
47 #define SAT_Lum_FULLSPECTRUM 0 // channel 0
48 
49 // 3 i2c address options!
50 #define SAT_Lum_ADDR_LOW 0x29
51 #define SAT_Lum_ADDR_FLOAT 0x39
52 #define SAT_Lum_ADDR_HIGH 0x49
53 
54 // Lux calculations differ slightly for CS package
55 //#define SAT_Lum_PACKAGE_CS
56 #define SAT_Lum_PACKAGE_T_FN_CL
57 
58 #define SAT_Lum_READBIT (0x01)
59 
60 #define SAT_Lum_COMMAND_BIT (0x80) // Must be 1
61 #define SAT_Lum_CLEAR_BIT (0x40) // Clears any pending interrupt (write 1 to clear)
62 #define SAT_Lum_WORD_BIT (0x20) // 1 = read/write word (rather than byte)
63 #define SAT_Lum_BLOCK_BIT (0x10) // 1 = using block read/write
64 
65 #define SAT_Lum_CONTROL_POWERON (0x03)
66 #define SAT_Lum_CONTROL_POWEROFF (0x00)
67 
68 #define SAT_Lum_LUX_LUXSCALE (14) // Scale by 2^14
69 #define SAT_Lum_LUX_RATIOSCALE (9) // Scale ratio by 2^9
70 #define SAT_Lum_LUX_CHSCALE (10) // Scale channel values by 2^10
71 #define SAT_Lum_LUX_CHSCALE_TINT0 (0x7517) // 322/11 * 2^SAT_Lum_LUX_CHSCALE
72 #define SAT_Lum_LUX_CHSCALE_TINT1 (0x0FE7) // 322/81 * 2^SAT_Lum_LUX_CHSCALE
73 
74 // T, FN and CL package values
75 #define SAT_Lum_LUX_K1T (0x0040) // 0.125 * 2^RATIO_SCALE
76 #define SAT_Lum_LUX_B1T (0x01f2) // 0.0304 * 2^LUX_SCALE
77 #define SAT_Lum_LUX_M1T (0x01be) // 0.0272 * 2^LUX_SCALE
78 #define SAT_Lum_LUX_K2T (0x0080) // 0.250 * 2^RATIO_SCALE
79 #define SAT_Lum_LUX_B2T (0x0214) // 0.0325 * 2^LUX_SCALE
80 #define SAT_Lum_LUX_M2T (0x02d1) // 0.0440 * 2^LUX_SCALE
81 #define SAT_Lum_LUX_K3T (0x00c0) // 0.375 * 2^RATIO_SCALE
82 #define SAT_Lum_LUX_B3T (0x023f) // 0.0351 * 2^LUX_SCALE
83 #define SAT_Lum_LUX_M3T (0x037b) // 0.0544 * 2^LUX_SCALE
84 #define SAT_Lum_LUX_K4T (0x0100) // 0.50 * 2^RATIO_SCALE
85 #define SAT_Lum_LUX_B4T (0x0270) // 0.0381 * 2^LUX_SCALE
86 #define SAT_Lum_LUX_M4T (0x03fe) // 0.0624 * 2^LUX_SCALE
87 #define SAT_Lum_LUX_K5T (0x0138) // 0.61 * 2^RATIO_SCALE
88 #define SAT_Lum_LUX_B5T (0x016f) // 0.0224 * 2^LUX_SCALE
89 #define SAT_Lum_LUX_M5T (0x01fc) // 0.0310 * 2^LUX_SCALE
90 #define SAT_Lum_LUX_K6T (0x019a) // 0.80 * 2^RATIO_SCALE
91 #define SAT_Lum_LUX_B6T (0x00d2) // 0.0128 * 2^LUX_SCALE
92 #define SAT_Lum_LUX_M6T (0x00fb) // 0.0153 * 2^LUX_SCALE
93 #define SAT_Lum_LUX_K7T (0x029a) // 1.3 * 2^RATIO_SCALE
94 #define SAT_Lum_LUX_B7T (0x0018) // 0.00146 * 2^LUX_SCALE
95 #define SAT_Lum_LUX_M7T (0x0012) // 0.00112 * 2^LUX_SCALE
96 #define SAT_Lum_LUX_K8T (0x029a) // 1.3 * 2^RATIO_SCALE
97 #define SAT_Lum_LUX_B8T (0x0000) // 0.000 * 2^LUX_SCALE
98 #define SAT_Lum_LUX_M8T (0x0000) // 0.000 * 2^LUX_SCALE
99 
100 // CS package values
101 #define SAT_Lum_LUX_K1C (0x0043) // 0.130 * 2^RATIO_SCALE
102 #define SAT_Lum_LUX_B1C (0x0204) // 0.0315 * 2^LUX_SCALE
103 #define SAT_Lum_LUX_M1C (0x01ad) // 0.0262 * 2^LUX_SCALE
104 #define SAT_Lum_LUX_K2C (0x0085) // 0.260 * 2^RATIO_SCALE
105 #define SAT_Lum_LUX_B2C (0x0228) // 0.0337 * 2^LUX_SCALE
106 #define SAT_Lum_LUX_M2C (0x02c1) // 0.0430 * 2^LUX_SCALE
107 #define SAT_Lum_LUX_K3C (0x00c8) // 0.390 * 2^RATIO_SCALE
108 #define SAT_Lum_LUX_B3C (0x0253) // 0.0363 * 2^LUX_SCALE
109 #define SAT_Lum_LUX_M3C (0x0363) // 0.0529 * 2^LUX_SCALE
110 #define SAT_Lum_LUX_K4C (0x010a) // 0.520 * 2^RATIO_SCALE
111 #define SAT_Lum_LUX_B4C (0x0282) // 0.0392 * 2^LUX_SCALE
112 #define SAT_Lum_LUX_M4C (0x03df) // 0.0605 * 2^LUX_SCALE
113 #define SAT_Lum_LUX_K5C (0x014d) // 0.65 * 2^RATIO_SCALE
114 #define SAT_Lum_LUX_B5C (0x0177) // 0.0229 * 2^LUX_SCALE
115 #define SAT_Lum_LUX_M5C (0x01dd) // 0.0291 * 2^LUX_SCALE
116 #define SAT_Lum_LUX_K6C (0x019a) // 0.80 * 2^RATIO_SCALE
117 #define SAT_Lum_LUX_B6C (0x0101) // 0.0157 * 2^LUX_SCALE
118 #define SAT_Lum_LUX_M6C (0x0127) // 0.0180 * 2^LUX_SCALE
119 #define SAT_Lum_LUX_K7C (0x029a) // 1.3 * 2^RATIO_SCALE
120 #define SAT_Lum_LUX_B7C (0x0037) // 0.00338 * 2^LUX_SCALE
121 #define SAT_Lum_LUX_M7C (0x002b) // 0.00260 * 2^LUX_SCALE
122 #define SAT_Lum_LUX_K8C (0x029a) // 1.3 * 2^RATIO_SCALE
123 #define SAT_Lum_LUX_B8C (0x0000) // 0.000 * 2^LUX_SCALE
124 #define SAT_Lum_LUX_M8C (0x0000) // 0.000 * 2^LUX_SCALE
125 
126 enum
127 {
141 };
142 
143 typedef enum
144 {
148 }
150 
151 typedef enum
152 {
153  SAT_Lum_GAIN_0X = 0x00, // No gain
154  SAT_Lum_GAIN_16X = 0x10, // 16x gain
155 }
157 
158 
159 class SAT_Lum {
160  public:
164  SAT_Lum(uint8_t addr);
165 
171  boolean begin(uint8_t nodeid);
172 
173  void enable(void);
174 
175  void disable(void);
176 
177  void write8(uint8_t r, uint8_t v);
178  uint16_t read16(uint8_t reg);
179 
181  uint32_t calculateLux(uint16_t ch0, uint16_t ch1);
182 
186  void setTiming(tsl2561IntegrationTime_t integration);
187 
191  void setGain(tsl2561Gain_t gain);
192 
194  uint16_t getLuminosity (uint8_t channel);
195 
197  uint32_t getFullLuminosity ();
198 
199  private:
200  int8_t _addr;
201  tsl2561IntegrationTime_t _integration;
202  tsl2561Gain_t _gain;
203 
204  boolean _initialized;
205 
206  //init
207  uint8_t _buff[2];
208  uint8_t _local_address;
209 };
210 #endif