@@ -8,7 +8,7 @@ AS726X::AS726X()
8
8
9
9
}
10
10
11
- bool AS726X::begin (TwoWire &wirePort, byte gain, byte measurementMode)
11
+ bool AS726X::begin (TwoWire &wirePort, uint8_t gain, uint8_t measurementMode)
12
12
{
13
13
_i2cPort = &wirePort;
14
14
_sensorVersion = virtualReadRegister (AS726x_HW_VERSION);
@@ -47,12 +47,12 @@ uint8_t AS726X::getVersion()
47
47
// Mode 1: Continuous reading of GYOR (7262) / RTUX (7263)
48
48
// Mode 2: Continuous reading of all channels (power-on default)
49
49
// Mode 3: One-shot reading of all channels
50
- void AS726X::setMeasurementMode (byte mode)
50
+ void AS726X::setMeasurementMode (uint8_t mode)
51
51
{
52
52
if (mode > 0b11 ) mode = 0b11 ;
53
53
54
54
// Read, mask/set, write
55
- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
55
+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
56
56
value &= 0b11110011 ; // Clear BANK bits
57
57
value |= (mode << 2 ); // Set BANK bits with user's choice
58
58
virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
@@ -63,29 +63,29 @@ void AS726X::setMeasurementMode(byte mode)
63
63
// Gain 1: 3.7x
64
64
// Gain 2: 16x
65
65
// Gain 3: 64x
66
- void AS726X::setGain (byte gain)
66
+ void AS726X::setGain (uint8_t gain)
67
67
{
68
68
if (gain > 0b11 ) gain = 0b11 ;
69
69
70
70
// Read, mask/set, write
71
- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
71
+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
72
72
value &= 0b11001111 ; // Clear GAIN bits
73
73
value |= (gain << 4 ); // Set GAIN bits with user's choice
74
74
virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
75
75
}
76
76
77
77
// Sets the integration value
78
- // Give this function a byte from 0 to 255.
78
+ // Give this function a uint8_t from 0 to 255.
79
79
// Time will be 2.8ms * [integration value]
80
- void AS726X::setIntegrationTime (byte integrationValue)
80
+ void AS726X::setIntegrationTime (uint8_t integrationValue)
81
81
{
82
82
virtualWriteRegister (AS726x_INT_T, integrationValue); // Write
83
83
}
84
84
85
85
void AS726X::enableInterrupt ()
86
86
{
87
87
// Read, mask/set, write
88
- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
88
+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
89
89
value |= 0b01000000 ; // Set INT bit
90
90
virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
91
91
}
@@ -94,7 +94,7 @@ void AS726X::enableInterrupt()
94
94
void AS726X::disableInterrupt ()
95
95
{
96
96
// Read, mask/set, write
97
- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
97
+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
98
98
value &= 0b10111111 ; // Clear INT bit
99
99
virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
100
100
}
@@ -144,10 +144,10 @@ int AS726X::getV() { return(getChannel(AS7263_V)); }
144
144
int AS726X::getW () { return (getChannel (AS7263_W)); }
145
145
146
146
// A the 16-bit value stored in a given channel registerReturns
147
- int AS726X::getChannel (byte channelRegister)
147
+ int AS726X::getChannel (uint8_t channelRegister)
148
148
{
149
- int colorData = virtualReadRegister (channelRegister) << 8 ; // High byte
150
- colorData |= virtualReadRegister (channelRegister + 1 ); // Low byte
149
+ int colorData = virtualReadRegister (channelRegister) << 8 ; // High uint8_t
150
+ colorData |= virtualReadRegister (channelRegister + 1 ); // Low uint8_t
151
151
return (colorData);
152
152
}
153
153
@@ -166,10 +166,10 @@ float AS726X::getCalibratedU() { return(getCalibratedValue(AS7263_U_CAL)); }
166
166
float AS726X::getCalibratedV () { return (getCalibratedValue (AS7263_V_CAL)); }
167
167
float AS726X::getCalibratedW () { return (getCalibratedValue (AS7263_W_CAL)); }
168
168
169
- // Given an address, read four bytes and return the floating point calibrated value
170
- float AS726X::getCalibratedValue (byte calAddress)
169
+ // Given an address, read four uint8_ts and return the floating point calibrated value
170
+ float AS726X::getCalibratedValue (uint8_t calAddress)
171
171
{
172
- byte b0, b1, b2, b3;
172
+ uint8_t b0, b1, b2, b3;
173
173
b0 = virtualReadRegister (calAddress + 0 );
174
174
b1 = virtualReadRegister (calAddress + 1 );
175
175
b2 = virtualReadRegister (calAddress + 2 );
@@ -185,26 +185,26 @@ float AS726X::getCalibratedValue(byte calAddress)
185
185
return (convertBytesToFloat (calBytes));
186
186
}
187
187
188
- // Given 4 bytes returns the floating point value
188
+ // Given 4 uint8_ts returns the floating point value
189
189
float AS726X::convertBytesToFloat (uint32_t myLong)
190
190
{
191
191
float myFloat;
192
- memcpy (&myFloat, &myLong, 4 ); // Copy bytes into a float
192
+ memcpy (&myFloat, &myLong, 4 ); // Copy uint8_ts into a float
193
193
return (myFloat);
194
194
}
195
195
196
196
// Checks to see if DRDY flag is set in the control setup register
197
- boolean AS726X::dataAvailable ()
197
+ bool AS726X::dataAvailable ()
198
198
{
199
- byte value = virtualReadRegister (AS726x_CONTROL_SETUP);
199
+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP);
200
200
return (value & (1 << 1 )); // Bit 1 is DATA_RDY
201
201
}
202
202
203
203
// Clears the DRDY flag
204
204
// Normally this should clear when data registers are read
205
- boolean AS726X::clearDataAvailable ()
205
+ void AS726X::clearDataAvailable ()
206
206
{
207
- byte value = virtualReadRegister (AS726x_CONTROL_SETUP);
207
+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP);
208
208
value &= ~(1 << 1 ); // Set the DATA_RDY bit
209
209
virtualWriteRegister (AS726x_CONTROL_SETUP, value);
210
210
}
@@ -213,7 +213,7 @@ boolean AS726X::clearDataAvailable()
213
213
void AS726X::enableIndicator ()
214
214
{
215
215
// Read, mask/set, write
216
- byte value = virtualReadRegister (AS726x_LED_CONTROL);
216
+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL);
217
217
value |= (1 << 0 ); // Set the bit
218
218
virtualWriteRegister (AS726x_LED_CONTROL, value);
219
219
}
@@ -222,17 +222,17 @@ void AS726X::enableIndicator()
222
222
void AS726X::disableIndicator ()
223
223
{
224
224
// Read, mask/set, write
225
- byte value = virtualReadRegister (AS726x_LED_CONTROL);
225
+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL);
226
226
value &= ~(1 << 0 ); // Clear the bit
227
227
virtualWriteRegister (AS726x_LED_CONTROL, value);
228
228
}
229
229
230
230
// Set the current limit of onboard LED. Default is max 8mA = 0b11.
231
- void AS726X::setIndicatorCurrent (byte current)
231
+ void AS726X::setIndicatorCurrent (uint8_t current)
232
232
{
233
233
if (current > 0b11 ) current = 0b11 ;
234
234
// Read, mask/set, write
235
- byte value = virtualReadRegister (AS726x_LED_CONTROL); // Read
235
+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL); // Read
236
236
value &= 0b11111001 ; // Clear ICL_IND bits
237
237
value |= (current << 1 ); // Set ICL_IND bits with user's choice
238
238
virtualWriteRegister (AS726x_LED_CONTROL, value); // Write
@@ -242,7 +242,7 @@ void AS726X::setIndicatorCurrent(byte current)
242
242
void AS726X::enableBulb ()
243
243
{
244
244
// Read, mask/set, write
245
- byte value = virtualReadRegister (AS726x_LED_CONTROL);
245
+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL);
246
246
value |= (1 << 3 ); // Set the bit
247
247
virtualWriteRegister (AS726x_LED_CONTROL, value);
248
248
}
@@ -251,7 +251,7 @@ void AS726X::enableBulb()
251
251
void AS726X::disableBulb ()
252
252
{
253
253
// Read, mask/set, write
254
- byte value = virtualReadRegister (AS726x_LED_CONTROL);
254
+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL);
255
255
value &= ~(1 << 3 ); // Clear the bit
256
256
virtualWriteRegister (AS726x_LED_CONTROL, value);
257
257
}
@@ -261,20 +261,20 @@ void AS726X::disableBulb()
261
261
// Current 1: 25mA
262
262
// Current 2: 50mA
263
263
// Current 3: 100mA
264
- void AS726X::setBulbCurrent (byte current)
264
+ void AS726X::setBulbCurrent (uint8_t current)
265
265
{
266
266
if (current > 0b11 ) current = 0b11 ; // Limit to two bits
267
267
268
268
// Read, mask/set, write
269
- byte value = virtualReadRegister (AS726x_LED_CONTROL); // Read
269
+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL); // Read
270
270
value &= 0b11001111 ; // Clear ICL_DRV bits
271
271
value |= (current << 4 ); // Set ICL_DRV bits with user's choice
272
272
virtualWriteRegister (AS726x_LED_CONTROL, value); // Write
273
273
}
274
274
275
275
// Returns the temperature in C
276
276
// Pretty inaccurate: +/-8.5C
277
- byte AS726X::getTemperature ()
277
+ uint8_t AS726X::getTemperature ()
278
278
{
279
279
return (virtualReadRegister (AS726x_DEVICE_TEMP));
280
280
}
@@ -292,22 +292,22 @@ float AS726X::getTemperatureF()
292
292
void AS726X::softReset ()
293
293
{
294
294
// Read, mask/set, write
295
- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
295
+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
296
296
value |= (1 << 7 ); // Set RST bit
297
297
virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
298
298
}
299
299
300
300
// Read a virtual register from the AS726x
301
- byte AS726X::virtualReadRegister (byte virtualAddr)
301
+ uint8_t AS726X::virtualReadRegister (uint8_t virtualAddr)
302
302
{
303
- byte status;
303
+ uint8_t status;
304
304
305
305
// Do a prelim check of the read register
306
306
status = readRegister (AS72XX_SLAVE_STATUS_REG);
307
307
if ((status & AS72XX_SLAVE_RX_VALID) != 0 ) // There is data to be read
308
308
{
309
309
// Serial.println("Premptive read");
310
- byte incoming = readRegister (AS72XX_SLAVE_READ_REG); // Read the byte but do nothing with it
310
+ uint8_t incoming = readRegister (AS72XX_SLAVE_READ_REG); // Read the uint8_t but do nothing with it
311
311
}
312
312
313
313
// Wait for WRITE flag to clear
@@ -329,14 +329,14 @@ byte AS726X::virtualReadRegister(byte virtualAddr)
329
329
delay (POLLING_DELAY);
330
330
}
331
331
332
- byte incoming = readRegister (AS72XX_SLAVE_READ_REG);
332
+ uint8_t incoming = readRegister (AS72XX_SLAVE_READ_REG);
333
333
return (incoming);
334
334
}
335
335
336
336
// Write to a virtual register in the AS726x
337
- void AS726X::virtualWriteRegister (byte virtualAddr, byte dataToWrite)
337
+ void AS726X::virtualWriteRegister (uint8_t virtualAddr, uint8_t dataToWrite)
338
338
{
339
- byte status;
339
+ uint8_t status;
340
340
341
341
// Wait for WRITE register to be empty
342
342
while (1 )
@@ -362,7 +362,7 @@ void AS726X::virtualWriteRegister(byte virtualAddr, byte dataToWrite)
362
362
}
363
363
364
364
// Reads from a give location from the AS726x
365
- byte AS726X::readRegister (byte addr)
365
+ uint8_t AS726X::readRegister (uint8_t addr)
366
366
{
367
367
_i2cPort->beginTransmission (AS726X_ADDR);
368
368
_i2cPort->write (addr);
@@ -379,7 +379,7 @@ byte AS726X::readRegister(byte addr)
379
379
}
380
380
381
381
// Write a value to a spot in the AS726x
382
- void AS726X::writeRegister (byte addr, byte val)
382
+ void AS726X::writeRegister (uint8_t addr, uint8_t val)
383
383
{
384
384
_i2cPort->beginTransmission (AS726X_ADDR);
385
385
_i2cPort->write (addr);
0 commit comments