Skip to content

Commit f40ce44

Browse files
committed
Cleanup with uint_t in place of int
1 parent 92c240b commit f40ce44

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

Grove_MultichannelGasSensor.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ MiCS6814Class::~MiCS6814Class() {
3434
* - RC 2 if the device attached at the slave address is not the device expected
3535
* - RC 4 if the device has a different version than v2 (only the v2 is supported)
3636
*/
37-
int MiCS6814Class::begin(uint8_t slaveAddress) {
38-
// Start the Wire prototol
37+
uint8_t MiCS6814Class::begin(uint8_t slaveAddress) {
38+
// Start the Wire protocol
3939
_slaveAddress = slaveAddress;
4040
_wire->begin();
4141

42-
// Check the init with the led (10 attempts)
42+
// Check the initialization with the led (10 attempts)
4343
bool isReady = false;
44-
for(int i = 0; i < 10 && !isReady; i++) {
44+
for(uint8_t i = 0; i < 10 && !isReady; i++) {
4545
isReady = ledOn() == 0;
4646
delay(50);
4747
ledOff();
@@ -98,9 +98,9 @@ void MiCS6814Class::sample() {
9898
heaterOn();
9999
delay(10);
100100

101-
int cycleCount = 1;
102-
int stableCycleCount = 0;
103-
int prevValueByChannel[3];
101+
uint8_t cycleCount = 1;
102+
uint8_t stableCycleCount = 0;
103+
uint8_t prevValueByChannel[3];
104104

105105
// First reading
106106
readRsValues();
@@ -139,9 +139,9 @@ void MiCS6814Class::warmup() {
139139
delay(10);
140140

141141
// For 30 minutes, let the heater on and blink the led
142-
for(int min = 29; min >= 0; min--) {
143-
for(int sec = 59; sec >= 0; sec--) {
144-
// Show the user that the warmup is in progress...
142+
for(uint8_t min = 29; min >= 0; min--) {
143+
for(uint8_t sec = 59; sec >= 0; sec--) {
144+
// Show the user that the warm up is in progress...
145145
if((min * 60 + sec) % 2 == 0) {
146146
ledOn();
147147
} else {
@@ -174,7 +174,7 @@ void MiCS6814Class::calibrate() {
174174
// Store the values as R0 on the EEPROM
175175
Wire.beginTransmission(_slaveAddress);
176176
Wire.write(MICS6814_CMD_SET_R0);
177-
for(int i = 0; i < 6; i++) {
177+
for(uint8_t i = 0; i < 6; i++) {
178178
Wire.write(tmp[i]);
179179
}
180180
Wire.endTransmission();
@@ -268,8 +268,8 @@ void MiCS6814Class::displayConfig() {
268268
* - 1 = version 1
269269
* - 2 = version 2
270270
*/
271-
int MiCS6814Class::getVersion() {
272-
unsigned int value = readOnCommand(MICS6814_CMD_READ_EEPROM, MICS6814_EEPROM_ADDR_SET);
271+
uint8_t MiCS6814Class::getVersion() {
272+
uint16_t value = readOnCommand(MICS6814_CMD_READ_EEPROM, MICS6814_EEPROM_ADDR_SET);
273273
if(value == 0x466) {
274274
return 2;
275275
} else if(value == 0xFFFF) {
@@ -283,39 +283,39 @@ int MiCS6814Class::getVersion() {
283283
* Switch the heater ON
284284
* Return codes, same as writeRegister()
285285
*/
286-
int MiCS6814Class::heaterOn() {
286+
uint8_t MiCS6814Class::heaterOn() {
287287
return command(MICS6814_CMD_CONTROL_PWR, 0x01);
288288
}
289289

290290
/**
291291
* Switch the heater OFF
292292
* Return codes, same as writeRegister()
293293
*/
294-
int MiCS6814Class::heaterOff() {
294+
uint8_t MiCS6814Class::heaterOff() {
295295
return command(MICS6814_CMD_CONTROL_PWR, 0x00);
296296
}
297297

298298
/**
299299
* Switch the LED ON
300300
* Return codes, same as writeRegister()
301301
*/
302-
int MiCS6814Class::ledOn() {
302+
uint8_t MiCS6814Class::ledOn() {
303303
return command(MICS6814_CMD_CONTROL_LED, 0x01);
304304
}
305305

306306
/**
307307
* Switch the LED OFF
308308
* Return codes, same as writeRegister()
309309
*/
310-
int MiCS6814Class::ledOff() {
310+
uint8_t MiCS6814Class::ledOff() {
311311
return command(MICS6814_CMD_CONTROL_LED, 0x00);
312312
}
313313

314314
/**
315315
* Read 2 bytes in return of a command sent (without parameter)
316-
* Return the unsigned int or 0 by default
316+
* Return the uint16_t value or 0 by default
317317
*/
318-
unsigned int MiCS6814Class::readOnCommand(uint8_t command) {
318+
uint16_t MiCS6814Class::readOnCommand(uint8_t command) {
319319
_wire->beginTransmission(_slaveAddress);
320320
_wire->write(command);
321321
_wire->endTransmission();
@@ -325,11 +325,11 @@ unsigned int MiCS6814Class::readOnCommand(uint8_t command) {
325325

326326
uint8_t raw[2];
327327

328-
for (size_t i = 0; i < 2; i++) {
328+
for (uint8_t i = 0; i < 2; i++) {
329329
raw[i] = _wire->read();
330330
}
331331

332-
unsigned int data = 0;
332+
uint16_t data = 0;
333333
data = raw[0];
334334
data <<= 8;
335335
data += raw[1];
@@ -338,9 +338,9 @@ unsigned int MiCS6814Class::readOnCommand(uint8_t command) {
338338

339339
/**
340340
* Read 2 bytes in return of a command sent with a parameter
341-
* Return the unsigned int or 0 by default
341+
* Return the uint16_t or 0 by default
342342
*/
343-
unsigned int MiCS6814Class::readOnCommand(uint8_t command, uint8_t parameter) {
343+
uint16_t MiCS6814Class::readOnCommand(uint8_t command, uint8_t parameter) {
344344
_wire->beginTransmission(_slaveAddress);
345345
_wire->write(command);
346346
_wire->write(parameter);
@@ -351,11 +351,11 @@ unsigned int MiCS6814Class::readOnCommand(uint8_t command, uint8_t parameter) {
351351

352352
uint8_t raw[2];
353353

354-
for (size_t i = 0; i < 2; i++) {
354+
for (uint8_t i = 0; i < 2; i++) {
355355
raw[i] = _wire->read();
356356
}
357357

358-
unsigned int data = 0;
358+
uint16_t data = 0;
359359
data = raw[0];
360360
data <<= 8;
361361
data += raw[1];
@@ -368,7 +368,7 @@ unsigned int MiCS6814Class::readOnCommand(uint8_t command, uint8_t parameter) {
368368
* - 0 OK
369369
* - 4 Problem during the transmission
370370
*/
371-
int MiCS6814Class::command(uint8_t command, uint8_t parameter) {
371+
uint8_t MiCS6814Class::command(uint8_t command, uint8_t parameter) {
372372
_wire->beginTransmission(_slaveAddress);
373373
_wire->write(command);
374374
_wire->write(parameter);

Grove_MultichannelGasSensor.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class MiCS6814Class {
4747

4848
// Start the driver for I2C address slaveAddress
4949
// By default: use the MICS6814_DEFAULT_I2C_ADDR (0x04)
50-
int begin(uint8_t slaveAddress = MICS6814_DEFAULT_I2C_ADDR);
50+
uint8_t begin(uint8_t slaveAddress = MICS6814_DEFAULT_I2C_ADDR);
5151
void end();
5252

5353
// Obtain the firmware version of the Grove Multichannel Gas Sensor
5454
// Return 0 if unknown, 1 = v1 and 2 = v2
55-
int getVersion();
55+
uint8_t getVersion();
5656

5757
// Output the configuration on Serial
5858
void displayConfig();
@@ -73,20 +73,20 @@ class MiCS6814Class {
7373

7474
private:
7575
// Internal helpers
76-
unsigned int readOnCommand(uint8_t command);
77-
unsigned int readOnCommand(uint8_t command, uint8_t parameter);
78-
int command(uint8_t command, uint8_t parameter);
76+
uint16_t readOnCommand(uint8_t command);
77+
uint16_t readOnCommand(uint8_t command, uint8_t parameter);
78+
uint8_t command(uint8_t command, uint8_t parameter);
7979
void readRsValues();
80-
int ledOn();
81-
int ledOff();
82-
int heaterOn();
83-
int heaterOff();
80+
uint8_t ledOn();
81+
uint8_t ledOff();
82+
uint8_t heaterOn();
83+
uint8_t heaterOff();
8484

8585
// Internal variables
8686
TwoWire* _wire;
8787
uint8_t _slaveAddress;
88-
int r0ByChannel[3] = {0, 0, 0};
89-
int rSByChannel[3] = {0, 0, 0};
88+
uint8_t r0ByChannel[3] = {0, 0, 0};
89+
uint8_t rSByChannel[3] = {0, 0, 0};
9090
};
9191

9292
extern MiCS6814Class MiCS6814;

0 commit comments

Comments
 (0)