@@ -8,7 +8,7 @@ AS726X::AS726X()
88
99}
1010
11- bool AS726X::begin (TwoWire &wirePort, byte gain, byte measurementMode)
11+ bool AS726X::begin (TwoWire &wirePort, uint8_t gain, uint8_t measurementMode)
1212{
1313 _i2cPort = &wirePort;
1414 _sensorVersion = virtualReadRegister (AS726x_HW_VERSION);
@@ -47,12 +47,12 @@ uint8_t AS726X::getVersion()
4747// Mode 1: Continuous reading of GYOR (7262) / RTUX (7263)
4848// Mode 2: Continuous reading of all channels (power-on default)
4949// Mode 3: One-shot reading of all channels
50- void AS726X::setMeasurementMode (byte mode)
50+ void AS726X::setMeasurementMode (uint8_t mode)
5151{
5252 if (mode > 0b11 ) mode = 0b11 ;
5353
5454 // Read, mask/set, write
55- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
55+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
5656 value &= 0b11110011 ; // Clear BANK bits
5757 value |= (mode << 2 ); // Set BANK bits with user's choice
5858 virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
@@ -63,29 +63,29 @@ void AS726X::setMeasurementMode(byte mode)
6363// Gain 1: 3.7x
6464// Gain 2: 16x
6565// Gain 3: 64x
66- void AS726X::setGain (byte gain)
66+ void AS726X::setGain (uint8_t gain)
6767{
6868 if (gain > 0b11 ) gain = 0b11 ;
6969
7070 // Read, mask/set, write
71- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
71+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
7272 value &= 0b11001111 ; // Clear GAIN bits
7373 value |= (gain << 4 ); // Set GAIN bits with user's choice
7474 virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
7575}
7676
7777// 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.
7979// Time will be 2.8ms * [integration value]
80- void AS726X::setIntegrationTime (byte integrationValue)
80+ void AS726X::setIntegrationTime (uint8_t integrationValue)
8181{
8282 virtualWriteRegister (AS726x_INT_T, integrationValue); // Write
8383}
8484
8585void AS726X::enableInterrupt ()
8686{
8787 // Read, mask/set, write
88- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
88+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
8989 value |= 0b01000000 ; // Set INT bit
9090 virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
9191}
@@ -94,7 +94,7 @@ void AS726X::enableInterrupt()
9494void AS726X::disableInterrupt ()
9595{
9696 // Read, mask/set, write
97- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
97+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
9898 value &= 0b10111111 ; // Clear INT bit
9999 virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
100100}
@@ -144,10 +144,10 @@ int AS726X::getV() { return(getChannel(AS7263_V)); }
144144int AS726X::getW () { return (getChannel (AS7263_W)); }
145145
146146// A the 16-bit value stored in a given channel registerReturns
147- int AS726X::getChannel (byte channelRegister)
147+ int AS726X::getChannel (uint8_t channelRegister)
148148{
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
151151 return (colorData);
152152}
153153
@@ -166,10 +166,10 @@ float AS726X::getCalibratedU() { return(getCalibratedValue(AS7263_U_CAL)); }
166166float AS726X::getCalibratedV () { return (getCalibratedValue (AS7263_V_CAL)); }
167167float AS726X::getCalibratedW () { return (getCalibratedValue (AS7263_W_CAL)); }
168168
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)
171171{
172- byte b0, b1, b2, b3;
172+ uint8_t b0, b1, b2, b3;
173173 b0 = virtualReadRegister (calAddress + 0 );
174174 b1 = virtualReadRegister (calAddress + 1 );
175175 b2 = virtualReadRegister (calAddress + 2 );
@@ -185,26 +185,26 @@ float AS726X::getCalibratedValue(byte calAddress)
185185 return (convertBytesToFloat (calBytes));
186186}
187187
188- // Given 4 bytes returns the floating point value
188+ // Given 4 uint8_ts returns the floating point value
189189float AS726X::convertBytesToFloat (uint32_t myLong)
190190{
191191 float myFloat;
192- memcpy (&myFloat, &myLong, 4 ); // Copy bytes into a float
192+ memcpy (&myFloat, &myLong, 4 ); // Copy uint8_ts into a float
193193 return (myFloat);
194194}
195195
196196// Checks to see if DRDY flag is set in the control setup register
197- boolean AS726X::dataAvailable ()
197+ bool AS726X::dataAvailable ()
198198{
199- byte value = virtualReadRegister (AS726x_CONTROL_SETUP);
199+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP);
200200 return (value & (1 << 1 )); // Bit 1 is DATA_RDY
201201}
202202
203203// Clears the DRDY flag
204204// Normally this should clear when data registers are read
205- boolean AS726X::clearDataAvailable ()
205+ void AS726X::clearDataAvailable ()
206206{
207- byte value = virtualReadRegister (AS726x_CONTROL_SETUP);
207+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP);
208208 value &= ~(1 << 1 ); // Set the DATA_RDY bit
209209 virtualWriteRegister (AS726x_CONTROL_SETUP, value);
210210}
@@ -213,7 +213,7 @@ boolean AS726X::clearDataAvailable()
213213void AS726X::enableIndicator ()
214214{
215215 // Read, mask/set, write
216- byte value = virtualReadRegister (AS726x_LED_CONTROL);
216+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL);
217217 value |= (1 << 0 ); // Set the bit
218218 virtualWriteRegister (AS726x_LED_CONTROL, value);
219219}
@@ -222,17 +222,17 @@ void AS726X::enableIndicator()
222222void AS726X::disableIndicator ()
223223{
224224 // Read, mask/set, write
225- byte value = virtualReadRegister (AS726x_LED_CONTROL);
225+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL);
226226 value &= ~(1 << 0 ); // Clear the bit
227227 virtualWriteRegister (AS726x_LED_CONTROL, value);
228228}
229229
230230// 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)
232232{
233233 if (current > 0b11 ) current = 0b11 ;
234234 // Read, mask/set, write
235- byte value = virtualReadRegister (AS726x_LED_CONTROL); // Read
235+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL); // Read
236236 value &= 0b11111001 ; // Clear ICL_IND bits
237237 value |= (current << 1 ); // Set ICL_IND bits with user's choice
238238 virtualWriteRegister (AS726x_LED_CONTROL, value); // Write
@@ -242,7 +242,7 @@ void AS726X::setIndicatorCurrent(byte current)
242242void AS726X::enableBulb ()
243243{
244244 // Read, mask/set, write
245- byte value = virtualReadRegister (AS726x_LED_CONTROL);
245+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL);
246246 value |= (1 << 3 ); // Set the bit
247247 virtualWriteRegister (AS726x_LED_CONTROL, value);
248248}
@@ -251,7 +251,7 @@ void AS726X::enableBulb()
251251void AS726X::disableBulb ()
252252{
253253 // Read, mask/set, write
254- byte value = virtualReadRegister (AS726x_LED_CONTROL);
254+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL);
255255 value &= ~(1 << 3 ); // Clear the bit
256256 virtualWriteRegister (AS726x_LED_CONTROL, value);
257257}
@@ -261,20 +261,20 @@ void AS726X::disableBulb()
261261// Current 1: 25mA
262262// Current 2: 50mA
263263// Current 3: 100mA
264- void AS726X::setBulbCurrent (byte current)
264+ void AS726X::setBulbCurrent (uint8_t current)
265265{
266266 if (current > 0b11 ) current = 0b11 ; // Limit to two bits
267267
268268 // Read, mask/set, write
269- byte value = virtualReadRegister (AS726x_LED_CONTROL); // Read
269+ uint8_t value = virtualReadRegister (AS726x_LED_CONTROL); // Read
270270 value &= 0b11001111 ; // Clear ICL_DRV bits
271271 value |= (current << 4 ); // Set ICL_DRV bits with user's choice
272272 virtualWriteRegister (AS726x_LED_CONTROL, value); // Write
273273}
274274
275275// Returns the temperature in C
276276// Pretty inaccurate: +/-8.5C
277- byte AS726X::getTemperature ()
277+ uint8_t AS726X::getTemperature ()
278278{
279279 return (virtualReadRegister (AS726x_DEVICE_TEMP));
280280}
@@ -292,22 +292,22 @@ float AS726X::getTemperatureF()
292292void AS726X::softReset ()
293293{
294294 // Read, mask/set, write
295- byte value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
295+ uint8_t value = virtualReadRegister (AS726x_CONTROL_SETUP); // Read
296296 value |= (1 << 7 ); // Set RST bit
297297 virtualWriteRegister (AS726x_CONTROL_SETUP, value); // Write
298298}
299299
300300// Read a virtual register from the AS726x
301- byte AS726X::virtualReadRegister (byte virtualAddr)
301+ uint8_t AS726X::virtualReadRegister (uint8_t virtualAddr)
302302{
303- byte status;
303+ uint8_t status;
304304
305305 // Do a prelim check of the read register
306306 status = readRegister (AS72XX_SLAVE_STATUS_REG);
307307 if ((status & AS72XX_SLAVE_RX_VALID) != 0 ) // There is data to be read
308308 {
309309 // 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
311311 }
312312
313313 // Wait for WRITE flag to clear
@@ -329,14 +329,14 @@ byte AS726X::virtualReadRegister(byte virtualAddr)
329329 delay (POLLING_DELAY);
330330 }
331331
332- byte incoming = readRegister (AS72XX_SLAVE_READ_REG);
332+ uint8_t incoming = readRegister (AS72XX_SLAVE_READ_REG);
333333 return (incoming);
334334}
335335
336336// 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)
338338{
339- byte status;
339+ uint8_t status;
340340
341341 // Wait for WRITE register to be empty
342342 while (1 )
@@ -362,7 +362,7 @@ void AS726X::virtualWriteRegister(byte virtualAddr, byte dataToWrite)
362362}
363363
364364// Reads from a give location from the AS726x
365- byte AS726X::readRegister (byte addr)
365+ uint8_t AS726X::readRegister (uint8_t addr)
366366{
367367 _i2cPort->beginTransmission (AS726X_ADDR);
368368 _i2cPort->write (addr);
@@ -379,7 +379,7 @@ byte AS726X::readRegister(byte addr)
379379}
380380
381381// 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)
383383{
384384 _i2cPort->beginTransmission (AS726X_ADDR);
385385 _i2cPort->write (addr);
0 commit comments